[Zope-CVS] CVS: Products/Ape/lib/apelib/zodb3 - serializers.py:1.8

Shane Hathaway shane at zope.com
Tue Mar 16 22:59:38 EST 2004


Update of /cvs-repository/Products/Ape/lib/apelib/zodb3
In directory cvs.zope.org:/tmp/cvs-serv19418

Modified Files:
	serializers.py 
Log Message:
Added a helper function for finding unmanaged persistent objects.


=== Products/Ape/lib/apelib/zodb3/serializers.py 1.7 => 1.8 ===
--- Products/Ape/lib/apelib/zodb3/serializers.py:1.7	Thu Feb 19 13:21:00 2004
+++ Products/Ape/lib/apelib/zodb3/serializers.py	Tue Mar 16 22:59:37 2004
@@ -312,3 +312,27 @@
     def deserialize(self, event, state):
         self.setTime(event.obj, state)
 
+
+def findUnmanaged(obj, managed):
+    """Gathers the list of unmanaged subobjects from an object.
+
+    'managed' is a list of subobjects known to be managed.
+    """
+    d = {}
+    for m in managed:
+        d[id(m)] = m
+    outfile = StringIO()
+    p = Pickler(outfile, 1)  # Binary pickle
+    unmanaged = []
+
+    def persistent_id(ob, d_get=d.get, unmanaged=unmanaged):
+        if d_get(id(ob)) is not None:
+            # Don't search inside managed subobjects.
+            return 'managed'
+        if hasattr(ob, '_p_oid'):
+            unmanaged.append(ob)
+        return None
+
+    p.persistent_id = persistent_id
+    p.dump(obj)
+    return unmanaged




More information about the Zope-CVS mailing list