Module pickle
[hide private]
[frames] | no frames]

Module pickle

source code

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: 72223 $

Classes [hide private]
  PickleError
A common base class for the other pickling exceptions.
  Pickler
  PicklingError
This exception is raised when an unpicklable object is passed to the dump() method.
  Unpickler
  UnpicklingError
This exception is raised when there is a problem unpickling an object, such as a security violation.
  _EmptyClass
  _Stop
Functions [hide private]
 
_keep_alive(x, memo)
Keeps a reference to the object x in the memo.
source code
 
_test() source code
 
decode_long(data)
Decode a long from a two's complement little-endian binary string.
source code
 
dump(obj, file, protocol=None) source code
 
dumps(obj, protocol=None) source code
 
encode_long(x)
Encode a long to a two's complement little-endian binary string.
source code
 
load(file) source code
 
loads(str) source code
 
whichmodule(func, funcname)
Figure out the module in which a function occurs.
source code
Variables [hide private]
  APPEND = 'a'
  APPENDS = 'e'
  BINFLOAT = 'G'
  BINGET = 'h'
  BININT = 'J'
  BININT1 = 'K'
  BININT2 = 'M'
  BINPERSID = 'Q'
  BINPUT = 'q'
  BINSTRING = 'T'
  BINUNICODE = 'X'
  BUILD = 'b'
  DICT = 'd'
  DUP = '2'
  EMPTY_DICT = '}'
  EMPTY_LIST = ']'
  EMPTY_TUPLE = ')'
  EXT1 = '\x82'
  EXT2 = '\x83'
  EXT4 = '\x84'
  FALSE = 'I00\n'
  FLOAT = 'F'
  GET = 'g'
  GLOBAL = 'c'
  HIGHEST_PROTOCOL = 2
  INST = 'i'
  INT = 'I'
  LIST = 'l'
  LONG = 'L'
  LONG1 = '\x8a'
  LONG4 = '\x8b'
  LONG_BINGET = 'j'
  LONG_BINPUT = 'r'
  MARK = '('
  NEWFALSE = '\x89'
  NEWOBJ = '\x81'
  NEWTRUE = '\x88'
  NONE = 'N'
  OBJ = 'o'
  PERSID = 'P'
  POP = '0'
  POP_MARK = '1'
  PROTO = '\x80'
  PUT = 'p'
  PyStringMap = None
hash(x)
  REDUCE = 'R'
  SETITEM = 's'
  SETITEMS = 'u'
  SHORT_BINSTRING = 'U'
  STOP = '.'
  STRING = 'S'
  StringTypes = (<type 'str'>, <type 'unicode'>)
  TRUE = 'I01\n'
  TUPLE = 't'
  TUPLE1 = '\x85'
  TUPLE2 = '\x86'
  TUPLE3 = '\x87'
  UNICODE = 'V'
  __package__ = None
hash(x)
  _extension_cache = {}
  _extension_registry = {}
  _inverted_registry = {}
  _tuplesize2code = [')', '\x85', '\x86', '\x87']
  classmap = {}
  compatible_formats = ['1.0', '1.1', '1.2', '1.3', '2.0']
  dispatch_table = {<type 'parser.st'>: <built-in function _pick...
  format_version = '2.0'
Function Details [hide private]

_keep_alive(x, memo)

source code 

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

decode_long(data)

source code 

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

encode_long(x)

source code 

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'
>>>

whichmodule(func, funcname)

source code 

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__".


Variables Details [hide private]

dispatch_table

Value:
{<type 'parser.st'>: <built-in function _pickler>,
 <type 'complex'>: <function pickle_complex at 0x7fee55d76aa0>,
 <type '_sre.SRE_Pattern'>: <function _pickle at 0x7fee55d22500>,
 <type 'posix.statvfs_result'>: <function _pickle_statvfs_result at 0x\
7fee55cf8050>,
 <type 'posix.stat_result'>: <function _pickle_stat_result at 0x7fee55\
d76ed8>}