[Zope-CVS] CVS: Products/Ape/lib/apelib/zope2 - basemapper.py:1.1.4.1 fsmapper.py:1.2.2.1 ofsserial.py:1.2.2.1 sqlmapper.py:1.5.2.1

Shane Hathaway shane@zope.com
Tue, 24 Jun 2003 17:38:45 -0400


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

Modified Files:
      Tag: ape-newconf-branch
	basemapper.py fsmapper.py ofsserial.py sqlmapper.py 
Log Message:
Reduced the number of things necessary to configure in a mapper.

This change centered around removing the arguments to the constructor
in zope2.basemapper.  They were making it hard to write a
configuration vocabulary.

Removed the app_key argument through the use of a read-only gateway
instead of a fixed persistent mapping, and removed the
stored_keychains argument by always storing keychains.  The filesystem
version of the folder items gateway doesn't actually store the
keychains, but it can verify that when the keychains are loaded again
they will be the same as they were at storage time.



=== Products/Ape/lib/apelib/zope2/basemapper.py 1.1 => 1.1.4.1 ===
--- Products/Ape/lib/apelib/zope2/basemapper.py:1.1	Wed Apr  9 23:09:58 2003
+++ Products/Ape/lib/apelib/zope2/basemapper.py	Tue Jun 24 17:38:44 2003
@@ -21,7 +21,7 @@
 from apelib.zope2 import classifier, ofsserial, scripts, security
 
 
-def createZope2Mapper(app_key, stored_keychains):
+def createZope2Mapper():
     """Returns a mapper tree for Zope 2 objects (without any gateways)."""
 
     # Create and configure the root mapper
@@ -29,18 +29,11 @@
     cfr = classifier.MetaTypeClassifier()
     root_mapper.setClassifier(cfr)
     cs = serializers.CompositeSerializer('Persistence', 'PersistentMapping')
-    serializer = zodb3serializers.FixedPersistentMapping()
-    serializer.add('Application', (app_key,), ('OFS.Application.Application',))
-    cs.addSerializer('items', serializer)
+    cs.addSerializer('items', zodb3serializers.BasicPersistentMapping())
     cs.addSerializer('roll_call', zodb3serializers.RollCall())
     root_mapper.setSerializer(cs)
-    root_mapper.setGateway(gateways.CompositeGateway())  # No storage necessary
 
-    # Prepare some common names
-    if stored_keychains:
-        folder_items_serializer = ofsserial.FolderItemsByKeychain()
-    else:
-        folder_items_serializer = ofsserial.FolderItems()
+    folder_items_serializer = ofsserial.FolderItems()
 
     # abstract base mapper
     m = root_mapper.addSubMapper('base')
@@ -158,8 +151,6 @@
     m.setSerializer(cs)
     cs.removeSerializer('id')
     cs.addSerializer('items', folder_items_serializer)
-    cfr.registerKey(
-        'Application', 'OFS.Application.Application', app_key)
 
     # Other stuff
     cfr.register('CMF Skins Tool', 'anyfile')  # XXX workaround


=== Products/Ape/lib/apelib/zope2/fsmapper.py 1.2 => 1.2.2.1 ===
--- Products/Ape/lib/apelib/zope2/fsmapper.py:1.2	Tue Apr 29 18:11:52 2003
+++ Products/Ape/lib/apelib/zope2/fsmapper.py	Tue Jun 24 17:38:44 2003
@@ -20,6 +20,7 @@
 from apelib.fs \
      import classification, connection, properties, security, structure
 from apelib.zope2 import basemapper
+from apelib.zodb3.gateways import ReadOnlyItems
 
 
 def createAbstractMapper():
