Trees | Indices | Help |
|
---|
|
"Executable documentation" for the pickle module. Extensive comments about the pickle protocols and pickle-machine opcodes can be found here. Some functions meant for external use: genops(pickle) Generate all the opcodes in a pickle, as (opcode, arg, position) triples. dis(pickle, out=None, memo=None, indentlevel=4) Print a symbolic disassembly of a pickle.
|
|||
ArgumentDescriptor | |||
StackObject | |||
OpcodeInfo | |||
_Example |
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
|||
UP_TO_NEWLINE = -1
|
|||
TAKEN_FROM_ARGUMENT1 = -2
|
|||
TAKEN_FROM_ARGUMENT4 = -3
|
|||
uint1 = ArgumentDescriptor(name= 'uint1', n= 1, reader= read_u
|
|||
uint2 = ArgumentDescriptor(name= 'uint2', n= 2, reader= read_u
|
|||
int4 = ArgumentDescriptor(name= 'int4', n= 4, reader= read_int
|
|||
stringnl = ArgumentDescriptor(name= 'stringnl', n= UP_TO_NEWLI
|
|||
stringnl_noescape = ArgumentDescriptor(name= 'stringnl_noescap
|
|||
stringnl_noescape_pair = ArgumentDescriptor(name= 'stringnl_no
|
|||
string4 = ArgumentDescriptor(name= "string4", n= TAKEN_FROM_AR
|
|||
string1 = ArgumentDescriptor(name= "string1", n= TAKEN_FROM_AR
|
|||
unicodestringnl = ArgumentDescriptor(name= 'unicodestringnl',
|
|||
unicodestring4 = ArgumentDescriptor(name= "unicodestring4", n=
|
|||
decimalnl_short = ArgumentDescriptor(name= 'decimalnl_short',
|
|||
decimalnl_long = ArgumentDescriptor(name= 'decimalnl_long', n=
|
|||
floatnl = ArgumentDescriptor(name= 'floatnl', n= UP_TO_NEWLINE
|
|||
float8 = ArgumentDescriptor(name= 'float8', n= 8, reader= read
|
|||
long1 = ArgumentDescriptor(name= "long1", n= TAKEN_FROM_ARGUME
|
|||
long4 = ArgumentDescriptor(name= "long4", n= TAKEN_FROM_ARGUME
|
|||
pyint = int
|
|||
pylong = long
|
|||
pyinteger_or_bool = int_or_bool
|
|||
pybool = bool
|
|||
pyfloat = float
|
|||
pystring = str
|
|||
pyunicode = unicode
|
|||
pynone = None
|
|||
pytuple = tuple
|
|||
pylist = list
|
|||
pydict = dict
|
|||
anyobject = any
|
|||
markobject = mark
|
|||
stackslice = stackslice
|
|||
opcodes = [I(name= 'INT', code= 'I', arg= decimalnl_short, sta
|
|||
code2op = {}
|
|||
_dis_test =
|
|||
_memo_test =
|
|||
__test__ =
|
Imports: _unpack, decode_long
|
>>> import StringIO >>> read_stringnl(StringIO.StringIO("'abcd'\nefg\n")) 'abcd' >>> read_stringnl(StringIO.StringIO("\n")) Traceback (most recent call last): ... ValueError: no string quotes around '' >>> read_stringnl(StringIO.StringIO("\n"), stripquotes=False) '' >>> read_stringnl(StringIO.StringIO("''\n")) '' >>> read_stringnl(StringIO.StringIO('"abcd"')) Traceback (most recent call last): ... ValueError: no newline found when trying to read stringnl Embedded escapes are undone in the result. >>> read_stringnl(StringIO.StringIO(r"'a\n\\b\x00c\td'" + "\n'e'")) 'a\n\\b\x00c\td' |
>>> import StringIO >>> read_decimalnl_long(StringIO.StringIO("1234\n56")) Traceback (most recent call last): ... ValueError: trailing 'L' required in '1234' Someday the trailing 'L' will probably go away from this output. >>> read_decimalnl_long(StringIO.StringIO("1234L\n56")) 1234L >>> read_decimalnl_long(StringIO.StringIO("123456789012345678901234L\n6")) 123456789012345678901234L |
Generate all the opcodes in a pickle. 'pickle' is a file-like object, or string, containing the pickle. Each opcode in the pickle is generated, from the current pickle position, stopping after a STOP opcode is delivered. A triple is generated for each opcode: opcode, arg, pos opcode is an OpcodeInfo record, describing the current opcode. If the opcode has an argument embedded in the pickle, arg is its decoded value, as a Python object. If the opcode doesn't have an argument, arg is None. If the pickle has a tell() method, pos was the value of pickle.tell() before reading the current opcode. If the pickle is a string object, it's wrapped in a StringIO object, and the latter's tell() result is used. Else (the pickle doesn't have a tell(), and it's not obvious how to query its current position) pos is None. |
Produce a symbolic disassembly of a pickle. 'pickle' is a file-like object, or string, containing a (at least one) pickle. The pickle is disassembled from the current position, through the first STOP opcode encountered. Optional arg 'out' is a file-like object to which the disassembly is printed. It defaults to sys.stdout. Optional arg 'memo' is a Python dict, used as the pickle's memo. It may be mutated by dis(), if the pickle contains PUT or BINPUT opcodes. Passing the same memo object to another dis() call then allows disassembly to proceed across multiple pickles that were all created by the same pickler with the same memo. Ordinarily you don't need to worry about this. Optional arg indentlevel is the number of blanks by which to indent a new MARK level. It defaults to 4. In addition to printing the disassembly, some sanity checks are made: + All embedded opcode arguments "make sense". + Explicit and implicit pop operations have enough items on the stack. + When an opcode implicitly refers to a markobject, a markobject is actually on the stack. + A memo entry isn't referenced before it's defined. + The markobject isn't stored in the memo. + A memo entry isn't redefined. |
|
uint1
|
uint2
|
int4
|
stringnl
|
stringnl_noescape
|
stringnl_noescape_pair
|
string4
|
string1
|
unicodestringnl
|
unicodestring4
|
decimalnl_short
|
decimalnl_long
|
floatnl
|
float8
|
long1
|
long4
|
opcodes
|
_dis_test
|
_memo_test
|
__test__
|
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0 on Tue Jan 29 22:41:09 2008 | http://epydoc.sourceforge.net |