
    h\                     J    d Z ddlZddlZddlmZ ddlmZ dZ G d de      Z	y)z4Tools for representing MongoDB internal Timestamps.
    N)integer_types)utcl        c                   p    e Zd ZdZdZd Zed        Zed        Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zy)	Timestampz3MongoDB internal timestamps used in the opLog.
       c                    t        |t        j                        rO|j                         ||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).

        :Parameters:
          - `time`: time in seconds since epoch UTC, or a naive UTC
            :class:`~datetime.datetime`, or an aware
            :class:`~datetime.datetime`
          - `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	timetupler   	TypeError
UPPERBOUND
ValueError_Timestamp__time_Timestamp__inc)selftimeincs      Q/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/bson/timestamp.py__init__zTimestamp.__init__!   s    $ dH--.~~+dnn..xt~~'789D$.=>>#}-<==D%:%CDD &CDDC$*$BCC %BCC
    c                     | j                   S )z9Get the time portion of this :class:`Timestamp`.
        )r   r   s    r   r   zTimestamp.timeC   s     {{r   c                     | j                   S )z8Get the inc portion of this :class:`Timestamp`.
        )r   r   s    r   r   zTimestamp.incI   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__O   s7    eY'KK5::-I$**		2IJ!!r   c                 X    t        | j                        t        | j                        z  S r   )hashr   r   r   s    r   __hash__zTimestamp.__hash__U   s    DIIdhh//r   c                     | |k(   S r    r!   s     r   __ne__zTimestamp.__ne__X   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   r+   r!   s     r   __le__zTimestamp.__le__`   7    eY'IItxx(UZZ,CCCr   c                     t        |t              r1| j                  | j                  f|j                  |j                  fkD  S t        S r   r+   r!   s     r   __gt__zTimestamp.__gt__e   r-   r   c                     t        |t              r1| j                  | j                  f|j                  |j                  fk\  S t        S r   r+   r!   s     r   __ge__zTimestamp.__ge__j   r0   r   c                 <    d| j                   d| j                  dS )Nz
Timestamp(z, ))r   r   r   s    r   __repr__zTimestamp.__repr__o   s    &*kk4::>>r   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_datetimer   s!       ..t{{C@@r   N)__name__
__module____qualname____doc___type_markerr   propertyr   r   r#   r&   r)   r,   r/   r2   r4   r7   r:   r(   r   r   r   r      sj     L D  
  
"0!



?Ar   r   )
r>   r   r
   bson.py3compatr   bson.tz_utilr   r   objectr   r(   r   r   <module>rD      s-      ( 
]A ]Ar   