[Zope-Checkins] CVS: Zope/lib/python/ZODB - serialize.py:1.8
jeremy at zope.com
Thu Feb 19 13:46:53 EST 2004
Update of /cvs-repository/Zope/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv24940
One more try. Commit the version with referencesf.
=== Zope/lib/python/ZODB/serialize.py 1.7 => 1.8 ===
--- Zope/lib/python/ZODB/serialize.py:1.7 Thu Feb 19 13:38:46 2004
+++ Zope/lib/python/ZODB/serialize.py Thu Feb 19 13:46:53 2004
@@ -427,3 +427,55 @@
if obj is not None:
+def referencesf(p, rootl=None):
+ if rootl is None:
+ rootl = 
+ u = cPickle.Unpickler(cStringIO.StringIO(p))
+ l = len(rootl)
+ u.persistent_load = rootl
+ # Hm. We failed to do second load. Maybe there wasn't a
+ # second pickle. Let's check:
+ f = cStringIO.StringIO(p)
+ u = cPickle.Unpickler(f)
+ u.persistent_load = 
+ if len(p) > f.tell():
+ raise ValueError, 'Error unpickling, %s' % p
+ # References may be:
+ # - A tuple, in which case they are an oid and class.
+ # In this case, just extract the first element, which is
+ # the oid
+ # - A list, which is a weak reference. We skip those.
+ # - Anything else must be an oid. This means that an oid
+ # may not be a list or a tuple. This is a bit lame.
+ # We could avoid this lamosity by allowing single-element
+ # tuples, so that we wrap oids that are lists or tuples in
+ # tuples.
+ # - oids may *not* be false. I'm not sure why.
+ out = 
+ for v in rootl:
+ assert v # Let's see if we ever get empty ones
+ if type(v) is list:
+ # skip wekrefs
+ if type(v) is tuple:
+ v = v
+ rootl[:] = out
+ return rootl
More information about the Zope-Checkins