[ZODB-Dev] ExportImport.py: failing on import of extension class
Jim Fulton
jim at zope.com
Thu Apr 26 10:10:17 EDT 2007
On Apr 26, 2007, at 2:13 AM, Paul Winkler wrote:
> In ExportImport._importDuringCommit() I found this little gem:
>
> pfile = StringIO(data)
> unpickler = Unpickler(pfile)
> unpickler.persistent_load = persistent_load
>
> newp = StringIO()
> pickler = Pickler(newp, 1)
> pickler.persistent_id = persistent_id
>
> pickler.dump(unpickler.load())
> pickler.dump(unpickler.load())
> data = newp.getvalue()
>
>
> What's with the two load-and-dump lines near the end?
It is transforming the pickles by assigning new object ids to the
objects imported.
The unpickler unpickles the pickles into an internal format that can
be creates without actually creating the original objects. It
collects object ids and reassigns them. The pickler then turns the
internal data back into pickles with the new object ids.
This is done in 2 steps because database records consist of 2
pickles. The first has enough information to create a ghost. The
second pickle contains the object state.
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the ZODB-Dev
mailing list