Module pickle
Create portable serialized representations of Python objects.
See module cPickle for a (much) faster implementation.
See module copy_reg 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
Version:
$Revision: 38432 $
|
|
_keep_alive(x,
memo)
Keeps a reference to the object x in the memo. |
|
|
|
|
whichmodule(func,
funcname)
Figure out the module in which a function occurs. |
|
|
|
|
encode_long(x)
Encode a long to a two's complement little-endian binary string. |
|
|
|
|
decode_long(data)
Decode a long from a two's complement little-endian binary string. |
|
|
|
|
| dump(obj,
file,
protocol=None) |
|
|
|
|
| dumps(obj,
protocol=None) |
|
|
|
|
|
|
|
|
|
|
|
|
|
format_version = '2.0'
|
|
|
compatible_formats = ['1.0', '1.1', '1.2', '1.3', '2.0']
|
|
|
HIGHEST_PROTOCOL = 2
|
|
|
PyStringMap = None
|
|
|
MARK = '('
|
|
|
STOP = '.'
|
|
|
POP = '0'
|
|
|
POP_MARK = '1'
|
|
|
DUP = '2'
|
|
|
FLOAT = 'F'
|
|
|
INT = 'I'
|
|
|
BININT = 'J'
|
|
|
BININT1 = 'K'
|
|
|
LONG = 'L'
|
|
|
BININT2 = 'M'
|
|
|
NONE = 'N'
|
|
|
PERSID = 'P'
|
|
|
BINPERSID = 'Q'
|
|
|
REDUCE = 'R'
|
|
|
STRING = 'S'
|
|
|
BINSTRING = 'T'
|
|
|
SHORT_BINSTRING = 'U'
|
|
|
UNICODE = 'V'
|
|
|
BINUNICODE = 'X'
|
|
|
APPEND = 'a'
|
|
|
BUILD = 'b'
|
|
|
GLOBAL = 'c'
|
|
|
DICT = 'd'
|
|
|
EMPTY_DICT = '}'
|
|
|
APPENDS = 'e'
|
|
|
GET = 'g'
|
|
|
BINGET = 'h'
|
|
|
INST = 'i'
|
|
|
LONG_BINGET = 'j'
|
|
|
LIST = 'l'
|
|
|
EMPTY_LIST = ']'
|
|
|
OBJ = 'o'
|
|
|
PUT = 'p'
|
|
|
BINPUT = 'q'
|
|
|
LONG_BINPUT = 'r'
|
|
|
SETITEM = 's'
|
|
|
TUPLE = 't'
|
|
|
EMPTY_TUPLE = ')'
|
|
|
SETITEMS = 'u'
|
|
|
BINFLOAT = 'G'
|
|
|
TRUE = 'I01\n'
|
|
|
FALSE = 'I00\n'
|
|
|
PROTO = '\x80'
|
|
|
NEWOBJ = '\x81'
|
|
|
EXT1 = '\x82'
|
|
|
EXT2 = '\x83'
|
|
|
EXT4 = '\x84'
|
|
|
TUPLE1 = '\x85'
|
|
|
TUPLE2 = '\x86'
|
|
|
TUPLE3 = '\x87'
|
|
|
NEWTRUE = '\x88'
|
|
|
NEWFALSE = '\x89'
|
|
|
LONG1 = '\x8a'
|
|
|
LONG4 = '\x8b'
|
|
|
_tuplesize2code = [')', '\x85', '\x86', '\x87']
|
|
|
classmap = {}
|
Imports:
IntType,
TypeType,
BooleanType,
CodeType,
UnboundMethodType,
StringType,
BuiltinMethodType,
FloatType,
DictionaryType,
NotImplementedType,
BuiltinFunctionType,
DictProxyType,
GeneratorType,
InstanceType,
ObjectType,
DictType,
GetSetDescriptorType,
FileType,
EllipsisType,
StringTypes,
ListType,
MethodType,
TupleType,
ModuleType,
FrameType,
LongType,
BufferType,
TracebackType,
ClassType,
MemberDescriptorType,
SliceType,
ComplexType,
LambdaType,
FunctionType,
XRangeType,
NoneType,
dispatch_table,
_extension_registry,
_inverted_registry,
_extension_cache,
marshal,
sys,
struct,
re,
mloads,
UnicodeType,
_binascii,
StringIO
|
Keeps a reference to the object x in the memo.
Because we remember objects by their id, we have to assure that
possibly temporary objects are kept alive by referencing them. We store a
reference at the id of the memo, which should normally not be used unless
someone tries to deepcopy the memo itself...
|
whichmodule(func,
funcname)
|
|
Figure out the module in which a function occurs.
Search sys.modules for the module. Cache in classmap. Return a module
name. If the function cannot be found, return "__main__".
|
|
Encode a long to a two's complement little-endian binary string. Note
that 0L is a special case, returning an empty string, to save a byte in
the LONG1 pickling context.
>>> encode_long(0L)
''
>>> encode_long(255L)
'\xff\x00'
>>> encode_long(32767L)
'\xff\x7f'
>>> encode_long(-256L)
'\x00\xff'
>>> encode_long(-32768L)
'\x00\x80'
>>> encode_long(-128L)
'\x80'
>>> encode_long(127L)
'\x7f'
>>>
|
|
Decode a long from a two's complement little-endian binary string.
>>> decode_long('')
0L
>>> decode_long("\xff\x00")
255L
>>> decode_long("\xff\x7f")
32767L
>>> decode_long("\x00\xff")
-256L
>>> decode_long("\x00\x80")
-32768L
>>> decode_long("\x80")
-128L
>>> decode_long("\x7f")
127L
|