Back to index

python3.2  3.2.2
Classes | Functions | Variables
pickle Namespace Reference

Classes

class  PickleError
class  PicklingError
class  UnpicklingError
class  _Stop
class  _Pickler
class  _Unpickler

Functions

def _keep_alive
def whichmodule
def encode_long
def decode_long
def dump
def dumps
def load
def loads
def _test

Variables

string __version__ = "$Revision$"
list __all__
tuple bytes_types = (bytes, bytearray)
string format_version = "3.0"
list compatible_formats
int HIGHEST_PROTOCOL = 3
int DEFAULT_PROTOCOL = 3
 mloads = marshal.loads
 PyStringMap = None
string MARK = '('
string STOP = '.'
string POP = '0'
string POP_MARK = '1'
string DUP = '2'
string FLOAT = 'F'
string INT = 'I'
string BININT = 'J'
string BININT1 = 'K'
string LONG = 'L'
string BININT2 = 'M'
string NONE = 'N'
string PERSID = 'P'
string BINPERSID = 'Q'
string REDUCE = 'R'
string STRING = 'S'
string BINSTRING = 'T'
string SHORT_BINSTRING = 'U'
string UNICODE = 'V'
string BINUNICODE = 'X'
string APPEND = 'a'
string BUILD = 'b'
string GLOBAL = 'c'
string DICT = 'd'
string EMPTY_DICT = '}'
string APPENDS = 'e'
string GET = 'g'
string BINGET = 'h'
string INST = 'i'
string LONG_BINGET = 'j'
string LIST = 'l'
string EMPTY_LIST = ']'
string OBJ = 'o'
string PUT = 'p'
string BINPUT = 'q'
string LONG_BINPUT = 'r'
string SETITEM = 's'
string TUPLE = 't'
string EMPTY_TUPLE = ')'
string SETITEMS = 'u'
string BINFLOAT = 'G'
string TRUE = 'I01\n'
string FALSE = 'I00\n'
string PROTO = '\x80'
string NEWOBJ = '\x81'
string EXT1 = '\x82'
string EXT2 = '\x83'
string EXT4 = '\x84'
string TUPLE1 = '\x85'
string TUPLE2 = '\x86'
string TUPLE3 = '\x87'
string NEWTRUE = '\x88'
string NEWFALSE = '\x89'
string LONG1 = '\x8a'
string LONG4 = '\x8b'
list _tuplesize2code = [EMPTY_TUPLE, TUPLE1, TUPLE2, TUPLE3]
string BINBYTES = 'B'
string SHORT_BINBYTES = 'C'
dictionary classmap = {}
tuple parser
string nargs = '*'
string help = 'run self-test suite'
tuple args = parser.parse_args()
tuple obj = load(f)

Detailed Description

Create portable serialized representations of Python objects.

See module copyreg 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

Function Documentation

def pickle._keep_alive (   x,
  memo 
) [private]
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...

Definition at line 727 of file pickle.py.

00727 
00728 def _keep_alive(x, memo):
00729     """Keeps a reference to the object x in the memo.
00730 
00731     Because we remember objects by their id, we have
00732     to assure that possibly temporary objects are kept
00733     alive by referencing them.
00734     We store a reference at the id of the memo, which should
00735     normally not be used unless someone tries to deepcopy
00736     the memo itself...
00737     """
00738     try:
00739         memo[id(memo)].append(x)
00740     except KeyError:
00741         # aha, this is the first one :-)
00742         memo[id(memo)]=[x]
00743 
00744 
00745 # A cache for whichmodule(), mapping a function object to the name of
00746 # the module in which the function was found.

Here is the call graph for this function:

def pickle._test ( ) [private]

Definition at line 1320 of file pickle.py.

01320 
01321 def _test():
01322     import doctest
01323     return doctest.testmod()

Here is the call graph for this function:

def pickle.decode_long (   data)

Definition at line 1270 of file pickle.py.

01270 
01271 def decode_long(data):
01272     r"""Decode a long from a two's complement little-endian binary string.
01273 
01274     >>> decode_long(b'')
01275     0
01276     >>> decode_long(b"\xff\x00")
01277     255
01278     >>> decode_long(b"\xff\x7f")
01279     32767
01280     >>> decode_long(b"\x00\xff")
01281     -256
01282     >>> decode_long(b"\x00\x80")
01283     -32768
01284     >>> decode_long(b"\x80")
01285     -128
01286     >>> decode_long(b"\x7f")
01287     127
01288     """
01289     return int.from_bytes(data, byteorder='little', signed=True)
01290 
01291 # Shorthands

