[Zope-CVS] CVS: Products/Ape/lib/apelib/zope2 - apeconf.xml:1.1.2.2 classifier.py:1.2.2.2 fsmapper.py:1.2.2.3 ofsserial.py:1.2.2.3 sqlmapper.py:1.5.2.2 baseconf.py:NONE baseconf.xml:NONE basemapper.py:NONE

Shane Hathaway shane@zope.com
Mon, 7 Jul 2003 23:58:25 -0400


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

Modified Files:
      Tag: ape-newconf-branch
	apeconf.xml classifier.py fsmapper.py ofsserial.py 
	sqlmapper.py 
Removed Files:
      Tag: ape-newconf-branch
	baseconf.py baseconf.xml basemapper.py 
Log Message:
Added a SQL variant to apeconf.xml and fixed uncovered bugs

=== Products/Ape/lib/apelib/zope2/apeconf.xml 1.1.2.1 => 1.1.2.2 ===
--- Products/Ape/lib/apelib/zope2/apeconf.xml:1.1.2.1	Mon Jul  7 18:59:32 2003
+++ Products/Ape/lib/apelib/zope2/apeconf.xml	Mon Jul  7 23:58:15 2003
@@ -9,13 +9,21 @@
    factory="apelib.zodb3.serializers.BasicPersistentMapping" />
  <serializer name="roll_call" factory="apelib.zodb3.serializers.RollCall" />
  <variant name="filesystem">
-  <classifier factory="apelib.zope2.classifier.MetaTypeClassifier">
+  <classifier factory="apelib.zope2.classifier.Classifier">
    <gateway factory="apelib.fs.classification.FSClassificationSection" />
   </classifier>
   <keygen factory="apelib.core.keygen.PathKeychainGenerator" />
   <gateway name="root_items" factory="apelib.zope2.ofsserial.ReadOnlyRoot"
     param="/" />
  </variant>
+ <variant name="sql">
+  <classifier factory="apelib.zope2.classifier.Classifier">
+   <gateway factory="apelib.sql.classification.SQLClassification" />
+  </classifier>
+  <keygen factory="apelib.sql.keygen.SQLKeychainGenerator" />
+  <gateway name="root_items" factory="apelib.zope2.ofsserial.ReadOnlyRoot"
+    param="0" />
+ </variant>
 </mapper>
 
 <!-- Abstract mappers -->
@@ -36,6 +44,12 @@
     param="remainder" />
   <gateway name="security" factory="apelib.fs.security.FSSecurityAttributes" />
  </variant>
+ <variant name="sql">
+  <gateway name="id" use="sql_id" />
+  <gateway name="modtime" use="sql_modtime" />
+  <gateway name="remainder" use="sql_remainder" />
+  <gateway name="security" use="sql_security" />
+ </variant>
 </mapper>
 
 <mapper name="base_p" class="none" extends="base">
@@ -44,6 +58,9 @@
  <variant name="filesystem">
   <gateway name="properties" factory="apelib.fs.properties.FSProperties" />
  </variant>
+ <variant name="sql">
+  <gateway name="properties" use="sql_properties" />
+ </variant>
 </mapper>
 
 <!-- Reusable serializers and gateways -->
@@ -54,30 +71,39 @@
   factory="apelib.zope2.ofsserial.OptionalOFSProperties" />
 
 <variant name="filesystem">
- <gateway name="fs_binary_data" factory="apelib.fs.structure.FSFileData"
+ <gateway name="binary_data" factory="apelib.fs.structure.FSFileData"
    param="binary" />
- <gateway name="fs_text_data" factory="apelib.fs.structure.FSFileData"
+ <gateway name="text_data" factory="apelib.fs.structure.FSFileData"
    param="text" />
- <gateway name="fs_dir_items" factory="apelib.fs.structure.FSDirectoryItems" />
+ <gateway name="dir_items" factory="apelib.fs.structure.FSDirectoryItems" />
+</variant>
+
+<variant name="sql">
+ <gateway name="binary_data" factory="apelib.sql.structure.SQLObjectData" />
+ <gateway name="text_data" use="binary_data" />
+ <gateway name="dir_items" factory="apelib.sql.structure.SQLFolderItems" />
+ <gateway name="sql_id" factory="apelib.sql.structure.SQLItemId" />
+ <gateway name="sql_remainder" factory="apelib.sql.structure.SQLRemainder" />
+ <gateway name="sql_modtime" factory="apelib.sql.structure.SQLModTime" />
+ <gateway name="sql_properties" factory="apelib.sql.properties.SQLProperties"/>
+ <gateway name="sql_security"
+   factory="apelib.sql.security.SQLSecurityAttributes" />
+ <gateway name="sql_userlist" factory="apelib.sql.security.SQLUserList" />
 </variant>
 
 <!-- Mappers for particular content types -->
 
 <mapper name="OFS.Folder.Folder" extends="base_p" parent="zope2">
  <serializer name="items" use="folder_items" />
