U .eN@sdZddlZddlZddlZejddkr@dZeefZddZ ndZeZe Z e Z ddZ ejd krpeZd d Znd d Zeed rddlmZzddlmZWn ek rddlmZYnXdZGdddeZndZddlmZddZddlmZmZm Z m!Z!m"Z"ddl#m$Z$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/e0e1fddZ2dd Z3d!d"Z4d#d$Z5ejd%krd,d&d'Z6nej7Z6Gd(d)d)eZ8Gd*d+d+eZ9dS)-z.Fallback pure Python implementation of msgpackNTcCs|SN)Z iteritemsdr@/usr/lib/python3.8/site-packages/pip/_vendor/msgpack/fallback.pydict_iteritems srFcCs|Sr)itemsrrrrrs)cCs.t|jdko,t|jdto,|jddS)Nrz maximum recursion depth exceeded)lenargs isinstancestr startswitherrr_is_recursionerrorsrcCsdS)NTrrrrrrsZpypy_version_info) newlist_hint) BytesBuilder) StringBuilderc@s&eZdZd ddZddZddZdS) StringIOcCs,|r tt||_|j|nt|_dSr)rr builderappendselfsrrr__init__*szStringIO.__init__cCs6t|tr|}nt|tr&t|}|j|dSr)r memoryviewtobytes bytearraybytesrrrrrrwrite0s    zStringIO.writecCs |jSr)rZbuildrrrrgetvalue6szStringIO.getvalueN)r)__name__ __module__ __qualname__rr$r&rrrrr)s r)BytesIOcCsgSrr)sizerrr;rr,r ) BufferFull OutOfData ExtraData FormatError StackError)ExtTyper r icCs(|||kr|||kS|||kSdSrr)objttypetuplerrr_check_type_strictXs  r8cCsdz t|}Wn@tk rLtrFtt|}tjdt|tddnYnX|jdkr`t d|S)Nzusing old buffer interface to unpack %s; this leads to unpacking errors if slicing is used and will be removed in a future versionr  stacklevelr z$cannot unpack from multi-byte object) r TypeErrorPY2bufferwarningswarnr6RuntimeWarningitemsize ValueError)r4viewrrr_get_data_from_buffer_s   rDcKs$tjdtdd|}t|f|S)NzbDirect calling implementation's unpack() is deprecated, Use msgpack.unpack() or unpackb() instead.rr9)r>r?DeprecationWarningreadunpackb)streamkwargsdatarrrunpackqsrKc 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) Unpackerr feed_unpackr.rBRecursionErrorrr1_got_extradatar/_get_extradata)ZpackedrIZunpackerretrrrrrGys    rG)rcCst|t||S)z.Explicit typcast for legacy struct.unpack_from)struct unpack_fromr#)fborrr _unpack_fromsr[c@seZdZdZdddddddddddedddddfddZd d Zd d Zd dZddZ ddZ ddZ ddZ e fddZe fddZddZddZeZdd Zd!d"Zd#d$Zd%d&Zd'd(ZdS))rMa 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. NrTFcCs| dk rtjdtdd| dkr$d} |dkr4d|_nt|jsFtd||_d|_t|_ d|_ d|_ | d krv| ptd } |d kr| pd }|d kr| pd }|d kr| dpd }|d kr| pd }| pd |_ ||j krt d|pt|j d|_t||_t||_| |_| |_||_||_||_||_| |_| |_||_||_||_||_d|_|dk rft|sftd|dk rt|std|dk rt|std|dk r|dk rtdt| stddS)N.encoding is deprecated, Use raw=False instead.rr9strictTz!`file_like.read` must be callableFrr\iiiiz.read_size must be smaller than max_buffer_sizei@z`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) r>r?rE_feedingcallablerFr; file_liker"_buffer_buff_i_buf_checkpoint_max_buffer_sizerBmin _read_sizebool_raw_strict_map_key _encoding_unicode_errors _use_list _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)rraZ read_sizeZuse_listrawZstrict_map_keyZ object_hookZobject_pairs_hookZ list_hookencodingunicode_errorsrLZext_hookZ max_str_lenZ max_bin_lenZ max_array_lenZ max_map_lenZ max_ext_lenrrrrsp         zUnpacker.__init__cCsr|js tt|}t|j|jt||jkr4t|jdkrb|jd|j=|j|j8_d|_|j |dSNr) r_AssertionErrorrDr rbrcrer-rdextend)rZ next_bytesrCrrrrNPs  z Unpacker.feedcCs"|j|j|j7_|j|_dS)z+ Gets rid of the used parts of the buffer. N)rwrcrdr%rrr_consume_szUnpacker._consumecCs|jt|jkSr)rcr rbr%rrrrQdszUnpacker._got_extradatacCs|j|jdSr)rbrcr%rrrrRgszUnpacker._get_extradatacCs ||Sr)_readrnrrr read_bytesjszUnpacker.read_bytescCs,|||j}|||_|j|||Sr)_reservercrb)rrirrrrms  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{) r rbrcr_rdr.maxrgrarFrr#r|)rrZ remain_bytesZ to_read_bytesZ read_datarrrrts,   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)LNrr r\z%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>Hr3>IZBbz%s exceeds max_ext_len(%s)r z>Hbr z>Ibz>fz>dz>QrYz>hz>iz>qZb1sZb2sZb4s Zb8sZb16szUnknown header: 0x%x)TYPE_IMMEDIATErrbrcTYPE_RAWrrrBr TYPE_ARRAYrtTYPE_MAPruTYPE_BINrsr[TYPE_EXTrvr0)rexecutetyprr4rYLrrr _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}npi}t|D]L}t }jrjt|ttfkrjtdtt|t ||<q.jdk r|}|S|tkrdS|tkrjdk r|jj}njrt|}n |d}|S|tkr|t|S|tkrt|S|tks&t|S)NzExpected arrayz Expected mapc3s"|]}ttfVqdSr)rO EX_CONSTRUCT).0_r%rr sz#Unpacker._unpack..z%s is not allowed for map keyutf_8) rEX_READ_ARRAY_HEADERrrBEX_READ_MAP_HEADERrEX_SKIPxrangerOrrrrnrmr7rprjr6unicoder#rrorrkdecoderlrirrqrrr|) rrrrr4rrSrkeyrr%rrOhsl                      zUnpacker._unpackcCs|Srrr%rrr__iter__szUnpacker.__iter__cCsTz|t}||WStk r8|tYntk rNtYnXdSr)rOrr~r. StopIterationrPr1rrSrrr__next__s zUnpacker.__next__cCs|t|dSr)rOrr~r%rrrskips z Unpacker.skipcCs4z|t}Wntk r&tYnX||Sr)rOrrPr1r~rrrrrKs  zUnpacker.unpackcCs|t}||Sr)rOrr~rrrrread_array_headers zUnpacker.read_array_headercCs|t}||Sr)rOrr~rrrrread_map_headers zUnpacker.read_map_headercCs|jSr)rwr%rrrtellsz Unpacker.tell)r'r(r)__doc__r2rrNr~rQrRrrrrrrOrrnextrrKrrrrrrrrMsBa  R U @ rMc@seZdZdZd#ddZeeefddZd d Z d d Z d dZ ddZ ddZ ddZddZefddZddZddZddZdd Zd!d"ZdS)$Packerah 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') NFTcCsx|dkrd}ntjdtdd|dkr*d}||_||_||_||_||_||_t |_ |dk rnt |snt d||_ dS)Nrr]rr9r^zdefault must be callable)r>r?rE _strict_types _use_float _autoreset _use_bin_typerkrlrrbr`r;_default)rdefaultryrzZuse_single_floatZ autoresetZ use_bin_typeZ strict_typesrrrrs(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 |krBbr>BHriz>Bhr>BIriz>Birlz>BQrlz>BqrTzInteger value out of rangez%s is too largez5Can't encode unicode string: no encoding is specifiedzString is too largezMemoryview is too largez>Bfrz>Bdrr rr3rr>BBrrrzCannot serialize %r)(rlistr7rBrbr$rh int_typesrVpackr OverflowErrorr#r"r r6r'_pack_bin_headerrrkr;encoderl_pack_raw_headerr rAfloatrr2coderJrintr|_pack_array_headerr_packdict_pack_map_pairsr) rr4 nest_limitZcheckZcheck_type_strictZ default_usedZ list_typesrrrJrrrrrrs                                 z Packer._packcCsFz||Wnt|_YnX|jrB|j}t|_|SdSr)rrrbrr&)rr4rSrrrrs z Packer.packcCs0|t|||jr,|j}t|_|SdSr)rr rrbr&r)rpairsrSrrrpack_map_pairss  zPacker.pack_map_pairscCs6|dkr t|||jr2|j}t|_|SdSNr)rBrrrbr&rrrrSrrrpack_array_headers  zPacker.pack_array_headercCs6|dkr t|||jr2|j}t|_|SdSr)rB_pack_map_headerrrbr&rrrrrpack_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 datar rrrr3rrrrrrrrrr) rrr;rBr#r rbr$rVr)rtypecoderJrrrr pack_ext_types4   zPacker.pack_ext_typecCsh|dkr |jtdd|S|dkr>|jtdd|S|dkr\|jtdd |Std dS) NrrrrrrrrrzArray is too largerbr$rVrrBrrrrrszPacker._pack_array_headercCsh|dkr |jtdd|S|dkr>|jtdd|S|dkr\|jtdd |Std dS) NrrrrrrrrrzDict is too largerrrrrrszPacker._pack_map_headercCs<|||D](\}}|||d|||dqdS)Nr )rr)rrrrkvrrrrs  zPacker._pack_map_pairscCs|dkr"|jtdd|nn|jrH|dkrH|jtdd|nH|dkrh|jtdd |n(|d kr|jtd d |ntd dS)NrrrrrrrrrrrrzRaw is too large)rbr$rVrrrBrrrrrszPacker._pack_raw_headercCsv|js||S|dkr.|jtdd|S|dkrL|jtdd|S|dkrj|jtdd |Std dS) NrrrrrrrrrzBin is too large)rrrbr$rVrrBrrrrrs zPacker._pack_bin_headercCs |jS)z/Return internal buffer contents as bytes object)rbr&r%rrrr#sz Packer.bytescCs t|_dS)zYReset internal buffer. This method is usaful only when autoreset=False. N)rrbr%rrrresetsz Packer.resetcCs"tstrt|S|jSdS)zReturn view of internal buffer.N)USING_STRINGBUILDERr<r r#rb getbufferr%rrrr s zPacker.getbuffer)NNNFTFF)r'r(r)rrDEFAULT_RECURSE_LIMITrr8rrrrrrrrrrrr#rr rrrrrs0(  n       r)r):rsysrVr> version_infor<rZlongrrrrranger RuntimeErrorrPrhasattrZ__pypy__rZ__pypy__.buildersrr ImportErrorr objectrior* exceptionsr-r.r/r0r1r2rrrrrrrrrrr r6r7r8rDrKrGr[rWrMrrrrrsj         :