pickletools

“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.

Functions

decode_long(data) Decode a long from a two’s complement little-endian binary string.
dis(pickle[, out, memo, indentlevel]) Produce a symbolic disassembly of a pickle.
genops(pickle) Generate all the opcodes in a pickle.
optimize(p) Optimize a pickle string by removing unused PUT opcodes
read_decimalnl_long(f)
>>> import StringIO
read_decimalnl_short(f)
>>> import StringIO
read_float8(f)
>>> import StringIO, struct
read_floatnl(f)
>>> import StringIO
read_int4(f)
>>> import StringIO
read_long1(f)
>>> import StringIO
read_long4(f)
>>> import StringIO
read_string1(f)
>>> import StringIO
read_string4(f)
>>> import StringIO
read_stringnl(f[, decode, stripquotes])
>>> import StringIO
read_stringnl_noescape(f)
read_stringnl_noescape_pair(f)
>>> import StringIO
read_uint1(f)
>>> import StringIO
read_uint2(f)
>>> import StringIO
read_unicodestring4(f)
>>> import StringIO
read_unicodestringnl(f)
>>> import StringIO

Classes

ArgumentDescriptor(name, n, reader, doc)
OpcodeInfo(name, code, arg, stack_before, ...)
StackObject(name, obtype, doc)