[Zope-CVS] CVS: Products/Ape/lib/apelib/zope2 - baseconf.py:1.1.2.2

Shane Hathaway shane@zope.com
Sat, 21 Jun 2003 13:25:09 -0400


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

Modified Files:
      Tag: ape-newconf-branch
	baseconf.py 
Log Message:
Worked on a new configuration style.


=== Products/Ape/lib/apelib/zope2/baseconf.py 1.1.2.1 => 1.1.2.2 ===
--- Products/Ape/lib/apelib/zope2/baseconf.py:1.1.2.1	Thu Jun 19 23:24:00 2003
+++ Products/Ape/lib/apelib/zope2/baseconf.py	Sat Jun 21 13:25:08 2003
@@ -1,28 +1,52 @@
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Basic Zope 2 mapper configurations.
 
+$Id$
+"""
 
 from apelib.core import gateways, mapper, serializers
 from apelib.zodb3 import serializers as zodb3serializers
 from apelib.zope2 import classifier, ofsserial, scripts, security
 
 
-class AbstractConfiguration(mapper.MapperConfiguration):
-    name = 'base'
-    serializers = [
-        ('id', ofsserial.IdAttribute()),
-        ('modtime', zodb3serializers.ModTimeAttribute()),
-        ('security', security.SecurityAttributes()),
-        ]
-    final_serializers = [
-        ('remainder', zodb3serializers.RemainingState()),
-        ]
-
-
-class AbstractPropertyConfiguration(mapper.MapperConfiguration):
-    base = 'base'
-    name = 'base_p'
-    serializers = [
-        ('properties', ofsserial.OFSProperties()),
-        ]
+class RootConf(mapper.MapperConfiguration):
+    mapper_name = ''
+    classifier = classifier.MetaTypeClassifier()
+    class_name = 'Persistent.PersistentMapping'
+    final_serializers = {'roll_call': zodb3serializers.RollCall()}
+    gateways = {}  # No storage necessary
+
+    def __init__(self, app_key):
+        s = zodb3serializers.FixedPersistentMapping()
+        s.add('Application', (app_key,), ('OFS.Application.Application',))
+        self.serializers = {'items': s}
+
+
+class BaseConf(mapper.MapperConfiguration):
+    mapper_name = 'base'
+    serializers = {
+        'id':       ofsserial.IdAttribute(),
+        'modtime':  zodb3serializers.ModTimeAttribute(),
+        'security': security.SecurityAttributes(),
+        }
+    final_serializers = {'remainder': zodb3serializers.RemainingState()}
+
+
+class BasePropertyConf(BaseConf):
+    mapper_name = 'base_p'
+    serializers = {'properties': ofsserial.OFSProperties()}
 
 
 def getFolderItemsSerializer(stored_keychains):
@@ -32,26 +56,112 @@
         return ofsserial.FolderItems()
 
 
-class FolderConfiguration(mapper.MapperConfiguration):
-    base = 'base_p'
-    name = class_name = 'OFS.Folder.Folder'
+class FolderConf(BasePropertyConf):
+    mapper_name = class_name = 'OFS.Folder.Folder'
+    classifier_options = {'default_for': ['directory']}
+
+    def __init__(self, stored_keychains):
+        self.serializers = {
+            'items': getFolderItemsSerializer(stored_keychains),
+            }
+
+
+class FileConf(BasePropertyConf):
+    mapper_name = class_name = 'OFS.Image.File'
+    serializers = {'data': ofsserial.FilePData()}
+    classifier_options = {
+        'content_type_attr': 'content_type',
+        'default_for': ['file'],
+        }
+
+
+class ImageConf(FileConfiguration):
+    mapper_name = class_name = 'OFS.Image.Image'
+    classifier_options = {
+        'extensions': ['.gif', '.jpg', '.jpeg', '.png'],
+        'default_for': [],
+        }
+
+
+class PageTemplateConf(BasePropertyConf):
+    mapper_name = 'Products.PageTemplates.ZopePageTemplate.ZopePageTemplate'
+    class_name = name
+    serializers = {'text': serializers.StringDataAttribute('_text')}
+    classifier_options = {'extensions': ['.html', '.htm', '.zpt', '.pt']}
+
+
+class DTMLMethodConf(BaseConf):
+    mapper_name = class_name = 'OFS.DTMLMethod.DTMLMethod'
+    serializers = {'text': serializers.StringDataAttribute('raw')}
+    classifier_options = {'extensions': ['.dtml']}
+
+
+class DTMLDocumentConf(BasePropertyConf):
+    mapper_name = class_name = 'OFS.DTMLMethod.DTMLDocument'
+    serializers = {'text': serializers.StringDataAttribute('raw')}
+
+
+class ZSQLMethodConf(BaseConf):
+    mapper_name = class_name = 'Products.ZSQLMethods.SQL.SQL'
+    serializers = {
+        'properties': scripts.ZSQLMethodPropertiesSerializer(),
+        'text': scripts.ZSQLMethodSerializer(),
+        }
+    classifier_options = {'extensions': ['.sql']}
+
+
+class PythonScriptConf(BaseConf):
+    mapper_name = 'Products.PythonScripts.PythonScript.PythonScript'
+    class_name = mapper_name
+    serializers = {'body': scripts.PythonScriptSerializer()}
+    classifier_options = {'extensions': ['.py']}
+
+
+class UserFolderConf(BaseConf):
+    mapper_name = class_name = 'AccessControl.User.UserFolder'
+    serializers = {'data': security.UserFolderSerializer()}
+
+
+class AnyFolderConf(BaseConf):
+    mapper_name = 'anyfolder'
+    class_name = None  # unknown
+    classifier_options = {'default_for': 'folderish_object'}
+
+    def __init__(self, stored_keychains):
+        p = serializers.OptionalSerializer(ofsserial.OFSProperties(), [])
+        i = getFolderItemsSerializer(stored_keychains)
+        self.serializers = {'properties': p, 'items': i}
+
+
+class AnyFileConf(BaseConf):
+    mapper_name = 'anyfile'
+    class_name = None  # Unknown
+    classifier_options = {'default_for': 'fileish_object'}
+
     def __init__(self, stored_keychains):
-        self.serializers = [
-            ('items', getFolderItemsSerializer(stored_keychains)),
-            ]
+        p = serializers.OptionalSerializer(ofsserial.OFSProperties(), [])
+        self.serializers = {'properties': p}
+    
 
+class ApplicationConf(BasePropertyConf):
+    mapper_name = class_name = 'OFS.Application.Application'
 
-class FileConfiguration(mapper.MapperConfiguration):
-    base = 'base_p'
-    name = class_name = 'OFS.Image.File'
-    serializers = [
-        ('data', ofsserial.FilePData()),
-        ]
-    classifier_flags = ('content_type_attr',)
+    def __init__(self, stored_keychains, app_key):
+        i = getFolderItemsSerializer(stored_keychains)
+        self.serializers = {'items': i, 'id': None}
+        self.classifier_options = {'key': app_key}
 
 
+class CMFSkinsConf(mapper.MapperConfiguration):
+    mapper_name = class_name = 'Products.CMFCore.SkinsTool.SkinsTool'
+    use_mapper = 'anyfile'  # XXX workaround
 
 
+class ControlPanelConf(mapper.MapperConfiguration):
+    mapper_name = class_name = 'App.ApplicationManager.ApplicationManager'
+    use_mapper = 'anyfile'  # XXX workaround
 
 
+# Put the above configurations into a collection of directives.
+directives = mapper.prepareDirectives()