+ <gateway name="items" use="dir_items" />
  <use-for fallback="directory" />
- <variant name="filesystem">
-  <gateway name="items" use="fs_dir_items" />
- </variant>
 </mapper>
 
 <mapper name="OFS.Image.File" extends="base_p" parent="zope2">
  <serializer name="data" factory="apelib.zope2.ofsserial.FilePData" />
+ <gateway name="data" use="binary_data" />
  <use-for fallback="file" />
  <option name="content_type_attr" value="content_type" />
- <variant name="filesystem">
-  <gateway name="data" use="fs_binary_data" />
- </variant>
 </mapper>
 
 <mapper name="OFS.Image.Image" extends="OFS.Image.File" parent="zope2">
@@ -89,19 +115,15 @@
   extends="base_p" parent="zope2">
  <serializer name="text" factory="apelib.core.serializers.StringDataAttribute"
   param="_text" />
+ <gateway name="text" use="text_data" />
  <use-for extensions=".html .htm .zpt .pt" />
- <variant name="filesystem">
-  <gateway name="text" use="fs_text_data" />
- </variant>
 </mapper>
 
 <mapper name="OFS.DTMLMethod.DTMLMethod" extends="base" parent="zope2">
  <serializer name="text" factory="apelib.core.serializers.StringDataAttribute"
   param="raw" />
+ <gateway name="text" use="text_data" />
  <use-for extensions=".dtml" />
- <variant name="filesystem">
-  <gateway name="text" use="fs_text_data" />
- </variant>
 </mapper>
 
 <mapper name="OFS.DTMLMethod.DTMLDocument"
@@ -114,11 +136,14 @@
    factory="apelib.zope2.scripts.ZSQLMethodPropertiesSerializer" />
  <serializer name="text"
    factory="apelib.zope2.scripts.ZSQLMethodSerializer" />
+ <gateway name="text" use="text_data" />
  <use-for extensions=".sql" />
  <variant name="filesystem">
   <gateway name="properties" factory="apelib.fs.properties.FSProperties"
     param="ZSQL Properties" />
-  <gateway name="text" use="fs_text_data" />
+ </variant>
+ <variant name="sql">
+  <gateway name="properties" use="sql_properties" />
  </variant>
 </mapper>
 
@@ -126,10 +151,8 @@
   extends="base" parent="zope2">
  <serializer name="body"
    factory="apelib.zope2.scripts.PythonScriptSerializer" />
+ <gateway name="body" use="text_data" />
  <use-for extensions=".py" />
- <variant name="filesystem">
-  <gateway name="body" use="fs_text_data" />
- </variant>
 </mapper>
 
 <mapper name="AccessControl.User.UserFolder" extends="base" parent="zope2">
@@ -138,36 +161,39 @@
  <variant name="filesystem">
   <gateway name="data" factory="apelib.fs.security.FSUserList" />
  </variant>
+ <variant name="sql">
+  <gateway name="data" use="sql_userlist" />
+ </variant>
 </mapper>
 
 <mapper name="anyfolder" class="any" extends="base_p" parent="zope2">
  <serializer name="properties" use="optional_properties" />
  <serializer name="items" use="folder_items" />
+ <gateway name="items" use="dir_items" />
  <use-for fallback="folderish_object" />
- <variant name="filesystem">
-  <gateway name="items" use="fs_dir_items" />
- </variant>
 </mapper>
 
 <mapper name="anyfile" class="any" extends="base_p" parent="zope2">
  <serializer name="properties" use="optional_properties" />
+ <gateway name="remainder" use="binary_data" />
  <use-for fallback="fileish_object" />
- <variant name="filesystem">
-  <gateway name="remainder" use="fs_binary_data" />
- </variant>
 </mapper>
 
 <mapper name="OFS.Application.Application" extends="base_p" parent="zope2">
  <serializer name="items" use="folder_items" />
  <serializer name="id" enabled="false" />
  <gateway name="id" enabled="false" />
+ <gateway name="items" use="dir_items" />
  <variant name="filesystem">
-  <gateway name="items" use="fs_dir_items" />
   <use-for key="/" />
  </variant>
