ó
Ð²Ebc           @   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 nB e Z	 y e j j Z Wn) e k
 r£ e j e j d ƒ ƒ Z n Xd e d d ƒ f d „  ƒ  YZ d e f d	 „  ƒ  YZ d S(
   iÿÿÿÿ(   t
   namedtupleNi    i   t   ExtTypes	   code datac           B   s   e  Z d  Z d „  Z RS(   s'   ExtType represents ext type in msgpack.c         C   sƒ   t  | t ƒ s t d ƒ ‚ n  t  | t ƒ s< t d ƒ ‚ n  d | k oS d k n sg t d ƒ ‚ n  t t |  ƒ j |  | | ƒ S(   Ns   code must be ints   data must be bytesi    i   s   code must be 0~127(   t
   isinstancet   intt	   TypeErrort   bytest
   ValueErrort   superR   t   __new__(   t   clst   codet   data(    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyR      s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyR      s   t	   Timestampc           B   sª   e  Z d  Z d d g Z d d „ Z d „  Z d „  Z d „  Z d „  Z e	 d	 „  ƒ Z
 d
 „  Z e	 d „  ƒ Z d „  Z e	 d „  ƒ Z d „  Z d „  Z e	 d „  ƒ Z RS(   sR  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.
    t   secondst   nanosecondsi    c         C   s}   t  | t ƒ s t d ƒ ‚ n  t  | t ƒ s< t d ƒ ‚ n  d | k oS d k  n sg t d ƒ ‚ n  | |  _ | |  _ d S(	   sÎ  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.
        s   seconds must be an intergers   nanoseconds must be an integeri    i
   i	   s?   nanoseconds must be a non-negative integer less than 999999999.Ni Êš;(   R   t	   int_typesR   R   R   R   (   t   selfR   R   (    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyt   __init__-   s    	c         C   s   d j  |  j |  j ƒ S(   s#   String representation of Timestamp.s'   Timestamp(seconds={0}, nanoseconds={1})(   t   formatR   R   (   R   (    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyt   __repr__E   s    c         C   s;   t  | ƒ |  j k r7 |  j | j k o6 |  j | j k St S(   s0   Check for equality with another Timestamp object(   t   typet	   __class__R   R   t   False(   R   t   other(    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyt   __eq__K   s    "c         C   s   |  j  | ƒ S(   s(   not-equals method (see :func:`__eq__()`)(   R   (   R   R   (    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyt   __ne__S   s    c         C   s   t  |  j |  j f ƒ S(   N(   t   hashR   R   (   R   (    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyt   __hash__W   s    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(   s  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
        i   s   !Li    i   s   !QIÿÿÿÿ   i"   i   s   !IqsF   Timestamp type can only be created from 32, 64, or 96-bit byte objects(   t   lent   structt   unpackR   R   (   t   bR   R   t   data64(    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyt
   from_bytesZ   s    	
	c         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(   sÂ   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
        i"   i    l       üÿ s   !Ls   !Qs   !Iq(   R   R   R    t   pack(   R   R#   R   (    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyt   to_bytesu   s    c         C   s1   t  |  d ƒ } t  |  d d ƒ } t | | ƒ S(   sœ   Create a Timestamp from posix timestamp in seconds.

        :param unix_float: Posix timestamp in seconds.
        :type unix_float: int or float.
        i   i
   i	   i Êš;(   R   R   (   t   unix_secR   R   (    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyt	   from_unixŠ   s    c         C   s   |  j  |  j d S(   sn   Get the timestamp as a floating-point value.

        :returns: posix timestamp
        :rtype: float
        g    eÍÍA(   R   R   (   R   (    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyt   to_unix•   s    c         C   s   t  t |  d ƒ Œ  S(   s—   Create a Timestamp from posix timestamp in nanoseconds.

        :param int unix_ns: Posix timestamp in nanoseconds.
        :rtype: Timestamp
        i
   i	   i Êš;(   R   t   divmod(   t   unix_ns(    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyt   from_unix_nano   s    c         C   s   |  j  d |  j S(   s~   Get the timestamp as a unixtime in nanoseconds.

        :returns: posix timestamp in nanoseconds
        :rtype: int
        i
   i	   i Êš;(   R   R   (   R   (    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyt   to_unix_nano¦   s    c         C   s   t  j  j |  j ƒ  t ƒ S(   sl   Get the timestamp as a UTC datetime.

        Python 2 is not supported.

        :rtype: datetime.
        (   t   datetimet   fromtimestampR)   t   _utc(   R   (    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyt   to_datetime®   s    c         C   s   t  j |  j ƒ  ƒ S(   su   Create a Timestamp from datetime with tzinfo.

        Python 2 is not supported.

        :rtype: Timestamp
        (   R   R(   t	   timestamp(   t   dt(    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyt   from_datetime·   s    (   R   R   R   t	   __slots__R   R   R   R   R   t   staticmethodR$   R&   R(   R)   R,   R-   R1   R4   (    (    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyR   "   s   										(   t   collectionsR    R.   t   sysR    t   version_infot   PY2R   t   longR   t   NoneR0   t   timezonet   utct   AttributeErrort	   timedeltaR   t   objectR   (    (    (    s4   /tmp/pip-build-UPPWic/pip/pip/_vendor/msgpack/ext.pyt   <module>   s   	