Yfp@sdZddlmZddlmZddlmZmZmZddlm Z ddl Z ddl m Z ddl m Z mZddlZddlZddlZddlZd d d d d ddddg ZeefZdZdddddddgZdZdZGdd d eZGdd d eZGdd d eZGdddeZydd l m!Z!Wne"k rdZ!YnXd!Z#d"Z$d#Z%d$Z&d%Z'd&Z(d'Z)d(Z*d)Z+d*Z,d+Z-d,Z.d-Z/d.Z0d/Z1d0Z2d1Z3d2Z4d3Z5d4Z6d5Z7d6Z8d7Z9d8Z:d9Z;d:Z<d;Z=d<Z>d=Z?d>Z@d?ZAd@ZBdAZCdBZDdCZEdDZFdEZGdFZHdGZIdHZJdIZKdJZLdKZMdLZNdMZOdNZPdOZQdPZRdQZSdRZTdSZUdTZVdUZWdVZXdWZYeIeSeTeUgZZdXZ[dYZ\dZZ]d[Z^d\Z_d]Z`d^Zad_Zbd`ZcdaZddbZedcZfejgdddeehDGdfdgdgZiGdhdidiZjdjdkZkdldmZldndoZmdpdqZnGdrdsdsZoGdtduduZpddvdwdxdyZqddvdwdzd{Zrdvdwd|d}d~dddZsdvdwd|d}d~dddZtyDddlumZmZmZmvZvmwZwmxZxmyZymzZzm{Z{WnBe"k reoepf\ZvZweqeresetf\ZxZyZzZ{YnXddZ|e}dkrddl~Z~e~jddZejdde~jdddddejddddddejdddddejZejrse|nPej rejn9ddlZx*ejD]ZezeZejeqWdS)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)isliceN)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+/opt/alt/python35/lib64/python3.5/pickle.pyr ?s c@seZdZdZdS)r z]This exception is raised when an unpicklable object is passed to the dump() method. N)rrrrrrrrr Cs c@seZdZdZdS)r aThis 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)rrrrrrrrr Js c@seZdZddZdS)_StopcCs ||_dS)N)value)selfrrrr__init__Xsz_Stop.__init__N)rrrrrrrrrWs r) PyStringMap(.012FIJKLMNPQRSTUVXabcd}eghijl]opqrst)uGsI01 sI00 ssssssssssssBCsssssssssscCs(g|]}tjd|r|qS)z[A-Z][A-Z0-9_]+$)rematch).0xrrr s rPc@sUeZdZdZddZddZddZd d d Zd d ZdS)_Framer@icCs||_d|_dS)N) file_write current_frame)rrSrrrrs z_Framer.__init__cCstj|_dS)N)ioBytesIOrT)rrrr start_framingsz_Framer.start_framingcCs;|jr7|jjdkr7|jddd|_dS)NrforceT)rTtell commit_frame)rrrr end_framingsz_Framer.end_framingFc Cs|jr|j}|j|jks-|r|jC}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    ryc Cst|dd}|dk r"|SxtttjjD]]\}}|dks8|dkr_q8y!t||d|kr|SWq8tk rYq8Xq8WdS)z$Find the module an object belong to.rN__main__r)rulistsysmodulesitemsryrs)rvrw module_namemodulerrr whichmodules "  rcCs|dkrdS|jd?d}|j|dddd}|dkr|dkr|d d kr|dd @dkr|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' >>> rrnrrj byteorderlittlesignedTNrkrk) bit_lengthto_bytes)rOnbytesresultrrr encode_long#s $rcCstj|ddddS)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 rrrT)int from_bytes)rcrrr decode_longAsrc@seZdZdddddZddZdd Zd d Zd d ZddZdddZ ddZ ddZ ddddddZ iZ ddZee edtknsStdty|j|_Wntk rtdYnXt|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' attributerjr)DEFAULT_PROTOCOLHIGHEST_PROTOCOL ValueErrorre _file_writers TypeErrorrQframermemorprotobinfastr)rfileprotocolrrrrrZs"      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_memocCst|ds(td|jjf|jdkrT|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__()rzdrs )rreBINFLOATr FLOATrr)rrvrrr save_floats z_Pickler.save_floatcCs|jdkrZ|s.|jtfd|n(|jtjt|ddfd|dSt|}|dkr|jtt d||nZ|dkr|jdkr|jt t d||n|jt t d |||j |dS) Nrrvlatin1rzd?Z5e5ee6dd sys.maxsize: %d)r rir|rrr8rp)rrorrrrp2sz_Unpickler.load_framec Cs^y#|jddjd}Wntk rCtdYnX|j|j|dS)Nrjrz2persistent IDs in protocol 0 must be ASCII stringsrk)rmdecodeUnicodeDecodeErrorr r<rA)rrrrr load_persid9s # z_Unpickler.load_persidcCs)|jj}|j|j|dS)N)r;popr<rA)rrrrrload_binpersidBsz_Unpickler.load_binpersidcCs|jddS)N)r<)rrrr load_noneGsz_Unpickler.load_nonecCs|jddS)NF)r<)rrrr load_falseKsz_Unpickler.load_falsecCs|jddS)NT)r<)rrrr load_trueOsz_Unpickler.load_truecCsj|j}|tddkr+d}n.|tddkrJd}nt|d}|j|dS)NrjFTr)rmrrrr<)rrcvalrrrload_intSs   z_Unpickler.load_intcCs'|jtd|jdddS)NzdrCr)r<r ri)rrrr load_binfloatsz_Unpickler.load_binfloatcCs-|jdkr|S|j|j|jSdS)Nr)r2rDr4)rrrrr_decode_stringsz_Unpickler._decode_stringcCs|jdd}t|dkr_|d|dkr_|ddkr_|dd}n td|j|jtj|ddS) Nrjrrs"'z)the STRING opcode argument must be quotedrkrkrk)rmr^r r<rWr escape_decode)rrcrrr load_strings 6 z_Unpickler.load_stringcCs\td|jd\}|dkr3td|j|}|j|j|dS)Nzs z(_Unpickler.load_dict..rr)r@r;ranger^)rrdr)r~r load_dicts  z_Unpickler.load_dictcCst|j|dd}|j|d=|sRt|t sRt|dry||}Wqtk r}z1td|jt|ftj dWYdd}~XqXn|j |}|j |dS)NrjZ__getinitargs__zin constructor for %s: %sr) rr;rrrrrrr|exc_inforr<)rklassrrrerrrrr _instantiates<z_Unpickler._instantiatecCsj|jddjd}|jddjd}|j||}|j||jdS)Nrjrrkrk)rmrD find_classrur@)rrrwrsrrr load_instsz_Unpickler.load_instcCs6|j}|jj|d}|j||dS)Nrj)r@r;rGru)rrrsrrrload_obj%s z_Unpickler.load_objcCsA|jj}|jj}|j||}|j|dS)N)r;rGrr<)rrrrvrrr load_newobj,sz_Unpickler.load_newobjcCsS|jj}|jj}|jj}|j|||}|j|dS)N)r;rGrr<)rrrrrvrrrload_newobj_ex3s z_Unpickler.load_newobj_excCsa|jddjd}|jddjd}|j||}|j|dS)Nrjzutf-8rkrk)rmrDrvr<)rrrwrsrrr load_global;sz_Unpickler.load_globalcCsk|jj}|jj}t|tk sBt|tk rNtd|j|j||dS)NzSTACK_GLOBAL requires str)r;rGrrr r<rv)rrwrrrrload_stack_globalBs $ z_Unpickler.load_stack_globalcCs$|jdd}|j|dS)Nrjr)ri get_extension)rr+rrr load_ext1Jsz_Unpickler.load_ext1cCs,td|jd\}|j|dS)Nzr)rvrrrbresrrr_dumpss   rr2r3r4r5cCs"t|d|d|d|jS)Nrr2r4)r1r)rrr2r4rrr_loadsrcCsLt|trtdtj|}t|d|d|d|jS)Nz%Can't load pickle from unicode stringrr2r4)rrrrUrVr1r)srr2r4rrrr_loadss  r) r r r rrrrrrcCsddl}|jS)Nr)doctestZtestmod)rrrr_test3s rrzZ descriptionz$display contents of the pickle files pickle_filerZbrnargs*helpzthe pickle filez-tz--testaction store_truezrun self-test suitez-vz)run verbosely; only affects self-test run)rtypesrcopyregrrrr itertoolsrr|rZstructr r rLrUrr*__all__r bytearrayr>Zformat_versionZcompatible_formatsrr Exceptionr r r rZorg.python.corer r"rrrrrrrrrrrrrrrrrrrrr rr)rrrrrrrr rrrrrrrrrrrrrrr$r%r&rrrrrrrrrrrrrrrrrr(rr_rdirrQrfryrrrrr1rrrr_picklerrrrrrrrargparseArgumentParserparser add_argumentZFileType parse_argsrZtestrZ print_helppprintrbrvrrrrs"           $*   };D #