NewUnpickler(file, *, fix_imports=True, encoding='ASCII', errors='strict', buffers=None)¶
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.
Read a pickled object representation from the open file.
Return the reconstituted object hierarchy specified in the file.
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)¶
If there is an updater defined for this class we will add it to the class as the __setstate__ method.
If the class has a user defined __setstate__ we back it up.
Overridden method from Unpickler.
NB __setstate__ is not called until later.
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.