3 ig@sddlmZddlZddlZddlZejddkZerDeefZ dZ n6eZ y ej j Z Wn$e k rxej ejdZ YnXGdddeddZGdddeZdS) ) namedtupleNcs eZdZdZfddZZS)ExtTypez'ExtType represents ext type in msgpack.csXt|tstdt|ts$tdd|ko6dknsDtdtt|j|||S)Nzcode must be intzdata must be bytesrzcode must be 0~127) isinstanceint TypeErrorbytes ValueErrorsuperr__new__)clscodedata) __class__6/tmp/pip-build-88gy_88q/pip/pip/_vendor/msgpack/ext.pyr s  zExtType.__new__)__name__ __module__ __qualname____doc__r __classcell__rr)rrrsrz code datac@seZdZdZddgZd ddZddZd d Zd d Zd dZ e ddZ ddZ e ddZ ddZe ddZddZddZe ddZdS)! TimestampaRTimestamp represents the Timestamp extension type in msgpack. When built with Cython, msgpack uses C methods to pack and unpack `Timestamp`. When using pure-Python msgpack, :func:`to_bytes` and :func:`from_bytes` are used to pack and unpack `Timestamp`. This class is immutable: Do not override seconds and nanoseconds. seconds nanosecondsrcCsTt|tstdt|ts$tdd|ko6dknsDtd||_||_dS) aInitialize a Timestamp object. :param int seconds: Number of seconds since the UNIX epoch (00:00:00 UTC Jan 1 1970, minus leap seconds). May be negative. :param int nanoseconds: Number of nanoseconds to add to `seconds` to get fractional time. Maximum is 999_999_999. Default is 0. Note: Negative times (before the UNIX epoch) are represented as negative seconds + positive ns. zseconds must be an intergerznanoseconds must be an integerr z?nanoseconds must be a non-negative integer less than 999999999.Niʚ;)r int_typesrr rr)selfrrrrr__init__-s  zTimestamp.__init__cCsdj|j|jS)z#String representation of Timestamp.z'Timestamp(seconds={0}, nanoseconds={1}))formatrr)rrrr__repr__EszTimestamp.__repr__cCs*t||jkr&|j|jko$|j|jkSdS)z0Check for equality with another Timestamp objectF)typerrr)rotherrrr__eq__KszTimestamp.__eq__cCs |j| S)z(not-equals method (see :func:`__eq__()`))r$)rr#rrr__ne__SszTimestamp.__ne__cCst|j|jfS)N)hashrr)rrrr__hash__WszTimestamp.__hash__cCst|dkr"tjd|d}d}nTt|dkrPtjd|d}|d@}|d?}n&t|dkrntjd |\}}ntd t||S) aUnpack bytes into a `Timestamp` object. Used for pure-Python msgpack unpacking. :param b: Payload from msgpack ext message with code -1 :type b: bytes :returns: Timestamp object unpacked from msgpack ext payload :rtype: Timestamp z!Lrz!Ql" z!IqzFTimestamp type can only be created from 32, 64, or 96-bit byte objects)lenstructunpackr r)brrdata64rrr from_bytesZs    zTimestamp.from_bytescCs\|jd?dkrF|jd>|jB}|d@dkr8tjd|}qXtjd|}ntjd|j|j}|S)zPack this Timestamp object into bytes. Used for pure-Python msgpack packing. :returns data: Payload for EXT message with code -1 (timestamp type) :rtype: bytes r*rlz!Lz!Qz!Iq)rrr-pack)rr0rrrrto_bytesus zTimestamp.to_bytescCs&t|d}t|dd}t||S)zCreate a Timestamp from posix timestamp in seconds. :param unix_float: Posix timestamp in seconds. :type unix_float: int or float. rriʚ;)rr)Zunix_secrrrrr from_unixs zTimestamp.from_unixcCs|j|jdS)znGet the timestamp as a floating-point value. :returns: posix timestamp :rtype: float geA)rr)rrrrto_unixszTimestamp.to_unixcCstt|dS)zCreate a Timestamp from posix timestamp in nanoseconds. :param int unix_ns: Posix timestamp in nanoseconds. :rtype: Timestamp rriʚ;)rdivmod)Zunix_nsrrrfrom_unix_nanoszTimestamp.from_unix_nanocCs|jd|jS)z~Get the timestamp as a unixtime in nanoseconds. :returns: posix timestamp in nanoseconds :rtype: int rriʚ;)rr)rrrr to_unix_nanoszTimestamp.to_unix_nanocCstjjdttj|jdS)zlGet the timestamp as a UTC datetime. Python 2 is not supported. :rtype: datetime. r)r)datetime fromtimestamp_utc timedeltar6)rrrr to_datetimeszTimestamp.to_datetimecCstj|jS)zuCreate a Timestamp from datetime with tzinfo. Python 2 is not supported. :rtype: Timestamp )rr5 timestamp)dtrrr from_datetimeszTimestamp.from_datetimeN)r)rrrr __slots__rr!r$r%r' staticmethodr1r3r5r6r8r9r>rArrrrr"s     r) collectionsrr:sysr- version_infoPY2rlongrr<timezoneutcAttributeErrorr=robjectrrrrrs