Qfn  ddlZddlZddlZddlZddlZgdZej ZdZdZdZ dZ dZ Gdd e Z dd lmZd Ze d d edZdZe ddedZdZe ddedZdZe ddedZdZe ddedZddZe d eed!Zd"Ze d#eed$Zd%Ze d&eed'Z d(Z!e d)ee!d*Z"d+Z#e d,e e#d-Z$d.Z%e d/ee%d0Z&d1Z'e d2e e'd3Z(d4Z)e d5e e)d6Z*d7Z+e d8e e+d9Z,d:Z-e d;ee-d<Z.d=Z/e d>ee/d?Z0d@Z1e dAe e1dBZ2dCZ3e dDe e3dEZ4dFZ5dGZ6e dHee5dIZ7e dJee6dKZ8dLZ9e dMee9dNZ:dOZ;e dPde;dQZe dTee>dUZ?dVZ@e dWe e@dXZAGdYdZe ZBeBd[eCd\]xZDZEeBd^eCeFfd_]ZGeBd`eFda]ZHeBdbeIdc]ZJeBddeKeLfde]xZMZNeBdfeKdg]ZOeBdhePdi]ZQeBdjeLdk]ZReBdleSddm]ZTeBdneUdo]ZVeBdpeWdq]ZXeBdreYds]ZZeBdte[du]Z\eBdve[dw]Z]eBdxe dy]Z^eBdze d{]Z_eBd|eBd}]Z`eBd~eBd]ZaGdde ZbebZcgecdde7geGgddecddegeDgd decddegeDgd decddegeDgd decdde8geDgddecdde?geDgddecddeAgeDgddecddegeMgddecdde$geMgd decdde"geMgd decdde(geOgddecdde&geOgddecdde*geOgddecdde,geQgddecdddge^gddecddde^ge^gddecdddgeTgddecdddgeHgddecdddgeHgddecdde.geRgddecdde0geRgddìecdde2geRgd dƬecdde4geRgddɬecdde:geJgdd̬ecddeecd?d@de_e_e_ge_gddAecdBdCeggddDecdEdFde_ggddGecdHdIeggddJecdKdLege_gddMecdNdOde_ge_gd dPZd[ciZeiZfegedD]\ZhZieijeevr&ekdQeijeeeijehfzeijefvr&ekdReijefeijehfzeheeeij<ehefeij<[e[f[h[iiZmedD]Zieiemeij<[iddSZnen[nddTZodUZpdVZqddWZrGdXdYZsdZZtd[Zueteud\Zvd]Zwexd^k(rcddlyZyeyjd_`Z{e{jdadbdcde{jdedfdghe{jdidjdkdlme{jdndodeCdpqe{jdrdsdkdtme{jdudvdwdxye{jdzd{dkd|me{jd}dkd~me{jZ~e~jrewye~jse{jye~jrdndZe~jrindZe~jej Znee~jdZ e~jD]Zee~jd kDr@edk(rdneZje~jjejZejedzedk(r.erejjeee~jeeed5Zereeee~jeddd eej urej!yyy#1swYxYw#eej urej!wwxYw(N)disgenopsoptimizeceZdZdZdZy)ArgumentDescriptornamenreaderdocc<||_||_||_||_yNr )selfrrrrs 2/opt/alt/python312/lib64/python3.12/pickletools.py__init__zArgumentDescriptor.__init__s"  N__name__ __module__ __qualname__ __slots__rrrr r sI$rr )unpackcJ |jd}|r|dStd)Nrz'not enough data in stream to read uint1)read ValueErrorfdatas r read_uint1r&s. 66!9D Aw > ??ruint1r zOne-byte unsigned integer.r cv |jd}t|dk(rtd|dStd)Nz ??ruint2r)z)Two-byte unsigned integer, little-endian.cv |jd}t|dk(rtd|dStd)Nz>rint4r1z8Four-byte signed integer, little-endian, 2's complement.cv |jd}t|dk(rtd|dStd)Nr1z??Abz 9D@A A ##D)!,33G< KrstringnlzA newline-terminated string. This is a repr-style string, with embedded escapes, and bracketing quotes. ct|dS)NF)rF)rHr$s rread_stringnl_noescaperLts  ..rstringnl_noescapeaA newline-terminated string. This is a str-style string, without embedded escapes, or bracketing quotes. It should consist solely of printable ASCII characters. c6 t|dt|S)N )rLrKs rread_stringnl_noescape_pairrPs -Q/1G1J KKrstringnl_noescape_pairaA pair of newline-terminated strings. These are str-style strings, without embedded escapes, or bracketing quotes. They should consist solely of printable ASCII characters. The pair is returned as a single string, with a single blank separating the two strings. c t|}|j|}t||k(r|jdSt d|t|fz)Nlatin-1z2expected %d bytes in a string1, but only %d remain)r&r!r+rEr"r$rr%s r read_string1rUsY 1 A 66!9D 4yA~{{9%% IT^$ %%rstring1zA counted string. The first argument is a 1-byte unsigned int giving the number of bytes in the string, and the second argument is that many bytes. c t|}|dkrtd|z|j|}t||k(r|j dStd|t|fz)Nrzstring4 byte count < 0: %drSz2expected %d bytes in a string4, but only %d remain)r2r"r!r+rErTs r read_string4rXsq  ! A1u59:: 66!9D 4yA~{{9%% IT^$ %%rstring4zA counted string. The first argument is a 4-byte little-endian signed int giving the number of bytes in the string, and the second argument is that many bytes. c t|}|j|}t||k(r|Std|t|fz)Nz1expected %d bytes in a bytes1, but only %d remain)r&r!r+r"rTs r read_bytes1r[sO 1 A 66!9D 4yA~ HT^$ %%rbytes1zA counted bytes string. The first argument is a 1-byte unsigned int giving the number of bytes, and the second argument is that many bytes. c t|}|tjkDrtd|z|j |}t ||k(r|Std|t |fz)Nz#bytes4 byte count > sys.maxsize: %dz1expected %d bytes in a bytes4, but only %d remain)r5sysmaxsizer"r!r+rTs r read_bytes4r`sk  1 A3;;>BCC 66!9D 4yA~ HT^$ %%rbytes4zA counted bytes string. The first argument is a 4-byte little-endian unsigned int giving the number of bytes, and the second argument is that many bytes. c t|}|tjkDrtd|z|j |}t ||k(r|Std|t |fz)Nz#bytes8 byte count > sys.maxsize: %dz1expected %d bytes in a bytes8, but only %d remain)r9r^r_r"r!r+rTs r read_bytes8rcsk  1 A3;;>BCC 66!9D 4yA~ HT^$ %%rbytes8zA counted bytes string. The first argument is an 8-byte little-endian unsigned int giving the number of bytes, and the second argument is that many bytes. c t|}|tjkDrtd|z|j |}t ||k(r t |Std|t |fz)Nz'bytearray8 byte count > sys.maxsize: %dz5expected %d bytes in a bytearray8, but only %d remain)r9r^r_r"r!r+ bytearrayrTs rread_bytearray8rg9sp  1 A3;;BQFGG 66!9D 4yA~ LT^$ %%r bytearray8zA counted bytearray. The first argument is an 8-byte little-endian unsigned int giving the number of bytes, and the second argument is that many bytes. c~ |j}|jds td|dd}t|dS)Nr<z4no newline found when trying to read unicodestringnlrzraw-unicode-escape)r@rAr"strr#s rread_unicodestringnlrk[sK :: sys.maxsize: %drnroz9expected %d bytes in a unicodestring4, but only %d remain)r5r^r_r"r!r+rjrTs rread_unicodestring4rsw" 1 A3;;FJKK 66!9D 4yA~4/22 !"CI/ 00runicodestring4aAA counted Unicode string. The first argument is a 4-byte little-endian signed int giving the number of bytes in the string, and the second argument-- the UTF-8 encoding of the Unicode string -- contains that many bytes. c t|}|tjkDrtd|z|j |}t ||k(r t |ddStd|t |fz)Nz+unicodestring8 byte count > sys.maxsize: %drnroz9expected %d bytes in a unicodestring8, but only %d remain)r9r^r_r"r!r+rjrTs rread_unicodestring8rwrtrunicodestring8aBA counted Unicode string. The first argument is an 8-byte little-endian signed int giving the number of bytes in the string, and the second argument-- the UTF-8 encoding of the Unicode string -- contains that many bytes. cN t|dd}|dk(ry|dk(ryt|S)NFrErFs00s01TrHintr$ss rread_decimalnl_shortrs6  a59A Ez e q6MrcP t|dd}|dddk(r|dd}t|S)NFrzrLr{r}s rread_decimalnl_longrs8 a59Av~ crF q6Mrdecimalnl_shortaA newline-terminated decimal integer literal. This never has a trailing 'L', and the integer fit in a short Python int on the box where the pickle was written -- but there's no guarantee it will fit in a short Python int on the box where the pickle is read. decimalnl_longzA newline-terminated decimal integer literal. This has a trailing 'L', and can represent integers of any size. c6 t|dd}t|S)NFrz)rHfloatr}s r read_floatnlr-s  a59A 8OrfloatnlaA newline-terminated decimal floating literal. In general this requires 17 significant digits for roundtrip identity, and pickling then unpickling infinities, NaNs, and minus zero doesn't work across boxes, or on some boxes even on itself (e.g., Windows can't read the strings it produces for infinities or NaNs). cv |jd}t|dk(rtd|dStd)Nr8z>drz(not enough data in stream to read float8r*r#s r read_float8rCs? 66!9D 4yA~tT"1%% ? @@rfloat8aAn 8-byte binary representation of a float, big-endian. The format is unique to Python, and shared with the struct module (format string '>d') "in theory" (the struct and pickle implementations don't share the code -- they should). It's strongly related to the IEEE-754 double format, and, in normal cases, is in fact identical to the big-endian 754 double format. On other boxes the dynamic range is limited to that of a 754 double, and "add a half and chop" rounding is used to reduce the precision to 53 bits. However, even on a 754 box, infinities, NaNs, and minus zero may not be handled correctly (may not survive roundtrip pickling intact). ) decode_longc t|}|j|}t||k7r tdt |S)Nz'not enough data in stream to read long1)r&r!r+r"rrTs r read_long1risA  1 A 66!9D 4yA~BCC t rlong1aA binary long, little-endian, using 1-byte size. This first reads one byte as an unsigned size, then reads that many bytes and interprets them as a little-endian 2's-complement long. If the size is 0, that's taken as a shortcut for the long 0L. c t|}|dkrtd|z|j|}t||k7r tdt |S)Nrzlong4 byte count < 0: %dz'not enough data in stream to read long4)r2r"r!r+rrTs r read_long4rsY  ! A1u3a788 66!9D 4yA~BCC t rlong4aA binary representation of a long, little-endian. This first reads four bytes as a signed size (but requires the size to be >= 0), then reads that many bytes and interprets them as a little-endian 2's-complement long. If the size is 0, that's taken as a shortcut for the int 0, although LONG1 should really be used then instead (and in any case where # of bytes < 256). ceZdZdZdZdZy) StackObjectrobtyperc\||_t|tr|D]}||_||_yr)r isinstancetuplerr)rrrr containeds rrzStackObject.__init__s,  fe $# V rc|jSrr)rs r__repr__zStackObject.__repr__s yyrN)rrrrrrrrrrrs I rrr|zA Python integer object.r int_or_boolz#A Python integer or boolean object.boolzA Python boolean object.rzA Python float object. bytes_or_strz*A Python bytes or (Unicode) string object.byteszA Python bytes object.rfzA Python bytearray object.rjz!A Python (Unicode) string object.NonezThe Python None object.rzA Python tuple object.listzA Python list object.dictzA Python dict object.setzA Python set object. frozensetzA Python frozenset object.bufferzA Python buffer-like object.anyzAny kind of object whatsoever.markaz'The mark' is a unique object. Opcodes that operate on a variable number of objects generally don't embed the count of objects in the opcode, or pull it off the stack. Instead the MARK opcode is used to push a special marker object on the stack, and then some other opcodes grab all the objects from the top of the stack down to (but not including) the topmost marker object. stacksliceaAn object representing a contiguous slice of the stack. This is used in conjunction with markobject, to represent all of the stack following the topmost markobject. For example, the POP_MARK opcode changes the stack from [..., markobject, stackslice] to [...] No matter how many object are on the stack after the topmost markobject, POP_MARK gets rid of all of them (including the topmost markobject too). ceZdZdZdZy) OpcodeInforcodearg stack_before stack_afterprotorc||_||_||_|D]}||_|D]}||_||_||_yrr) rrrrrrrrxs rrzOpcodeInfo.__init__dsQ  A(A& rNrrrrrrEsI:rrINTIaPush an integer or bool. The argument is a newline-terminated decimal literal string. The intent may have been that this always fit in a short Python int, but INT can be generated in pickles written on a 64-bit box that require a Python long on a 32-bit box. The difference between this and LONG then is that INT skips a trailing 'L', and produces a short int whenever possible. Another difference is due to that, when bool was introduced as a distinct type in 2.3, builtin names True and False were also added to 2.2.2, mapping to ints 1 and 0. For compatibility in both directions, True gets pickled as INT + "I01\n", and False as INT + "I00\n". Leading zeroes are never produced for a genuine integer. The 2.3 (and later) unpicklers special-case these and return bool instead; earlier unpicklers ignore the leading "0" and return the int. rBININTJa1Push a four-byte signed integer. This handles the full range of Python (short) integers on a 32-bit box, directly as binary bytes (1 for the opcode and 4 for the integer). If the integer is non-negative and fits in 1 or 2 bytes, pickling via BININT1 or BININT2 saves space. BININT1KzPush a one-byte unsigned integer. This is a space optimization for pickling very small non-negative ints, in range(256). BININT2MzPush a two-byte unsigned integer. This is a space optimization for pickling small positive ints, in range(256, 2**16). Integers in range(256) can also be pickled via BININT2, but BININT1 instead saves a byte. LONGLaPush a long integer. The same as INT, except that the literal ends with 'L', and always unpickles to a Python long. There doesn't seem a real purpose to the trailing 'L'. Note that LONG takes time quadratic in the number of digits when unpickling (this is simply due to the nature of decimal->binary conversion). Proto 2 added linear-time (in C; still quadratic-time in Python) LONG1 and LONG4 opcodes. LONG1Šz|Long integer using one-byte length. A more efficient encoding of a Python long; the long1 encoding says it all.LONG4‹z}Long integer using four-byte length. A more efficient encoding of a Python long; the long4 encoding says it all.STRINGSaPush a Python string object. The argument is a repr-style string, with bracketing quote characters, and perhaps embedded escapes. The argument extends until the next newline character. These are usually decoded into a str instance using the encoding given to the Unpickler constructor. or the default, 'ASCII'. If the encoding given was 'bytes' however, they will be decoded as bytes object instead. BINSTRINGTaPush a Python string object. There are two arguments: the first is a 4-byte little-endian signed int giving the number of bytes in the string, and the second is that many bytes, which are taken literally as the string content. These are usually decoded into a str instance using the encoding given to the Unpickler constructor. or the default, 'ASCII'. If the encoding given was 'bytes' however, they will be decoded as bytes object instead. SHORT_BINSTRINGUaPush a Python string object. There are two arguments: the first is a 1-byte unsigned int giving the number of bytes in the string, and the second is that many bytes, which are taken literally as the string content. These are usually decoded into a str instance using the encoding given to the Unpickler constructor. or the default, 'ASCII'. If the encoding given was 'bytes' however, they will be decoded as bytes object instead. BINBYTESBzPush a Python bytes object. There are two arguments: the first is a 4-byte little-endian unsigned int giving the number of bytes, and the second is that many bytes, which are taken literally as the bytes content. SHORT_BINBYTESCzPush a Python bytes object. There are two arguments: the first is a 1-byte unsigned int giving the number of bytes, and the second is that many bytes, which are taken literally as the string content. BINBYTES8ŽzPush a Python bytes object. There are two arguments: the first is an 8-byte unsigned int giving the number of bytes in the string, and the second is that many bytes, which are taken literally as the string content. BYTEARRAY8–zPush a Python bytearray object. There are two arguments: the first is an 8-byte unsigned int giving the number of bytes in the bytearray, and the second is that many bytes, which are taken literally as the bytearray content. NEXT_BUFFER—z"Push an out-of-band buffer object.READONLY_BUFFER˜z,Make an out-of-band buffer object read-only.NONENzPush None on the stack.NEWTRUEˆzPush True onto the stack.NEWFALSE‰zPush False onto the stack.UNICODEVzPush a Python Unicode string object. The argument is a raw-unicode-escape encoding of a Unicode string, and so may contain embedded escape sequences. The argument extends until the next newline character. SHORT_BINUNICODEŒaPush a Python Unicode string object. There are two arguments: the first is a 1-byte little-endian signed int giving the number of bytes in the string. The second is that many bytes, and is the UTF-8 encoding of the Unicode string. BINUNICODEXaPush a Python Unicode string object. There are two arguments: the first is a 4-byte little-endian unsigned int giving the number of bytes in the string. The second is that many bytes, and is the UTF-8 encoding of the Unicode string. BINUNICODE8aPush a Python Unicode string object. There are two arguments: the first is an 8-byte little-endian signed int giving the number of bytes in the string. The second is that many bytes, and is the UTF-8 encoding of the Unicode string. FLOATFaNewline-terminated decimal float literal. The argument is repr(a_float), and in general requires 17 significant digits for roundtrip conversion to be an identity (this is so for IEEE-754 double precision values, which is what Python float maps to on most boxes). In general, FLOAT cannot be used to transport infinities, NaNs, or minus zero across boxes (or even on a single box, if the platform C library can't read the strings it produces for such things -- Windows is like that), but may do less damage than BINFLOAT on boxes with greater precision or dynamic range than IEEE-754 double. BINFLOATGaFloat stored in binary form, with 8 bytes of data. This generally requires less than half the space of FLOAT encoding. In general, BINFLOAT cannot be used to transport infinities, NaNs, or minus zero, raises an exception if the exponent exceeds the range of an IEEE-754 double, and retains no more than 53 bits of precision (if there are more than that, "add a half and chop" rounding is used to cut it back to 53 significant bits). EMPTY_LIST]zPush an empty list.APPENDazAppend an object to a list. Stack before: ... pylist anyobject Stack after: ... pylist+[anyobject] although pylist is really extended in-place. APPENDSezExtend a list by a slice of stack objects. Stack before: ... pylist markobject stackslice Stack after: ... pylist+stackslice although pylist is really extended in-place. LISTlasBuild a list out of the topmost stack slice, after markobject. All the stack entries following the topmost markobject are placed into a single Python list, which single list object replaces all of the stack from the topmost markobject onward. For example, Stack before: ... markobject 1 2 3 'abc' Stack after: ... [1, 2, 3, 'abc'] EMPTY_TUPLE)zPush an empty tuple.TUPLEtavBuild a tuple out of the topmost stack slice, after markobject. All the stack entries following the topmost markobject are placed into a single Python tuple, which single tuple object replaces all of the stack from the topmost markobject onward. For example, Stack before: ... markobject 1 2 3 'abc' Stack after: ... (1, 2, 3, 'abc') TUPLE1…zBuild a one-tuple out of the topmost item on the stack. This code pops one value off the stack and pushes a tuple of length 1 whose one item is that value back onto it. In other words: stack[-1] = tuple(stack[-1:]) TUPLE2†aBuild a two-tuple out of the top two items on the stack. This code pops two values off the stack and pushes a tuple of length 2 whose items are those values back onto it. In other words: stack[-2:] = [tuple(stack[-2:])] TUPLE3‡aBuild a three-tuple out of the top three items on the stack. This code pops three values off the stack and pushes a tuple of length 3 whose items are those values back onto it. In other words: stack[-3:] = [tuple(stack[-3:])] EMPTY_DICT}zPush an empty dict.DICTdaBuild a dict out of the topmost stack slice, after markobject. All the stack entries following the topmost markobject are placed into a single Python dict, which single dict object replaces all of the stack from the topmost markobject onward. The stack slice alternates key, value, key, value, .... For example, Stack before: ... markobject 1 2 3 'abc' Stack after: ... {1: 2, 3: 'abc'} SETITEMr~zAdd a key+value pair to an existing dict. Stack before: ... pydict key value Stack after: ... pydict where pydict has been modified via pydict[key] = value. SETITEMSua\Add an arbitrary number of key+value pairs to an existing dict. The slice of the stack following the topmost markobject is taken as an alternating sequence of keys and values, added to the dict immediately under the topmost markobject. Everything at and after the topmost markobject is popped, leaving the mutated dict at the top of the stack. Stack before: ... pydict markobject key_1 value_1 ... key_n value_n Stack after: ... pydict where pydict has been modified via pydict[key_i] = value_i for i in 1, 2, ..., n, and in that order. EMPTY_SETzPush an empty set.ADDITEMSa$Add an arbitrary number of items to an existing set. The slice of the stack following the topmost markobject is taken as a sequence of items, added to the set immediately under the topmost markobject. Everything at and after the topmost markobject is popped, leaving the mutated set at the top of the stack. Stack before: ... pyset markobject item_1 ... item_n Stack after: ... pyset where pyset has been modified via pyset.add(item_i) = item_i for i in 1, 2, ..., n, and in that order. FROZENSET‘azBuild a frozenset out of the topmost slice, after markobject. All the stack entries following the topmost markobject are placed into a single Python frozenset, which single frozenset object replaces all of the stack from the topmost markobject onward. For example, Stack before: ... markobject 1 2 3 Stack after: ... frozenset({1, 2, 3}) POP0z. BUILDbaFinish building an object, via __setstate__ or dict update. Stack before: ... anyobject argument Stack after: ... anyobject where anyobject may have been mutated, as follows: If the object has a __setstate__ method, anyobject.__setstate__(argument) is called. Else the argument must be a dict, the object must have a __dict__, and the object is updated via anyobject.__dict__.update(argument) INSTiaqBuild a class instance. This is the protocol 0 version of protocol 1's OBJ opcode. INST is followed by two newline-terminated strings, giving a module and class name, just as for the GLOBAL opcode (and see GLOBAL for more details about that). self.find_class(module, name) is used to get a class object. In addition, all the objects on the stack following the topmost markobject are gathered into a tuple and popped (along with the topmost markobject), just as for the TUPLE opcode. Now it gets complicated. If all of these are true: + The argtuple is empty (markobject was at the top of the stack at the start). + The class object does not have a __getinitargs__ attribute. then we want to create an old-style class instance without invoking its __init__() method (pickle has waffled on this over the years; not calling __init__() is current wisdom). In this case, an instance of an old-style dummy class is created, and then we try to rebind its __class__ attribute to the desired class object. If this succeeds, the new instance object is pushed on the stack, and we're done. Else (the argtuple is not empty, it's not an old-style class object, or the class object does have a __getinitargs__ attribute), the code first insists that the class object have a __safe_for_unpickling__ attribute. Unlike as for the __safe_for_unpickling__ check in REDUCE, it doesn't matter whether this attribute has a true or false value, it only matters whether it exists (XXX this is a bug). If __safe_for_unpickling__ doesn't exist, UnpicklingError is raised. Else (the class object does have a __safe_for_unpickling__ attr), the class object obtained from INST's arguments is applied to the argtuple obtained from the stack, and the resulting instance object is pushed on the stack. NOTE: checks for __safe_for_unpickling__ went away in Python 2.3. NOTE: the distinction between old-style and new-style classes does not make sense in Python 3. OBJoaBuild a class instance. This is the protocol 1 version of protocol 0's INST opcode, and is very much like it. The major difference is that the class object is taken off the stack, allowing it to be retrieved from the memo repeatedly if several instances of the same class are created. This can be much more efficient (in both time and space) than repeatedly embedding the module and class names in INST opcodes. Unlike INST, OBJ takes no arguments from the opcode stream. Instead the class object is taken off the stack, immediately above the topmost markobject: Stack before: ... markobject classobject stackslice Stack after: ... new_instance_object As for INST, the remainder of the stack above the markobject is gathered into an argument tuple, and then the logic seems identical, except that no __safe_for_unpickling__ check is done (XXX this is a bug). See INST for the gory details. NOTE: In Python 2.3, INST and OBJ are identical except for how they get the class object. That was always the intent; the implementations had diverged for accidental reasons. NEWOBJaLBuild an object instance. The stack before should be thought of as containing a class object followed by an argument tuple (the tuple being the stack top). Call these cls and args. They are popped off the stack, and the value returned by cls.__new__(cls, *args) is pushed back onto the stack. NEWOBJ_EX’auBuild an object instance. The stack before should be thought of as containing a class object followed by an argument tuple and by a keyword argument dict (the dict being the stack top). Call these cls and args. They are popped off the stack, and the value returned by cls.__new__(cls, *args, *kwargs) is pushed back onto the stack. PROTO€zProtocol version indicator. For protocol 2 and above, a pickle must start with this opcode. The argument is the protocol version, an int in range(2, 256). STOP.zStop the unpickling machine. Every pickle ends with this opcode. The object at the top of the stack is popped, and that's the result of unpickling. The stack should be empty then. FRAME•zIndicate the beginning of a new frame. The unpickler may use this opcode to safely prefetch data from its underlying stream. PERSIDPaPush an object identified by a persistent ID. The pickle module doesn't define what a persistent ID means. PERSID's argument is a newline-terminated str-style (no embedded escapes, no bracketing quote characters) string, which *is* "the persistent ID". The unpickler passes this string to self.persistent_load(). Whatever object that returns is pushed on the stack. There is no implementation of persistent_load() in Python's unpickler: it must be supplied by an unpickler subclass. BINPERSIDQaXPush an object identified by a persistent ID. Like PERSID, except the persistent ID is popped off the stack (instead of being a string embedded in the opcode bytestream). The persistent ID is passed to self.persistent_load(), and whatever object that returns is pushed on the stack. See PERSID for more detail. z%repeated name %r at indices %d and %dz%repeated code %r at indices %d and %dc tj}tjD]}t j d|s|rt d|z*tt|}t|trt|dk7r|rt d|d|dm|jd}||vrJ|rt d|d |d ||}|j|k7rtd |d |d |j||=td|d|d|rVdg}|jD]&\}}|jd|jd|(tdj!|y)Nz[A-Z][A-Z0-9_]+$z0skipping %r: it doesn't look like an opcode namer z skipping z: value z doesn't look like a pickle coderSzchecking name z w/ code z for consistencyzfor pickle code z, pickle.py uses name z but we're using name z4pickle.py appears to have a pickle opcode with name z and code z, but we don'tz=we appear to have pickle opcodes that pickle.py doesn't have:z name z with code  )code2opcopypickle__all__rematchprintgetattrrrr+rErr"itemsappendjoin)verboser@r picklecodermsgrs rassure_pickle_consistencyrMsJ <<>Dxx*D1H4OP VT* *e,J10D!%z35 &&y1  J()Z Avv~ >H>B>?ff"FGG Z "J01 15: NOzz|GD! JJQVVTB C$3((  rc#Kt|trtj|}t |dr |j }nd} |}|j d}tj|jd}|&|dk(r tdtd|dn|d |d |jd}n|jj|}|r||||fn|||f|d k(ryw) Ntellcyrrrrrz_genops..srr rSrz#pickle exhausted before seeing STOPz at position z z , opcode z unknown.) r bytes_typesioBytesIOhasattrrOr!r?getrEr"rr)r% yield_end_posgetposposropcoders r_genopsr\s$ $zz$tV hyy|T[[34 >s{ !FGG 03 !D!%"'(( :: C**##D)C #sFH, ,#s" " 4< + sC/C1c t|Sr)r\)rAs rrrs, 6?rc d}d}t}i}g}d}d}t|dD]\}} } } d|jvr%|j| |j || f<|jdk(r0t |} |j| |j || f{d|jvrd|jvr4|j |kDr |j }d|| <|j || f|jd k(r'| |kDr| }| dk(r|| | }|j | | f|j | | f~tj} | j|tj| |}|d k\r|jjd} |D]\}} d }||ur!| |vr|j| }| || <| d z } n@||ur|j|| }n'||| }t ||jj kD}|jj#| |r|jj%||j||jj'| j)S)NrrrrT)rXrr7r3r1Fr )force)rr\raddrHr+rrTrUwriterA_Picklerframer start_framingputrW_FRAME_SIZE_TARGET commit_frame file_write end_framinggetvalue)rrerWoldidsnewidsopcodesr protoheaderr[rrZend_posidxoutpicklerop framelessr%s rrr sQ= C C UF FG EK%,Qd%C%C!S' FKK  JJsO NNC: & [[I %f+C JJsO NNC: &  #  fkk !||e# F3K NNC: & [[G #U{axGn W~. NNC> */&D0  **,CIIkooc5)G z$$& CC 9& ;;s#DF3K 1HC 3Y;;vc{+DR9DD GNN$E$EEI##)#4  NN % %d + MM$ #$ NN <<>rc g}|i}d}g}d|z}d} |} t|D]\} } } | td| zd|t| jdddd|t |z| j }t || j}| j}| j}t |}d}t|vs| j dk(r||rz|dturo |rh|j}|d}nd |z}|dtur|j|dtur|j |jt}nd x} }| j d vrH| j d k(rt |}d|z}n| }||vrd| z} n:|sd} n5|dturd} n'|d||<n| j dvr| |vr|| g}nd| z} | |r;|ddt | j z zz }| |dt| zz }|r|d|zz }|rK|d| t |z zz }t |} | dkDr|} |d| jjddd zz }t||| r t| t ||krtd|t |fz|r|| d=t|vr|j!| |j#|td|||rtd|zy#t$rd }YwxYw)NrrOz%5d:)endfiler 4rz(MARK at unknown opcode offset)z (MARK at %d)rzno MARK exists on stack)rrrrrz(as %d)zmemo key %r already definedz'stack is empty -- can't store into memoz"can't store markobject in the memo)rrrz&memo key %r has never been stored into 2r>)rwz3tries to pop %d items from stack with only %d itemsz highest protocol among opcodes =zstack not empty after STOP: %r)rrEreprrr+rmaxrrr markobjectpopindexr"rsplitrHextend)rArqmemo indentlevelannotatestackmaxproto markstack indentchunkerrormsgannocolr[rrZlinebeforeafternumtopopmarkmsgmarkposmemo_idxs rrr[ sQ&X E |HI #KHG"6NS ? &3,Cc 2"6;;/"5)C N:$kk+x.$$""v;  FKK5$8$)$)"I$;#--/??G,w6GBiz1IIKBiz1 !%||J7H &?>7 ;;E E{{i't9#h.483>Drj(?!&rX [[< <d{c CcI ?g C2FKK 001 1Dd3i'g %  C7SY./ /D$iG|" C&****43A66 6D d X& & u: -08#e*/EFG G xij!     S ! U+B ,hSA 9EABB "! H!s%K K#"K#ceZdZdZy)_Examplec||_yr)value)rrs rrz_Example.__init__ s  rN)rrrrrrrrr srra >>> import pickle >>> x = [1, 2, (3, 4), {b'abc': "def"}] >>> pkl0 = pickle.dumps(x, 0) >>> dis(pkl0) 0: ( MARK 1: l LIST (MARK at 0) 2: p PUT 0 5: I INT 1 8: a APPEND 9: I INT 2 12: a APPEND 13: ( MARK 14: I INT 3 17: I INT 4 20: t TUPLE (MARK at 13) 21: p PUT 1 24: a APPEND 25: ( MARK 26: d DICT (MARK at 25) 27: p PUT 2 30: c GLOBAL '_codecs encode' 46: p PUT 3 49: ( MARK 50: V UNICODE 'abc' 55: p PUT 4 58: V UNICODE 'latin1' 66: p PUT 5 69: t TUPLE (MARK at 49) 70: p PUT 6 73: R REDUCE 74: p PUT 7 77: V UNICODE 'def' 82: p PUT 8 85: s SETITEM 86: a APPEND 87: . STOP highest protocol among opcodes = 0 Try again with a "binary" pickle. >>> pkl1 = pickle.dumps(x, 1) >>> dis(pkl1) 0: ] EMPTY_LIST 1: q BINPUT 0 3: ( MARK 4: K BININT1 1 6: K BININT1 2 8: ( MARK 9: K BININT1 3 11: K BININT1 4 13: t TUPLE (MARK at 8) 14: q BINPUT 1 16: } EMPTY_DICT 17: q BINPUT 2 19: c GLOBAL '_codecs encode' 35: q BINPUT 3 37: ( MARK 38: X BINUNICODE 'abc' 46: q BINPUT 4 48: X BINUNICODE 'latin1' 59: q BINPUT 5 61: t TUPLE (MARK at 37) 62: q BINPUT 6 64: R REDUCE 65: q BINPUT 7 67: X BINUNICODE 'def' 75: q BINPUT 8 77: s SETITEM 78: e APPENDS (MARK at 3) 79: . STOP highest protocol among opcodes = 1 Exercise the INST/OBJ/BUILD family. >>> import pickletools >>> dis(pickle.dumps(pickletools.dis, 0)) 0: c GLOBAL 'pickletools dis' 17: p PUT 0 20: . STOP highest protocol among opcodes = 0 >>> from pickletools import _Example >>> x = [_Example(42)] * 2 >>> dis(pickle.dumps(x, 0)) 0: ( MARK 1: l LIST (MARK at 0) 2: p PUT 0 5: c GLOBAL 'copy_reg _reconstructor' 30: p PUT 1 33: ( MARK 34: c GLOBAL 'pickletools _Example' 56: p PUT 2 59: c GLOBAL '__builtin__ object' 79: p PUT 3 82: N NONE 83: t TUPLE (MARK at 33) 84: p PUT 4 87: R REDUCE 88: p PUT 5 91: ( MARK 92: d DICT (MARK at 91) 93: p PUT 6 96: V UNICODE 'value' 103: p PUT 7 106: I INT 42 110: s SETITEM 111: b BUILD 112: a APPEND 113: g GET 5 116: a APPEND 117: . STOP highest protocol among opcodes = 0 >>> dis(pickle.dumps(x, 1)) 0: ] EMPTY_LIST 1: q BINPUT 0 3: ( MARK 4: c GLOBAL 'copy_reg _reconstructor' 29: q BINPUT 1 31: ( MARK 32: c GLOBAL 'pickletools _Example' 54: q BINPUT 2 56: c GLOBAL '__builtin__ object' 76: q BINPUT 3 78: N NONE 79: t TUPLE (MARK at 31) 80: q BINPUT 4 82: R REDUCE 83: q BINPUT 5 85: } EMPTY_DICT 86: q BINPUT 6 88: X BINUNICODE 'value' 98: q BINPUT 7 100: K BININT1 42 102: s SETITEM 103: b BUILD 104: h BINGET 5 106: e APPENDS (MARK at 3) 107: . STOP highest protocol among opcodes = 1 Try "the canonical" recursive-object test. >>> L = [] >>> T = L, >>> L.append(T) >>> L[0] is T True >>> T[0] is L True >>> L[0][0] is L True >>> T[0][0] is T True >>> dis(pickle.dumps(L, 0)) 0: ( MARK 1: l LIST (MARK at 0) 2: p PUT 0 5: ( MARK 6: g GET 0 9: t TUPLE (MARK at 5) 10: p PUT 1 13: a APPEND 14: . STOP highest protocol among opcodes = 0 >>> dis(pickle.dumps(L, 1)) 0: ] EMPTY_LIST 1: q BINPUT 0 3: ( MARK 4: h BINGET 0 6: t TUPLE (MARK at 3) 7: q BINPUT 1 9: a APPEND 10: . STOP highest protocol among opcodes = 1 Note that, in the protocol 0 pickle of the recursive tuple, the disassembler has to emulate the stack in order to realize that the POP opcode at 16 gets rid of the MARK at 0. >>> dis(pickle.dumps(T, 0)) 0: ( MARK 1: ( MARK 2: l LIST (MARK at 1) 3: p PUT 0 6: ( MARK 7: g GET 0 10: t TUPLE (MARK at 6) 11: p PUT 1 14: a APPEND 15: 0 POP 16: 0 POP (MARK at 0) 17: g GET 1 20: . STOP highest protocol among opcodes = 0 >>> dis(pickle.dumps(T, 1)) 0: ( MARK 1: ] EMPTY_LIST 2: q BINPUT 0 4: ( MARK 5: h BINGET 0 7: t TUPLE (MARK at 4) 8: q BINPUT 1 10: a APPEND 11: 1 POP_MARK (MARK at 0) 12: h BINGET 1 14: . STOP highest protocol among opcodes = 1 Try protocol 2. >>> dis(pickle.dumps(L, 2)) 0: \x80 PROTO 2 2: ] EMPTY_LIST 3: q BINPUT 0 5: h BINGET 0 7: \x85 TUPLE1 8: q BINPUT 1 10: a APPEND 11: . STOP highest protocol among opcodes = 2 >>> dis(pickle.dumps(T, 2)) 0: \x80 PROTO 2 2: ] EMPTY_LIST 3: q BINPUT 0 5: h BINGET 0 7: \x85 TUPLE1 8: q BINPUT 1 10: a APPEND 11: 0 POP 12: h BINGET 1 14: . STOP highest protocol among opcodes = 2 Try protocol 3 with annotations: >>> dis(pickle.dumps(T, 3), annotate=1) 0: \x80 PROTO 3 Protocol version indicator. 2: ] EMPTY_LIST Push an empty list. 3: q BINPUT 0 Store the stack top into the memo. The stack is not popped. 5: h BINGET 0 Read an object from the memo and push it on the stack. 7: \x85 TUPLE1 Build a one-tuple out of the topmost item on the stack. 8: q BINPUT 1 Store the stack top into the memo. The stack is not popped. 10: a APPEND Append an object to a list. 11: 0 POP Discard the top stack item, shrinking the stack by one item. 12: h BINGET 1 Read an object from the memo and push it on the stack. 14: . STOP Stop the unpickling machine. highest protocol among opcodes = 2 a= >>> import pickle >>> import io >>> f = io.BytesIO() >>> p = pickle.Pickler(f, 2) >>> x = [1, 2, 3] >>> p.dump(x) >>> p.dump(x) >>> f.seek(0) 0 >>> memo = {} >>> dis(f, memo=memo) 0: \x80 PROTO 2 2: ] EMPTY_LIST 3: q BINPUT 0 5: ( MARK 6: K BININT1 1 8: K BININT1 2 10: K BININT1 3 12: e APPENDS (MARK at 5) 13: . STOP highest protocol among opcodes = 2 >>> dis(f, memo=memo) 14: \x80 PROTO 2 16: h BINGET 0 18: . STOP highest protocol among opcodes = 2 )disassembler_testdisassembler_memo_testc*ddl}|jS)Nr)doctesttestmod)rs r_testr s ?? r__main__z$disassemble one or more pickle files) description pickle_file*zthe pickle file)nargshelpz-oz--outputz+the file where the output should be written)rz-mz--memo store_truez#preserve memo between disassemblies)actionrz-lz --indentlevelz8the number of blanks by which to indent a new MARK level)defaulttyperz-az --annotatez2annotate each line with a short opcode descriptionz-pz --preamblez==> {name} <==zMif more than one pickle file is specified, print this before each disassembly)rrz-tz--testzrun self-test suitez-vz)run verbosely; only affects self-test runw-zrr>rb)TT)F)NNr1r)rCrTrArCr^rBrS UP_TO_NEWLINETAKEN_FROM_ARGUMENT1TAKEN_FROM_ARGUMENT4TAKEN_FROM_ARGUMENT4UTAKEN_FROM_ARGUMENT8Uobjectr structrr,r&r'r-r/r2r3r5r6r9r:rHrIrLrMrPrQrUrVrXrYr[r\r`rarcrdrgrhrkrlrprqrsrurwrxrrrrrrrrrrrrrrr|pyintpylongrpyinteger_or_boolpyboolrpyfloatrrjpybytes_or_strpystringpybytesrf pybytearray pyunicoderpynonerpytuplerpylistrpydictrpyset pyfrozensetpybuffer anyobjectr}rrrrmname2icode2i enumerater,rrr"rr?rMr\rrrr _dis_test _memo_test__test__rrargparseArgumentParserparser add_argument parse_argsargstestr print_helprroutputstdoutopenrr+preambleformatrastdinrrr$closerrrrsA  '  ` ""H% @ ,  . @ ;  = ? I K @ <  > @ =  ?-^ #  /'0'5 L,":,$?"! "%" $! %, $! %" $   %. %   %0 %   %0 %$   +%,%1 04$)*. 08$)+. 08$)+. ,"%,%1 $*$/  !  A    (*     .     (&<  "$$   ;-/   " $     " (  3<466     "   $&   + -   :! #     "    !    !       $&   & (   ( *          *99vQ 5  $%   Q :8  '   ;Q V9  '   WQ n9  '   oQ H6  '   IQ l7  '   mQ B7  '   CQ \8  !"   ]Q |;  !"   }Q ^   !"   _Q D:  )   EQ ^   )   _Q x;  )   yQ V<  -   WQ t=  * . 0uQ D   :* 8 :EQ X6  ( # %YQ n9  ( % 'oQ ~:  ( & (Q R9  +   SQ l   +   mQ F <  +   G Q ` =  +   a Q ~ 7  )    Q f :  )   g Q J <  (  !K Q Z 8  I&(   [ Q v 9  J 3(   w Q R 6   +(   S Q v =  ) "w Q F 7   +)   G Q f 8  ;)   g Q D8  y))   EQ b8  y)4)   cQ D<  (  !EQ T6   +(   UQ v9  Iy1(   wQ R:  J 3(   SQ @;  '   AQ P:  :z2'   QQ |;   +-   }Q `5  ; H JaQ p5  ;i( I KqQ @6  ,   AQ Z:   +   [Q z5  +   {Q T8  +   UQ l=  +   mQ D5     EQ ^8     _Q v=     wQ N9  ;+   OQ l6  +   mQ X6  +   YQ n6  +   oQ J8  +   KQ h>  y)+   iQ D8  y)+   EQ ~7  y)+   Q p6   ++ * 0 qQ T5   :6+   UQ T8  y)+   UQ r;  y)4+   sQ T7     UQ l6  ;   mQ J7     KQ f8  +   gQ H ;  ;+   I Q d    g DAqvv@&&&.!456 6vv@&&&.!456 6F166NF166N  FAq  AGAFFO $)L @8>FXCv}  ~ :"+&0  z $X $ $: k >k k #k-