Here is the caller graph for this function:

def pickle.dump (   obj,
  file,
  protocol = None,
  fix_imports = True 
)

Definition at line 1292 of file pickle.py.

01292 
01293 def dump(obj, file, protocol=None, *, fix_imports=True):
01294     Pickler(file, protocol, fix_imports=fix_imports).dump(obj)

Here is the caller graph for this function:

def pickle.dumps (   obj,
  protocol = None,
  fix_imports = True 
)

Definition at line 1295 of file pickle.py.

01295 
01296 def dumps(obj, protocol=None, *, fix_imports=True):
01297     f = io.BytesIO()
01298     Pickler(f, protocol, fix_imports=fix_imports).dump(obj)
01299     res = f.getvalue()
01300     assert isinstance(res, bytes_types)
01301     return res

Here is the call graph for this function:

Here is the caller graph for this function:

def pickle.encode_long (   x)

Definition at line 1240 of file pickle.py.

01240 
01241 def encode_long(x):
01242     r"""Encode a long to a two's complement little-endian binary string.
01243     Note that 0 is a special case, returning an empty string, to save a
01244     byte in the LONG1 pickling context.
01245 
01246     >>> encode_long(0)
01247     b''
01248     >>> encode_long(255)
01249     b'\xff\x00'
01250     >>> encode_long(32767)
01251     b'\xff\x7f'
01252     >>> encode_long(-256)
01253     b'\x00\xff'
01254     >>> encode_long(-32768)
01255     b'\x00\x80'
01256     >>> encode_long(-128)
01257     b'\x80'
01258     >>> encode_long(127)
01259     b'\x7f'
01260     >>>
01261     """
01262     if x == 0:
01263         return b''
01264     nbytes = (x.bit_length() >> 3) + 1
01265     result = x.to_bytes(nbytes, byteorder='little', signed=True)
01266     if x < 0 and nbytes > 1:
01267         if result[-1] == 0xff and (result[-2] & 0x80) != 0:
01268             result = result[:-1]
01269     return result

Here is the caller graph for this function:

def pickle.load (   file,
  fix_imports = True,
  encoding = "ASCII",
  errors = "strict" 
)

Definition at line 1302 of file pickle.py.

01302 
01303 def load(file, *, fix_imports=True, encoding="ASCII", errors="strict"):
01304     return Unpickler(file, fix_imports=fix_imports,
01305                      encoding=encoding, errors=errors).load()

Here is the caller graph for this function:

def pickle.loads (   s,
  fix_imports = True,
  encoding = "ASCII",
  errors = "strict" 
)

Definition at line 1306 of file pickle.py.

01306 
01307 def loads(s, *, fix_imports=True, encoding="ASCII", errors="strict"):
01308     if isinstance(s, str):
01309         raise TypeError("Can't load pickle from unicode string")
01310     file = io.BytesIO(s)
01311     return Unpickler(file, fix_imports=fix_imports,
01312                      encoding=encoding, errors=errors).load()
01313 
01314 # Use the faster _pickle if possible
01315 try:
    from _pickle import *

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 749 of file pickle.py.

00749 
00750 def whichmodule(func, funcname):
00751     """Figure out the module in which a function occurs.
00752 
00753     Search sys.modules for the module.
00754     Cache in classmap.
00755     Return a module name.
00756     If the function cannot be found, return "__main__".
00757     """
00758     # Python functions should always get an __module__ from their globals.
00759     mod = getattr(func, "__module__", None)
00760     if mod is not None:
00761         return mod
00762     if func in classmap:
00763         return classmap[func]
00764 
00765     for name, module in list(sys.modules.items()):
00766         if module is None:
00767             continue # skip dummy package entries
00768         if name != '__main__' and getattr(module, funcname, None) is func:
00769             break
00770     else:
00771         name = '__main__'
00772     classmap[func] = name
00773     return name
00774 
00775 
00776 # Unpickling machinery

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 ["PickleError", "PicklingError", "UnpicklingError", "Pickler",
00002            "Unpickler", "dump", "dumps", "load", "loads"]

