[Zope-CVS] CVS: Products/Ape/lib/apelib/zope2 - apeconf.xml:1.3.2.4 classifier.py:1.5.2.3 ofsserial.py:1.5.2.2

Shane Hathaway shane at zope.com
Sat Dec 20 23:24:09 EST 2003


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

Modified Files:
      Tag: ape-0_8-branch
	apeconf.xml classifier.py ofsserial.py 
Log Message:
Continued cleanup after refactoring the interfaces.  See CHANGES.txt.

All tests now pass except for the SQL tests.



=== Products/Ape/lib/apelib/zope2/apeconf.xml 1.3.2.3 => 1.3.2.4 ===
--- Products/Ape/lib/apelib/zope2/apeconf.xml:1.3.2.3	Sat Dec 20 02:31:08 2003
+++ Products/Ape/lib/apelib/zope2/apeconf.xml	Sat Dec 20 23:24:08 2003
@@ -21,17 +21,18 @@
 
 <!-- Root mapper -->
 
-<mapper name="root" class="Persistence.PersistentMapping">
- <serializer name="root_items"
+<mapper name="root" register-class="false"
+   class="Persistence.PersistentMapping">
+ <serializer name="items"
    factory="apelib.zodb3.serializers.StringToPersistentPM" />
  <serializer name="roll_call" factory="apelib.zodb3.serializers.RollCall" />
  <variation name="filesystem">
-  <gateway name="root_items" factory="apelib.zope2.ofsserial.ReadOnlyRoot"
-    param="/" />
+  <gateway name="items" factory="apelib.fs.structure.RootDirectoryItems" />
+  <use-for oid="/_root" />
  </variation>
  <variation name="sql">
-  <gateway name="root_items" factory="apelib.zope2.ofsserial.ReadOnlyRoot"
-    param="0" />
+  <gateway name="items" factory="apelib.sql.structure.SQLFolderItems" />
+  <use-for oid="0" />
  </variation>
 </mapper>
 


=== Products/Ape/lib/apelib/zope2/classifier.py 1.5.2.2 => 1.5.2.3 ===
--- Products/Ape/lib/apelib/zope2/classifier.py:1.5.2.2	Sat Dec 20 02:31:08 2003
+++ Products/Ape/lib/apelib/zope2/classifier.py	Sat Dec 20 23:24:08 2003
@@ -47,6 +47,7 @@
 
     def __init__(self, gw=None):
         self.gw = gw
+        self.oid_to_mapper = {}
         self.class_to_mapper = {}
         self.ext_to_mapper = {}
         self.generic_to_mapper = {}
@@ -55,8 +56,8 @@
     def getGateway(self):
         return self.gw
 
-
     def register(self, condition, value, mapper_name):
+        value = str(value)  # Avoid unicode
         if condition == 'extension':
             self.ext_to_mapper[value] = mapper_name
         elif condition == 'class':
@@ -65,29 +66,34 @@
             assert value in (
                 'directory', 'file', 'folder_object', 'file_object'), value
             self.generic_to_mapper[value] = mapper_name
+        elif condition == 'oid':
+            self.oid_to_mapper[value] = mapper_name
         else:
             raise ValueError('Unknown classification condition: %s'
                              % repr(condition))
 
-
     def setOption(self, mapper_name, option, value):
         assert option in ('default_extension', 'content_type_attr'), option
         self.options[(mapper_name, option)] = value
 
 
     def classifyObject(self, event):
-        """Chooses a mapper and classification for storing an object."""
-        klass = value.__class__
+        """Chooses a mapper and classification for storing an object.
+        """
+        mapper_name = self.oid_to_mapper.get(event.oid)
+        if mapper_name is not None:
+            return {'mapper_name': mapper_name}, mapper_name
+        klass = event.obj.__class__
         class_name = '%s.%s' % (klass.__module__, klass.__name__)
         classification = {'class_name': class_name}
         mapper_name = self.class_to_mapper.get(class_name)
         if mapper_name is None:
-            folderish = isinstance(value, ObjectManager)
+            folderish = isinstance(event.obj, ObjectManager)
             # Store in a generic format
             if folderish:
-                generic = 'folderish_object'
+                generic = 'folder_object'
             else:
