Ϫf#XdZddlZddlmZmZddlmZddlmZdZGddeZ dgZ y) a Utilities for handling RFC1982 Serial Number Arithmetic. @see: U{http://tools.ietf.org/html/rfc1982} @var RFC4034_TIME_FORMAT: RRSIG Time field presentation format. The Signature Expiration Time and Inception Time field values MUST be represented either as an unsigned decimal integer indicating seconds since 1 January 1970 00:00:00 UTC, or in the form YYYYMMDDHHmmSS in UTC. See U{RRSIG Presentation Format} N)datetime timedelta) nativeString) FancyStrMixinz %Y%m%d%H%M%SceZdZdZdZddedefdZdeddfdZde fd Z d Z dede fd Z dede fd Zdede fd Zdede fdZdede fdZdeddfdZdZedZdZy) SerialNumbera An RFC1982 Serial Number. This class implements RFC1982 DNS Serial Number Arithmetic. SNA is used in DNS and specifically in DNSSEC as defined in RFC4034 in the DNSSEC Signature Expiration and Inception Fields. @see: U{https://tools.ietf.org/html/rfc1982} @see: U{https://tools.ietf.org/html/rfc4034} @ivar _serialBits: See C{serialBits} of L{__init__}. @ivar _number: See C{number} of L{__init__}. @ivar _modulo: The value at which wrapping will occur. @ivar _halfRing: Half C{_modulo}. If another L{SerialNumber} value is larger than this, it would lead to a wrapped value which is larger than the first and comparisons are therefore ambiguous. @ivar _maxAdd: Half C{_modulo} plus 1. If another L{SerialNumber} value is larger than this, it would lead to a wrapped value which is larger than the first. Comparisons with the original value would therefore be ambiguous. ))_numbernumber%d) _serialBits serialBitsr r r c||_d|z|_d|dz z|_d|dz zdz |_t ||jz|_y)a Construct an L{SerialNumber} instance. @param number: An L{int} which will be stored as the modulo C{number % 2 ^ serialBits} @type number: L{int} @param serialBits: The size of the serial number space. The power of two which results in one larger than the largest integer corresponding to a serial number value. @type serialBits: L{int} N)r _modulo _halfRing_maxAddintr )selfr r s 8/usr/lib/python3/dist-packages/twisted/names/_rfc1982.py__init__zSerialNumber.__init__8sP&*} JN3Z!^,q0 K$,,6 otherreturnct|tstd|d||j|jk7rtd|d||S)a} Check that a foreign object is suitable for use in the comparison or arithmetic magic methods of this L{SerialNumber} instance. Raise L{TypeError} if not. @param other: The foreign L{object} to be checked. @return: C{other} after compatibility checks and possible coercion. @raise TypeError: If C{other} is not compatible. zcannot compare or combine z and zLcannot compare or combine SerialNumber instances with different serialBits. ) isinstancer TypeErrorr rrs r _convertOtherzSerialNumber._convertOtherKsZ%.8eYOP P   u00 0595B   rc4td|jfzS)zs Return a string representation of this L{SerialNumber} instance. @rtype: L{nativeString} r )rr rs r__str__zSerialNumber.__str__`s DDLL?233rc|jS)ze @return: The integer value of this L{SerialNumber} instance. @rtype: L{int} )r r!s r__int__zSerialNumber.__int__hs ||rc |j|}|j|jk(S#t$r tcYSwxYw)zW Allow rich equality comparison with another L{SerialNumber} instance. )rrNotImplementedr rs r__eq__zSerialNumber.__eq__osC "&&u-E}} ,, "! ! "s ,>>cX |j|}|j|jkxr&|j|jz |jkxsA|j|jkDxr&|j|jz |jkDS#t$r tcYSwxYw)zV Allow I{less than} comparison with another L{SerialNumber} instance. rrr&r rrs r__lt__zSerialNumber.__lt__ys "&&u-E LL5== ( @-?  LL5== ( @ -?   "! ! "BB)(B)cX |j|}|j|jkxr&|j|jz |jkDxsA|j|jkDxr&|j|jz |jkS#t$r tcYSwxYw)zY Allow I{greater than} comparison with another L{SerialNumber} instance. r))rrother_sns r__gt__zSerialNumber.__gt__s "))%0H LL8++ + C!!DLL0DNNB  LL8++ + C 0 00DNNB   "! ! "r+ch |j|}||k(xs||kS#t$r tcYSwxYw)zg Allow I{less than or equal} comparison with another L{SerialNumber} instance. rrr&rs r__le__zSerialNumber.__le__C  "&&u-Eu},u , "! ! " 11ch |j|}||k(xs||kDS#t$r tcYSwxYw)zj Allow I{greater than or equal} comparison with another L{SerialNumber} instance. r0rs r__ge__zSerialNumber.__ge__r2r3cB |j|}|j|jkr;t |j|jz|j z|jStd|jd|j#t$r tcYSwxYw)ab Allow I{addition} with another L{SerialNumber} instance. Serial numbers may be incremented by the addition of a positive integer n, where n is taken from the range of integers [0 .. (2^(SERIAL_BITS - 1) - 1)]. For a sequence number s, the result of such an addition, s', is defined as s' = (s + n) modulo (2 ^ SERIAL_BITS) where the addition and modulus operations here act upon values that are non-negative values of unbounded size in the usual ways of integer arithmetic. Addition of a value outside the range [0 .. (2^(SERIAL_BITS - 1) - 1)] is undefined. @see: U{http://tools.ietf.org/html/rfc1982#section-3.1} @raise ArithmeticError: If C{other} is more than C{_maxAdd} ie more than half the maximum value of this serial number. r zvalue z outside the range 0 .. ) rrr&r rrrr ArithmeticErrorrs r__add__zSerialNumber.__add__s. "&&u-E ==DLL ( -=++  "MMLL  "! ! "sB BBc,t|jS)zo Allow L{SerialNumber} instances to be hashed for use as L{dict} keys. @rtype: L{int} )hashr r!s r__hash__zSerialNumber.__hash__s DLL!!rctj|t}tj|j }||dS)a Create an L{SerialNumber} instance from a date string in format 'YYYYMMDDHHMMSS' described in U{RFC4034 3.2}. The L{SerialNumber} instance stores the date as a 32bit UNIX timestamp. @see: U{https://tools.ietf.org/html/rfc4034#section-3.1.5} @param utcDateString: A UTC date/time string of format I{YYMMDDhhmmss} which will be converted to seconds since the UNIX epoch. @type utcDateString: L{unicode} @return: An L{SerialNumber} instance containing the supplied date as a 32bit UNIX timestamp. r7)rstrptimeRFC4034_TIME_FORMATcalendartimegm utctimetuple)cls utcDateString parsedDatesecondsSinceEpochs rfromRFC4034DateStringz"SerialNumber.fromRFC4034DateStrings=$&&}6IJ $OOJ,C,C,EF$44rctdddt|jz}t|j t S)a  Calculate a date by treating the current L{SerialNumber} value as a UNIX timestamp and return a date string in the format described in U{RFC4034 3.2}. @return: The date string. ir)seconds)rrr rstrftimer@)rds rtoRFC4034DateStringz SerialNumber.toRFC4034DateStrings5 T1a 9T\\#B BAJJ':;<)__name__ __module__ __qualname____doc__showAttributesrrobjectrstrr"r$boolr'r*r.r1r5r9r< classmethodrHrMrrrrs.N 7s77&6n*44-F-t- F t  F t -F -t - -F -t -'V''R"55* =rr) rQrArrtwisted.python.compatrtwisted.python.utilrr@r__all__rWrrr[s7 (.-$g==g=T  r