o
    '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    J/var/www/html/olx_land/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 )zReturn 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   