o Sb@sXdZddlZddlZddlmZmZddlmZmZddl m Z dZ Gddde Z dS) z4Tools for representing MongoDB internal Timestamps. N)AnyUnion)_getstate_slots_setstate_slots)utclc@seZdZdZdZeZeZdZ de e j e fde ddfdd Z ede fd d Zede fd d ZdedefddZde fddZdedefddZdedefddZdedefddZdedefddZdedefddZddZde j fdd ZdS)! Timestampz.MongoDB internal timestamps used in the opLog.)Z__timeZ__inctimeincreturnNcCst|tjr|}|dur||}tt|}t|ts$tdt|ts-tdd|kr:tks?t dt dd|krLtksQt dt d||_ ||_ dS)aCreate 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 Nztime must be an instance of intzinc must be an instance of intrz$time must be contained in [0, 2**32)z#inc must be contained in [0, 2**32)) isinstancedatetime utcoffsetintcalendartimegm timetuple TypeError UPPERBOUND ValueError_Timestamp__time_Timestamp__inc)selfr r offsetr5/tmp/pip-target-onvjaxws/lib/python/bson/timestamp.py__init__&s&    zTimestamp.__init__cC|jS)z0Get the time portion of this :class:`Timestamp`.)rrrrrr IzTimestamp.timecCr)z/Get the inc portion of this :class:`Timestamp`.)rrrrrr Nrz Timestamp.incothercCs&t|tr|j|jko|j|jkStSN)r rrr rr NotImplementedrr rrr__eq__Ss zTimestamp.__eq__cCst|jt|jASr!)hashr r rrrr__hash__YszTimestamp.__hash__cCs ||k Sr!rr#rrr__ne__\s zTimestamp.__ne__cCs&t|tr|j|jf|j|jfkStSr!r rr r r"r#rrr__lt___ zTimestamp.__lt__cCs&t|tr|j|jf|j|jfkStSr!r(r#rrr__le__dr*zTimestamp.__le__cCs&t|tr|j|jf|j|jfkStSr!r(r#rrr__gt__ir*zTimestamp.__gt__cCs&t|tr|j|jf|j|jfkStSr!r(r#rrr__ge__nr*zTimestamp.__ge__cCsd|j|jfS)NzTimestamp(%s, %s))rrrrrr__repr__sszTimestamp.__repr__cCstj|jtS)zReturn a :class:`~datetime.datetime` instance corresponding to the time portion of this :class:`Timestamp`. The returned datetime's timezone is UTC. )r fromtimestamprrrrrr as_datetimevszTimestamp.as_datetime)__name__ __module__ __qualname____doc__ __slots__r __getstate__r __setstate__Z _type_markerrr rrpropertyr r rboolr$r&r'r)r+r,r-r.r0rrrrrs( #r)r4rr typingrrZ bson._helpersrrZ bson.tz_utilrrobjectrrrrrs