
    Ii                    h    S r SSKJr  SSKrSSKrSSKJrJr  SSKJ	r	J
r
  SSKJr  Sr " S S	5      rg)
z3Tools for representing MongoDB internal Timestamps.    )annotationsN)AnyUnion)_getstate_slots_setstate_slots)utcl        c                      \ rS rSrSrSr\r\r	Sr
SS jr\SS j5       r\SS j5       rSS jrSS	 jrSS
 jrSS jrSS jrSS jrSS jrSS jrSS jrSrg)	Timestamp   z.MongoDB internal timestamps used in the opLog.)__time__inc   c                   [        U[        R                  5      (       aD  UR                  5       nUb  X-
  n[        [        R
                  " UR                  5       5      5      n[        U[        5      (       d  [        S5      e[        U[        5      (       d  [        S5      eSUs=::  a
  [        :  d  O  [        S5      eSUs=::  a
  [        :  d  O  [        S5      eXl
        X l        g)a3  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       4/venv/lib/python3.13/site-packages/bson/timestamp.py__init__Timestamp.__init__&   s    " dH--..^^%F!}xt~~'789D$$$=>>#s##<==D%:%CDDC$*$BCC
    c                    U R                   $ )z0Get the time portion of this :class:`Timestamp`.)r   r   s    r    r   Timestamp.timeH   s     {{r#   c                    U R                   $ )z/Get the inc portion of this :class:`Timestamp`.)r   r%   s    r    r   Timestamp.incM   s     zzr#   c                    [        U[        5      (       a9  U R                  UR                  :H  =(       a    U R                  UR
                  :H  $ [        $ N)r   r
   r   r   r   r   NotImplementedr   others     r    __eq__Timestamp.__eq__R   s:    eY'';;%**,Huyy1HH!!r#   c                X    [        U R                  5      [        U R                  5      -  $ r*   )hashr   r   r%   s    r    __hash__Timestamp.__hash__X   s    DIIdhh//r#   c                    X:X  + $ r*    r,   s     r    __ne__Timestamp.__ne__[   s      r#   c                    [        U[        5      (       a1  U R                  U R                  4UR                  UR                  4:  $ [        $ r*   r   r
   r   r   r+   r,   s     r    __lt__Timestamp.__lt__^   :    eY''IItxx(EJJ		+BBBr#   c                    [        U[        5      (       a1  U R                  U R                  4UR                  UR                  4:*  $ [        $ r*   r9   r,   s     r    __le__Timestamp.__le__c   :    eY''IItxx(UZZ,CCCr#   c                    [        U[        5      (       a1  U R                  U R                  4UR                  UR                  4:  $ [        $ r*   r9   r,   s     r    __gt__Timestamp.__gt__h   r<   r#   c                    [        U[        5      (       a1  U R                  U R                  4UR                  UR                  4:  $ [        $ r*   r9   r,   s     r    __ge__Timestamp.__ge__m   r@   r#   c                <    SU R                    SU R                   S3$ )Nz
Timestamp(z, ))r   r   r%   s    r    __repr__Timestamp.__repr__r   s    DKK=4::,a88r#   c                ^    [         R                   R                  U R                  [        5      $ )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_datetimeTimestamp.as_datetimeu   s!       ..t{{C@@r#   )r   r   N)r   zUnion[datetime.datetime, int]r   r   returnNone)rO   r   )r-   r   rO   bool)rO   str)rO   zdatetime.datetime)__name__
__module____qualname____firstlineno____doc__	__slots__r   __getstate__r   __setstate___type_markerr!   propertyr   r   r.   r2   r6   r:   r>   rB   rE   rI   rM   __static_attributes__r5   r#   r    r
   r
      su    8#I"L"LL D    "0!



9Ar#   r
   )rW   
__future__r   r   r   typingr   r   bson._helpersr   r   bson.tz_utilr   r   r
   r5   r#   r    <module>rb      s/    : "    : 
_A _Ar#   