Commit 355ff4ac authored by Jeremy Hylton's avatar Jeremy Hylton

One more try. Commit the version with referencesf.

parent ae7e113e
......@@ -427,3 +427,55 @@ class ConnectionObjectReader(BaseObjectReader):
if obj is not None:
return obj
return self._conn[oid]
def referencesf(p, rootl=None):
if rootl is None:
rootl = []
u = cPickle.Unpickler(cStringIO.StringIO(p))
l = len(rootl)
u.persistent_load = rootl
u.noload()
try:
u.noload()
except:
# 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 = []
u.noload()
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
continue
if type(v) is tuple:
v = v[0]
out.append(v)
rootl[:] = out
return rootl
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment