[Zope-CVS] CVS: Products/Ape/lib/apelib/zope2 - ofsserial.py:1.9

Shane Hathaway shane at zope.com
Tue Mar 16 23:03:00 EST 2004


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

Modified Files:
	ofsserial.py 
Log Message:
Added compatibility with BTreeFolder2.


=== Products/Ape/lib/apelib/zope2/ofsserial.py 1.8 => 1.9 ===
--- Products/Ape/lib/apelib/zope2/ofsserial.py:1.8	Sat Feb 28 15:06:29 2004
+++ Products/Ape/lib/apelib/zope2/ofsserial.py	Tue Mar 16 23:02:59 2004
@@ -28,6 +28,7 @@
 from apelib.core.interfaces import ISerializer, SerializationError
 from apelib.core.schemas import FieldSchema, RowSequenceSchema
 from apelib.core.serializers import OptionalSerializer
+from apelib.zodb3.serializers import findUnmanaged
 
 
 string_repr_types = {
@@ -87,34 +88,56 @@
     def canSerialize(self, obj):
         return isinstance(obj, ObjectManager)
 
+    def _isABTreeFolder(self, ob):
+        # Maybe this should use isinstance(), but then Ape
+        # would depend on the BTreeFolder2 product.
+        return hasattr(ob, '_tree') and hasattr(ob, '_mt_index')
+
     def serialize(self, event):
         obj = event.obj
         assert isinstance(obj, ObjectManager), repr(obj)
         state = []
         event.ignore('_objects')
-        mps = getattr(obj, '_mount_points', None)
-        for id, subob in obj.objectItems():
-            if mps and mps.has_key(id):
-                # Store the mount point rather than the mounted object.
-                subob = mps[id]
-            base = aq_base(subob)
+        d = obj.__dict__
+        btree_folder = self._isABTreeFolder(obj)
+        if btree_folder:
+            d = obj._tree
+            event.ignore(('_tree', '_mt_index', '_count'))
+        for id in obj.objectIds():
+            if d.has_key(id):
+                base = d[id]
+            else:
+                # Fall back to _getOb.
+                base = aq_base(obj._getOb(id))
             oid = event.obj_db.identify(base)
             if oid is None:
                 oid = event.conf.oid_gen.new_oid(event, id, True)
             event.referenced(id, base, True, oid)
             # No need to pass classification.
             state.append((id, oid, None))
+        if btree_folder:
+            # The structure that makes up the BTree (the root node and
+            # the buckets) are unmanaged.  Tell the event about them.
+            event.upos.extend(findUnmanaged(obj._tree, obj._tree.values()))
         return state
 
     def deserialize(self, event, state):
         obj = event.obj
         assert isinstance(obj, ObjectManager), obj
+        btree_folder = self._isABTreeFolder(obj)
+        if btree_folder:
+            obj._initBTrees()
         for (id, oid, classification) in state:
             subob = event.resolve(id, oid, classification)
-            setattr(obj, id, subob)
-            obj._objects += ({'id': id, 'meta_type':
-                              subob.__class__.meta_type},)
-
+            obj._setOb(id, subob)
+            if not btree_folder:
+                obj._objects += ({
+                    'id': id,
+                    'meta_type': subob.__class__.meta_type,
+                    },)
+        if btree_folder:
+            # The tree and the buckets are unmanaged.
+            event.upos.extend(findUnmanaged(obj._tree, obj._tree.values()))
 
 
 class IdAttribute:




More information about the Zope-CVS mailing list