-                generic = 'fileish_object'
+                generic = 'file_object'
             mapper_name = self.generic_to_mapper.get(generic)
             if mapper_name is not None:
                 # Force a particular mapper
@@ -97,7 +103,7 @@
                 'No mapper known for class %s' % repr(class_name))
         cta = self.options.get((mapper_name, 'content_type_attr'))
         if cta is not None:
-            ct = str(getattr(aq_base(value), cta, None))
+            ct = str(getattr(aq_base(event.obj), cta, None))
             ext = fixed_extensions.get(ct)
             if ext is None:
                 ext = guess_extension(ct)
@@ -110,7 +116,11 @@
 
 
     def classifyState(self, event):
-        """Chooses a mapper and classification for loading an object."""
+        """Chooses a mapper and classification for loading an object.
+        """
+        mapper_name = self.oid_to_mapper.get(event.oid)
+        if mapper_name is not None:
+            return {'mapper_name': mapper_name}, mapper_name
         classification, serial = self.gw.load(event)
         class_name = classification.get('class_name')
         if class_name and ':' in class_name:
@@ -122,9 +132,9 @@
             # bw compat: look for certain meta_types.
             mt = classification.get('meta_type')
             if mt == '(folderish object)':
-                mapper_name = self.generic_to_mapper.get('folderish_object')
+                mapper_name = self.generic_to_mapper.get('folder_object')
             elif mt == '(fileish object)':
-                mapper_name = self.generic_to_mapper.get('fileish_object')
+                mapper_name = self.generic_to_mapper.get('file_object')
         if mapper_name is None and class_name is not None:
             mapper_name = self.class_to_mapper.get(class_name)
         if mapper_name is None:


=== Products/Ape/lib/apelib/zope2/ofsserial.py 1.5.2.1 => 1.5.2.2 ===
--- Products/Ape/lib/apelib/zope2/ofsserial.py:1.5.2.1	Fri Dec 19 21:52:50 2003
+++ Products/Ape/lib/apelib/zope2/ofsserial.py	Sat Dec 20 23:24:08 2003
@@ -28,7 +28,6 @@
 from apelib.core.interfaces import ISerializer, SerializationError
 from apelib.core.schemas import FieldSchema, RowSequenceSchema
 from apelib.core.serializers import OptionalSerializer
-from apelib.zodb3.gateways import ReadOnlyItems
 
 
 string_repr_types = {
@@ -72,7 +71,7 @@
             # The properties serializer is authoritative.  Defer to it.
             content_type = None
         obj.update_data(data, content_type, size)
-        event.seserialized('data', obj.data)
+        event.deserialized('data', obj.data)
 
 
 class FolderItems:
@@ -81,7 +80,7 @@
     __implements__ = ISerializer
 
     schema = RowSequenceSchema()
-    schema.addField('id', 'string', 1)
+    schema.addField('key', 'string', 1)
     schema.addField('oid', 'string')
 
     # The fixed_oids flag must be turned on when serializing to
@@ -149,7 +148,8 @@
         obj = event.obj
         attrname = self.getAttrNameFor(obj)
         id = getattr(obj, attrname)
-        assert id, 'ID of %r is %r' % (obj, id)
+        if not id:
+            raise SerializationError('ID of %r is %r' % (obj, id))
         event.serialized(attrname, id, 1)
         return id
 
@@ -181,11 +181,11 @@
         obj = event.obj
         assert isinstance(obj, PropertyManager), repr(obj)
         assert obj._properties is obj._propertyMap()
-        event.ignoreAttribute('_properties')
+        event.ignore('_properties')
         for p in obj._properties:
             name = p['id']
             t = p['type']
-            event.ignoreAttribute(name)
+            event.ignore(name)
             data = obj.getProperty(name)
             if t == 'lines':
                 v = '\n'.join(data)
@@ -262,18 +262,6 @@
                 # Fall back to a default.
                 data = ''
             obj._updateProperty(id, data)
-
-
-class ReadOnlyRoot(ReadOnlyItems):
-    """Zope 2 application root.
-    """
-
-    def __init__(self, root_key):
-        try:
-            root_key = int(root_key)
-        except ValueError:
-            root_key = str(root_key)
-        ReadOnlyItems.__init__(self, {'Application': (root_key,)})
 
 
 class OptionalOFSProperties(OptionalSerializer):




More information about the Zope-CVS mailing list