+ <variant name="sql">
+  <use-for key="0" />
+ </variant>
 </mapper>
 
 <mapper name="anyfile">
+ <!-- Workaround -->
  <use-for class="Products.CMFCore.SkinsTool.SkinsTool" />
  <use-for class="App.ApplicationManager.ApplicationManager" />
 </mapper>


=== Products/Ape/lib/apelib/zope2/classifier.py 1.2.2.1 => 1.2.2.2 ===
--- Products/Ape/lib/apelib/zope2/classifier.py:1.2.2.1	Mon Jul  7 18:59:32 2003
+++ Products/Ape/lib/apelib/zope2/classifier.py	Mon Jul  7 23:58:15 2003
@@ -11,7 +11,7 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""Zope 2 meta_type based classification.
+"""Zope 2 object classification.
 
 $Id$
 """
@@ -24,7 +24,7 @@
 from apelib.core.interfaces import IClassifier
 from apelib.core.exceptions import SerializationError, DeserializationError
 
-# guess_extension() is useful but it's unoptimized and sometimes
+# guess_extension() is useful, but it's unoptimized and sometimes
 # chooses strange extensions.  fixed_extensions does nothing other than
 # suggest a filename extension given a content type.  It contains
 # some better defaults.
@@ -39,8 +39,8 @@
     }
 
 
-class MetaTypeClassifier:
-    """A classifier based on meta_type attributes.
+class Classifier:
+    """A classifier with some minimal Zope 2 extensions.
     """
     __implements__ = IClassifier
 
@@ -53,6 +53,9 @@
         self.fallback_to_mapper = {}
         self.options = {}  # { (mapper_name, option) -> value }
 
+    def getGateway(self):
+        return self.gw
+
 
     def register(self, attr, value, mapper_name):
         if attr == 'key':
@@ -76,12 +79,14 @@
 
     def classifyObject(self, value, keychain):
         """Chooses a mapper and classification for storing an object."""
+        mapper_name = self.key_to_mapper.get(keychain[-1])
+        if mapper_name is not None:
+            # Shortcut.
+            return {'mapper_name': mapper_name}, mapper_name
         klass = value.__class__
         class_name = '%s.%s' % (klass.__module__, klass.__name__)
         classification = {'class_name': class_name}
-        mapper_name = self.key_to_mapper.get(keychain[-1])
-        if mapper_name is None:
-            mapper_name = self.class_to_mapper.get(class_name)
+        mapper_name = self.class_to_mapper.get(class_name)
         if mapper_name is None:
             folderish = isinstance(value, ObjectManager)
             # Store in a fallback format
@@ -112,11 +117,13 @@
 
     def classifyState(self, event):
         """Chooses a mapper and classification for loading an object."""
+        mapper_name = self.key_to_mapper.get(event.getKey())
+        if mapper_name is not None:
+            # Shortcut.
+            return {'mapper_name': mapper_name}, mapper_name
         classification, serial = self.gw.load(event)
         class_name = classification.get('class_name')
         mapper_name = classification.get('mapper_name')
-        if mapper_name is None:
-            mapper_name = self.key_to_mapper.get(event.getKey())
         if mapper_name is None:
             # bw compat: look for certain meta_types.
             mt = classification.get('meta_type')


=== Products/Ape/lib/apelib/zope2/fsmapper.py 1.2.2.2 => 1.2.2.3 ===
--- Products/Ape/lib/apelib/zope2/fsmapper.py:1.2.2.2	Mon Jul  7 18:59:32 2003
+++ Products/Ape/lib/apelib/zope2/fsmapper.py	Mon Jul  7 23:58:15 2003
@@ -16,115 +16,12 @@
 $Id$
 """
 
