pickle (version 1.156)
index
/usr/local/lib/python2.3/pickle.py

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

 
Modules
       
binascii
marshal
re
struct
sys
warnings

 
Classes
       
exceptions.Exception
PickleError
PicklingError
UnpicklingError
Pickler
Unpickler

 
class PickleError(exceptions.Exception)
    A common base class for the other pickling exceptions.
 
  Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class Pickler
     Methods defined here:
__init__(self, file, protocol=None, bin=None)
This takes a file-like object for writing a pickle data stream.
 
The optional protocol argument tells the pickler to use the
given protocol; supported protocols are 0, 1, 2.  The default
protocol is 0, to be backwards compatible.  (Protocol 0 is the
only protocol that can be written to a file opened in text
mode and read back successfully.  When using a protocol higher
than 0, make sure the file is opened in binary mode, both when
pickling and unpickling.)
 
Protocol 1 is more efficient than protocol 0; protocol 2 is
more efficient than protocol 1.
 
Specifying a negative protocol version selects the highest
protocol version supported.  The higher the protocol used, the
more recent the version of Python needed to read the pickle
produced.
 
The file parameter must have a write() method that accepts a single
string argument.  It can thus be an open file object, a StringIO
object, or any other custom object that meets this interface.
clear_memo(self)
Clears the pickler's "memo".
 
The memo is the data structure that remembers which objects the
pickler has already seen, so that shared or recursive objects are
pickled by reference and not by value.  This method is useful when
re-using picklers.
dump(self, obj)
Write a pickled representation of obj to the open file.
get(self, i, pack=<built-in function pack>)
# Return a GET (BINGET, LONG_BINGET) opcode string, with argument i.
memoize(self, obj)
Store an object in the memo.
persistent_id(self, obj)
put(self, i, pack=<built-in function pack>)
# Return a PUT (BINPUT, LONG_BINPUT) opcode string, with argument i.
save(self, obj)
save_bool(self, obj)
save_dict(self, obj)
save_empty_tuple(self, obj)
save_empty_tuple() isn't used by anything in Python 2.3.  However, I
# found a Pickler subclass in Zope3 that calls it, so it's not harmless
# to remove it.
save_float(self, obj, pack=<built-in function pack>)
save_global(self, obj, name=None, pack=<built-in function pack>)
save_inst(self, obj)
save_int(self, obj, pack=<built-in function pack>)
save_list(self, obj)
save_long(self, obj, pack=<built-in function pack>)
save_none(self, obj)
save_pers(self, pid)
save_reduce(self, func, args, state=None, listitems=None, dictitems=None, obj=None)
save_string(self, obj, pack=<built-in function pack>)
save_tuple(self, obj)
save_unicode(self, obj, pack=<built-in function pack>)

Data and other attributes defined here:
dispatch = {<type 'classobj'>: <function save_global>, <type 'instance'>: <function save_inst>, <type 'float'>: <function save_float>, <type 'int'>: <function save_int>, <type 'list'>: <function save_list>, <type 'long'>: <function save_long>, <type 'dict'>: <function save_dict>, <type 'NoneType'>: <function save_none>, <type 'str'>: <function save_string>, <type 'tuple'>: <function save_tuple>, ...}

 
class PicklingError(PickleError)
    This exception is raised when an unpicklable object is passed to the
dump() method.
 
 
Method resolution order:
PicklingError
PickleError
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class Unpickler
     Methods defined here:
__init__(self, file)
This takes a file-like object for reading a pickle data stream.
 
The protocol version of the pickle is detected automatically, so no
proto argument is needed.
 
The file-like object must have two methods, a read() method that
takes an integer argument, and a readline() method that requires no
arguments.  Both methods should return a string.  Thus file-like
object can be a file object opened for reading, a StringIO object,
or any other custom object that meets this interface.
find_class(self, module, name)
get_extension(self, code)
load(self)
Read a pickled object representation from the open file.
 
Return the reconstituted object hierarchy specified in the file.
load_append(self)
load_appends(self)
load_binfloat(self, unpack=<built-in function unpack>)
load_binget(self)
load_binint(self)
load_binint1(self)
load_binint2(self)
load_binpersid(self)
load_binput(self)
load_binstring(self)
load_binunicode(self)
load_build(self)
load_dict(self)
load_dup(self)
load_empty_dictionary(self)
load_empty_list(self)
load_empty_tuple(self)
load_eof(self)
load_ext1(self)
load_ext2(self)
load_ext4(self)
load_false(self)
load_float(self)
load_get(self)
load_global(self)
load_inst(self)
load_int(self)
load_list(self)
load_long(self)
load_long1(self)
load_long4(self)
load_long_binget(self)
load_long_binput(self)
load_mark(self)
load_newobj(self)
load_none(self)
load_obj(self)
load_persid(self)
load_pop(self)
load_pop_mark(self)
load_proto(self)
load_put(self)
load_reduce(self)
load_setitem(self)
load_setitems(self)
load_short_binstring(self)
load_stop(self)
load_string(self)
load_true(self)
load_tuple(self)
load_tuple1(self)
load_tuple2(self)
load_tuple3(self)
load_unicode(self)
marker(self)
# Return largest index k such that self.stack[k] is self.mark.
# If the stack doesn't contain a mark, eventually raises IndexError.
# This could be sped by maintaining another stack, of indices at which
# the mark appears.  For that matter, the latter stack would suffice,
# and we wouldn't need to push mark objects on self.stack at all.
# Doing so is probably a good thing, though, since if the pickle is
# corrupt (or hostile) we may get a clue from finding self.mark embedded
# in unpickled objects.

Data and other attributes defined here:
dispatch = {'': <function load_eof>, '(': <function load_mark>, ')': <function load_empty_tuple>, '.': <function load_stop>, '0': <function load_pop>, '1': <function load_pop_mark>, '2': <function load_dup>, 'F': <function load_float>, 'G': <function load_binfloat>, 'I': <function load_int>, ...}

 
class UnpicklingError(PickleError)
    This exception is raised when there is a problem unpickling an object,
such as a security violation.
 
Note that other exceptions may also be raised during unpickling, including
(but not necessarily limited to) AttributeError, EOFError, ImportError,
and IndexError.
 
 
Method resolution order:
UnpicklingError
PickleError
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
Functions
       
StringIO(...)
StringIO([s]) -- Return a StringIO-like stream for reading or writing
decode_long(data)
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
dump(obj, file, protocol=None, bin=None)
dumps(obj, protocol=None, bin=None)
encode_long(x)
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'
>>>
load(file)
loads(str)
mloads = loads(...)
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__".

 
Data
        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
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'
__all__ = ['PickleError', 'PicklingError', 'UnpicklingError', 'Pickler', 'Unpickler', 'dump', 'dumps', 'load', 'loads', 'APPEND', 'APPENDS', 'BINFLOAT', 'BINGET', 'BININT', 'BININT1', 'BININT2', 'BINPERSID', 'BINPUT', 'BINSTRING', 'BINUNICODE', ...]
__version__ = '$Revision: 1.156 $'
classmap = {}
compatible_formats = ['1.0', '1.1', '1.2', '1.3', '2.0']
dispatch_table = {<type 'code'>: <function pickle_code>, <type '_sre.SRE_Pattern'>: <function _pickle>, <type 'complex'>: <function pickle_complex>, <type 'posix.stat_result'>: <function _pickle_stat_result>, <type 'posix.statvfs_result'>: <function _pickle_statvfs_result>, <type 'parser.st'>: <built-in function _pickler>}
format_version = '2.0'