Definition at line 39 of file pickle.py.

string pickle.__version__ = "$Revision$"

Definition at line 26 of file pickle.py.

Definition at line 166 of file pickle.py.

Definition at line 126 of file pickle.py.

Definition at line 131 of file pickle.py.

tuple pickle.args = parser.parse_args()

Definition at line 1337 of file pickle.py.

Definition at line 170 of file pickle.py.

Definition at line 146 of file pickle.py.

Definition at line 133 of file pickle.py.

Definition at line 113 of file pickle.py.

Definition at line 114 of file pickle.py.

Definition at line 116 of file pickle.py.

Definition at line 119 of file pickle.py.

Definition at line 140 of file pickle.py.

Definition at line 122 of file pickle.py.

Definition at line 125 of file pickle.py.

Definition at line 127 of file pickle.py.

tuple pickle.bytes_types = (bytes, bytearray)

Definition at line 43 of file pickle.py.

Definition at line 747 of file pickle.py.

Initial value:
00001 ["1.0",            # Original protocol 0
00002                       "1.1",            # Protocol 0 with INST added
00003                       "1.2",            # Original protocol 1
00004                       "1.3",            # Protocol 1 with BINFLOAT added
00005                       "2.0",            # Protocol 2
00006                       "3.0",            # Protocol 3
00007                       ]

Definition at line 47 of file pickle.py.

Definition at line 61 of file pickle.py.

Definition at line 129 of file pickle.py.

Definition at line 110 of file pickle.py.

Definition at line 130 of file pickle.py.

Definition at line 137 of file pickle.py.

Definition at line 144 of file pickle.py.

string pickle.EXT1 = '\x82'

Definition at line 155 of file pickle.py.

string pickle.EXT2 = '\x83'

Definition at line 156 of file pickle.py.

string pickle.EXT4 = '\x84'

Definition at line 157 of file pickle.py.

Definition at line 149 of file pickle.py.

Definition at line 111 of file pickle.py.

Definition at line 46 of file pickle.py.

Definition at line 132 of file pickle.py.

Definition at line 128 of file pickle.py.

string pickle.help = 'run self-test suite'

Definition at line 1333 of file pickle.py.

Definition at line 56 of file pickle.py.

Definition at line 134 of file pickle.py.

Definition at line 112 of file pickle.py.

Definition at line 136 of file pickle.py.

Definition at line 115 of file pickle.py.

string pickle.LONG1 = '\x8a'

Definition at line 163 of file pickle.py.

string pickle.LONG4 = '\x8b'

Definition at line 164 of file pickle.py.

Definition at line 135 of file pickle.py.

Definition at line 141 of file pickle.py.

Definition at line 106 of file pickle.py.

pickle.mloads = marshal.loads

Definition at line 66 of file pickle.py.

Definition at line 1330 of file pickle.py.

Definition at line 162 of file pickle.py.

Definition at line 154 of file pickle.py.

Definition at line 161 of file pickle.py.

Definition at line 117 of file pickle.py.

Definition at line 138 of file pickle.py.

tuple pickle.obj = load(f)

Definition at line 1346 of file pickle.py.

Initial value:
00001 argparse.ArgumentParser(
00002         description='display contents of the pickle files')

Definition at line 1326 of file pickle.py.

Definition at line 118 of file pickle.py.

Definition at line 108 of file pickle.py.

Definition at line 109 of file pickle.py.

string pickle.PROTO = '\x80'

Definition at line 153 of file pickle.py.

Definition at line 139 of file pickle.py.

Definition at line 100 of file pickle.py.

Definition at line 120 of file pickle.py.

Definition at line 142 of file pickle.py.

Definition at line 145 of file pickle.py.

Definition at line 171 of file pickle.py.

Definition at line 123 of file pickle.py.

Definition at line 107 of file pickle.py.

Definition at line 121 of file pickle.py.

Definition at line 148 of file pickle.py.

Definition at line 143 of file pickle.py.

Definition at line 158 of file pickle.py.

Definition at line 159 of file pickle.py.

Definition at line 160 of file pickle.py.

Definition at line 124 of file pickle.py.