pymor.core.pickle

This module contains methods for object serialization.

Instead of importing serialization functions from Python’s pickle module directly, you should use the dump, dumps, load, loads functions defined here. In particular, these methods will use dumps_function to serialize function objects which cannot be pickled by Python’s standard methods. Note, however, pickling such methods should be avoided since the implementation of dumps_function uses non-portable implementation details of CPython to achieve its goals.

Module Contents

Classes

Module

Functions

dump

_generate_opcode

_global_names

Return all names in code_object.co_names which are used in a LOAD_GLOBAL statement.

dumps_function

Tries hard to pickle a function object:

loads_function

Restores a function serialized with dumps_function.

_function_pickling_handler

_function_unpickling_handler

Attributes

PicklingError

UnpicklingError

PROTOCOL

pymor.core.pickle.PicklingError[source]
pymor.core.pickle.UnpicklingError[source]
pymor.core.pickle.PROTOCOL[source]
pymor.core.pickle.dump(obj, file, protocol=None)[source]
pymor.core.pickle._generate_opcode(code_object)[source]
pymor.core.pickle._global_names(code_object)[source]

Return all names in code_object.co_names which are used in a LOAD_GLOBAL statement.

class pymor.core.pickle.Module(mod)[source]
__getstate__(self)[source]
__setstate__(self, s)[source]
pymor.core.pickle.dumps_function(function)[source]

Tries hard to pickle a function object:

  1. The function’s code object is serialized using the marshal module.

  2. For all global names used in the function’s code object the corresponding object in the function’s global namespace is pickled. In case this object is a module, the modules __package__ name is pickled.

  3. All default arguments are pickled.

  4. All objects in the function’s closure are pickled.

Note that also this is heavily implementation specific and will probably only work with CPython. If possible, avoid using this method.

pymor.core.pickle.loads_function(s)[source]

Restores a function serialized with dumps_function.

pymor.core.pickle._function_pickling_handler(f)[source]
pymor.core.pickle._function_unpickling_handler(persid)[source]