Re @s\dZddlmZddlZddlZejddkZerbeefZ ddZ neZ e Z e ZddZ ejdd fkreZd d Zn d d Zeed r-ddlmZyddlmZWn"ek r ddlmZYnXdZGdddeZn"dZddlmZddZddlmZm Z m!Z!m"Z"m#Z#ddl$m%Z%m&Z&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/d Z0dZ1e2e3ddZ4dd Z5d!d"Z6ejdd#d$fkr#dd%d&Z7n ej8Z7Gd'd(d(eZ9Gd)d*d*eZ:dS)+z.Fallback pure Python implementation of msgpack)datetimeNcCs |jS)N) iteritems)dr/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/msgpack/fallback.pydict_iteritems srcCs |jS)N)items)rrrrrscCs?t|jdko>t|jdto>|jdjdS)Nrz maximum recursion depth exceeded)lenargs isinstancestr startswith)errr_is_recursionerrorsrcCsdS)NTr)rrrrr'spypy_version_info) newlist_hint) BytesBuilder) StringBuilderTc@s7eZdZdddZddZddZdS) StringIOcCs>|r.tt||_|jj|n t|_dS)N)rr builderappend)selfsrrr__init__7szStringIO.__init__cCsMt|tr|j}nt|tr9t|}|jj|dS)N)r memoryviewtobytes bytearraybytesrr)rrrrrwrite>s  zStringIO.writecCs |jjS)N)rbuild)rrrrgetvalueEszStringIO.getvalueN)__name__ __module__ __qualname__rr#r%rrrrr6s  rF)BytesIOcCsgS)Nr)sizerrrMsr+r ) BufferFull OutOfData ExtraData FormatError StackError)ExtType TimestampicCs6|||kr"|||kS|||kSdS)Nr)objttypetuplerrr_check_type_strictdsr8cCs+t|}|jdkr'td|S)Nr z$cannot unpack from multi-byte object)ritemsize ValueError)r4viewrrr_get_data_from_bufferks  r<cKstddt||}|j|y|j}WnWtk rXtdYn:tk r}zt|r|tWYdd}~XnX|j rt ||j |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) Unpackerr feed_unpackr-r:RecursionErrorrr0_got_extradatar._get_extradata)packedkwargsunpackerretrrrrunpackbrs     rHcCstj|t||S)z0Explicit type cast for legacy struct.unpack_from)struct unpack_fromr")fborrr _unpack_fromsrPc@s!eZdZdZddddddddddd,ed-d.d/d0d1d d Zd d Zd dZddZddZ ddZ ddZ ddZ e ddZe ddZddZdd ZeZd!d"Zd#d$Zd%d&Zd'd(Zd)d*ZdS)2r>a 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. NrTFdir cCs| dkrd} |dkr*d|_n-t|jsEtd||_d|_t|_d|_d|_| sd} | dkr| } |dkr| }|dkr| }|dkr| d}|dkr| }| |_ ||j krt d |pt |j d|_ t ||_t ||_| |_||_d|koed knsvt d ||_| |_||_||_| |_| |_||_||_||_||_d|_| dk rt|  rtd|dk r#t| r#td|dk rHt| rHtd|dk rl|dk rltdt| stddS)NstrictTz!`file_like.read` must be callableFrrr z.read_size must be smaller than max_buffer_sizeir 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 callablelirUrUrUrUi@)_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)rrZ read_sizeuse_listraw timestampstrict_map_key object_hookobject_pairs_hook list_hookunicode_errorsr=ext_hook max_str_len max_bin_len max_array_len max_map_len max_ext_lenrrrrsn                                   zUnpacker.__init__cCs|jstt|}t|j|jt||jkrJt|jdkr|jd|j=|j|j8_d|_|jj |dS)Nr) rVAssertionErrorr<r r[r\r^r,r]extend)r next_bytesr;rrrr?Us ) z Unpacker.feedcCs)|j|j|j7_|j|_dS)z+ Gets rid of the used parts of the buffer. N)rpr\r])rrrr_consumedszUnpacker._consumecCs|jt|jkS)N)r\r r[)rrrrrBiszUnpacker._got_extradatacCs|j|jdS)N)r[r\)rrrrrClszUnpacker._get_extradatacCs|j|}|j|S)N)_readr)rnrGrrr read_bytesos zUnpacker.read_bytescCs8|j||j}|||_|j|||S)N)_reserver\r[)rrirrrrts   zUnpacker._readcCs*t|j|j|}|dkr*dS|jrE|j|_t|jdkr|jd|j=|j|j8_d|_| }xo|dkrt|j|}|jj |}|sPt |t st |j|7_|t|8}qWt|j||jkr&d|_tdS)Nr) r r[r\rVr]r-maxr`rZrXrr"r)rr remain_bytes to_read_bytes read_datarrrr{s,     zUnpacker._reservecCs t}d}d}|jd|j|j}|jd7_|d@dkrW|}n |d@dkrxdK|dA}n |d@dkr|d@}t}||jkrtd||j|j|}n. |d @d kr|d @}t}||j kr td ||j n |d @dkr\|d @}t }||j kr td ||j n |dkrqd}n |dkrd}nv |dkrd}na |dkrt }|jd|j|j}|jd7_||j krtd||j f|j|}n |dkrt }|jdtd|j|jd}|jd7_||j krtd||j f|j|}ne |dkrt }|jdtd|j|jd}|jd7_||j kr td||j f|j|}n |dkrt}|jdtd|j|j\}}|jd7_||jkrtd||jf|j|}n[ |dkr't}|jdtd |j|j\}}|jd7_||jkrtd||jf|j|}n|d!krt}|jd"td#|j|j\}}|jd"7_||jkrtd||jf|j|}nO|d$kr|jdtd%|j|jd}|jd7_n|d&kr;|jd'td(|j|jd}|jd'7_n|d)krv|jd|j|j}|jd7_n|d*kr|jdtd|j|jd}|jd7_n?|d+kr|jdtd|j|jd}|jd7_n|d,krK|jd'td-|j|jd}|jd'7_n|d.kr|jdtd/|j|jd}|jd7_nj|d0kr|jdtd1|j|jd}|jd7_n#|d2kr |jdtd3|j|jd}|jd7_n|d4krg|jd'td5|j|jd}|jd'7_n|d6krt}|jdkrtdd|jf|jdtd7|j|j\}}|jd7_n|d8krUt}|jdkrtdd|jf|jdtd9|j|j\}}|jd7_n|d:krt}|jdkrtdd|jf|jd"td;|j|j\}}|jd"7_n0|d<krC t}|jd'kr tdd'|jf|jd=td>|j|j\}}|jd=7_n|d?kr t}|jd@kr} tdd@|jf|jdAtdB|j|j\}}|jdA7_nB|dCkr. t}|jd|j|j}|jd7_||jkr td||j|j|}n|dDkr t}|jdtd|j|j\}|jd7_||jkr td||j|j|}nO|dEkr, t}|jdtd|j|j\}|jd7_||jkr td||j|j|}n|dFkr t}|jdtd|j|j\}|jd7_||j kr td ||j n`|dGkr t}|jdtd|j|j\}|jd7_||j kr td ||j n|dHkr| |jdtd|j|j\}|jd7_||j krs td ||j t }n|dIkr |jdtd|j|j\}|jd7_||j kr td ||j t }ntdJ||||fS)LNrr rSz%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)rz>Hr3z>IBbz%s exceeds max_ext_len(%s)r z>Hbr z>Ibz>fz>dz>QrNz>hz>iz>qb1sb2sb4s b8srTb16szUnknown header: 0x%xrU)TYPE_IMMEDIATErr[r\TYPE_RAWrkr:r TYPE_ARRAYrmTYPE_MAPrnTYPE_BINrlrPTYPE_EXTror/)rexecutetyprr4rNLrrr _read_headers                                                                     zUnpacker._read_headerc sqj|\}}}|tkr@|tkr<td|S|tkrh|tkrdtd|S|tkr|tkrx!t|D]}jtqWdSt |}x*t|D]}|j jt qWj dk rj |}j r |St|S|tkrc|tkrcx.t|D] }jtjtq;WdSjdk rjfddt|D}ni}xt|D]}jt }jrt|ttfkrtdtt|t r*t|tkr*tj|}jt ||| j$S| Snj%|t|S|t&ksmt'|S) NzExpected arrayz Expected mapc3s-|]#}jtjtfVqdS)N)r@ EX_CONSTRUCT).0_)rrr sz#Unpacker._unpack..z%s is not allowed for map keyutf_8r rr rU)(rEX_READ_ARRAY_HEADERrr:EX_READ_MAP_HEADERrEX_SKIPxranger@rrrrgrer7rircr6unicoder"rPY2sysinternrhrrbdecoderdrrr2 from_bytesrfto_unix to_unix_nano to_datetimerjrr) rrrrr4rrGrkeytsr)rrr@os            !          zUnpacker._unpackcCs|S)Nr)rrrr__iter__szUnpacker.__iter__c Csay!|jt}|j|SWn9tk rE|jtYntk r\tYnXdS)N)r@rrr- StopIterationrAr0)rrGrrr__next__s     zUnpacker.__next__cCs|jt|jdS)N)r@rr)rrrrskips z Unpacker.skipc Cs<y|jt}Wntk r-tYnX|j|S)N)r@rrAr0r)rrGrrrunpacks    zUnpacker.unpackcCs|jt}|j|S)N)r@rr)rrGrrrread_array_headers zUnpacker.read_array_headercCs|jt}|j|S)N)r@rr)rrGrrrread_map_headers zUnpacker.read_map_headercCs|jS)N)rp)rrrrtellsz Unpacker.tellii@rUrUrUrUrU)r&r'r(__doc__r1rr?rrBrCrrrrrr@rrnextrrrrrrrrrr>sF ^K       M      r>c @seZdZdZdddddddddZeeeddZd d Z d d Z d dZ ddZ ddZ ddZddZeddZddZddZddZdd 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. NFTcCs||_||_||_||_t|_trH|rHtdt||_ |p`d|_ |dk rt |st d||_ dS)Nz%datetime is not supported in Python 2rRzdefault must be callable) _strict_types _use_float _autoreset _use_bin_typerr[rr:ra _datetimerdrWrY_default)rdefaultuse_single_float autoreset use_bin_type strict_typesrryrrrrs          zPacker.__init__c Csid}|jr|}t}n ttf}x8|dkrEtd|dkra|jjdS||tr|r|jjdS|jjdS||tr'd|kodknr|jjtj d|Sd;|kodknr|jjtj d |Sd|ko,d knrP|jjtj d d |Sd<|kogdknr|jjtj dd|Sd |kodknr|jjtj dd|Sd=|kod>knr|jjtj dd|Sd|kodknr<|jjtj dd|Sd?|koSd@knrw|jjtj dd|Sd|kodknr|jjtj dd|SdA|kodBknr|jjtj d d!|S| r|j dk r|j |}d"}q-t d#||t t frt|}|dCkrmtd%t|j|j||jj|S||tr|jd&|j}t|}|dDkrtd'|j||jj|S||trFt||j}|dEkr)td(|j||jj|S||tr|jr}|jjtj d)d*|S|jjtj d+d,|S||ttfrc||trdF}|j} n|j}|j} t|t st!t| t st!t| } | d-kr<|jjd.n| d$kr[|jjd/n| d0krz|jjd1n| d2kr|jjd3n| d4kr|jjd5n{| d kr|jjtj d6d7| nM| dkr|jjtj dd8| n|jjtj dd9| |jjtj d ||jj| dS|||rt|}|j"|x,t#|D]} |j$|| |d-qWdS||t%r|j&t|t'||d-S|j(r ||t)r tj*|}d-}q-| rN|j dk rN|j |}d-}q-t+d:|fq-WdS)GNFrzrecursion limit exceededsssrB rNrBBrz>Bbriz>BHriz>Bhrlz>BIrlz>Birlz>BQrlz>BqrTzInteger value out of rangerz%s is too largezutf-8zString is too largezMemoryview is too largez>Bfrz>Bdrr ssr3srsrTsz>BBrrrzCannot serialize %riiiiiililllrU),rlistr7r:r[r#ra int_typesrKpackr OverflowErrorr"r!r r6r&_pack_bin_headerrencoderd_pack_raw_headerrr9floatrr1r2to_bytescodedatarintr_pack_array_headerr_packdict_pack_map_pairsrr _DateTime from_datetimerY) rr4 nest_limitcheckcheck_type_strict default_used list_typesrrrrrrrrr,s                           " "  z Packer._packc CsWy|j|Wnt|_YnX|jrS|jj}t|_|SdS)N)rrr[rr%)rr4rGrrrrs   z Packer.packcCsB|jt|||jr>|jj}t|_|SdS)N)rr rr[r%r)rpairsrGrrrpack_map_pairss   zPacker.pack_map_pairscCsK|dkrt|j||jrG|jj}t|_|SdS)Nrrl)r:rrr[r%r)rrrGrrrpack_array_headers    zPacker.pack_array_headercCsK|dkrt|j||jrG|jj}t|_|SdS)Nrrl)r:_pack_map_headerrr[r%r)rrrGrrrpack_map_headers    zPacker.pack_map_headercCst|tstdd|ko2dknsCtdt|ts^tdt|}|dkrtd|dkr|jjd n|d kr|jjd n|d kr|jjd n|dkr|jjdn|dkr|jjdn~|dkrL|jjdtj d|nO|dkr{|jjdtj d|n |jjdtj d||jjtj d||jj|dS)Nztypecode must have int type.rztypecode should be 0-127zdata must have bytes typelzToo large datar srsr3srsrTsrsrisz>Hsz>I) rrrYr:r"r r[r#rKr)rtypecoderrrrr pack_ext_types4            # # zPacker.pack_ext_typecCs|dkr,|jjtjdd|S|dkrW|jjtjdd|S|dkr|jjtjdd |Std dS) Nrrriz>BHrlz>BIrzArray is too large)r[r#rKrr:)rrrrrrs    zPacker._pack_array_headercCs|dkr,|jjtjdd|S|dkrW|jjtjdd|S|dkr|jjtjdd |Std dS) Nrrriz>BHrlz>BIrzDict is too large)r[r#rKrr:)rrrrrr s    zPacker._pack_map_headercCsP|j|x<|D]4\}}|j||d|j||dqWdS)Nr )r r)rrr rkvrrrrs zPacker._pack_map_pairscCs|dkr/|jjtjdd|n|jrf|dkrf|jjtjdd|nh|dkr|jjtjdd |n:|d kr|jjtjd d |n td dS)NrSrrrz>BBriz>BHrlz>BIrzRaw is too large)r[r#rKrrr:)rrrrrrs #" " "zPacker._pack_raw_headercCs|js|j|S|dkrA|jjtjdd|S|dkrl|jjtjdd|S|dkr|jjtjdd |Std dS) Nrz>BBriz>BHrlz>BIrzBin is too large)rrr[r#rKrr:)rrrrrr s     zPacker._pack_bin_headercCs |jjS)z/Return internal buffer contents as bytes object)r[r%)rrrrr"sz Packer.bytescCst|_dS)zYReset internal buffer. This method is useful only when autoreset=False. N)rr[)rrrrresetsz Packer.resetcCs-ts trt|jS|jjSdS)zReturn view of internal buffer.N)USING_STRINGBUILDERrrr"r[ getbuffer)rrrrr"s zPacker.getbuffer)r&r'r(rrDEFAULT_RECURSE_LIMITrr8rrr r rrrr rrrr"rrrrrrrs0 ,u     r);rrrrrK version_inforrlongrrrrranger RuntimeErrorrArhasattrZ__pypy__rZ__pypy__.buildersrr ImportErrorrobjectrior) exceptionsr,r-r.r/r0extr1r2rrrrrrrrrrrr6r7r8r<rHrPrLr>rrrrrsb       (   P