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

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

For more information about ZODB, see the ZODB Wiki:

ZODB-Dev mailing list  -  ZODB-Dev@zope.org

Reply via email to