| | |
- exceptions.Exception(exceptions.BaseException)
-
- PickleError
-
- PicklingError
- UnpicklingError
- Pickler
- Unpickler
class Pickler |
| | |
Methods defined here:
- __init__(self, file, protocol=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=<function pack at 0x9cb8c0>)
- # 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=<function pack at 0x9cb8c0>)
- # 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=<function pack at 0x9cb8c0>)
- save_global(self, obj, name=None, pack=<function pack at 0x9cb8c0>)
- save_inst(self, obj)
- save_int(self, obj, pack=<function pack at 0x9cb8c0>)
- save_list(self, obj)
- save_long(self, obj, pack=<function pack at 0x9cb8c0>)
- 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=<function pack at 0x9cb8c0>)
- save_tuple(self, obj)
- save_unicode(self, obj, pack=<function pack at 0x9cb8c0>)
Data and other attributes defined here:
- dispatch = {<type 'bool'>: <function save_bool at 0x1057b18>, <type 'classobj'>: <function save_global at 0x105a1b8>, <type 'instance'>: <function save_inst at 0x105a140>, <type 'float'>: <function save_float at 0x1057c80>, <type 'int'>: <function save_int at 0x1057b90>, <type 'list'>: <function save_list at 0x1057ed8>, <type 'long'>: <function save_long at 0x1057c08>, <type 'dict'>: <function save_dict at 0x105a050>, <type 'NoneType'>: <function save_none at 0x1057aa0>, <type 'str'>: <function save_string at 0x1057cf8>, ...}
|
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=<function unpack at 0x9cb9b0>)
- 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 at 0x105a488>, '(': <function load_mark at 0x105bed8>, ')': <function load_empty_tuple at 0x105aed8>, '.': <function load_stop at 0x105bf50>, '0': <function load_pop at 0x105b848>, '1': <function load_pop_mark at 0x105b8c0>, '2': <function load_dup at 0x105b938>, 'F': <function load_float at 0x105ab18>, 'G': <function load_binfloat at 0x105ab90>, 'I': <function load_int at 0x105a7d0>, ...}
|
|