-from apelib.core import gateways, keygen
-from apelib.fs \
-     import classification, connection, properties, security, structure
-from apelib.zope2 import basemapper
-from apelib.zodb3.gateways import ReadOnlyItems
-
-
-def XXXcreateAbstractMapper():
-    """Object mapper factory.
-
-    Usage in database configuration file:
-    factory=apelib.zope2.fsmapper.createMapper
-    """
-    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)
-
-    # abstract base gateway
-    g = gateways.CompositeGateway()
-    g.addGateway('id', structure.FSAutoId())
-    g.addGateway('modtime', structure.FSModTime())
-    g.addGateway('remainder', properties.FSSectionData('remainder'))
-    g.addGateway('security', security.FSSecurityAttributes())
-    root_mapper.getSubMapper('base').setGateway(g)
-    base = g
-
-    # abstract base gateway with properties
-    g = gateways.CompositeGateway(base)
-    g.addGateway('properties', properties.FSProperties())
-    root_mapper.getSubMapper('base_p').setGateway(g)
-    base_p = g
-
-    # folder gateway
-    g = gateways.CompositeGateway(base_p)
-    g.addGateway('items', structure.FSDirectoryItems())
-    root_mapper.getSubMapper('OFS.Folder.Folder').setGateway(g)
-
-    # page template gateway
-    g = gateways.CompositeGateway(base_p)
-    g.addGateway('text', file_text_data)
-    root_mapper.getSubMapper('ZopePageTemplate').setGateway(g)
-
-    # dtml method gateway
-    g = gateways.CompositeGateway(base)
-    g.addGateway('text', file_text_data)
-    root_mapper.getSubMapper('OFS.DTMLMethod.DTMLMethod').setGateway(g)
-    
-    # dtml document gateway
-    g = gateways.CompositeGateway(base_p)
-    g.addGateway('text', file_text_data)
-    root_mapper.getSubMapper('OFS.DTMLDocument.DTMLDocument').setGateway(g)
-
-    # zsqlmethod mapper
-    g = gateways.CompositeGateway(base)
-    g.addGateway('text', file_text_data)
-    g.addGateway('properties', properties.FSProperties('ZSQL Properties'), 1)
-    root_mapper.getSubMapper('Products.ZSQLMethods.SQL.SQL').setGateway(g)
-
-    # python script mapper
-    g = gateways.CompositeGateway(base)
-    g.addGateway('body', file_text_data)
-    root_mapper.getSubMapper('PythonScript').setGateway(g)
-
-    # file gateway
-    g = gateways.CompositeGateway(base_p)
-    g.addGateway('data', file_binary_data)
-    root_mapper.getSubMapper('OFS.Image.File').setGateway(g)
-
-    # image gateway is identical
-    root_mapper.getSubMapper('OFS.Image.Image').setGateway(g)
-
-    # user folder gateway
-    g = gateways.CompositeGateway(base)
-    g.addGateway('data', security.FSUserList())
-    root_mapper.getSubMapper('AccessControl.User.UserFolder').setGateway(g)
-
-    # anyfolder object gateway
-    g = gateways.CompositeGateway(base_p)
-    g.addGateway('items', structure.FSDirectoryItems())
-    root_mapper.getSubMapper('anyfolder').setGateway(g)
-
-    # anyfile object gateway
-    g = gateways.CompositeGateway(base_p)
-    g.addGateway('remainder', file_binary_data, 1)
-    root_mapper.getSubMapper('anyfile').setGateway(g)
-
-    # application gateway
-    g = gateways.CompositeGateway(base_p)
-    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()
-
-    return root_mapper
+import os
+from apelib.config.apeconf import makeComponentSystem
+from apelib.fs import classification
 
 
 def createAbstractMapper():
-    import os
-    from apelib.config.apeconf import makeComponentSystem
     here = os.path.dirname(__file__)
     filenames = (os.path.join(here, 'apeconf.xml'),)
     vnames = ('filesystem', '')


=== Products/Ape/lib/apelib/zope2/ofsserial.py 1.2.2.2 => 1.2.2.3 ===
--- Products/Ape/lib/apelib/zope2/ofsserial.py:1.2.2.2	Mon Jul  7 18:59:32 2003
+++ Products/Ape/lib/apelib/zope2/ofsserial.py	Mon Jul  7 23:58:15 2003
@@ -271,7 +271,11 @@
     """Zope 2 application root."""
 
     def __init__(self, root_key):
-        ReadOnlyItems.__init__(self, {'Application': (str(root_key),)})
+        try:
+            root_key = int(root_key)
+        except ValueError:
+            root_key = str(root_key)
+        ReadOnlyItems.__init__(self, {'Application': (root_key,)})
 
 
 class OptionalOFSProperties(OptionalSerializer):


=== Products/Ape/lib/apelib/zope2/sqlmapper.py 1.5.2.1 => 1.5.2.2 ===
--- Products/Ape/lib/apelib/zope2/sqlmapper.py:1.5.2.1	Tue Jun 24 17:38:44 2003
+++ Products/Ape/lib/apelib/zope2/sqlmapper.py	Mon Jul  7 23:58:15 2003
@@ -11,131 +11,24 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""A basic mapping from Zope 2 objects to a Postgres database.
+"""A basic mapping from Zope 2 objects to a SQL database.
 
 $Id$
 """
 
-from apelib.core import gateways
-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
+import os
 
+from apelib.sql import dbapi
+from apelib.config.apeconf import makeComponentSystem
 
 def createAbstractMapper():
