
|S\c           @   sE  d  Z  d d l Z d d l Z d d l Z e j d d k r[ e Z e e f Z	 d   Z
 n! e Z e Z	 e Z e Z d   Z
 e j d d f k  r e Z d	   Z n	 d
   Z e e d  r"d d l m Z y d d l m Z Wn! e k
 rd d l m Z n Xe Z d e f d     YZ n e Z d d l m Z d   Z d d l m  Z  m! Z! m" Z" m# Z# m$ Z$ d d l% m& Z& d Z' d Z( d Z) d Z* d Z+ d Z, d Z- d Z. d Z/ d Z0 d Z1 e2 e3 d  Z4 d   Z5 d   Z6 d   Z7 e j d d d f k  rd d  Z8 n	 e j9 Z8 d e f d      YZ: d! e f d"     YZ; d S(#   s.   Fallback pure Python implementation of msgpackiNi    i   c         C   s
   |  j    S(   N(   t	   iteritems(   t   d(    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   dict_iteritems   s    c         C   s
   |  j    S(   N(   t   items(   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR      s    i   i   c         C   s?   t  |  j  d k o> t |  j d t  o> |  j d j d  S(   Ni   i    s    maximum recursion depth exceeded(   t   lent   argst
   isinstancet   strt
   startswith(   t   e(    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   _is_recursionerror   s    +c         C   s   t  S(   N(   t   True(   R	   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR
      s    t   pypy_version_info(   t   newlist_hint(   t   BytesBuilder(   t   StringBuildert   StringIOc           B   s&   e  Z d  d  Z d   Z d   Z RS(   t    c         C   s>   | r. t  t |   |  _ |  j j |  n t    |  _ d  S(   N(   R   R   t   buildert   append(   t   selft   s(    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   __init__*   s    c         C   sP   t  | t  r | j   } n t  | t  r< t |  } n  |  j j |  d  S(   N(   R   t
   memoryviewt   tobytest	   bytearrayt   bytesR   R   (   R   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   write0   s
    c         C   s   |  j  j   S(   N(   R   t   build(   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   getvalue6   s    (   t   __name__t
   __module__R   R   R   (    (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR   )   s   	(   t   BytesIOc         C   s   g  S(   N(    (   t   size(    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   <lambda>;   s    (   t
   BufferFullt	   OutOfDatat	   ExtraDatat   FormatErrort
   StackError(   t   ExtTypei   i   i  c         C   s6   | |  | k r" | |   | k S| |   | k Sd  S(   N(    (   t   objt   tt   typet   tuple(    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   _check_type_strictX   s    c         C   s   y t  |   } WnO t k
 ra t r[ t  t |    } t j d t |   t d d qb   n X| j d k r t	 d   n  | S(   Ns   using old buffer interface to unpack %s; this leads to unpacking errors if slicing is used and will be removed in a future versiont
   stackleveli   i   s$   cannot unpack from multi-byte object(
   R   t	   TypeErrort   PY2t   buffert   warningst   warnR+   t   RuntimeWarningt   itemsizet
   ValueError(   R)   t   view(    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   _get_data_from_buffer_   s    	
c         K   s/   t  j d t d d |  j   } t | |  S(   Nsb   Direct calling implementation's unpack() is deprecated, Use msgpack.unpack() or unpackb() instead.R.   i   (   R2   R3   t   DeprecationWarningt   readt   unpackb(   t   streamt   kwargst   data(    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   unpackq   s
    c         K   s   t  d d t |   | } | j |   y | j   } WnG t k
 rW t d   n+ t k
 r } t |  r{ t	  n    n X| j
   r t | | j     n  | S(   sw  
    Unpack an object from `packed`.

    Raises ``ExtraData`` when *packed* contains extra bytes.
    Raises ``ValueError`` when *packed* is incomplete.
    Raises ``FormatError`` when *packed* is not valid msgpack.
    Raises ``StackError`` when *packed* contains too nested.
    Other exceptions can be raised during unpacking.

    See :class:`Unpacker` for options.
    t   max_buffer_sizes   Unpack failed: incomplete inputN(   t   Unpackert   NoneR   t   feedt   _unpackR$   R6   t   RecursionErrorR
   R'   t   _got_extradataR%   t   _get_extradata(   t   packedR=   t   unpackert   retR	   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR;   y   s    	i   i   c         C   s   t  j |  t |  |  S(   s.   Explicit typcast for legacy struct.unpack_from(   t   structt   unpack_fromR   (   t   ft   bt   o(    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   _unpack_from   s    RA   c           B   s   e  Z d  Z d d e e e d d d d d d e d d d d d d  Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z d
   Z e d  Z e d  Z d   Z d   Z e Z d   Z d   Z d   Z d   Z d   Z RS(   s  Streaming unpacker.

    arguments:

    :param file_like:
        File-like object having `.read(n)` method.
        If specified, unpacker reads serialized data from it and :meth:`feed()` is not usable.

    :param int read_size:
        Used as `file_like.read(read_size)`. (default: `min(16*1024, max_buffer_size)`)

    :param bool use_list:
        If true, unpack msgpack array to Python list.
        Otherwise, unpack to Python tuple. (default: True)

    :param bool raw:
        If true, unpack msgpack raw to Python bytes (default).
        Otherwise, unpack to Python str (or unicode on Python 2) by decoding
        with UTF-8 encoding (recommended).
        Currently, the default is true, but it will be changed to false in
        near future.  So you must specify it explicitly for keeping backward
        compatibility.

        *encoding* option which is deprecated overrides this option.

    :param bool strict_map_key:
        If true, only str or bytes are accepted for map (dict) keys.
        It's False by default for backward-compatibility.
        But it will be True from msgpack 1.0.

    :param callable object_hook:
        When specified, it should be callable.
        Unpacker calls it with a dict argument after unpacking msgpack map.
        (See also simplejson)

    :param callable object_pairs_hook:
        When specified, it should be callable.
        Unpacker calls it with a list of key-value pairs after unpacking msgpack map.
        (See also simplejson)

    :param str encoding:
        Encoding used for decoding msgpack raw.
        If it is None (default), msgpack raw is deserialized to Python bytes.

    :param str unicode_errors:
        (deprecated) Used for decoding msgpack raw with *encoding*.
        (default: `'strict'`)

    :param int max_buffer_size:
        Limits size of data waiting unpacked.  0 means system's INT_MAX (default).
        Raises `BufferFull` exception when it is insufficient.
        You should set this parameter when unpacking data from untrusted source.

    :param int max_str_len:
        Deprecated, use *max_buffer_size* instead.
        Limits max length of str. (default: max_buffer_size or 1024*1024)

    :param int max_bin_len:
        Deprecated, use *max_buffer_size* instead.
        Limits max length of bin. (default: max_buffer_size or 1024*1024)

    :param int max_array_len:
        Limits max length of array.
        (default: max_buffer_size or 128*1024)

    :param int max_map_len:
        Limits max length of map.
        (default: max_buffer_size//2 or 32*1024)

    :param int max_ext_len:
        Deprecated, use *max_buffer_size* instead.
        Limits max size of ext type.  (default: max_buffer_size or 1024*1024)

    Example of streaming deserialize from file-like object::

        unpacker = Unpacker(file_like, raw=False, max_buffer_size=10*1024*1024)
        for o in unpacker:
            process(o)

    Example of streaming deserialize from socket::

        unpacker = Unpacker(raw=False, max_buffer_size=10*1024*1024)
        while True:
            buf = sock.recv(1024**2)
            if not buf:
                break
            unpacker.feed(buf)
            for o in unpacker:
                process(o)

    Raises ``ExtraData`` when *packed* contains extra bytes.
    Raises ``OutOfData`` when *packed* is incomplete.
    Raises ``FormatError`` when *packed* is not valid msgpack.
    Raises ``StackError`` when *packed* contains too nested.
    Other exceptions can be raised during unpacking.
    i    ic         C   s  |	 d  k	 r% t j d t d d n  |
 d  k r: d }
 n  | d  k rR t |  _ n0 t | j  sp t d   n  | |  _	 t
 |  _ t   |  _ d |  _ d |  _ | d k r | p d } n  | d k r | p d } n  | d k r | p d } n  | d k r| d p
d } n  | d k r+| p%d } n  | p4d |  _ | |  j k rXt d   n  | pmt |  j d  |  _ t |  |  _ t |  |  _ |	 |  _ |
 |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _  | |  _! d |  _" | d  k	 r.t |  r.t d   n  | d  k	 rVt |  rVt d   n  | d  k	 r~t |  r~t d   n  | d  k	 r| d  k	 rt d   n  t |  st d   n  d  S(   Ns.   encoding is deprecated, Use raw=False instead.R.   i   t   stricts!   `file_like.read` must be callablei    ii   i   i    i   i   s.   read_size must be smaller than max_buffer_sizei   s   `list_hook` is not callables   `object_hook` is not callables#   `object_pairs_hook` is not callables8   object_pairs_hook and object_hook are mutually exclusives   `ext_hook` is not callablei   i   i   i   i   I       ii @  (#   RB   R2   R3   R9   R   t   _feedingt   callableR:   R/   t	   file_liket   FalseR   t   _buffert   _buff_it   _buf_checkpointt   _max_buffer_sizeR6   t   mint
   _read_sizet   boolt   _rawt   _strict_map_keyt	   _encodingt   _unicode_errorst	   _use_listt
   _list_hookt   _object_hookt   _object_pairs_hookt	   _ext_hookt   _max_str_lent   _max_bin_lent   _max_array_lent   _max_map_lent   _max_ext_lent   _stream_offset(   R   RT   t	   read_sizet   use_listt   rawt   strict_map_keyt   object_hookt   object_pairs_hookt	   list_hookt   encodingt   unicode_errorsR@   t   ext_hookt   max_str_lent   max_bin_lent   max_array_lent   max_map_lent   max_ext_len(    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR      sl    																				c         C   s   |  j  s t  t |  } t |  j  |  j t |  |  j k rM t  n  |  j d k r |  j |  j 4|  j |  j 8_ d |  _ n  |  j j	 |  d  S(   Ni    (
   RR   t   AssertionErrorR8   R   RV   RW   RY   R#   RX   t   extend(   R   t
   next_bytesR7   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyRC   P  s    )	c         C   s)   |  j  |  j |  j 7_  |  j |  _ d S(   s+    Gets rid of the used parts of the buffer. N(   Rk   RW   RX   (   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   _consume_  s    c         C   s   |  j  t |  j  k  S(   N(   RW   R   RV   (   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyRF   d  s    c         C   s   |  j  |  j S(   N(   RV   RW   (   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyRG   g  s    c         C   s   |  j  |  S(   N(   t   _read(   R   t   n(    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt
   read_bytesj  s    c         C   s5   |  j  |  |  j } | | |  _ |  j | | | !S(   N(   t   _reserveRW   RV   (   R   R   t   i(    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR   m  s    	c         C   s0  t  |  j  |  j | } | d k r* d  S|  j rH |  j |  _ t  n  |  j d k r |  j |  j 4|  j |  j 8_ d |  _ n  | } xr | d k r t |  j |  } |  j j	 |  } | s Pn  t
 | t  s t  |  j | 7_ | t  |  8} q Wt  |  j  | |  j k  r,d |  _ t  n  d  S(   Ni    (   R   RV   RW   RR   RX   R$   t   maxR[   RT   R:   R   R   R{   (   R   R   t   remain_bytest   to_read_bytest	   read_data(    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR   t  s,    			c         C   sH  t  } d } d  } |  j d  |  j |  j } |  j d 7_ | d @d k rW | } n| d @d k rx d | d A} n| d @d k r | d @} t } | |  j k r t d	 | |  j   n  |  j |  } nj| d
 @d k r| d @} t	 } | |  j
 k r;t d | |  j
   q;n | d
 @d k re| d @} t } | |  j k r;t d | |  j   q;n| d k rzd  } n| d k rt } n| d k rt } n| d k rt } |  j d  |  j |  j } |  j d 7_ | |  j k rt d | |  j f   n  |  j |  } n| d k rt } |  j d  t d |  j |  j  d } |  j d 7_ | |  j k rt d | |  j f   n  |  j |  } n
| d k r-t } |  j d  t d |  j |  j  d } |  j d 7_ | |  j k rt d | |  j f   n  |  j |  } n
| d k rt } |  j d  t d |  j |  j  \ } } |  j d 7_ | |  j k rt d | |  j f   n  |  j |  } n	| d k r?t } |  j d  t d |  j |  j  \ } } |  j d 7_ | |  j k r-t d | |  j f   n  |  j |  } n| d  k rt } |  j d!  t d" |  j |  j  \ } } |  j d! 7_ | |  j k rt d | |  j f   n  |  j |  } ns| d# k r|  j d  t d$ |  j |  j  d } |  j d 7_ n,| d% k rV|  j d&  t d' |  j |  j  d } |  j d& 7_ n| d( k r|  j d  |  j |  j } |  j d 7_ n| d) k r|  j d  t d |  j |  j  d } |  j d 7_ nc| d* k r|  j d  t d |  j |  j  d } |  j d 7_ n| d+ k rf|  j d&  t d, |  j |  j  d } |  j d& 7_ n| d- k r|  j d  t d. |  j |  j  d } |  j d 7_ n| d/ k r|  j d  t d0 |  j |  j  d } |  j d 7_ nG| d1 k r;|  j d  t d2 |  j |  j  d } |  j d 7_ n | d3 k r|  j d&  t d4 |  j |  j  d } |  j d& 7_ n| d5 k rt } |  j d k  rt d d |  j f   n  |  j d  t d6 |  j |  j  \ } } |  j d 7_ n?| d7 k rvt } |  j d k  r9t d d |  j f   n  |  j d  t d8 |  j |  j  \ } } |  j d 7_ n| d9 k rt } |  j d k  rt d d |  j f   n  |  j d!  t d: |  j |  j  \ } } |  j d! 7_ nK| d; k rj	t } |  j d& k  r-	t d d& |  j f   n  |  j d<  t d= |  j |  j  \ } } |  j d< 7_ n| d> k r	t } |  j d? k  r	t d d? |  j f   n  |  j d@  t dA |  j |  j  \ } } |  j d@ 7_ nW| dB k r[
t } |  j d  |  j |  j } |  j d 7_ | |  j k rI
t d	 | |  j   n  |  j |  } n| dC k r
t } |  j d  t d |  j |  j  \ } |  j d 7_ | |  j k r
t d	 | |  j   n  |  j |  } n^| dD k r_t } |  j d  t d |  j |  j  \ } |  j d 7_ | |  j k rMt d	 | |  j   n  |  j |  } n| dE k rt	 } |  j d  t d |  j |  j  \ } |  j d 7_ | |  j
 k r;t d | |  j
   q;ni| dF k rEt	 } |  j d  t d |  j |  j  \ } |  j d 7_ | |  j
 k r;t d | |  j
   q;n | dG k r|  j d  t d |  j |  j  \ } |  j d 7_ | |  j k rt d | |  j   n  t } n | dH k r+|  j d  t d |  j |  j  \ } |  j d 7_ | |  j k r"t d | |  j   n  t } n t dI |   | | | f S(J   Ni    i   i   i   ii   i   i   s   %s exceeds max_str_len(%s)i   i   i   s   %s exceeds max_array_len(%s)s   %s exceeds max_map_len(%s)i   i   i   i   s   %s exceeds max_bin_len(%s)i   i   s   >Hi   i   s   >Ii   t   Bbs   %s exceeds max_ext_len(%s)i   i   s   >Hbi   i   s   >Ibi   s   >fi   i   s   >di   i   i   i   s   >Qi   RN   i   s   >hi   s   >ii   s   >qi   t   b1si   t   b2si   t   b4si   i	   t   b8si   i   i   t   b16si   i   i   i   i   i   i   s   Unknown header: 0x%x(   t   TYPE_IMMEDIATERB   R   RV   RW   t   TYPE_RAWRf   R6   R   t
   TYPE_ARRAYRh   t   TYPE_MAPRi   RU   R   t   TYPE_BINRg   RP   t   TYPE_EXTRj   R&   (   R   t   executet   typR   R)   RN   t   L(    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   _read_header  s   	


					c   	         s    j  |  \ } } } | t k rC | t k r? t d   n  | S| t k rn | t k rj t d   n  | S| t k r| t k r x! t |  D] }   j t  q Wd  St	 |  } x* t |  D] } | j
   j t   q W  j d  k	 r  j |  } n    j r| St |  S| t k rG| t k rlx. t |  D]  }   j t    j t  qDWd  S  j d  k	 r  j   f d   t |  D  } n i  } xv t |  D]h }   j t  }   j rt |  t t f k rt d t t |     n    j t  | | <qW  j d  k	 rC  j |  } n  | S| t k rWd  S| t k r  j d  k	 r| j   j   j  } n'   j rt |  } n | j d  } | S| t k r  j | t |   S| t k rt |  S| t k st   | S(   Ns   Expected arrays   Expected mapc         3   s-   |  ]# }   j  t    j  t  f Vq d  S(   N(   RD   t   EX_CONSTRUCT(   t   .0t   _(   R   (    s/   lib/python2.7/site-packages/msgpack/fallback.pys	   <genexpr>  s   s   %s is not allowed for map keyt   utf_8(!   R   t   EX_READ_ARRAY_HEADERR   R6   t   EX_READ_MAP_HEADERR   t   EX_SKIPt   xrangeRD   R   R   R   Rb   RB   Ra   R,   Rd   R^   R+   t   unicodeR   R   Rc   R   R_   t   decodeR`   R]   R   Re   R   R   R{   (	   R   R   R   R   R)   R   RJ   R   t   key(    (   R   s/   lib/python2.7/site-packages/msgpack/fallback.pyRD   h  sl    !	
