o
    ?8¾\\  ã                   @   sD   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„ deƒZ	dS )z4Tools for representing MongoDB internal Timestamps.
é    N)Úinteger_types)Úutcl        c                   @   s|   e Zd Zd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dS )Ú	Timestampz3MongoDB internal timestamps used in the opLog.
    é   c                 C   s²   t |tjƒr| ¡ dur|| ¡  }tt | ¡ ¡ƒ}t |tƒs$tdƒ‚t |tƒs-tdƒ‚d|  kr:t	k s?t
dƒ‚ t
dƒ‚d|  krLt	k sQt
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).

        :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Úinc© r   ú@/var/www/html/env/lib/python3.10/site-packages/bson/timestamp.pyÚ__init__!   s$   

ÿÿ
zTimestamp.__init__c                 C   ó   | j S )z9Get the time portion of this :class:`Timestamp`.
        )r   ©r   r   r   r   r   C   ó   zTimestamp.timec                 C   r   )z8Get the inc portion of this :class:`Timestamp`.
        )r   r   r   r   r   r   I   r   zTimestamp.incc                 C   s&   t |tƒr| j|jko| j|jkS tS ©N)r   r   r   r   r   r   ÚNotImplemented©r   Úotherr   r   r   Ú__eq__O   s   
zTimestamp.__eq__c                 C   s   t | jƒt | jƒA S r   )Úhashr   r   r   r   r   r   Ú__hash__U   s   zTimestamp.__hash__c                 C   s
   | |k S r   r   r   r   r   r   Ú__ne__X   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__`   r%   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__e   r%   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__j   r%   zTimestamp.__ge__c                 C   s   d| j | jf S )NzTimestamp(%s, %s))r   r   r   r   r   r   Ú__repr__o   s   zTimestamp.__repr__c                 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_datetimer   s   zTimestamp.as_datetimeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú_type_markerr   Úpropertyr   r   r   r!   r"   r$   r&   r'   r(   r)   r+   r   r   r   r   r      s"    "

r   )
r/   r
   r   Úbson.py3compatr   Úbson.tz_utilr   r   Úobjectr   r   r   r   r   Ú<module>   s   