apptools.persistence.versioned_unpickler module

class apptools.persistence.versioned_unpickler.NewUnpickler(file, *, fix_imports=True, encoding='ASCII', errors='strict', buffers=None)[source]

Bases: _Unpickler

An unpickler that implements a two-stage pickling process to make it possible to unpickle complicated Python object hierarchies where the unserialized state of an object depends on the state of other objects in the same pickle.

initialize(max_pass)[source]
load(max_pass=-1)[source]

Read a pickled object representation from the open file.

Return the reconstituted object hierarchy specified in the file.

classmethod load_build(obj)[source]
class apptools.persistence.versioned_unpickler.VersionedUnpickler(file, updater=None)[source]

Bases: NewUnpickler

This class reads in a pickled file created at revision version ‘n’ and then applies the transforms specified in the updater class to generate a new set of objects which are at revision version ‘n+1’.

I decided to keep the loading of the updater out of this generic class because we will want updaters to be generated for each plugin’s type of project.

This ensures that the VersionedUnpickler can remain ignorant about the actual version numbers - all it needs to do is upgrade one release.

add_updater(module, name, klass)[source]

If there is an updater defined for this class we will add it to the class as the __setstate__ method.

backup_setstate(module, klass)[source]

If the class has a user defined __setstate__ we back it up.

find_class(module, name)[source]

Overridden method from Unpickler.

NB __setstate__ is not called until later.

import_name(module, name)[source]

If the class is needed for the latest version of the application then it should presumably exist.

If the class no longer exists then we should perhaps return a proxy of the class.

If the persisted file is at v1 say and the application is at v3 then objects that are required for v1 and v2 do not have to exist they only need to be placeholders for the state during an upgrade.