
    FCf                    h    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	      Zy)
z3Tools for representing MongoDB internal Timestamps.    )annotationsN)AnyUnion)_getstate_slots_setstate_slots)utcl        c                      e Zd ZdZdZeZeZdZ	ddZ
edd       Zedd       ZddZddZdd	Zdd
ZddZddZddZddZddZy)	Timestampz.MongoDB internal timestamps used in the opLog.)__time__inc   c                   t        |t        j                        rC|j                         }|||z
  }t        t	        j
                  |j                                     }t        |t              st        d      t        |t              st        d      d|cxk  rt        k  st        d       t        d      d|cxk  rt        k  st        d       t        d      || _
        || _        y)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 intzinc must be an instance of intr   z$time must be contained in [0, 2**32)z#inc must be contained in [0, 2**32))
isinstancedatetime	utcoffsetintcalendartimegm	timetuple	TypeError
UPPERBOUND
ValueError_Timestamp__time_Timestamp__inc)selftimeincoffsets       N/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/bson/timestamp.py__init__zTimestamp.__init__&   s    " dH--.^^%F!f}xt~~'789D$$=>>#s#<==D%:%CDD &CDDC$*$BCC %BCC
    c                    | j                   S )z0Get the time portion of this :class:`Timestamp`.)r   r   s    r   r   zTimestamp.timeH   s     {{r!   c                    | j                   S )z/Get the inc portion of this :class:`Timestamp`.)r   r#   s    r   r   zTimestamp.incM   s     zzr!   c                    t        |t              r4| j                  |j                  k(  xr | j                  |j
                  k(  S t        S N)r   r
   r   r   r   r   NotImplementedr   others     r   __eq__zTimestamp.__eq__R   s7    eY';;%**,Huyy1HH!!r!   c                X    t        | j                        t        | j                        z  S r&   )hashr   r   r#   s    r   __hash__zTimestamp.__hash__X   s    DIIdhh//r!   c                    | |k(   S r&    r(   s     r   __ne__zTimestamp.__ne__[   s    5=  r!   c                    t        |t              r1| j                  | j                  f|j                  |j                  fk  S t        S r&   r   r
   r   r   r'   r(   s     r   __lt__zTimestamp.__lt__^   7    eY'IItxx(EJJ		+BBBr!   c                    t        |t              r1| j                  | j                  f|j                  |j                  fk  S t        S r&   r2   r(   s     r   __le__zTimestamp.__le__c   7    eY'IItxx(UZZ,CCCr!   c                    t        |t              r1| j                  | j                  f|j                  |j                  fkD  S t        S r&   r2   r(   s     r   __gt__zTimestamp.__gt__h   r4   r!   c                    t        |t              r1| j                  | j                  f|j                  |j                  fk\  S t        S r&   r2   r(   s     r   __ge__zTimestamp.__ge__m   r7   r!   c                <    d| j                    d| j                   dS )Nz
Timestamp(z, ))r   r   r#   s    r   __repr__zTimestamp.__repr__r   s    DKK=4::,a88r!   c                ^    t         j                   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#   s    r   as_datetimezTimestamp.as_datetimeu   s!       ..t{{C@@r!   N)r   zUnion[datetime.datetime, int]r   r   returnNone)rB   r   )r)   r   rB   bool)rB   str)rB   zdatetime.datetime)__name__
__module____qualname____doc__	__slots__r   __getstate__r   __setstate___type_markerr    propertyr   r   r*   r-   r0   r3   r6   r9   r;   r>   rA   r/   r!   r   r
   r
      su    8#I"L"LL D    "0!



9Ar!   r
   )rI   
__future__r   r   r   typingr   r   bson._helpersr   r   bson.tz_utilr   r   r
   r/   r!   r   <module>rS      s/    : "    : 
_A _Ar!   