@@ -28,10 +29,14 @@
     Usage in database configuration file:
     factory=apelib.zope2.fsmapper.createMapper
     """
-    root_mapper = basemapper.createZope2Mapper('/', 0)
+    root_mapper = basemapper.createZope2Mapper()
     root_mapper.getClassifier().setGateway(
         classification.FSClassificationSection())
     root_mapper.setKeychainGenerator(keygen.PathKeychainGenerator())
+    g = gateways.CompositeGateway()
+    g.addGateway('items', ReadOnlyItems({'Application': ('/',)}))
+    root_mapper.setGateway(g)
+
     file_binary_data = structure.FSFileData(text=0)
     file_text_data = structure.FSFileData(text=1)
 
@@ -109,6 +114,8 @@
     g.removeGateway('id')
     g.addGateway('items', structure.FSDirectoryItems())
     root_mapper.getSubMapper('OFS.Application.Application').setGateway(g)
+    root_mapper.getClassifier().registerKey(
+        'Application', 'OFS.Application.Application', '/')
 
     root_mapper.checkConfiguration()
 


=== Products/Ape/lib/apelib/zope2/ofsserial.py 1.2 => 1.2.2.1 ===
--- Products/Ape/lib/apelib/zope2/ofsserial.py:1.2	Wed Jun 11 09:58:53 2003
+++ Products/Ape/lib/apelib/zope2/ofsserial.py	Tue Jun 24 17:38:44 2003
@@ -77,78 +77,32 @@
 
 
 class FolderItems:
-    """Serializer for the items in an ObjectManager.
-
-    This version does not store keychains, but instead assumes they
-    can be computed."""
-
-    __implements__ = ISerializer
-
-    schema = RowSequenceSchema()
-    schema.addField('id', 'string', 1)
-
-    def getSchema(self):
-        return self.schema
-
-    def canSerialize(self, object):
-        return isinstance(object, ObjectManager)
-
-    def serialize(self, object, event):
-        assert isinstance(object, ObjectManager), repr(object)
-        state = []
-        event.ignoreAttribute('_objects')
-        mps = getattr(object, '_mount_points', None)
-        for id, subob in object.objectItems():
-            if mps and mps.has_key(id):
-                # Store the mount point rather than the mounted object.
-                subob = mps[id]
-            base = aq_base(subob)
-            keychain = event.identifyObject(base)
-            expected = event.makeKeychain(id, 0)
-            if keychain is not None and keychain != expected:
-                raise SerializationError(
-                    "Subobject %s has unexpected keychain, %s. Expected %s." %
-                    (repr(base), repr(keychain), repr(expected)))
-            keychain = expected
-            event.notifySerializedRef(id, base, 1, keychain)
-            state.append((id,))
-        event.ignoreAttribute('_use_fixed_oids_')
-        # Add a marker that tells the folder it has to move/rename
-        # in a special way.  The _setOb patch sees this attribute.
-        object._use_fixed_oids_ = 1
-        return state
-
-    def deserialize(self, object, event, state):
-        assert isinstance(object, ObjectManager)
-        object._use_fixed_oids_ = 1
-        for (id,) in state:
-            keychain = event.makeKeychain(id, 0)
-            subob = event.dereference(id, keychain)
-            setattr(object, id, subob)
-            object._objects += ({'id': id, 'meta_type':
-                                 subob.__class__.meta_type},)
-
-
-class FolderItemsByKeychain:
-    """ """
+    """Zope 2 folder items (de)serializer
+    """
     __implements__ = ISerializer
 
     schema = RowSequenceSchema()
     schema.addField('id', 'string', 1)
     schema.addField('keychain', 'keychain')
 
+    # The fixed_oids flag must be turned on when serializing to
+    # an object system with meaningful OIDs (like the filesystem.)
+    # It doesn't need to be on for object systems with arbitrary
+    # OIDs such as SQL databases.
+    fixed_oids = 1
+
     def getSchema(self):
         return self.schema
 
-    def canSerialize(self, object):
-        return isinstance(object, ObjectManager)
+    def canSerialize(self, obj):
+        return isinstance(obj, ObjectManager)
 
-    def serialize(self, object, event):
-        assert isinstance(object, ObjectManager), repr(object)
+    def serialize(self, obj, event):
+        assert isinstance(obj, ObjectManager), repr(obj)
         state = []
         event.ignoreAttribute('_objects')
-        mps = getattr(object, '_mount_points', None)
-        for id, subob in object.objectItems():
+        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]
@@ -158,14 +112,21 @@
                 keychain = event.makeKeychain(id, 1)
             event.notifySerializedRef(id, base, 1, keychain)
             state.append((id, keychain))
+        if self.fixed_oids:
+            event.ignoreAttribute('_use_fixed_oids_')
+            # Add a marker that tells the folder it has to move/rename
+            # in a special way.  The _setOb patch sees this attribute.
+            obj._use_fixed_oids_ = 1
         return state
 
-    def deserialize(self, object, event, state):
-        assert isinstance(object, ObjectManager)
+    def deserialize(self, obj, event, state):
+        assert isinstance(obj, ObjectManager)
+        if self.fixed_oids:
+            obj._use_fixed_oids_ = 1
         for (id, keychain) in state:
             subob = event.dereference(id, keychain)
-            setattr(object, id, subob)
-            object._objects += ({'id': id, 'meta_type':
+            setattr(obj, id, subob)
+            obj._objects += ({'id': id, 'meta_type':
                                  subob.__class__.meta_type},)
 
 


=== Products/Ape/lib/apelib/zope2/sqlmapper.py 1.5 => 1.5.2.1 ===
--- Products/Ape/lib/apelib/zope2/sqlmapper.py:1.5	Mon May 19 15:32:36 2003
+++ Products/Ape/lib/apelib/zope2/sqlmapper.py	Tue Jun 24 17:38:44 2003
@@ -20,12 +20,16 @@
 from apelib.sql import classification, keygen, properties, security, structure
 from apelib.sql import dbapi
 from apelib.zope2 import basemapper
+from apelib.zodb3.gateways import ReadOnlyItems
 
 
 def createAbstractMapper():
     """Object mapper factory, with extra return arg for testing purposes
     """
-    root_mapper = basemapper.createZope2Mapper(0, 1)
+    root_mapper = basemapper.createZope2Mapper()
+    g = gateways.CompositeGateway()
+    g.addGateway('items', ReadOnlyItems({'Application': (0,)}))
+    root_mapper.setGateway(g)
     root_mapper.setKeychainGenerator(keygen.SQLKeychainGenerator())
 
     folder_items_gw = structure.SQLFolderItems()
@@ -126,6 +130,8 @@
     g.removeGateway('id')
     g.addGateway('items', folder_items_gw)
     root_mapper.getSubMapper('OFS.Application.Application').setGateway(g)
+    root_mapper.getClassifier().registerKey(
+        'Application', 'OFS.Application.Application', 0)
 
     root_mapper.checkConfiguration()