[Zope-CVS] CVS: Products/Ape/lib/apelib/zope2 - apeconf.xml:1.3.2.3
classifier.py:1.5.2.2 mapper.py:1.2.4.1
Shane Hathaway
shane at zope.com
Sat Dec 20 02:31:09 EST 2003
Update of /cvs-repository/Products/Ape/lib/apelib/zope2
In directory cvs.zope.org:/tmp/cvs-serv30479/zope2
Modified Files:
Tag: ape-0_8-branch
apeconf.xml classifier.py mapper.py
Log Message:
Continued refactoring and renaming.
Over 60 tests now pass.
=== Products/Ape/lib/apelib/zope2/apeconf.xml 1.3.2.2 => 1.3.2.3 ===
--- Products/Ape/lib/apelib/zope2/apeconf.xml:1.3.2.2 Sat Dec 13 23:24:47 2003
+++ Products/Ape/lib/apelib/zope2/apeconf.xml Sat Dec 20 02:31:08 2003
@@ -4,25 +4,32 @@
<configuration>
+<!-- Classifier and OID generator -->
+
+<variation name="filesystem">
+ <classifier factory="apelib.zope2.classifier.Classifier">
+ <gateway factory="apelib.fs.classification.FSClassificationSection" />
+ </classifier>
+ <oid-generator factory="apelib.core.oidgen.PathOIDGenerator" />
+ </variation>
+ <variation name="sql">
+ <classifier factory="apelib.zope2.classifier.Classifier">
+ <gateway factory="apelib.sql.classification.SQLClassification" />
+ </classifier>
+ <oid-generator factory="apelib.sql.oidgen.SQLOIDGenerator" />
+</variation>
+
<!-- Root mapper -->
<mapper name="root" class="Persistence.PersistentMapping">
<serializer name="root_items"
- factory="apelib.zodb3.serializers.BasicPersistentMapping" />
+ factory="apelib.zodb3.serializers.StringToPersistentPM" />
<serializer name="roll_call" factory="apelib.zodb3.serializers.RollCall" />
<variation name="filesystem">
- <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="/" />
</variation>
<variation 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" />
</variation>
@@ -97,33 +104,33 @@
<!-- Mappers for particular content types -->
-<mapper name="OFS.Folder.Folder" extends="base_p" parent="root">
+<mapper name="OFS.Folder.Folder" extends="base_p">
<serializer name="items" use="folder_items" />
<gateway name="items" use="dir_items" />
<use-for generic="directory" />
</mapper>
-<mapper name="OFS.Image.File" extends="base_p" parent="root">
+<mapper name="OFS.Image.File" extends="base_p">
<serializer name="data" factory="apelib.zope2.ofsserial.FilePData" />
<gateway name="data" use="binary_data" />
<use-for generic="file" />
<option name="content_type_attr" value="content_type" />
</mapper>
-<mapper name="OFS.Image.Image" extends="OFS.Image.File" parent="root">
+<mapper name="OFS.Image.Image" extends="OFS.Image.File">
<use-for extensions=".gif .jpg .jpeg .png" />
<option name="content_type_attr" value="content_type" />
</mapper>
<mapper name="Products.PageTemplates.ZopePageTemplate.ZopePageTemplate"
- extends="base_p" parent="root">
+ extends="base_p">
<serializer name="text" factory="apelib.core.serializers.StringDataAttribute"
param="_text" />
<gateway name="text" use="text_data" />
<use-for extensions=".html .htm .zpt .pt" />
</mapper>
-<mapper name="OFS.DTMLMethod.DTMLMethod" extends="base" parent="root">
+<mapper name="OFS.DTMLMethod.DTMLMethod" extends="base">
<serializer name="text" factory="apelib.core.serializers.StringDataAttribute"
param="raw" />
<gateway name="text" use="text_data" />
@@ -131,11 +138,11 @@
</mapper>
<mapper name="OFS.DTMLMethod.DTMLDocument"
- extends="OFS.DTMLMethod.DTMLMethod" parent="root">
+ extends="OFS.DTMLMethod.DTMLMethod">
<serializer name="properties" enabled="false" />
</mapper>
-<mapper name="Products.ZSQLMethods.SQL.SQL" extends="base" parent="root">
+<mapper name="Products.ZSQLMethods.SQL.SQL" extends="base">
<serializer name="properties"
factory="apelib.zope2.scripts.ZSQLMethodPropertiesSerializer" />
<serializer name="text"
@@ -152,14 +159,14 @@
</mapper>
<mapper name="Products.PythonScripts.PythonScript.PythonScript"
- extends="base" parent="root">
+ extends="base">
<serializer name="body"
factory="apelib.zope2.scripts.PythonScriptSerializer" />
<gateway name="body" use="text_data" />
<use-for extensions=".py" />
</mapper>
-<mapper name="AccessControl.User.UserFolder" extends="base" parent="root">
+<mapper name="AccessControl.User.UserFolder" extends="base">
<serializer name="data"
factory="apelib.zope2.security.UserFolderSerializer" />
<variation name="filesystem">
@@ -170,29 +177,26 @@
</variation>
</mapper>
-<mapper name="anyfolder" class="any" extends="base_p" parent="root">
+<mapper name="anyfolder" class="any" extends="base_p">
<serializer name="properties" use="optional_properties" />
<serializer name="items" use="folder_items" />
<gateway name="items" use="dir_items" />
<use-for generic="folder_object" />
</mapper>
-<mapper name="anyfile" class="any" extends="base_p" parent="root">
+<mapper name="anyfile" class="any" extends="base_p">
<serializer name="properties" use="optional_properties" />
<gateway name="remainder" use="binary_data" />
<use-for generic="file_object" />
</mapper>
-<mapper name="OFS.Application.Application" extends="base_p" parent="root">
+<mapper name="OFS.Application.Application" extends="base_p">
<serializer name="items" use="folder_items" />
<serializer name="id" enabled="false" />
<gateway name="id" enabled="false" />
<gateway name="items" use="dir_items" />
<variation name="filesystem">
- <use-for key="/" />
- </variation>
- <variation name="sql">
- <use-for key="0" />
+ <use-for oid="/" />
</variation>
</mapper>
=== Products/Ape/lib/apelib/zope2/classifier.py 1.5.2.1 => 1.5.2.2 ===
--- Products/Ape/lib/apelib/zope2/classifier.py:1.5.2.1 Fri Dec 19 21:52:50 2003
+++ Products/Ape/lib/apelib/zope2/classifier.py Sat Dec 20 02:31:08 2003
@@ -47,10 +47,9 @@
def __init__(self, gw=None):
self.gw = gw
- self.key_to_mapper = {}
self.class_to_mapper = {}
self.ext_to_mapper = {}
- self.fallback_to_mapper = {}
+ self.generic_to_mapper = {}
self.options = {} # { (mapper_name, option) -> value }
def getGateway(self):
@@ -58,16 +57,14 @@
def register(self, condition, value, mapper_name):
- if condition == 'key':
- self.key_to_mapper[value] = mapper_name
- elif condition == 'extension':
+ if condition == 'extension':
self.ext_to_mapper[value] = mapper_name
elif condition == 'class':
self.class_to_mapper[value] = mapper_name
- elif condition == 'fallback':
- assert value in ('directory', 'file',
- 'folderish_object', 'fileish_object'), value
- self.fallback_to_mapper[value] = mapper_name
+ elif condition == 'generic':
+ assert value in (
+ 'directory', 'file', 'folder_object', 'file_object'), value
+ self.generic_to_mapper[value] = mapper_name
else:
raise ValueError('Unknown classification condition: %s'
% repr(condition))
@@ -76,26 +73,22 @@
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."""
- 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.class_to_mapper.get(class_name)
if mapper_name is None:
folderish = isinstance(value, ObjectManager)
- # Store in a fallback format
+ # Store in a generic format
if folderish:
- fallback = 'folderish_object'
+ generic = 'folderish_object'
else:
- fallback = 'fileish_object'
- mapper_name = self.fallback_to_mapper.get(fallback)
+ generic = 'fileish_object'
+ mapper_name = self.generic_to_mapper.get(generic)
if mapper_name is not None:
# Force a particular mapper
classification['mapper_name'] = mapper_name
@@ -118,10 +111,6 @@
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')
if class_name and ':' in class_name:
@@ -133,16 +122,16 @@
# bw compat: look for certain meta_types.
mt = classification.get('meta_type')
if mt == '(folderish object)':
- mapper_name = self.fallback_to_mapper.get('folderish_object')
+ mapper_name = self.generic_to_mapper.get('folderish_object')
elif mt == '(fileish object)':
- mapper_name = self.fallback_to_mapper.get('fileish_object')
+ mapper_name = self.generic_to_mapper.get('fileish_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:
t = classification.get('node_type')
if t == 'd':
# Directory
- mapper_name = self.fallback_to_mapper.get('directory')
+ mapper_name = self.generic_to_mapper.get('directory')
elif t == 'f':
# File
ext = classification.get('extension')
@@ -151,7 +140,7 @@
ext = '.' + ext
mapper_name = self.ext_to_mapper.get(ext.lower())
if not mapper_name:
- mapper_name = self.fallback_to_mapper.get('file')
+ mapper_name = self.generic_to_mapper.get('file')
if mapper_name is None:
raise DeserializationError(
'No mapper known for class %s' % repr(class_name))
=== Products/Ape/lib/apelib/zope2/mapper.py 1.2 => 1.2.4.1 ===
--- Products/Ape/lib/apelib/zope2/mapper.py:1.2 Wed Jul 9 11:40:15 2003
+++ Products/Ape/lib/apelib/zope2/mapper.py Sat Dec 20 02:31:08 2003
@@ -18,10 +18,10 @@
import os
import Products
-from apelib.config.apeconf import wireMapper
+from apelib.config.apeconf import configure
-def createMapper(vname, search_products=0):
+def loadConf(vname, search_products=0):
"""Builds a mapper from apeconf.xml files.
"""
here = os.path.dirname(__file__)
@@ -35,7 +35,7 @@
fn = os.path.join(path, name, 'apeconf.xml')
if os.path.exists(fn):
filenames.append(fn)
- return wireMapper(filenames, vname, 'root')
+ return configure(filenames, vname)
def createFSMapper(basepath, **kw):
@@ -49,7 +49,7 @@
"""
from apelib.fs.connection import FSConnection
- mapper = createMapper('filesystem', search_products=1)
+ mapper = loadConf('filesystem', search_products=1)
conn = FSConnection(basepath, **kw)
return mapper, {'fs': conn}
@@ -68,7 +68,7 @@
"""
from apelib.sql.dbapi import DBAPIConnector
- mapper = createMapper('sql', search_products=1)
+ mapper = loadConf('sql', search_products=1)
conn = DBAPIConnector(module_name, **kw)
return mapper, {'db': conn}
More information about the Zope-CVS
mailing list