a
    hbòfÈ  ã                   @   s¢   d dl mZ d dlZd dlZd dlZejd  dkZerDeefZ	dZ
n4eZ	zejjZ
W n" eyv   e e d ¡¡Z
Y n0 G dd„ deddƒƒZG dd„ deƒZdS )	é    )Ú
namedtupleNé   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚExtTypez'ExtType represents ext type in msgpack.c                    sV   t |tƒstdƒ‚t |tƒs$tdƒ‚d|  kr8dksBn tdƒ‚tt| ƒ | ||¡S )Nzcode must be intzdata must be bytesr   é   zcode must be 0~127)Ú
isinstanceÚintÚ	TypeErrorÚbytesÚ
ValueErrorÚsuperr   Ú__new__)ÚclsÚcodeÚdata©Ú	__class__© úT/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/pip/_vendor/msgpack/ext.pyr      s    

zExtType.__new__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__r   r   r   r   r      s   r   z	code datac                   @   s’   e Zd ZdZddgZd dd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	e
dd„ ƒZdd„ Ze
dd„ ƒZdd„ Ze
dd„ ƒZdd„ Zdd„ Ze
dd„ ƒZdS )!Ú	TimestampaR  Timestamp 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Únanosecondsr   c                 C   sR   t |tƒstdƒ‚t |tƒs$tdƒ‚d|  kr8dk sBn tdƒ‚|| _|| _dS )aÎ  Initialize 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.
        zseconds must be an intergerznanoseconds must be an integerr   é Êš;z?nanoseconds must be a non-negative integer less than 999999999.N)r   Ú	int_typesr   r
   r   r   )Úselfr   r   r   r   r   Ú__init__-   s    

ÿzTimestamp.__init__c                 C   s   d  | j| j¡S )z#String representation of Timestamp.z'Timestamp(seconds={0}, nanoseconds={1}))Úformatr   r   ©r   r   r   r   Ú__repr__E   s    ÿzTimestamp.__repr__c                 C   s*   t |ƒ| ju r&| j|jko$| j|jkS dS )z0Check for equality with another Timestamp objectF)Útyper   r   r   ©r   Úotherr   r   r   Ú__eq__K   s    ÿzTimestamp.__eq__c                 C   s   |   |¡ S )z(not-equals method (see :func:`__eq__()`))r&   r$   r   r   r   Ú__ne__S   s    zTimestamp.__ne__c                 C   s   t | j| jfƒS )N)Úhashr   r   r!   r   r   r   Ú__hash__W   s    zTimestamp.__hash__c                 C   s€   t | ƒdkr"t d| ¡d }d}nTt | ƒdkrPt d| ¡d }|d@ }|d? }n&t | ƒdkrnt d	| ¡\}}ntd
ƒ‚t||ƒS )a  Unpack 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
        é   ú!Lr   é   ú!Ql   ÿÿ é"   é   ú!IqzFTimestamp type can only be created from 32, 64, or 96-bit byte objects)ÚlenÚstructÚunpackr
   r   )Úbr   r   Údata64r   r   r   Ú
from_bytesZ   s    
ÿzTimestamp.from_bytesc                 C   s\   | j d? dkrF| jd> | j B }|d@ dkr8t d|¡}qXt d|¡}nt d| j| j ¡}|S )zÂPack 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.   r   l       üÿ r+   r-   r0   )r   r   r2   Úpack)r   r5   r   r   r   r   Úto_bytesu   s    zTimestamp.to_bytesc                 C   s&   t | d ƒ}t | d d ƒ}t||ƒS )zœCreate a Timestamp from posix timestamp in seconds.

        :param unix_float: Posix timestamp in seconds.
        :type unix_float: int or float.
        é   r   )r   r   )Úunix_secr   r   r   r   r   Ú	from_unixŠ   s    zTimestamp.from_unixc                 C   s   | j | jd  S )znGet the timestamp as a floating-point value.

        :returns: posix timestamp
        :rtype: float
        g    eÍÍA©r   r   r!   r   r   r   Úto_unix•   s    zTimestamp.to_unixc                 C   s   t t| dƒŽ S )z—Create a Timestamp from posix timestamp in nanoseconds.

        :param int unix_ns: Posix timestamp in nanoseconds.
        :rtype: Timestamp
        r   )r   Údivmod)Úunix_nsr   r   r   Úfrom_unix_nano�   s    zTimestamp.from_unix_nanoc                 C   s   | j d | j S )z~Get the timestamp as a unixtime in nanoseconds.

        :returns: posix timestamp in nanoseconds
        :rtype: int
        r   r<   r!   r   r   r   Úto_unix_nano¦   s    zTimestamp.to_unix_nanoc                 C   s   t j  dt¡t j|  ¡ d� S )zlGet the timestamp as a UTC datetime.

        Python 2 is not supported.

        :rtype: datetime.
        r   )r   )ÚdatetimeÚfromtimestampÚ_utcÚ	timedeltar=   r!   r   r   r   Úto_datetime®   s    ÿzTimestamp.to_datetimec                 C   s   t  |  ¡ ¡S )zuCreate a Timestamp from datetime with tzinfo.

        Python 2 is not supported.

        :rtype: Timestamp
        )r   r;   Ú	timestamp)Údtr   r   r   Úfrom_datetime¹   s    zTimestamp.from_datetimeN)r   )r   r   r   r   Ú	__slots__r   r"   r&   r'   r)   Ústaticmethodr6   r8   r;   r=   r@   rA   rF   rI   r   r   r   r   r   "   s&   




r   )Úcollectionsr   rB   Úsysr2   Úversion_infoÚPY2r   Úlongr   rD   ÚtimezoneÚutcÚAttributeErrorrE   r   Úobjectr   r   r   r   r   Ú<module>   s   