U o a @sdZddlmZddlZddlZejddkZerDeefZ ddZ neZ e Z e ZddZ ejdkrpeZd d Znd d Zeed rdd lmZzddlmZWn ek rddlmZYnXdZGdddeZndZddlmZddZddlmZm Z m!Z!m"Z"m#Z#ddl$m%Z%m&Z&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1e2e3fddZ4d d!Z5d"d#Z6ejd$kr|d+d%d&Z7nej8Z7Gd'd(d(eZ9Gd)d*d*eZ:dS),z.Fallback pure Python implementation of msgpack)datetimeNcCs|SN) iteritemsdr]C:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-6mt8ur68\pip\_vendor\msgpack\fallback.pydict_iteritems sr cCs|Sr)itemsrrrr r s)cCs.t|jdko,t|jdto,|jddS)Nrz maximum recursion depth exceeded)lenargs isinstancestr startswitherrr _is_recursionerrors rcCsdS)NTrrrrr r'spypy_version_info) newlist_hint) BytesBuilder) StringBuilderTc@s&eZdZd ddZddZddZdS) StringIOcCs,|r tt||_|j|nt|_dSr)rrbuilderappendselfsrrr __init__7szStringIO.__init__cCs6t|tr|}nt|tr&t|}|j|dSr)r memoryviewtobytes bytearraybytesrrrrrr write>s    zStringIO.writecCs |jSr)rbuildr rrr getvalueEszStringIO.getvalueN)r)__name__ __module__ __qualname__r"r'r*rrrr r6s rF)BytesIOcCsgSrr)sizerrr Mrr0r) BufferFull OutOfData ExtraData FormatError StackError)ExtType Timestampr r icCs(|||kr|||kS|||kSdSrr)objttypetuplerrr _check_type_strictds  r=cCst|}|jdkrtd|S)Nrz$cannot unpack from multi-byte object)r#itemsize ValueError)r9viewrrr _get_data_from_bufferks rAc Kstddt|i|}||z |}WnJtk rHtdYn0tk rv}zt|rdtW5d}~XYnX| rt || |S)aw 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. Nmax_buffer_sizezUnpack failed: incomplete input)N) Unpackerrfeed_unpackr2r?RecursionErrorrr5_got_extradatar3_get_extradata)packedkwargsunpackerretrrrr unpackbrs    rM)rcCst|t||S)z0Explicit type cast for legacy struct.unpack_from)struct unpack_fromr&)fborrr _unpack_fromsrUc@seZdZdZdddddddddddedddddfdd Zd d Zd d ZddZddZ ddZ ddZ ddZ e fddZe fddZddZddZeZd d!Zd"d#Zd$d%Zd&d'Zd(d)ZdS)*rCa 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. Otherwise, unpack to Python str by decoding with UTF-8 encoding (default). :param int timestamp: Control how timestamp type is unpacked: 0 - Timestamp 1 - float (Seconds from the EPOCH) 2 - int (Nanoseconds from the EPOCH) 3 - datetime.datetime (UTC). Python 2 is not supported. :param bool strict_map_key: If true (default), only str or bytes are accepted for map (dict) keys. :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 unicode_errors: The error handler for decoding unicode. (default: 'strict') This option should be used only when you have msgpack data which contains invalid UTF-8 string. :param int max_buffer_size: Limits size of data waiting unpacked. 0 means 2**32-1. The default value is 100*1024*1024 (100MiB). 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) :param int max_bin_len: Deprecated, use *max_buffer_size* instead. Limits max length of bin. (default: max_buffer_size) :param int max_array_len: Limits max length of array. (default: max_buffer_size) :param int max_map_len: Limits max length of map. (default: max_buffer_size//2) :param int max_ext_len: Deprecated, use *max_buffer_size* instead. Limits max size of ext type. (default: max_buffer_size) Example of streaming deserialize from file-like object:: unpacker = Unpacker(file_like) for o in unpacker: process(o) Example of streaming deserialize from socket:: unpacker = Unpacker(max_buffer_size) 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. NrTFi@cCs| dkr d} |dkrd|_nt|js.td||_d|_t|_d|_d|_| sVd} | dkrb| } |dkrn| }|dkrz| }|dkr| d}|dkr| }| |_ ||j krt d |pt |j d |_ t ||_t ||_| |_||_d|krd ksnt d ||_| |_||_||_| |_| |_||_||_||_||_d|_| dk r\t| s\td |dk rxt|sxtd|dk rt|std|dk r|dk rtdt| stddS)NstrictTz!`file_like.read` must be callableFrirVrz.read_size must be smaller than max_buffer_sizei@r ztimestamp must be 0..3z`list_hook` is not callablez`object_hook` is not callablez#`object_pairs_hook` is not callablez8object_pairs_hook and object_hook are mutually exclusivez`ext_hook` is not callable)_feedingcallableread TypeError file_liker%_buffer_buff_i_buf_checkpoint_max_buffer_sizer?min _read_sizebool_raw_strict_map_key_unicode_errors _use_list _timestamp _list_hook _object_hook_object_pairs_hook _ext_hook _max_str_len _max_bin_len_max_array_len _max_map_len _max_ext_len_stream_offset)r r\ read_sizeuse_listraw timestampstrict_map_key object_hookobject_pairs_hook list_hookunicode_errorsrBext_hook max_str_len max_bin_len max_array_len max_map_len max_ext_lenrrr r"sp      zUnpacker.__init__cCsr|js tt|}t|j|jt||jkr4t|jdkrb|jd|j=|j|j8_d|_|j |dSNr) rXAssertionErrorrArr]r^r`r1r_extend)r next_bytesr@rrr rDUs  z Unpacker.feedcCs"|j|j|j7_|j|_dS)z+ Gets rid of the used parts of the buffer. N)rrr^r_r)rrr _consumedszUnpacker._consumecCs|jt|jkSr)r^rr]r)rrr rGiszUnpacker._got_extradatacCs|j|jdSr)r]r^r)rrr rHlszUnpacker._get_extradatacCs||}||Sr)_readrr nrLrrr read_bytesos zUnpacker.read_bytescCs,|||j}|||_|j|||Sr)_reserver^r])r rirrr rts  zUnpacker._readcCst|j|j|}|dkr dS|jr2|j|_t|jdkr`|jd|j=|j|j8_d|_| }|dkrt|j|}|j |}|sqt |t st |j|7_|t|8}qft|j||jkrd|_tdSr) rr]r^rXr_r2maxrbr\rZrr&r)r r remain_bytes to_read_bytes read_datarrr r{s,   zUnpacker._reservecCs& t}d}d}|d|j|j}|jd7_|d@dkrD|} n|d@dkr`d|dA} n|d@dkr|d@}t}||jkrtd ||j||} n~|d @d kr|d @}t}||j krtd ||j  nJ|d @dkr |d @}t }||j k rtd||j  n|dkrd} n|dkr.d}n|dkr@d}n|dkrt }|d|j|j}|jd7_||j krtd||j f||}n~|dkrt }|dtd|j|jd}|jd7_||j krtd||j f||}n|dkrjt }|dtd|j|jd}|jd7_||j kr\td||j f||}n|dkrt}|dtd|j|j\}}|jd7_||jkrtd||jf||}nL|dkr6t}|d td!|j|j\}}|jd 7_||jkr(td||jf||}n|d"krt}|d#td$|j|j\}}|jd#7_||jkrtd||jf||}n|d%kr|dtd&|j|jd}|jd7_nF|d'kr|d(td)|j|jd}|jd(7_n |d*krB|d|j|j}|jd7_n|d+kr||dtd|j|jd}|jd7_n|d,kr|dtd|j|jd}|jd7_nf|d-kr|d(td.|j|jd}|jd(7_n,|d/kr*|dtd0|j|jd}|jd7_n|d1krd|dtd2|j|jd}|jd7_n|d3kr|dtd4|j|jd}|jd7_n~|d5kr|d(td6|j|jd}|jd(7_nD|d7kr4t}|jdkrtdd|jf|dtd8|j|j\}}|jd7_n|d9krt}|jdkr`tdd|jf|d td:|j|j\}}|jd 7_n|d;krt}|jdkrtdd|jf|d#td<|j|j\}}|jd#7_n0|d=krHt}|jd(krtdd(|jf|d>td?|j|j\}}|jd>7_n|d@krt}|jdAkrttddA|jf|dBtdC|j|j\}}|jdB7_nx|dDkrt}|d|j|j}|jd7_||jkrtd ||j||}n|dEkr^t}|dtd|j|j\}|jd7_||jkrPtd ||j||}n|dFkrt}|dtd|j|j\}|jd7_||jkrtd ||j||}n^|dGk rt}|dtd|j|j\}|jd7_||j k rtd ||j n|dHk rht}|dtd|j|j\}|jd7_||j k rtd ||j n|dIk r|dtd|j|j\}|jd7_||j k rtd||j t }n`|dJk r|dtd|j|j\}|jd7_||j k r td||j t }n tdK||||fS)LNrrrVz%s exceeds max_str_len(%s)z%s exceeds max_array_len(%s)z%s exceeds max_map_len(%s)FTz%s exceeds max_bin_len(%s)r>Hr8>IBbz%s exceeds max_ext_len(%s)r z>Hbr z>Ibz>fz>dz>QrSz>hz>iz>qb1sb2sb4s b8sb16szUnknown header: 0x%x)TYPE_IMMEDIATErr]r^TYPE_RAWrmr?r TYPE_ARRAYroTYPE_MAPrpTYPE_BINrnrUTYPE_EXTrqr4)r executetyprr9rSLrrr _read_headers                                                                                          zUnpacker._read_headerc s|\}}}|tkr,|tkr(td|S|tkrH|tkrDtd|S|tkr|tkrtt|D]}tq`dSt |}t|D]}| t qj dk r |}j r|St|S|tkr|tkrt|D]}ttqdSjdk r"fddt|D}ni}t|D]j}t }jrjt|ttfkrjtdtt|tst|tkrt|}t ||<q.jdk r|}|S|tkrdS|tkrjrt|}n|dj}|S|tkrt|S|tkrv|dkrft t|} j!dkr8| "Sj!d krL| #Sj!d kr`| $S| Sn%|t|S|t&kst'|S) NzExpected arrayz Expected mapc3s"|]}ttfVqdSr)rE EX_CONSTRUCT).0_r)rr sz#Unpacker._unpack..z%s is not allowed for map keyutf_8rVrrr )(rEX_READ_ARRAY_HEADERrr?EX_READ_MAP_HEADERrEX_SKIPxrangerErrrrirgr<rkrer;unicoder&rPY2sysinternrjrrddecoderfrrr7 from_bytesrhto_unix to_unix_nano to_datetimerlrr) r rrrr9rrLrkeytsrr)r rEos                         zUnpacker._unpackcCs|Srrr)rrr __iter__szUnpacker.__iter__cCsTz|t}||WStk r8|tYntk rNtYnXdSr)rErrr2 StopIterationrFr5r rLrrr __next__s zUnpacker.__next__cCs|t|dSr)rErrr)rrr skips z Unpacker.skipcCs4z|t}Wntk r&tYnX||Sr)rErrFr5rrrrr unpacks  zUnpacker.unpackcCs|t}||Sr)rErrrrrr read_array_headers zUnpacker.read_array_headercCs|t}||Sr)rErrrrrr read_map_headers zUnpacker.read_map_headercCs|jSr)rrr)rrr tellsz Unpacker.tell)r+r,r-__doc__r6r"rDrrGrHrrrrrrErrnextrrrrrrrrr rCsJa ] U M rCc@seZdZdZd#ddZeeefddZd d Z d d Z d dZ ddZ ddZ ddZddZefddZddZddZddZdd Zd!d"ZdS)$Packerag 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. (default: True) :param bool strict_types: If set to true, types will be checked to be exact. Derived classes from serializable 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 bool datetime: If set to true, datetime with tzinfo is packed into Timestamp type. Note that the tzinfo is stripped in the timestamp. You can get UTC datetime with `timestamp=3` option of the Unpacker. (Python 2 is not supported). :param str unicode_errors: The error handler for encoding unicode. (default: 'strict') DO NOT USE THIS!! This option is kept for very specific usage. NFTcCsf||_||_||_||_t|_tr0|r0tdt||_ |p@d|_ |dk r\t |s\t d||_ dS)Nz%datetime is not supported in Python 2rWzdefault must be callable) _strict_types _use_float _autoreset _use_bin_typerr]rr?rc _datetimerfrYr[_default)r defaultuse_single_float autoreset use_bin_type strict_typesrr{rrr r"s   zPacker.__init__c Csd}|jr|}t}nttf}|dkr,td|dkr@|jdS||trf|rZ|jdS|jdS||trd|krdkrnn|jt d|Sd |krdkrnn|jt d |Sd|krd krnn|jt d d |Sd|krdkr*nn|jt dd|Sd |krBdkr\nn|jt dd|Sd|krtdkrnn|jt dd|Sd|krdkrnn|jt dd|Sd|krdkrnn|jt dd|Sd|kr dkr$nn|jt dd|Sd |krNFrzrecursion limit exceededrBirSrBBriz>Bbr>BHriz>Bhr>BIriz>Birlz>BQrlz>BqrTzInteger value out of rangez%s is too largezutf-8zString is too largezMemoryview is too largez>Bfrz>BdrrVrrr8rr>BBrrrzCannot serialize %r),rlistr<r?r]r'rc int_typesrPpackr OverflowErrorr&r%rr;r+_pack_bin_headerrencoderf_pack_raw_headerr#r>floatrr6r7to_bytescodedatarintr_pack_array_headerr_packdict_pack_map_pairsr r _DateTime from_datetimer[) r r9 nest_limitcheckcheck_type_strict default_used list_typesrrrrrrrr r,s                                  z Packer._packcCsFz||Wnt|_YnX|jrB|j}t|_|SdSr)rrr]rr*)r r9rLrrr r s z Packer.packcCs0|t|||jr,|j}t|_|SdSr)rrrr]r*r)r pairsrLrrr pack_map_pairss  zPacker.pack_map_pairscCs6|dkr t|||jr2|j}t|_|SdSNr)r?rrr]r*rrrrr pack_array_headers  zPacker.pack_array_headercCs6|dkr t|||jr2|j}t|_|SdSr")r?_pack_map_headerrr]r*rrrrr pack_map_headers  zPacker.pack_map_headercCsJt|tstdd|kr&dks0ntdt|tsBtdt|}|dkrZtd|dkrp|jd n|d kr|jd n|d kr|jd n|dkr|jdnt|dkr|jdn^|dkr|jdt d|n<|dkr|jdt d|n|jdt d||jt d||j|dS)Nztypecode must have int type.rztypecode should be 0-127zdata must have bytes typerzToo large datarrrrr8rrrrrrrrrr) rrr[r?r&rr]r'rPr )r typecoderrrrr pack_ext_types4   zPacker.pack_ext_typecCsh|dkr |jtdd|S|dkr>|jtdd|S|dkr\|jtdd |Std dS) NrrrrrrrrrzArray is too larger]r'rPr r?r rrrr rszPacker._pack_array_headercCsh|dkr |jtdd|S|dkr>|jtdd|S|dkr\|jtdd |Std dS) NrrrrrrrrrzDict is too larger,r-rrr r$szPacker._pack_map_headercCs<|||D](\}}|||d|||dqdS)Nr)r$r)r rr rkvrrr rs  zPacker._pack_map_pairscCs|dkr"|jtdd|nn|jrH|dkrH|jtdd|nH|dkrh|jtdd |n(|d kr|jtd d |ntd dS)NrrrrrrrrrrrrzRaw is too large)r]r'rPr rr?r-rrr rszPacker._pack_raw_headercCsv|js||S|dkr.|jtdd|S|dkrL|jtdd|S|dkrj|jtdd |Std dS) NrrrrrrrrrzBin is too large)rrr]r'rPr r?r-rrr r  s zPacker._pack_bin_headercCs |jS)z/Return internal buffer contents as bytes object)r]r*r)rrr r&sz Packer.bytescCs t|_dS)zYReset internal buffer. This method is useful only when autoreset=False. N)rr]r)rrr resetsz Packer.resetcCs"tstrt|S|jSdS)zReturn view of internal buffer.N)USING_STRINGBUILDERrr#r&r] getbufferr)rrr r2"s zPacker.getbuffer)NFTTFFN)r+r,r-rr"DEFAULT_RECURSE_LIMITrr=rr r!r#r%r+rr$rrr r&r0r2rrrr rs4/  z       r)r);rrrrrP version_inforrlongr r rrranger RuntimeErrorrFrhasattrZ__pypy__rZ__pypy__.buildersrr ImportErrorr1objectrior. exceptionsr1r2r3r4r5extr6r7rrrrrrrrrrr3r;r<r=rArMrUrQrCrrrrr sf         R