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:[EMAIL PROTECTED]                Python 
Powered!
CTO                             (540) 361-1714                  
http://www.python.org
Zope Corporation        http://www.zope.com             http://www.zope.org



_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev

Reply via email to