o
    C©Ìh®  ã                   @  sb   d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	m
Z
 ddlmZ dZG dd	„ d	ƒZdS )
z3Tools for representing MongoDB internal Timestamps.é    )ÚannotationsN)ÚAnyÚUnion)Ú_getstate_slotsÚ_setstate_slots)Úutcl        c                   @  s    e Zd ZdZdZeZeZdZ	d(d
d„Z
ed)dd„ƒZed)dd„ƒZd*dd„Zd)dd„Zd*dd„Zd*dd„Zd*dd„Zd*dd„Zd*dd „Zd+d"d#„Zd,d%d&„Zd'S )-Ú	Timestampz.MongoDB internal timestamps used in the opLog.)Ú__timeÚ__incé   ÚtimeúUnion[datetime.datetime, int]ÚincÚintÚreturnÚNonec                 C  sÆ   t |tjƒr| ¡ }|dur|| }tt | ¡ ¡ƒ}t |tƒs)tdt|ƒ› �ƒ‚t |tƒs7tdt|ƒ› �ƒ‚d|  krDt	k sIt
dƒ‚ t
dƒ‚d|  krVt	k s[t
dƒ‚ t
dƒ‚|| _|| _dS )a“  Create a new :class:`Timestamp`.

        This class is only for use with the MongoDB opLog. If you need
        to store a regular timestamp, please use a
        :class:`~datetime.datetime`.

        Raises :class:`TypeError` if `time` is not an instance of
        :class: `int` or :class:`~datetime.datetime`, or `inc` is not
        an instance of :class:`int`. Raises :class:`ValueError` if
        `time` or `inc` is not in [0, 2**32).

        :param time: time in seconds since epoch UTC, or a naive UTC
            :class:`~datetime.datetime`, or an aware
            :class:`~datetime.datetime`
        :param inc: the incrementing counter
        Nz%time must be an instance of int, not z$inc must be an instance of int, not r   z$time must be contained in [0, 2**32)z#inc must be contained in [0, 2**32))Ú
isinstanceÚdatetimeÚ	utcoffsetr   ÚcalendarÚtimegmÚ	timetupleÚ	TypeErrorÚtypeÚ
UPPERBOUNDÚ
ValueErrorÚ_Timestamp__timeÚ_Timestamp__inc)Úselfr   r   Úoffset© r    ú]/var/www/html/Moveonwheels/move_on_wheels/venv/lib/python3.10/site-packages/bson/timestamp.pyÚ__init__&   s&   

ÿÿ
zTimestamp.__init__c                 C  ó   | j S )z0Get the time portion of this :class:`Timestamp`.)r   ©r   r    r    r!   r   H   ó   zTimestamp.timec                 C  r#   )z/Get the inc portion of this :class:`Timestamp`.)r   r$   r    r    r!   r   M   r%   zTimestamp.incÚotherr   Úboolc                 C  s&   t |tƒr| j|jko| j|jkS tS ©N)r   r   r   r   r   r   ÚNotImplemented©r   r&   r    r    r!   Ú__eq__R   s   
zTimestamp.__eq__c                 C  s   t | jƒt | jƒA S r(   )Úhashr   r   r$   r    r    r!   Ú__hash__X   s   zTimestamp.__hash__c                 C  s
   | |k S r(   r    r*   r    r    r!   Ú__ne__[   s   
zTimestamp.__ne__c                 C  s&   t |tƒr| j| jf|j|jfk S tS r(   ©r   r   r   r   r)   r*   r    r    r!   Ú__lt__^   ó   
zTimestamp.__lt__c                 C  s&   t |tƒr| j| jf|j|jfkS tS r(   r/   r*   r    r    r!   Ú__le__c   r1   zTimestamp.__le__c                 C  s&   t |tƒr| j| jf|j|jfkS tS r(   r/   r*   r    r    r!   Ú__gt__h   r1   zTimestamp.__gt__c                 C  s&   t |tƒr| j| jf|j|jfkS tS r(   r/   r*   r    r    r!   Ú__ge__m   r1   zTimestamp.__ge__Ústrc                 C  s   d| j › d| j› d�S )Nz
Timestamp(z, ú))r   r   r$   r    r    r!   Ú__repr__r   s   zTimestamp.__repr__údatetime.datetimec                 C  s   t j  | jt¡S )z®Return a :class:`~datetime.datetime` instance corresponding
        to the time portion of this :class:`Timestamp`.

        The returned datetime's timezone is UTC.
        )r   Úfromtimestampr   r   r$   r    r    r!   Úas_datetimeu   s   zTimestamp.as_datetimeN)r   r   r   r   r   r   )r   r   )r&   r   r   r'   )r   r5   )r   r8   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   Ú__getstate__r   Ú__setstate__Ú_type_markerr"   Úpropertyr   r   r+   r-   r.   r0   r2   r3   r4   r7   r:   r    r    r    r!   r      s(    
"







r   )r>   Ú
__future__r   r   r   Útypingr   r   Úbson._helpersr   r   Úbson.tz_utilr   r   r   r    r    r    r!   Ú<module>   s   