c         C   s   |  S(   N(    (   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   __iter__  s    c         C   s_   y! |  j  t  } |  j   | SWn7 t k
 rD |  j   t  n t k
 rZ t  n Xd  S(   N(   RD   R   R~   R$   t   StopIterationRE   R'   (   R   RJ   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   __next__  s    

	c         C   s   |  j  t  |  j   d  S(   N(   RD   R   R~   (   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   skip  s    c         C   s;   y |  j  t  } Wn t k
 r, t  n X|  j   | S(   N(   RD   R   RE   R'   R~   (   R   RJ   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR?     s    

c         C   s   |  j  t  } |  j   | S(   N(   RD   R   R~   (   R   RJ   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   read_array_header  s    
c         C   s   |  j  t  } |  j   | S(   N(   RD   R   R~   (   R   RJ   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   read_map_header  s    
c         C   s   |  j  S(   N(   Rk   (   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   tell  s    N(   R   R   t   __doc__RB   R   RU   R(   R   RC   R~   RF   RG   R   R   R   R   R   RD   R   R   t   nextR   R?   R   R   R   (    (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyRA      s6   `		J							 @						t   Packerc           B   s   e  Z d  Z d d d e e e e d  Z e e e	 d  Z
 d   Z d   Z d   Z d   Z d   Z d   Z d	   Z e d
  Z d   Z d   Z d   Z d   Z d   Z RS(   sh  
    MessagePack Packer

    usage:

        packer = Packer()
        astream.write(packer.pack(a))
        astream.write(packer.pack(b))

    Packer's constructor has some keyword arguments:

    :param callable default:
        Convert user type to builtin type that Packer supports.
        See also simplejson's document.

    :param bool use_single_float:
        Use single precision float type for float. (default: False)

    :param bool autoreset:
        Reset buffer after each pack and return its content as `bytes`. (default: True).
        If set this to false, use `bytes()` to get content and `.reset()` to clear buffer.

    :param bool use_bin_type:
        Use bin type introduced in msgpack spec 2.0 for bytes.
        It also enables str8 type for unicode.

    :param bool strict_types:
        If set to true, types will be checked to be exact. Derived classes
        from serializeable types will not be serialized and will be
        treated as unsupported type and forwarded to default.
        Additionally tuples will not be serialized as lists.
        This is useful when trying to implement accurate serialization
        for python types.

    :param str encoding:
        (deprecated) Convert unicode to bytes with this encoding. (default: 'utf-8')

    :param str unicode_errors:
        Error handler for encoding unicode. (default: 'strict')
    c         C   s   | d  k r d } n t j d t d d | d  k r@ d } n  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 t
   |  _ | d  k	 r t |  s t d   q n  | |  _ d  S(   NR   s.   encoding is deprecated, Use raw=False instead.R.   i   RQ   s   default must be callable(   RB   R2   R3   R9   t   _strict_typest
   _use_floatt
   _autoresett   _use_bin_typeR_   R`   R   RV   RS   R/   t   _default(   R   t   defaultRs   Rt   t   use_single_floatt	   autoresett   use_bin_typet   strict_types(    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR     s$    								c         C   sK  t  } |  j r | } t } n t t f } xt rF| d k  rN t d   n  | d  k rj |  j j d  S| | t	  r | r |  j j d  S|  j j d  S| | t
  r6d | k o d k  n r |  j j t j d |   Sd | k o d k  n r|  j j t j d	 |   Sd | k o5d
 k n rY|  j j t j d d |   Sd | k opd k  n r|  j j t j d d |   Sd
 | k  od k n r|  j j t j d d |   Sd | k od k  n r
|  j j t j d d |   Sd | k  o!d k n rE|  j j t j d d |   Sd | k o\d k  n r|  j j t j d d |   Sd | k  od k n r|  j j t j d d |   Sd | k od k  n r|  j j t j d  d! |   S| r'|  j d  k	 r'|  j |  } t } q- n  t d"   n  | | t t f  rt |  } | d; k rt d% t |  j   n  |  j |  |  j j |  S| | t  r%|  j d  k rt d&   n  | j |  j |  j  } t |  } | d< k rt d'   n  |  j |  |  j j |  S| | t  rt |  | j } | d= k rbt d(   n  |  j |  |  j j |  S| | t  r|  j r|  j j t j d) d* |   S|  j j t j d+ d, |   S| | t  rr| j  } | j! }	 t" | t#  st$  t" |	 t  s t$  t |	  }
 |
 d- k rK|  j j d.  n |
 d# k rj|  j j d/  n |
 d0 k r|  j j d1  n |
 d2 k r|  j j d3  n |
 d4 k r|  j j d5  n{ |
 d
 k r|  j j t j d6 d7 |
   nM |
 d k r#|  j j t j d d8 |
   n |  j j t j d d9 |
   |  j j t j d	 |   |  j j |	  d  S| | |  rt |  } |  j% |  x, t& |  D] } |  j' | | | d-  qWd  S| | t(  r|  j) t |  t* |  | d-  S| r0|  j d  k	 r0|  j |  } d- } q- n  t d: | f   q- Wd  S(>   Ni    s   recursion limit exceededs   s   s   i   t   BiRN   i   t   BBi   is   >Bbi   i  s   >BHi   i s   >Bhi   I    s   >BIi   i   s   >Bii   l    s   >BQi   I       s   >Bqi   s   Integer value out of rangei   i    s   %s is too larges5   Can't encode unicode string: no encoding is specifieds   String is too larges   Memoryview is too larges   >Bfi   s   >Bdi   i   s   s   i   s   i   s   i   s   s   >BBi   i   i   s   Cannot serialize %rI       I       I       (+   RU   R   t   listR,   R   R6   RB   RV   R   R\   t	   int_typesRK   t   packR   t   OverflowErrorR   R   R   R+   R   t   _pack_bin_headerR   R_   R/   t   encodeR`   t   _pack_raw_headerR   R5   t   floatR   R(   t   codeR>   R   t   intR{   t   _pack_array_headerR   t   _packt   dictt   _pack_map_pairsR   (   R   R)   t
   nest_limitt   checkt   check_type_strictt   default_usedt
   list_typesR   R   R>   R   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR     s    						""c         C   sV   y |  j  |  Wn t   |  _   n X|  j rR |  j j   } t   |  _ | Sd  S(   N(   R   R   RV   R   R   (   R   R)   RJ   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR     s    	c         C   sB   |  j  t |  |  |  j r> |  j j   } t   |  _ | Sd  S(   N(   R   R   R   RV   R   R   (   R   t   pairsRJ   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   pack_map_pairs  s
    	c         C   sN   | d k r t   n  |  j |  |  j rJ |  j j   } t   |  _ | Sd  S(   Ni   i    I       (   R6   R   R   RV   R   R   (   R   R   RJ   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   pack_array_header  s    		c         C   sN   | d k r t   n  |  j |  |  j rJ |  j j   } t   |  _ | Sd  S(   Ni   i    I       (   R6   t   _pack_map_headerR   RV   R   R   (   R   R   RJ   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   pack_map_header  s    		c         C   s  t  | t  s t d   n  d | k o5 d k n sI t d   n  t  | t  sg t d   n  t |  } | d k r t d   n  | d k r |  j j d	  n | d
 k r |  j j d  n | d k r |  j j d  n | d k r
|  j j d  n | d k r)|  j j d  n~ | d k rX|  j j d t j	 d |   nO | d k r|  j j d t j	 d |   n  |  j j d t j	 d |   |  j j t j	 d |   |  j j |  d  S(   Ns   typecode must have int type.i    i   s   typecode should be 0-127s   data must have bytes typeI    s   Too large datai   s   i   s   i   s   i   s   i   s   i   s   R   i  s   s   >Hs   s   >I(
   R   R   R/   R6   R   R   RV   R   RK   R   (   R   t   typecodeR>   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   pack_ext_type  s4    ## c         C   s   | d k r, |  j  j t j d d |   S| d k rW |  j  j t j d d |   S| d k r |  j  j t j d d	 |   St d
   d  S(   Ni   R   i   i  s   >BHi   I    s   >BIi   s   Array is too large(   RV   R   RK   R   R6   (   R   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR     s     c         C   s   | d k r, |  j  j t j d d |   S| d k rW |  j  j t j d d |   S| d k r |  j  j t j d d	 |   St d
   d  S(   Ni   R   i   i  s   >BHi   I    s   >BIi   s   Dict is too large(   RV   R   RK   R   R6   (   R   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR     s     c         C   sP   |  j  |  x< | D]4 \ } } |  j | | d  |  j | | d  q Wd  S(   Ni   (   R   R   (   R   R   R   R   t   kt   v(    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR     s    c         C   s   | d k r/ |  j  j t j d d |   n |  j rf | d k rf |  j  j t j d d |   nh | d k r |  j  j t j d d	 |   n: | d
 k r |  j  j t j d d |   n t d   d  S(   Ni   R   i   i   s   >BBi   i  s   >BHi   I    s   >BIi   s   Raw is too large(   RV   R   RK   R   R   R6   (   R   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR     s    #"""c         C   s   |  j  s |  j |  S| d k rA |  j j t j d d |   S| d k rl |  j j t j d d |   S| d k r |  j j t j d d	 |   St d
   d  S(   Ni   s   >BBi   i  s   >BHi   I    s   >BIi   s   Bin is too large(   R   R   RV   R   RK   R   R6   (   R   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR     s    	c         C   s   |  j  j   S(   s/   Return internal buffer contents as bytes object(   RV   R   (   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR     s    c         C   s   t    |  _ d S(   sY   Reset internal buffer.

        This method is usaful only when autoreset=False.
        N(   R   RV   (   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   reset  s    c         C   s-   t  s t r t |  j    S|  j j   Sd S(   s   Return view of internal buffer.N(   t   USING_STRINGBUILDERR0   R   R   RV   t	   getbuffer(   R   (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR     s    N(   R   R   R   RB   RU   R   R   t   DEFAULT_RECURSE_LIMITR   R-   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyR     s&   (		m															(<   R   t   sysRK   R2   t   version_infoR   R0   R   t   longR   R   RU   R   R   t   rangeR   t   RuntimeErrorRE   R
   t   hasattrt   __pypy__R   t   __pypy__.buildersR   R   t   ImportErrorR   t   objectR   t   ioR    t   msgpack.exceptionsR#   R$   R%   R&   R'   t   msgpackR(   R   R   R   R   R   R   R   R   R   R   R   R+   R,   R-   R8   R?   R;   RP   RL   RA   R   (    (    (    s/   lib/python2.7/site-packages/msgpack/fallback.pyt   <module>   sf   			(				  8