3 \@sdZddlmZddlmZddlmZmZmZddlm Z ddl m Z ddl Z ddl m Z dd lmZmZddlZddlZddlZddlZd d d d dddddg ZeefZdZdddddddgZdZdZGdd d eZGdd d eZGdd d eZ Gdd d eZ!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`ZddaZedbZfdcZgddZhejidedfejDGdgdhdhZkGdidjdjZldkdlZmdmdnZndodpZodqdrZpGdsdtdtZqGdudvdvZrddwdxdydzZsddwdxd{d|Ztdwd}d~dddZudwd}d~dddZvy0ddlwmZmZm Z mxZxmyZymzZzm{Z{m|Z|m}Z}Wn4e$k rbeqerZxZyeseteuevf\ZzZ{Z|Z}YnXddZ~edkrddlZejddZejdejddddejdddddejddddejZejre~n>ejsejn,ddlZx"ejD]Ze|eZejeqWdS)aCreate 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)packunpack PickleError PicklingErrorUnpicklingErrorPickler Unpicklerdumpdumpsloadloadsz4.0z1.0z1.1z1.2z1.3z2.0z3.0c@seZdZdZdS)r z6A common base class for the other pickling exceptions.N)__name__ __module__ __qualname____doc__rr/usr/lib64/python3.6/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@seZdZddZdS)_StopcCs ||_dS)N)value)selfrrrr__init__Ysz_Stop.__init__N)rrrr rrrrrXsr) PyStringMap(.012FIJKLMNPQRSTUVXabcd}eghijl]opqrst)uGsI01 sI00 BCcCsg|]}tjd|r|qS)z[A-Z][A-Z0-9_]+$)rematch).0xrrr srgc@s:eZdZdZddZddZddZdd d Zd d ZdS)_Framer@icCs||_d|_dS)N) file_write current_frame)rrjrrrr sz_Framer.__init__cCstj|_dS)N)ioBytesIOrk)rrrr start_framingsz_Framer.start_framingcCs*|jr&|jjdkr&|jddd|_dS)NrT)force)rktell commit_frame)rrrr end_framings z_Framer.end_framingFc Cst|jrp|j}|j|jks|rp|j2}t|}|j}|t|td|||WdQRX|jd|j dS)Nzz&Can't get local attribute {!r} on {!r}z Can't get attribute {!r} on {!r})splitAttributeErrorformatgetattr)objnameZsubpathparentrrr _getattributes rc Cszt|dd}|dk r|Sx\ttjjD]J\}}|dks(|dkrBq(yt||d|krZ|SWq(tk rpYq(Xq(WdS)z$Find the module an object belong to.rN__main__r)rlistsysmodulesitemsrr)rr module_namemodulerrr whichmodules  rcCsh|dkr dS|jd?d}|j|ddd}|dkrd|dkrd|d dkrd|d d @dkrd|d d}|S)aEncode 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' >>> rrrrlittleT) byteordersignedNrr) bit_lengthto_bytes)rfnbytesresultrrr encode_long$s rcCstj|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 rT)rr)int from_bytes)rzrrr decode_longBsrc@sheZdZd7ddddZddZdd Zd d Zd d ZddZd8ddZ ddZ ddZ d9ddZ iZ ddZee ed<ddZee e<ddZee e<ddZee 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/d0Z$e$e e%<d1d2Z&e&e e'<d:d3d4Z(d5d6Z)e(e e*<e)e e<dS);_PicklerNT) fix_importsc Cs|dkr t}|dkrt}n$d|ko,tkns>tdty |j|_Wntk rftdYnXt|j|_|jj|_i|_ t ||_ |dk|_ d|_ |o|dk|_dS)aThis takes a binary file for writing a pickle data stream. The optional *protocol* argument tells the pickler to use the given protocol; supported protocols are 0, 1, 2, 3 and 4. The default protocol is 3; a backward-incompatible protocol designed for Python 3. Specifying a negative protocol version selects the highest protocol version supported. The higher the protocol used, the more recent the version of Python needed to read the pickle produced. The *file* argument must have a write() method that accepts a single bytes argument. It can thus be a file object opened for binary writing, an io.BytesIO instance, or any other custom object that meets this interface. If *fix_imports* is True and *protocol* is less than 3, pickle will try to map the new Python 3 names to the old module names used in Python 2, so that the pickle data stream is readable with Python 2. Nrzpickle protocol must be <= %dz"file must have a 'write' attributerr)DEFAULT_PROTOCOLHIGHEST_PROTOCOL ValueErrorr| _file_writer TypeErrorrhframermemorprotobinfastr)rfileprotocolrrrrr [s"      z_Pickler.__init__cCs|jjdS)aClears the pickler's "memo". The memo is the data structure that remembers which objects the pickler has already seen, so that shared or recursive objects are pickled by reference and not by value. This method is useful when re-using picklers. N)rclear)rrrr clear_memosz_Pickler.clear_memocCsrt|dstd|jjf|jdkr<|jttd|j|jdkrP|jj |j ||jt |jj dS)z7Write a pickled representation of obj to the open file.rz2Pickler.__init__() was not called by %s.__init__()rzy |jtt|jddWntk r\tdYnXdS)NF)rrrz2persistent IDs in protocol 0 must be ASCII strings) rrr| BINPERSIDPERSIDrrUnicodeEncodeErrorr )rrrrrrs  z_Pickler.save_persc Cst|tstdt|s"td|j}|j}t|dd} |jdkr| dkr|\} }} t| dsntdj | |dk r| |j k rtd j | |jd kr|| |||| |t n,t | j | f|| }|||f|tn|jdko| d kr\|d } t| dstd |dk r6| |j k r6td|dd}|| |||tn|||||t|dk rt||jkr|t|j|jt|d n |j||dk r|j||dk r|j||dk r|||tdS)Nz'args from save_reduce() must be a tuplez(func from save_reduce() must be callablerr __newobj_ex____new__z#args[0] from {} args has no __new__z(args[0] from {} args has the wrong classr __newobj__rz+args[0] from __newobj__ args has no __new__z0args[0] from __newobj__ args has the wrong classr)rrr callablerr|rrrrr NEWOBJ_EXrrREDUCENEWOBJrrPOPrr_batch_appends_batch_setitemsBUILD) rfuncargsstateZ listitemsZ dictitemsrrr|Z func_nameclskwargsrrrrsd           "      z_Pickler.save_reducecCs|jtdS)N)r|NONE)rrrrr save_nonesz_Pickler.save_nonecCs4|jdkr|j|rtntn|j|r*tntdS)Nr)rr|NEWTRUENEWFALSETRUEFALSE)rrrrr save_bools z_Pickler.save_boolcCs|jr~|dkrN|dkr.|jttd|dS|dkrN|jttd|dSd |ko`dknr~|jttd|dS|jd krt|}t|}|d kr|jt td||n|jt td||dS|jt t |j d d dS)Nrrzdrr)rr|BINFLOATr FLOATrr)rrrrr save_floatsz_Pickler.save_floatcCs|jdkr@|s |jtf|dn|jtjt|ddf|ddSt|}|dkrj|jtt d||nD|dkr|jdkr|jt t d||n|jt t d |||j |dS) Nr)rlatin1rzdSq>WdS)Nrr) rr|rAPPENDiterrr _BATCHSIZErurAPPENDS)rrrr|rfittmpr{rrrrs*       z_Pickler._batch_appendscCs<|jr|jtn|jtt|j||j|jdS)N)rr| EMPTY_DICTrDICTrrr)rrrrr save_dict.s   z_Pickler.save_dictc Cs|j}|j}|js@x(|D] \}}|||||tqWdSt|}xtt||j}t|}|dkr|t x |D]\}}||||qxW|t n(|r|d\}}|||||t||jkrJdSqJWdS)Nrr) rr|rSETITEMr#rrr$rurSETITEMS) rrrr|kvr&r'r{rrrr;s2     z_Pickler._batch_setitemscCs|j}|j}|jdkr0|jtt|f|ddS|t|j|t|}xXtt ||j }t |}|dkr|t x|D] }||qzW|t ||j krLdSqLWdS)Nr)rr)rr|rrsetr EMPTY_SETrr#rr$rurADDITEMS)rrrr|r&Zbatchr{itemrrrsave_setZs$     z_Pickler.save_setcCs|j}|j}|jdkr0|jtt|f|ddS|tx|D] }||q>Wt||jkr|t |j |jt|ddS|t |j |dS)Nr)rr) rr|rr frozensetrrrrrr FROZENSETr)rrrr|r2rrrsave_frozensetrs    z_Pickler.save_frozensetc CsT|j}|j}|dkr t|dd}|dkr.|j}t||}y(t|ddtj|}t||\}}Wn,t t t fk rt d|||fYnX||k rt d|||f|j dkrtj||f} | r| dkr|ttd| n0| d kr|ttd | n|ttd | dS|jd d} ||kr4| }|j d kr^|j||j||tn||k rz|jt|| fn|j dkr|tt|ddt|ddn|jrtj} tj} ||f| kr| ||f\}}n|| kr| |}y(|tt|ddt|ddWn*tk rDt d|||j fYnX|j|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.%srrzd?Z7e7ee8d<d@dAZ9e9ee:d<dBdCZ;e;eed<dFdGZ?e?ee@d<dHdIZAeAeeBd<dJdKZCeCeeDd<dLdMZEeEeeFd<dNdOZGeGeeHd<dPdQZIeIeeJd<dRdSZKeKeeLd<dTdUZMeMeeNd<dVdWZOeOeePd<dXdYZQeQeeRd<dZd[ZSd\d]ZTeTeeUd<d^d_ZVeVeeWd<d`daZXeXeeYd<dbdcZZeZee[d<dddeZ\e\ee]d<dfdgZ^e^ee_d<dhdiZ`e`eead<djdkZbebeecd<dldmZdedeeed<dndoZfdpdqZgdrdsZheheeid<dtduZjejeekd<dvdwZleleemd<dxdyZneneeod<dzd{Zpepeeqd<d|d}Zrereesd<d~dZteteeud<ddZveveewd<ddZxexeeyd<ddZzezee{d<ddZ|e|ee}d<ddZ~e~eed<ddZeeed<ddZeeed<ddZeeed<ddZeeed<ddZeeed<ddZeeed<ddZeeed<dS) _UnpicklerTASCIIstrict)rencodingerrorscCs2|j|_|j|_i|_||_||_d|_||_dS)aThis 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_readrrKrLrr)rrrrKrLrrrr sz_Unpickler.__init__cCst|dstd|jjft|j|j|_|jj|_|jj |_ g|_ g|_ |j j |_ d|_ |j}|j}y*x$|d}|s|t||d|qlWWn"tk r}z|jSd}~XnXdS)zRead a pickled object representation from the open file. Return the reconstituted object hierarchy specified in the file. rNz4Unpickler.__init__() was not called by %s.__init__()rrN)rrrrr}rNrM _unframerrr metastackstackappendrrEOFErrorrr)rrrkeyZstopinstrrrrs(    z_Unpickler.loadcCs |j}|jj|_|jj|_|S)N)rQrPpoprR)rrrrrpop_marks  z_Unpickler.pop_markcCs tddS)Nz%unsupported persistent id encountered)r)rrrrrpersistent_load%sz_Unpickler.persistent_loadcCs<|jdd}d|ko tkns2td|||_dS)Nrrzunsupported pickle protocol: %d)rrrr)rrrrr load_proto*s z_Unpickler.load_protorcCs8td|jd\}|tjkr(td||jj|dS)Nz sys.maxsize: %d)r rrr rrOr)rrrrrr1s  z_Unpickler.load_framec CsLy|jddjd}Wntk r6tdYnX|j|j|dS)Nrrz2persistent IDs in protocol 0 must be ASCII stringsr)rdecodeUnicodeDecodeErrorrrRrW)rrrrr load_persid8s  z_Unpickler.load_persidcCs|jj}|j|j|dS)N)rQrUrRrW)rrrrrload_binpersidAs z_Unpickler.load_binpersidcCs|jddS)N)rR)rrrr load_noneFsz_Unpickler.load_nonecCs|jddS)NF)rR)rrrr load_falseJsz_Unpickler.load_falsecCs|jddS)NT)rR)rrrr load_trueNsz_Unpickler.load_truecCsL|j}|tddkrd}n |tddkr4d}n t|d}|j|dS)NrFTr)rrrrrR)rrzvalrrrload_intRs z_Unpickler.load_intcCs|jtd|jdddS)Nztd|jd\}|dkr"td|j|}|jt|dS)NzdrYr)rRr r)rrrr load_binfloatsz_Unpickler.load_binfloatcCs"|jdkr|S|j|j|jSdS)Nr )rKrZrL)rrrrr_decode_strings z_Unpickler._decode_stringcCsl|jdd}t|dkrF|d|dkrF|ddkrF|dd}ntd|j|jtj|ddS) Nrrrs"'z)the STRING opcode argument must be quotedrrr)rrurrRrlr  escape_decode)rrzrrr load_strings (z_Unpickler.load_stringcCs@td|jd\}|dkr"td|j|}|j|j|dS)Nzsz(_Unpickler.load_dict..rr)rVrangerurR)rdr)rr load_dicts z_Unpickler.load_dictcCs|st|t st|drly ||}Wqvtk rh}z&td|jt|ftjdWYdd}~XqvXn |j|}|j |dS)NZ__getinitargs__zin constructor for %s: %sr) rrrrrrrexc_inforrR)rklassrrerrrrr _instantiates  0 z_Unpickler._instantiatecCsL|jddjd}|jddjd}|j||}|j||jdS)Nrrrr)rrZ find_classrrV)rrrrrrr load_insts z_Unpickler.load_instcCs"|j}|jd}|j||dS)Nr)rVrUr)rrrrrrload_obj!s z_Unpickler.load_objcCs2|jj}|jj}|j|f|}|j|dS)N)rQrUrrR)rrrrrrr load_newobj(s  z_Unpickler.load_newobjcCs>|jj}|jj}|jj}|j|f||}|j|dS)N)rQrUrrR)rrrrrrrrload_newobj_ex/s    z_Unpickler.load_newobj_excCsF|jddjd}|jddjd}|j||}|j|dS)Nrzutf-8rr)rrZrrR)rrrrrrr load_global7s z_Unpickler.load_globalcCsJ|jj}|jj}t|tk s,t|tk r4td|j|j||dS)NzSTACK_GLOBAL requires str)rQrUrrrrRr)rrrrrrload_stack_global>s   z_Unpickler.load_stack_globalcCs|jdd}|j|dS)Nrr)r get_extension)rrBrrr load_ext1Fsz_Unpickler.load_ext1cCs td|jd\}|j|dS)Nzs.        $* -0