-    """Object mapper factory, with extra return arg for testing purposes
-    """
-    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()
-    item_id_gw = structure.SQLItemId()
-    remainder_gw = structure.SQLRemainder()
-    file_data_gw = structure.SQLObjectData()
-    modtime_gw = structure.SQLModTime()
-    properties_gw = properties.SQLProperties()
-    security_gw = security.SQLSecurityAttributes()
-    userlist_gw = security.SQLUserList()
-    classification_gw = classification.SQLClassification()
-    keychain_gen = keygen.SQLKeychainGenerator()
-
-    for initializer in (
-        folder_items_gw,
-        item_id_gw,
-        remainder_gw,
-        file_data_gw,
-        modtime_gw,
-        properties_gw,
-        security_gw,
-        userlist_gw,
-        classification_gw,
-        keychain_gen):
-        root_mapper.addInitializer(initializer)
-
-    root_mapper.getClassifier().setGateway(classification_gw)
-
-    # abstract base gateway
-    g = gateways.CompositeGateway()
-    g.addGateway('id', item_id_gw)
-    g.addGateway('modtime', modtime_gw)
-    g.addGateway('remainder', remainder_gw)
-    g.addGateway('security', security_gw)
-    root_mapper.getSubMapper('base').setGateway(g)
-    base = g
-
-    # abstract base gateway with properties
-    g = gateways.CompositeGateway(base)
-    g.addGateway('properties', properties_gw)
-    root_mapper.getSubMapper('base_p').setGateway(g)
-    base_p = g
-
-    # folder gateway
-    g = gateways.CompositeGateway(base_p)
-    g.addGateway('items', folder_items_gw)
-    root_mapper.getSubMapper('OFS.Folder.Folder').setGateway(g)
-
-    # page template gateway
-    g = gateways.CompositeGateway(base_p)
-    g.addGateway('text', file_data_gw)
-    root_mapper.getSubMapper('ZopePageTemplate').setGateway(g)
-
-    # dtml method gateway
-    g = gateways.CompositeGateway(base)
-    g.addGateway('text', file_data_gw)
-    root_mapper.getSubMapper('OFS.DTMLMethod.DTMLMethod').setGateway(g)
-    
-    # dtml document gateway
-    g = gateways.CompositeGateway(base_p)
-    g.addGateway('text', file_data_gw)
-    root_mapper.getSubMapper('OFS.DTMLDocument.DTMLDocument').setGateway(g)
-
-    # zsqlmethod mapper
-    g = gateways.CompositeGateway(base_p)
-    g.addGateway('text', file_data_gw)
-    root_mapper.getSubMapper('Products.ZSQLMethods.SQL.SQL').setGateway(g)
-
-    # python script mapper
-    g = gateways.CompositeGateway(base)
-    g.addGateway('body', file_data_gw)
-    root_mapper.getSubMapper('PythonScript').setGateway(g)
-
-    # file gateway
-    g = gateways.CompositeGateway(base_p)
-    g.addGateway('data', file_data_gw)
-    root_mapper.getSubMapper('OFS.Image.File').setGateway(g)
-
-    # image gateway is identical
-    root_mapper.getSubMapper('OFS.Image.Image').setGateway(g)
-
-    # user folder gateway
-    g = gateways.CompositeGateway(base)
-    g.addGateway('data', userlist_gw)
-    root_mapper.getSubMapper('AccessControl.User.UserFolder').setGateway(g)
-
-    # anyfolder object gateway
-    g = gateways.CompositeGateway(base_p)
-    g.addGateway('items', folder_items_gw)
-    root_mapper.getSubMapper('anyfolder').setGateway(g)
-
-    # anyfile object gateway
-    g = gateways.CompositeGateway(base_p)
-    root_mapper.getSubMapper('anyfile').setGateway(g)
-
-    # application gateway
-    g = gateways.CompositeGateway(base_p)
-    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()
-
-    return root_mapper
+    here = os.path.dirname(__file__)
+    filenames = (os.path.join(here, 'apeconf.xml'),)
+    vnames = ('sql', '')
+    cs = makeComponentSystem(filenames, vnames)
+    m = cs.get('mapper', 'zope2')
+    m.checkConfiguration(path='zope2')
+    return m
 
 
 def createMapper(module_name, **kw):

=== Removed File Products/Ape/lib/apelib/zope2/baseconf.py ===

=== Removed File Products/Ape/lib/apelib/zope2/baseconf.xml ===

=== Removed File Products/Ape/lib/apelib/zope2/basemapper.py ===