
0c@_                 @   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 rb e e f Z	 d Z
 nC e Z	 y e j j Z
 Wn* e k
 r e j e j d    Z
 Yn XGd d   d e d d   Z Gd d   d e  Z d S)	    )
namedtupleN   c                   s(   e  Z d  Z d Z   f d d   Z   S)ExtTypez'ExtType represents ext type in msgpack.c                sz   t  | t  s t d   t  | t  s6 t d   d | k oM d k n s^ t d   t t |   j |  | |  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__ 6/tmp/pip-build-jynh7p1z/pip/pip/_vendor/msgpack/ext.pyr      s    zExtType.__new__)__name__
__module____qualname____doc__r   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   st   t  | t  s t d   t  | t  s6 t d   d | k oM d k  n s^ 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.Ni ʚ;)r   	int_typesr   r
   r   r   )selfr   r   r   r   r   __init__-   s    		zTimestamp.__init__c             C   s   d j  |  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 k r7 |  j | j k o6 |  j | j k Sd S)z0Check for equality with another Timestamp objectF)typer   r   r   )r   otherr   r   r   __eq__K   s    "zTimestamp.__eq__c             C   s   |  j  |  S)z(not-equals method (see :func:`__eq__()`))r#   )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 r1 t j d |   d } d } nx t  |   d k rp t j d |   d } | d @} | d ?} n9 t  |   d k r t j 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
           z!Lr      z!Ql    "      z!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 ra |  j d >|  j  B} | d @d k rL t j d |  } q| t j d |  } n t j d |  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)   r   l        z!Lz!Qz!Iq)r   r   r,   pack)r   r/   r   r   r   r   to_bytesu   s    zTimestamp.to_bytesc             C   s1   t  |  d  } t  |  d d  } t | |  S)zCreate a Timestamp from posix timestamp in seconds.

        :param unix_float: Posix timestamp in seconds.
        :type unix_float: int or float.
           r   r   i ʚ;)r   r   )Z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    eA)r   r   )r   r   r   r   to_unix   s    zTimestamp.to_unixc             C   s   t  t |  d    S)zCreate a Timestamp from posix timestamp in nanoseconds.

        :param int unix_ns: Posix timestamp in nanoseconds.
        :rtype: Timestamp
        r   r   i ʚ;)r   divmod)Z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   i ʚ;)r   r   )r   r   r   r   to_unix_nano   s    zTimestamp.to_unix_nanoc             C   s   t  j  j |  j   t  S)zlGet the timestamp as a UTC datetime.

        Python 2 is not supported.

        :rtype: datetime.
        )datetimefromtimestampr5   _utc)r   r   r   r   to_datetime   s    zTimestamp.to_datetimec             C   s   t  j |  j    S)zuCreate a Timestamp from datetime with tzinfo.

        Python 2 is not supported.

        :rtype: Timestamp
        )r   r4   	timestamp)dtr   r   r   from_datetime   s    zTimestamp.from_datetimeN)r   r   r   r   	__slots__r   r    r#   r$   r&   staticmethodr0   r2   r4   r5   r7   r8   r<   r?   r   r   r   r   r   "   s   		r   )collectionsr   r9   sysr,   version_infoPY2r   longr   r;   timezoneutcAttributeError	timedeltar   objectr   r   r   r   r   <module>   s   	