File: //usr/lib/python3/dist-packages/twisted/names/__pycache__/_rfc1982.cpython-38.pyc
U
W[�# � @ sd d Z ddlmZmZ ddlZddlmZmZ ddlmZ ddl m
Z
dZG dd � d e
e�Z
d gZdS )
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>}
� )�division�absolute_importN)�datetime� timedelta)�nativeString)�
FancyStrMixinz%Y%m%d%H%M%Sc @ s� e Zd ZdZdZd!dd�Zdd� Zdd � Zd
d� Zdd
� Z dd� Z
dd� Zdd� Zdd� Z
dd� Zdd� Zdd� Zedd� �Zdd� Zd S )"�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�
serialBitsr � c C sD || _ d| | _d|d | _d|d d | _t|�| j | _dS )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
� r �8/usr/lib/python3/dist-packages/twisted/names/_rfc1982.py�__init__; s
zSerialNumber.__init__c C s: t |t�std| |f ��| j|jkr6td| |f ��|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.
@raises: L{TypeError} if C{other} is not compatible.
z#cannot compare or combine %r and %rzUcannot compare or combine SerialNumber instances with different serialBits. %r and %r)�
isinstancer � TypeErrorr �r �otherr r r �
_convertOtherO s
���zSerialNumber._convertOtherc C s t d| jf �S )zs
Return a string representation of this L{SerialNumber} instance.
@rtype: L{nativeString}
r )r r �r r r r �__str__e s zSerialNumber.__str__c C s | j S )ze
@return: The integer value of this L{SerialNumber} instance.
@rtype: L{int}
)r r r r r �__int__n s zSerialNumber.__int__c C s | � |�}|j| jkS �z}
Allow rich equality comparison with another L{SerialNumber} instance.
@type other: L{SerialNumber}
)r r r r r r �__eq__v s
zSerialNumber.__eq__c C s | � |� S r! )r"