B ‚Ž\]Šâã @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ÚnameÚsubpathÚparentrrrÚ _getattribute!s r‘c 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Úitemsr‘rŠ)rrŽÚ 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 dictitemsrr¾ryÚ func_nameÚclsÚkwargsrrrrß7sd           "      z_Pickler.save_reducecCs| t¡dS)N)ryÚNONE)rrrrrÚ save_nonesz_Pickler.save_nonecCs4|jdkr| |rtnt¡n| |r*tnt¡dS)Nrº)r³ryÚNEWTRUEÚNEWFALSEÚTRUEÚFALSE)rrrrrÚ 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Í)rrrrrÚ 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Útmprrrrró9s*       z_Pickler._batch_appendscCs<|jr| t¡n| tt¡| |¡| | ¡¡dS)N)r´ryÚ EMPTY_DICTr#ÚDICTrÄrôr–)rrrrrÚ 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Úvr0r1rrrrrô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)rr)r¾ryr³rßÚsetr“Ú EMPTY_SETrÄr-rr.rtr#ÚADDITEMS)rrr¾ryr0ZbatchrÚ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)rr) r¾ryr³rßÚ frozensetr“r#rÀr²r&rÒÚ FROZENSETrÄ)rrr¾ryr<rrrÚ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žzrÛrNrrrrrr©tsV*   B  c 1    B r©c@sneZdZddddœdd„Zdd„Zd d „Zd d „ZiZd d„Zeee d<dd„Z e ee d<dd„Z e ee d<dd„Zeeed<dd„Zeeed<dd„Zeeed<dd„Zeeed<dd„Zeeed<dd„Zeeed<d d!„Zeeed<d"d#„Zeeed<d$d%„Zeeed<d&d'„Z e ee!d<d(d)„Z"e"ee#d<d*d+„Z$e$ee%d<d,d-„Z&e&ee'd<d.d/„Z(d0d1„Z)e)ee*d<d2d3„Z+e+ee,d<d4d5„Z-e-ee.d<d6d7„Z/e/ee0d<d8d9„Z1e1ee2d<d:d;„Z3e3ee4d<dd?„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²rUrVr³rª)rr¶rªrUrVrrrr 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. rXz4Unpickler.__init__() was not called by %s.__init__()rršN)r»rr¼rr}rXrWÚ _unframerr€r„Ú metastackÚstackÚappendr³rÙÚEOFErrorrÜÚ bytes_typesrÁrr)rr€rÙÚkeyZstopinstrrrr's*    z_Unpickler.loadcCs |j}|j ¡|_|jj|_|S)N)r[rZÚpopr\)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)r€r¬r­r³)rr³rrrÚ load_protoPs z_Unpickler.load_protorcCs8td| d¡ƒ\}|tjkr(td|ƒ‚|j |¡dS)Nz sys.maxsize: %d)r r€r”r r­rYr‡)rr†rrrr‡Ws  z_Unpickler.load_framecCsLy| ¡dd… d¡}Wntk r6tdƒ‚YnX| | |¡¡dS)Nr‚rÆz2persistent IDs in protocol 0 must be ASCII strings)r„ÚdecodeÚUnicodeDecodeErrorrr\rb)rrárrrÚ load_persid^s  z_Unpickler.load_persidcCs|j ¡}| | |¡¡dS)N)r[r`r\rb)rrárrrÚload_binpersidgs z_Unpickler.load_binpersidcCs| d¡dS)N)r\)rrrrÚ load_nonelsz_Unpickler.load_nonecCs| d¡dS)NF)r\)rrrrÚ load_falsepsz_Unpickler.load_falsecCs| d¡dS)NT)r\)rrrrÚ load_truetsz_Unpickler.load_truecCsL| ¡}|tdd…krd}n |tdd…kr4d}n t|dƒ}| |¡dS)NršFTr)r„rrr¦r\)rrxÚvalrrrÚload_intxs z_Unpickler.load_intcCs| td| d¡ƒd¡dS)Nztd| d¡ƒ\}|dkr"tdƒ‚| |¡}| t|ƒ¡dS)Nzdrdr)r\r r€)rrrrÚ load_binfloat©sz_Unpickler.load_binfloatcCs"|jdkr|S| |j|j¡SdS)Nr)rUrerV)rrrrrÚ_decode_string­s z_Unpickler._decode_stringcCsl| ¡dd…}t|ƒdkrF|d|dkrF|ddkrF|dd…}ntdƒ‚| | t |¡d¡¡dS)Nr‚rºrs"'ršz)the STRING opcode argument must be quoted)r„rtrr\rwrÚ escape_decode)rrxrrrÚ load_string¶s (z_Unpickler.load_stringcCs@td| d¡ƒ\}|dkr"tdƒ‚| |¡}| | |¡¡dS)Nz)rr–rrrÚload_frozensetsz_Unpickler.load_frozensetcCs| ¡}| |¡dS)N)rar\)rr–rrrÚ load_list#sz_Unpickler.load_listcs4| ¡‰‡fdd„tdtˆƒdƒDƒ}| |¡dS)Ncsi|]}ˆ|dˆ|“qS)ršr)rerÑ)r–rrú *sz(_Unpickler.load_dict..rrº)raÚrangertr\)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ìr\)rÚklassr÷rÚerrrrrÚ _instantiate4s  0 z_Unpickler._instantiatecCsL| ¡dd… d¡}| ¡dd… d¡}| ||¡}| || ¡¡dS)Nr‚rÆ)r„reÚ find_classr–ra)rr˜rŽr”rrrÚ load_inst@s z_Unpickler.load_instcCs"| ¡}| d¡}| ||¡dS)Nr)rar`r–)rr÷rúrrrÚload_objGs z_Unpickler.load_objcCs2|j ¡}|j ¡}|j|f|žŽ}| |¡dS)N)r[r`rìr\)rr÷rúrrrrÚ load_newobjNs  z_Unpickler.load_newobjcCs>|j ¡}|j ¡}|j ¡}|j|f|ž|Ž}| |¡dS)N)r[r`rìr\)rrûr÷rúrrrrÚload_newobj_exUs    z_Unpickler.load_newobj_excCsF| ¡dd… d¡}| ¡dd… d¡}| ||¡}| |¡dS)Nr‚zutf-8)r„rer—r\)rr˜rŽr”rrrÚ load_global]s z_Unpickler.load_globalcCsJ|j ¡}|j ¡}t|ƒtk s,t|ƒtk r4tdƒ‚| | ||¡¡dS)NzSTACK_GLOBAL requires str)r[r`rØrÝrr\r—)rrŽr˜rrrÚload_stack_globalds   z_Unpickler.load_stack_globalcCs| d¡d}| |¡dS)Nršr)r€Ú get_extension)rrLrrrÚ load_ext1lsz_Unpickler.load_ext1cCs td| d¡ƒ\}| |¡dS)Nzs   rÏ) r r rrrrrrrcCsddl}| ¡S)Nr)ÚdoctestZtestmod)rÐrrrÚ_testWsrÑr’z$display contents of the pickle files)Ú 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 Ústructr r rcrkrrKÚ__all__rÚ bytearrayr^Zformat_versionZcompatible_formatsr¬r«Ú Exceptionr r rrZorg.python.corer!rCr#r¿ròr&rÈr rrrr rrürèrçrðrÀrÁrÂr rr,rõrJr3r2r/rÐrÎrÆrÏr*r)rÇrËrÉrÊr5r$r"r6r rrr½rñrErFrGrÃrÄrÅrþrÿrrr%rrrrrr:r;r?rïrIrÈrvr¯Údirrhr}r‘r™r¥r¨r©rRrÉrÌrÍrÏÚ_picklerrrrrrrÑrÚargparseÚArgumentParserÚparserÚ add_argumentÚFileTypeÚ parse_argsr÷ÚtestrÓÚ print_helpÚpprintrwrrrrrÚs.        ?* 40