B ïY6dŠâã @sdZddlmZddlmZddlmZmZmZddlm Z ddl m Z ddl Z ddl m Z dd lmZmZddlZddlZddlZddlZd d d d dddddg ZeefZdZdddddddgZdZdZGdd „d eƒZGdd „d eƒZGdd „d eƒZ Gdd „d eƒZ!ydd!l"m#Z#Wne$k r2dZ#YnXd"Z%d#Z&d$Z'd%Z(d&Z)d'Z*d(Z+d)Z,d*Z-d+Z.d,Z/d-Z0d.Z1d/Z2d0Z3d1Z4d2Z5d3Z6d4Z7d5Z8d6Z9d7Z:d8Z;d9ZdZAd?ZBd@ZCdAZDdBZEdCZFdDZGdEZHdFZIdGZJdHZKdIZLdJZMdKZNdLZOdMZPdNZQdOZRdPZSdQZTdRZUdSZVdTZWdUZXdVZYdWZZdXZ[eKeUeVeWgZ\dYZ]dZZ^d[Z_d\Z`d]Zad^Zbd_Zcd`ZddaZedbZfdcZgddZhe idedf„ejƒDƒ¡Gdgdh„dhƒZkGdidj„djƒZldkdl„Zmdmdn„Zndodp„Zodqdr„ZpGdsdt„dtƒZqGdudv„dvƒZrd–dwdxœdydz„Zsd—dwdxœd{d|„Ztdwd}d~dœd€d„Zudwd}d~dœd‚dƒ„Zvy0dd„lwmZmZm Z mxZxmyZymzZzm{Z{m|Z|m}Z}Wn4e$k rbeqerZxZyeseteuevf\ZzZ{Z|Z}YnXd…d†„Z~ed‡krddl€Z€e€jdˆd‰Z‚e‚jƒdŠe€ „d‹¡dŒddŽe‚jƒddd‘d’d“e‚jƒd”d‘d•d“e‚ …¡Z†e†j‡rÜe~ƒn>e†jˆsîe‚ ‰¡n,ddlŠZŠx"e†jˆD]Z‹e|e‹ƒZŒeŠ ŠeŒ¡qþWdS)˜a Create portable serialized representations of Python objects. See module copyreg for a mechanism for registering custom picklers. See module pickletools source for extensive comments. Classes: Pickler Unpickler Functions: dump(object, file) dumps(object) -> string load(file) -> object loads(string) -> object Misc variables: __version__ format_version compatible_formats é)Ú FunctionType)Údispatch_table)Ú_extension_registryÚ_inverted_registryÚ_extension_cache)Úislice)ÚpartialN)Úmaxsize)ÚpackÚunpackÚ PickleErrorÚ PicklingErrorÚUnpicklingErrorÚPicklerÚ UnpicklerÚdumpÚdumpsÚloadÚloadsz4.0z1.0z1.1z1.2z1.3z2.0z3.0ééc@seZdZdZdS)r z6A common base class for the other pickling exceptions.N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©rrú"/usr/local/lib/python3.7/pickle.pyr @sc@seZdZdZdS)r z]This exception is raised when an unpicklable object is passed to the dump() method. N)rrrrrrrrr Dsc@seZdZdZdS)raThis exception is raised when there is a problem unpickling an object, such as a security violation. Note that other exceptions may also be raised during unpickling, including (but not necessarily limited to) AttributeError, EOFError, ImportError, and IndexError. N)rrrrrrrrrKsc@seZdZdd„ZdS)Ú_StopcCs ||_dS)N)Úvalue)ÚselfrrrrÚ__init__Ysz_Stop.__init__N)rrrr rrrrrXsr)Ú PyStringMapó(ó.ó0ó1ó2óFóIóJóKóLóMóNóPóQóRóSóTóUóVóXóaóbócódó}óeógóhóiójóló]óoópóqórósótó)óuóGsI01 sI00 ó€óó‚óƒó„ó…ó†ó‡óˆó‰óŠó‹óBóCóŒóóŽóóó‘ó’ó“ó”ó•cCsg|]}t d|¡r|‘qS)z[A-Z][A-Z0-9_]+$)ÚreÚmatch)Ú.0Úxrrrú µsrgc@sFeZdZdZdZdd„Zdd„Zdd„Zdd d „Zd d „Z dd„Z dS)Ú_FramerricCs||_d|_dS)N)Ú file_writeÚ current_frame)rrirrrr ½sz_Framer.__init__cCst ¡|_dS)N)ÚioÚBytesIOrj)rrrrÚ start_framingÁsz_Framer.start_framingcCs*|jr&|j ¡dkr&|jddd|_dS)NrT)Úforce)rjÚtellÚ commit_frame)rrrrÚ end_framingÄs z_Framer.end_framingFcCsf|jrb|j}| ¡|jks|rb| ¡}|j}t|ƒ|jkrP|ttdt|ƒƒƒ||ƒt   ¡|_dS)Nzz&Can't get local attribute {!r} on {!r}z Can't get attribute {!r} on {!r})ÚsplitÚAttributeErrorÚformatÚgetattr)ÚobjÚnameZsubpathÚparentrrrÚ _getattribute!s rc Cszt|ddƒ}|dk r|Sx\ttj ¡ƒD]J\}}|dks(|dkrBq(yt||ƒd|krZ|SWq(tk rpYq(Xq(WdS)z$Find the module an object belong to.rNÚ__main__r)r‹ÚlistÚsysÚmodulesÚitemsrr‰)rŒrÚ module_nameÚmodulerrrÚ whichmodule.s  r—cCsh|dkr dS| ¡d?d}|j|ddd}|dkrd|dkrd|dd krd|d d @dkrd|d d…}|S) aÒEncode a long to a two's complement little-endian binary string. Note that 0 is a special case, returning an empty string, to save a byte in the LONG1 pickling context. >>> encode_long(0) b'' >>> encode_long(255) b'\xff\x00' >>> encode_long(32767) b'\xff\x7f' >>> encode_long(-256) b'\x00\xff' >>> encode_long(-32768) b'\x00\x80' >>> encode_long(-128) b'\x80' >>> encode_long(127) b'\x7f' >>> rr„réÚlittleT)Ú byteorderÚsignedréÿéþÿÿÿé€N)Ú bit_lengthÚto_bytes)rfÚnbytesÚresultrrrÚ encode_long?s r£cCstj|dddS)a\Decode a long from a two's complement little-endian binary string. >>> decode_long(b'') 0 >>> decode_long(b"\xff\x00") 255 >>> decode_long(b"\xff\x7f") 32767 >>> decode_long(b"\x00\xff") -256 >>> decode_long(b"\x00\x80") -32768 >>> decode_long(b"\x80") -128 >>> decode_long(b"\x7f") 127 r™T)ršr›)ÚintÚ from_bytes)rxrrrÚ decode_long]sr¦c@sheZdZd7ddœdd„Zdd„Zdd „Zd d „Zd d „Zdd„Zd8dd„Z dd„Z dd„Z d9dd„Z iZ dd„Zee edƒ<dd„Zee e<dd„Zee e<dd„Zee e<d d!„Zee e<d"d#„Zee e<d$d%„Zee e<d&d'„Zee e<d(Zd)d*„Zd+d,„Z e e e!<e"dk re e e"<d-d.„Z#d/d0„Z$e$e e%<d1d2„Z&e&e e'<d:d3d4„Z(d5d6„Z)e(e e*<e)e e<dS);Ú_PicklerNT)Ú fix_importscCs¸|dkr t}|dkrt}n"d|kr.tksy | tt|ƒ d¡d¡Wntk r\tdƒ‚YnXdS)NF)rÞrÄrÅz2persistent IDs in protocol 0 must be ASCII strings) r²r¼ryÚ BINPERSIDÚPERSIDrÛrËÚUnicodeEncodeErrorr )rrßrrrrÕ+s  z_Pickler.save_persc Cst|tƒstdƒ‚t|ƒs"tdƒ‚|j}|j}t|ddƒ} |jdkrè| dkrè|\} }} t| dƒsntd  | ¡ƒ‚|dk rŽ| |j k rŽtd   | ¡ƒ‚|jd krº|| ƒ||ƒ|| ƒ|t ƒn,t | j | f|ž| Ž}||ƒ|d ƒ|tƒnŽ|jdkr^| d kr^|d } t| dƒstdƒ‚|dk r8| |j k r8tdƒ‚|dd…}|| ƒ||ƒ|tƒn||ƒ||ƒ|tƒ|dk r¼t|ƒ|jkr²|t| |jt|ƒd ¡ƒn | |¡|dk rÐ| |¡|dk rä| |¡|dk rþ||ƒ|tƒdS)Nz'args from save_reduce() must be a tuplez(func from save_reduce() must be callablerÚr¸Ú __newobj_ex__Ú__new__z#args[0] from {} args has no __new__z(args[0] from {} args has the wrong classrrÚ __newobj__rz+args[0] from __newobj__ args has no __new__z0args[0] from __newobj__ args has the wrong classr˜)rÚrÜr Úcallabler¼ryr‹r±r¹rŠrºÚ NEWOBJ_EXrréÚREDUCEÚNEWOBJr¾r°ÚPOPrÐrÂÚ_batch_appendsÚ_batch_setitemsÚBUILD) rÚfuncÚargsÚstateZ listitemsZ dictitemsrŒr¼ryZ func_nameÚclsÚkwargsrrrrÝ7sd           "      z_Pickler.save_reducecCs| t¡dS)N)ryÚNONE)rrŒrrrÚ save_nonesz_Pickler.save_nonecCs4|jdkr| |rtnt¡n| |r*tnt¡dS)Nr¸)r±ryÚNEWTRUEÚNEWFALSEÚTRUEÚFALSE)rrŒrrrÚ save_bool¡s z_Pickler.save_boolcCs.|jr~|dkrN|dkr.| ttd|ƒ¡dS|dkrN| ttd|ƒ¡dSd|krbdkr~nn| ttd|ƒ¡dS|jd krÖt|ƒ}t|ƒ}|d krº| t td|ƒ|¡n| t td|ƒ|¡dSd|krìdkrnn| t t |ƒ  d ¡d ¡n| tt |ƒ  d ¡d ¡dS)NrrœzdrÄrÅ)r²ryÚBINFLOATr ÚFLOATrÊrË)rrŒrrrÚ save_floatÇsz_Pickler.save_floatcCsÞ|jdkr@|s |jtd|dn|jtjt|dƒdf|ddSt|ƒ}|dkrj| tt d|ƒ|¡nf|dkr”|jdkr”|  t t d |ƒ|¡n<||j j kr¸|  tt d |ƒ|¡n| tt d |ƒ|¡| |¡dS) Nrr)rŒÚlatin1rœzdSq>WdS)Nr˜r) r¼ryr²ÚAPPENDÚiterr‘rÚ _BATCHSIZErtrÚAPPENDS)rr”r¼ryrfÚitÚtmpr€rrrrð9s*       z_Pickler._batch_appendscCs<|jr| t¡n| tt¡| |¡| | ¡¡dS)N)r²ryÚ EMPTY_DICTrÚDICTrÂrñr”)rrŒrrrÚ save_dictTs   z_Pickler.save_dictc CsÜ|j}|j}|js@x(|D] \}}||ƒ||ƒ|tƒqWdSt|ƒ}xŽtt||jƒƒ}t|ƒ}|dkrž|t ƒx |D]\}}||ƒ||ƒqxW|t ƒn(|rÆ|d\}}||ƒ||ƒ|tƒ||jkrJdSqJWdS)Nr˜r) r¼ryr²ÚSETITEMr)r‘rr*rtrÚSETITEMS) rr”r¼ryÚkÚvr,r-r€rrrrñas2     z_Pickler._batch_setitemscCs¨|j}|j}|jdkr0|jtt|ƒf|ddS|tƒ| |¡t|ƒ}xXtt ||j ƒƒ}t |ƒ}|dkr’|t ƒx|D] }||ƒqzW|t ƒ||j krLdSqLWdS)Nr)rŒr)r¼ryr±rÝÚsetr‘Ú EMPTY_SETrÂr)rr*rtrÚADDITEMS)rrŒr¼ryr,Zbatchr€ÚitemrrrÚsave_set€s$     z_Pickler.save_setcCs–|j}|j}|jdkr0|jtt|ƒf|ddS|tƒx|D] }||ƒq>Wt|ƒ|jkr€|t |  |jt|ƒd¡ƒdS|t ƒ|  |¡dS)Nr)rŒr) r¼ryr±rÝÚ frozensetr‘rr¾r°r"rÐÚ FROZENSETrÂ)rrŒr¼ryr8rrrÚsave_frozenset˜s    z_Pickler.save_frozensetc Csd|j}|j}|dkr t|ddƒ}|dkr.|j}t||ƒ}y(t|ddtj|}t||ƒ\}}Wn.t t t fk rŽt d|||fƒd‚YnX||k rªt d|||fƒ‚|j dkr&t ||f¡} | r&| dksÖt‚| dkrò|ttd| ƒƒn0| d kr|ttd | ƒƒn|ttd | ƒƒdS| d ¡d} ||krB| }|j d krl| |¡| |¡|tƒnê||k rˆ| t|| f¡nÎ|j dkrº|tt|dƒdt|dƒdƒnœ|jrtj} tj} ||f| krî| ||f\}}n|| kr| |}y(|tt|dƒdt|dƒdƒWn,tk rTt d|||j fƒd‚YnX|  |¡dS)Nrr)Úlevelz(Can't pickle %r: it's not found as %s.%sz2Can't pickle %r: it's not the same object as %s.%sr¸rœzd?„Z7e7ee8d<d@dA„Z9e9ee:d<dBdC„Z;e;eed<dFdG„Z?e?ee@d<dHdI„ZAeAeeBd<dJdK„ZCeCeeDd<dLdM„ZEeEeeFd<dNdO„ZGeGeeHd<dPdQ„ZIeIeeJd<dRdS„ZKeKeeLd<dTdU„ZMeMeeNd<dVdW„ZOeOeePd<dXdY„ZQeQeeRd<dZd[„ZSd\d]„ZTeTeeUd<d^d_„ZVeVeeWd<d`da„ZXeXeeYd<dbdc„ZZeZee[d<ddde„Z\e\ee]d<dfdg„Z^e^ee_d<dhdi„Z`e`eead<djdk„Zbebeecd<dldm„Zdedeeed<dndo„Zfdpdq„Zgdrds„Zheheeid<dtdu„Zjejeekd<dvdw„Zleleemd<dxdy„Zneneeod<dzd{„Zpepeeqd<d|d}„Zrereesd<d~d„Zteteeud<d€d„Zveveewd<d‚dƒ„Zxexeeyd<d„d…„Zzezee{d<d†d‡„Z|e|ee}d<dˆd‰„Z~e~eed<dŠd‹„Z€e€eed<dŒd„Z‚e‚eeƒd<dŽd„Z„e„ee…d<dd‘„Z†e†ee‡d<d’d“„Zˆeˆee‰d<d”d•„ZŠeŠee‹d<d–d—„ZŒeŒeed<d˜S)™Ú _UnpicklerTÚASCIIÚstrict)r¨ÚencodingÚerrorscCs2|j|_|j|_i|_||_||_d|_||_dS)a¿This takes a binary file for reading a pickle data stream. The protocol version of the pickle is detected automatically, so no proto argument is needed. The argument *file* must have two methods, a read() method that takes an integer argument, and a readline() method that requires no arguments. Both methods should return bytes. Thus *file* can be a binary file object opened for reading, an io.BytesIO object, or any other custom object that meets this interface. The file-like object must have two methods, a read() method that takes an integer argument, and a readline() method that requires no arguments. Both methods should return bytes. Thus file-like object can be a binary file object opened for reading, a BytesIO object, or any other custom object that meets this interface. Optional keyword arguments are *fix_imports*, *encoding* and *errors*, which are used to control compatibility support for pickle stream generated by Python 2. If *fix_imports* is True, pickle will try to map the old Python 2 names to the new names used in Python 3. The *encoding* and *errors* tell pickle how to decode 8-bit string instances pickled by Python 2; these default to 'ASCII' and 'strict', respectively. *encoding* can be 'bytes' to read theses 8-bit string instances as bytes objects. rN) rƒÚ_file_readlinerÚ _file_readr°rQrRr±r¨)rr´r¨rQrRrrrr sz_Unpickler.__init__c CsÊt|dƒstd|jjfƒ‚t|j|jƒ|_|jj|_|jj |_ g|_ g|_ |j j |_ d|_ |j}|j}y8x2|dƒ}|s|t‚t|tƒsŠt‚||d|ƒqlWWn$tk rÄ}z|jSd}~XYnXdS)z‹Read a pickled object representation from the open file. Return the reconstituted object hierarchy specified in the file. rTz4Unpickler.__init__() was not called by %s.__init__()rr˜N)r¹rrºrr|rTrSÚ _unframerrrƒÚ metastackÚstackÚappendr±r×ÚEOFErrorrÚÚ bytes_typesr¿rr)rrr×ÚkeyZstopinstrrrr's*    z_Unpickler.loadcCs |j}|j ¡|_|jj|_|S)N)rWrVÚpoprX)rr”rrrÚpop_markEs  z_Unpickler.pop_markcCs tdƒ‚dS)Nz%unsupported persistent id encountered)r)rrßrrrÚpersistent_loadKsz_Unpickler.persistent_loadcCs:| d¡d}d|kr"tks0ntd|ƒ‚||_dS)Nr˜rzunsupported pickle protocol: %d)rrªr«r±)rr±rrrÚ load_protoPs z_Unpickler.load_protorcCs8td| d¡ƒ\}|tjkr(td|ƒ‚|j |¡dS)Nz sys.maxsize: %d)r rr’r r«rUr†)rr…rrrr†Ws  z_Unpickler.load_framecCsLy| ¡dd… d¡}Wntk r6tdƒ‚YnX| | |¡¡dS)NrrÄz2persistent IDs in protocol 0 must be ASCII strings)rƒÚdecodeÚUnicodeDecodeErrorrrXr^)rrßrrrÚ load_persid^s  z_Unpickler.load_persidcCs|j ¡}| | |¡¡dS)N)rWr\rXr^)rrßrrrÚload_binpersidgs z_Unpickler.load_binpersidcCs| d¡dS)N)rX)rrrrÚ load_nonelsz_Unpickler.load_nonecCs| d¡dS)NF)rX)rrrrÚ load_falsepsz_Unpickler.load_falsecCs| d¡dS)NT)rX)rrrrÚ load_truetsz_Unpickler.load_truecCsL| ¡}|tdd…krd}n |tdd…kr4d}n t|dƒ}| |¡dS)Nr˜FTr)rƒrýrür¤rX)rrxÚvalrrrÚload_intxs z_Unpickler.load_intcCs| td| d¡ƒd¡dS)Nztd| d¡ƒ\}|dkr"tdƒ‚| |¡}| t|ƒ¡dS)Nzdr`r)rXr r)rrrrÚ load_binfloat©sz_Unpickler.load_binfloatcCs"|jdkr|S| |j|j¡SdS)Nr )rQrarR)rrrrrÚ_decode_string­s z_Unpickler._decode_stringcCsl| ¡dd…}t|ƒdkrF|d|dkrF|ddkrF|dd…}ntdƒ‚| | t |¡d¡¡dS)Nrr¸rs"'r˜z)the STRING opcode argument must be quoted)rƒrtrrXrsr Ú escape_decode)rrxrrrÚ load_string¶s (z_Unpickler.load_stringcCs@td| d¡ƒ\}|dkr"tdƒ‚| |¡}| | |¡¡dS)Nz*sz(_Unpickler.load_dict..rr¸)r]ÚrangertrX)rÚdr)r”rÚ load_dict(s z_Unpickler.load_dictc Cs‚|st|tƒrt|dƒrjy ||Ž}Wqttk rf}z$td|jt|ƒft ¡dƒ‚Wdd}~XYqtXn | |¡}|  |¡dS)NÚ__getinitargs__zin constructor for %s: %sr¸) rÚrÖr¹r­rrÛr’Úexc_inforérX)rÚklassrôrÚerrrrrÚ _instantiate4s  0 z_Unpickler._instantiatecCsL| ¡dd… d¡}| ¡dd… d¡}| ||¡}| || ¡¡dS)NrrÄ)rƒraÚ find_classr’r])rr–rrrrrÚ load_inst@s z_Unpickler.load_instcCs"| ¡}| d¡}| ||¡dS)Nr)r]r\r’)rrôrörrrÚload_objGs z_Unpickler.load_objcCs2|j ¡}|j ¡}|j|f|žŽ}| |¡dS)N)rWr\rérX)rrôrörŒrrrÚ load_newobjNs  z_Unpickler.load_newobjcCs>|j ¡}|j ¡}|j ¡}|j|f|ž|Ž}| |¡dS)N)rWr\rérX)rr÷rôrörŒrrrÚload_newobj_exUs    z_Unpickler.load_newobj_excCsF| ¡dd… d¡}| ¡dd… d¡}| ||¡}| |¡dS)Nrzutf-8)rƒrar“rX)rr–rrrrrÚ load_global]s z_Unpickler.load_globalcCsJ|j ¡}|j ¡}t|ƒtk s,t|ƒtk r4tdƒ‚| | ||¡¡dS)NzSTACK_GLOBAL requires str)rWr\rÖrÛrrXr“)rrr–rrrÚload_stack_globalds   z_Unpickler.load_stack_globalcCs| d¡d}| |¡dS)Nr˜r)rÚ get_extension)rrHrrrÚ load_ext1lsz_Unpickler.load_ext1cCs td| d¡ƒ\}| |¡dS)Nzrr’r“r‹)rr–rrrrr“‹s    z_Unpickler.find_classcCs&|j}| ¡}|d}||Ž|d<dS)Nr)rWr\)rrWrôrórrrÚ load_reduce˜sz_Unpickler.load_reducecCs|jr|jd=n| ¡dS)Nr)rWr])rrrrÚload_popŸs z_Unpickler.load_popcCs | ¡dS)N)r])rrrrÚ load_pop_mark¦sz_Unpickler.load_pop_markcCs| |jd¡dS)Nr)rXrW)rrrrÚload_dupªsz_Unpickler.load_dupcCs(t| ¡dd…ƒ}| |j|¡dS)Nr)r¤rƒrXr°)rrÏrrrÚload_get®sz_Unpickler.load_getcCs"| d¡d}| |j|¡dS)Nr˜r)rrXr°)rrÏrrrÚ load_binget³sz_Unpickler.load_bingetcCs&td| d¡ƒ\}| |j|¡dS)Nzs   rÉ) r r rrrrrrrcCsddl}| ¡S)Nr)ÚdoctestZtestmod)rÊrrrÚ_testWsrËrz$display contents of the pickle files)Z descriptionÚ pickle_fileÚbrÚ*zthe pickle file)rÖÚnargsÚhelpz-tz--testÚ store_truezrun self-test suite)ÚactionrÐz-vz)run verbosely; only affects self-test run)N)N)rÚtypesrÚcopyregrrrrÚ itertoolsrÚ functoolsrr’r Zstructr r rcrkr rGÚ__all__r Ú bytearrayrZZformat_versionZcompatible_formatsrªr©Ú Exceptionr r rrZorg.python.corer!r?rr½rïr"rÂr rrrÿrrrørårärírºr»r¼rrr(ròrFr/r.r+rÎrÌrÀrÍr&r%rÁrÉrÇrÈr1r rr2rrürýr»rîrArBrCr½r¾r¿rúrûrrr!rrrrrr6r7r;rìrErÆrvrªÚdirrhr|rr—r£r¦r§rNrÃrÆrÇrÉÚ_picklerrrrrrrËrÚargparseÚArgumentParserÚparserÚ add_argumentZFileTypeÚ parse_argsrôZtestrÌZ print_helpZpprintrwrŒrrrrÚs.        ?* 40