%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/names/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/names/__pycache__/_rfc1982.cpython-312.pyc

�

Ϫ�f�#��X�dZddlZddlmZmZddlmZddlmZdZGd�de�Z	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<https://tools.ietf.org/html/rfc4034#section-3.2>}
�N)�datetime�	timedelta)�nativeString)�
FancyStrMixinz%Y%m%d%H%M%Sc���eZdZdZdZddedefd�Zdeddfd�Zde	fd	�Z
d
�Zdedefd�Z
dedefd�Zdedefd
�Zdedefd�Zdedefd�Zdeddfd�Zd�Zed��Zd�Zy)�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.
    ))�_number�number�%d)�_serialBits�
serialBitsrr
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�_maxAdd�intr	)�selfr
r
s   �8/usr/lib/python3/dist-packages/twisted/names/_rfc1982.py�__init__zSerialNumber.__init__8sP��&����*�}����J��N�3����Z�!�^�,�q�0�����K�$�,�,�6����other�returnc��t|t�std|�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���%��.��8����e�Y�O�P�P����u�0�0�0��59�5�B��
�
�rc�4�td|jfz�S)zs
        Return a string representation of this L{SerialNumber} instance.

        @rtype: L{nativeString}
        r)rr	�rs r�__str__zSerialNumber.__str__`s���D�D�L�L�?�2�3�3rc��|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.
        )rr�NotImplementedr	rs  r�__eq__zSerialNumber.__eq__osC��	"��&�&�u�-�E��}�}����,�,���	"�!�!�	"�s�,�>�>c�X�	|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�
�L�L�5�=�=�(�
@�������-����?�
�
�L�L�5�=�=�(�
@�����
�
�-����?�	
���	"�!�!�	"���B�B)�(B)c�X�	|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))rr�other_sns   r�__gt__zSerialNumber.__gt__�s���	"��)�)�%�0�H�
�L�L�8�+�+�+�
C��!�!�D�L�L�0�D�N�N�B�
�
�L�L�8�+�+�+�
C����� 0� 0�0�D�N�N�B�	
���	"�!�!�	"�r+c�h�	|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�-�E��u�}�,��u��,���	"�!�!�	"����1�1c�h�	|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__�r2r3c�B�	|j|�}|j|jkr;t|j|jz|jz|j��Std|j�d|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��=�=�D�L�L�(������
�
�-����=��+�+��
�
"��M�M��L�L���
���	"�!�!�	"�s�B�B�Bc�,�t|j�S)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���D�L�L�!�!rc��tj|t�}tj|j��}||d��S)a�
        Create an L{SerialNumber} instance from a date string in format
        'YYYYMMDDHHMMSS' described in U{RFC4034
        3.2<https://tools.ietf.org/html/rfc4034#section-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)r�strptime�RFC4034_TIME_FORMAT�calendar�timegm�utctimetuple)�cls�
utcDateString�
parsedDate�secondsSinceEpochs    r�fromRFC4034DateStringz"SerialNumber.fromRFC4034DateString�s=��$�&�&�}�6I�J�
�$�O�O�J�,C�,C�,E�F���$��4�4rc��tddd�t|j��z}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<https://tools.ietf.org/html/rfc4034#section-3.2>}.

        @return: The date string.
        i�r)�seconds)rrr	r�strftimer@)r�ds  r�toRFC4034DateStringz SerialNumber.toRFC4034DateString�s5��
�T�1�a� �9�T�\�\�#B�B���A�J�J�':�;�<�<rN)r>)�__name__�
__module__�__qualname__�__doc__�showAttributesrr�objectr�strr"r$�boolr'r*r.r1r5r9r<�classmethodrHrM�rrrrs����.�N�
7�s�7��7�&�6��n��*4��4��-�F�-�t�-�
�F�
�t�
� 
�F�
�t�
� 	-�F�	-�t�	-�	-�F�	-�t�	-�'�V�'��'�R"��5��5�*=rr)rQrArr�twisted.python.compatr�twisted.python.utilrr@r�__all__rWrr�<module>r[s7��

��(�.�-�$��g=�=�g=�T�
�r

Zerion Mini Shell 1.0