[Zope-CVS] CVS: Products/Ape/lib/apelib/zope2 -
classifier.py:1.7.2.1 apeconf.xml:1.5.2.3
Shane Hathaway
shane at zope.com
Sat Feb 28 14:56:32 EST 2004
Update of /cvs-repository/Products/Ape/lib/apelib/zope2
In directory cvs.zope.org:/tmp/cvs-serv29078/zope2
Modified Files:
Tag: ape-fs-oid-branch
classifier.py apeconf.xml
Log Message:
Provided a means of classifying things by filesystem path.
In particular, you can now specify which mapper to use at the base path.
=== Products/Ape/lib/apelib/zope2/classifier.py 1.7 => 1.7.2.1 ===
--- Products/Ape/lib/apelib/zope2/classifier.py:1.7 Tue Feb 17 00:25:13 2004
+++ Products/Ape/lib/apelib/zope2/classifier.py Sat Feb 28 14:56:31 2004
@@ -38,6 +38,9 @@
'application/octet-stream': '', # No extension--too overloaded.
}
+generic_classifications = (
+ 'directory', 'file', 'folder_object', 'file_object', 'basepath')
+
class Classifier:
"""A classifier with some minimal Zope 2 extensions.
@@ -60,8 +63,7 @@
elif condition == 'class':
self.class_to_mapper[value] = mapper_name
elif condition == 'generic':
- assert value in (
- 'directory', 'file', 'folder_object', 'file_object'), value
+ assert value in generic_classifications, value
self.generic_to_mapper[value] = mapper_name
elif condition == 'oid':
self.oid_to_mapper[value] = mapper_name
@@ -124,28 +126,37 @@
classification['class_name'] = class_name
mapper_name = classification.get('mapper_name')
if mapper_name is None:
- # bw compat: look for certain meta_types.
- mt = classification.get('meta_type')
- if mt == '(folderish object)':
- mapper_name = self.generic_to_mapper.get('folder_object')
- elif mt == '(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:
- t = classification.get('node_type')
- if t == 'd':
- # Directory
- mapper_name = self.generic_to_mapper.get('directory')
- elif t == 'f':
- # File
- ext = classification.get('extension')
- if ext:
- if not ext.startswith('.'):
- ext = '.' + ext
- mapper_name = self.ext_to_mapper.get(ext.lower())
- if not mapper_name:
- mapper_name = self.generic_to_mapper.get('file')
+ # The choice of mapper is not stored explicitly. Choose
+ # one based on several criteria.
+ if 1:
+ # bw compat: look for certain meta_types.
+ mt = classification.get('meta_type')
+ if mt == '(folderish object)':
+ mapper_name = self.generic_to_mapper.get('folder_object')
+ elif mt == '(fileish object)':
+ mapper_name = self.generic_to_mapper.get('file_object')
+ if mapper_name is None:
+ if class_name is not None:
+ mapper_name = self.class_to_mapper.get(class_name)
+ if mapper_name is None:
+ subpath = classification.get('subpath')
+ if subpath is not None and not subpath:
+ # Application base
+ mapper_name = self.generic_to_mapper.get('basepath')
+ if mapper_name is None:
+ t = classification.get('node_type')
+ if t == 'd':
+ # Directory
+ mapper_name = self.generic_to_mapper.get('directory')
+ elif t == 'f':
+ # File
+ ext = classification.get('extension')
+ if ext:
+ if not ext.startswith('.'):
+ ext = '.' + ext
+ mapper_name = self.ext_to_mapper.get(ext.lower())
+ if not mapper_name:
+ mapper_name = self.generic_to_mapper.get('file')
if mapper_name is None:
raise ClassificationError(
'No mapper known for oid %s' % repr(event.oid))
=== Products/Ape/lib/apelib/zope2/apeconf.xml 1.5.2.2 => 1.5.2.3 ===
--- Products/Ape/lib/apelib/zope2/apeconf.xml:1.5.2.2 Fri Feb 27 11:21:38 2004
+++ Products/Ape/lib/apelib/zope2/apeconf.xml Sat Feb 28 14:56:31 2004
@@ -197,6 +197,7 @@
<serializer name="id" enabled="false" />
<gateway name="id" enabled="false" />
<gateway name="items" use="dir_items" />
+ <use-for generic="basepath" />
</mapper>
<mapper name="anyfile">
More information about the Zope-CVS
mailing list