Specifying a module when Unpickling

Jeff Epler jepler at unpythonic.net
Thu May 8 17:01:36 EDT 2003


On Thu, May 08, 2003 at 04:24:34PM -0400, Markus Wankus wrote:
> My problem is - my *binary* pickles are now out in the wild and I need to 
> support and deal with them...  I wonder if there is a way to apply your 
> module-passing-on-load mechanisms to the standard Pickle module...hmmm.

If you can use the regular (not cPickle) module, it looks like you can
override Unpickler.find_class to do something clever.

find_class is used by load_inst and load_global, which would mean that
it would be used both to find the class m.C when reloading a pickled
instance of m.C, and reloading an object which happens to contain a
reference to m.C.  So, this might not be good enough.  You might also
override load_global to call Unpickler.find_class(self, module, name)
and solve this problem (I suggest to override this and not load_inst
because load_global is much smaller, and you're essentially duplicating
the function's body except for the one call)

Jeff





More information about the Python-list mailing list