[Zope-CVS] CVS: Products/Ape/apelib/zope2 - basemapper.py:1.2
Shane Hathaway
shane@zope.com
Wed, 19 Mar 2003 16:38:50 -0500
Update of /cvs-repository/Products/Ape/apelib/zope2
In directory cvs.zope.org:/tmp/cvs-serv25719
Modified Files:
basemapper.py
Log Message:
Imported modules rather than classes, shortening the total code
=== Products/Ape/apelib/zope2/basemapper.py 1.1.1.1 => 1.2 ===
--- Products/Ape/apelib/zope2/basemapper.py:1.1.1.1 Sat Mar 15 18:44:43 2003
+++ Products/Ape/apelib/zope2/basemapper.py Wed Mar 19 16:38:50 2003
@@ -16,158 +16,153 @@
$Id$
"""
-from apelib.core.gateways import CompositeGateway
-from apelib.core.mapper import Mapper
-from apelib.core.serializers \
- import CompositeSerializer, IgnoredAttribute, AnyObjectSerializer, \
- StringDataAttribute, OptionalSerializer
-from apelib.zodb3.serializers \
- import RollCall, FixedPersistentMapping, RemainingState
-from apelib.zope2.classifier import MetaTypeClassifier
-from apelib.zope2.ofsserial \
- import FolderItems, FolderItemsByKeychain, IdAttribute, \
- FilePData, OFSProperties
-from apelib.zope2.scripts \
- import PythonScriptSerializer, ZSQLMethodSerializer, \
- ZSQLMethodPropertiesSerializer
-from apelib.zope2.security import SecurityAttributes, UserFolderSerializer
+from apelib.core import gateways, mapper, serializers
+from apelib.zodb3 import serializers as zodb3serializers
+from apelib.zope2 import classifier, ofsserial, scripts, security
def createZope2Mapper(app_key, stored_keychains):
"""Returns a mapper tree for Zope 2 objects (without any gateways)."""
# Create and configure the root mapper
- root_mapper = Mapper()
- classifier = MetaTypeClassifier()
- root_mapper.setClassifier(classifier)
- cs = CompositeSerializer('Persistence', 'PersistentMapping')
- serializer = FixedPersistentMapping()
+ root_mapper = mapper.Mapper()
+ cfr = classifier.MetaTypeClassifier()
+ root_mapper.setClassifier(cfr)
+ cs = serializers.CompositeSerializer('Persistence', 'PersistentMapping')
+ serializer = zodb3serializers.FixedPersistentMapping()
serializer.add('Application', (app_key,), ('OFS.Application.Application',))
cs.addSerializer('items', serializer)
- cs.addSerializer('roll_call', RollCall())
+ cs.addSerializer('roll_call', zodb3serializers.RollCall())
root_mapper.setSerializer(cs)
- root_mapper.setGateway(CompositeGateway()) # No storage necessary
+ root_mapper.setGateway(gateways.CompositeGateway()) # No storage necessary
# Prepare some common names
if stored_keychains:
- folder_items_serializer = FolderItemsByKeychain()
+ folder_items_serializer = ofsserial.FolderItemsByKeychain()
else:
- folder_items_serializer = FolderItems()
+ folder_items_serializer = ofsserial.FolderItems()
# abstract base mapper
m = root_mapper.addSubMapper('base')
- cs = CompositeSerializer(None, None)
+ cs = serializers.CompositeSerializer(None, None)
m.setSerializer(cs)
- cs.addSerializer('id', IdAttribute())
- cs.addSerializer('security', SecurityAttributes())
- cs.addSerializer('remainder', RemainingState(), final=1)
+ cs.addSerializer('id', ofsserial.IdAttribute())
+ cs.addSerializer('security', security.SecurityAttributes())
+ cs.addSerializer('remainder', zodb3serializers.RemainingState(), final=1)
base = cs
# abstract mapper with properties
m = root_mapper.addSubMapper('base_p')
- cs = CompositeSerializer(None, None, base)
+ cs = serializers.CompositeSerializer(None, None, base)
m.setSerializer(cs)
- cs.addSerializer('properties', OFSProperties())
+ cs.addSerializer('properties', ofsserial.OFSProperties())
base_p = cs
# folder mapper
m = root_mapper.addSubMapper('OFS.Folder.Folder')
- cs = CompositeSerializer('OFS.Folder', 'Folder', base_p)
+ cs = serializers.CompositeSerializer('OFS.Folder', 'Folder', base_p)
m.setSerializer(cs)
cs.addSerializer('items', folder_items_serializer)
- classifier.registerDefaultLoader('Folder', 'OFS.Folder.Folder', 1)
+ cfr.registerDefaultLoader('Folder', 'OFS.Folder.Folder', 1)
# file mapper
m = root_mapper.addSubMapper('OFS.Image.File')
- cs = CompositeSerializer('OFS.Image', 'File', base_p)
+ cs = serializers.CompositeSerializer('OFS.Image', 'File', base_p)
m.setSerializer(cs)
- cs.addSerializer('data', FilePData())
- classifier.registerDefaultLoader('File', 'OFS.Image.File', 0)
- classifier.setFlags('OFS.Image.File', classifier.CONTENT_TYPE_ATTR)
+ cs.addSerializer('data', ofsserial.FilePData())
+ cfr.registerDefaultLoader('File', 'OFS.Image.File', 0)
+ cfr.setFlags('OFS.Image.File', cfr.CONTENT_TYPE_ATTR)
# image mapper
m = root_mapper.addSubMapper('OFS.Image.Image')
- cs = CompositeSerializer('OFS.Image', 'Image', base_p)
+ cs = serializers.CompositeSerializer('OFS.Image', 'Image', base_p)
m.setSerializer(cs)
- cs.addSerializer('data', FilePData())
- classifier.register('Image', 'OFS.Image.Image', (
+ cs.addSerializer('data', ofsserial.FilePData())
+ cfr.register('Image', 'OFS.Image.Image', (
'.gif', '.jpg', '.jpeg', '.png'))
- classifier.setFlags('OFS.Image.Image', classifier.CONTENT_TYPE_ATTR)
+ cfr.setFlags('OFS.Image.Image', cfr.CONTENT_TYPE_ATTR)
# page template mapper
m = root_mapper.addSubMapper('ZopePageTemplate') # abbreviated name
- cs = CompositeSerializer('Products.PageTemplates.ZopePageTemplate',
- 'ZopePageTemplate', base_p)
+ cs = serializers.CompositeSerializer(
+ 'Products.PageTemplates.ZopePageTemplate', 'ZopePageTemplate', base_p)
m.setSerializer(cs)
- cs.addSerializer('text', StringDataAttribute('_text'))
- classifier.register('Page Template', 'ZopePageTemplate', (
+ cs.addSerializer('text', serializers.StringDataAttribute('_text'))
+ cfr.register('Page Template', 'ZopePageTemplate', (
'.html', '.htm', '.zpt', '.pt'))
# dtml method mapper
m = root_mapper.addSubMapper('OFS.DTMLMethod.DTMLMethod')
- cs = CompositeSerializer('OFS.DTMLMethod', 'DTMLMethod', base)
+ cs = serializers.CompositeSerializer('OFS.DTMLMethod', 'DTMLMethod', base)
m.setSerializer(cs)
- cs.addSerializer('text', StringDataAttribute('raw'))
- classifier.register('DTML Method', 'OFS.DTMLMethod.DTMLMethod', ('.dtml',))
+ cs.addSerializer('text', serializers.StringDataAttribute('raw'))
+ cfr.register('DTML Method', 'OFS.DTMLMethod.DTMLMethod', ('.dtml',))
# dtml document mapper
m = root_mapper.addSubMapper('OFS.DTMLDocument.DTMLDocument')
- cs = CompositeSerializer('OFS.DTMLDocument', 'DTMLDocument', base_p)
+ cs = serializers.CompositeSerializer(
+ 'OFS.DTMLDocument', 'DTMLDocument', base_p)
m.setSerializer(cs)
- cs.addSerializer('text', StringDataAttribute('raw'))
- classifier.register('DTML Document', 'OFS.DTMLDocument.DTMLDocument')
+ cs.addSerializer('text', serializers.StringDataAttribute('raw'))
+ cfr.register('DTML Document', 'OFS.DTMLDocument.DTMLDocument')
# zsql mapper
m = root_mapper.addSubMapper('Products.ZSQLMethods.SQL.SQL')
- cs = CompositeSerializer('Products.ZSQLMethods.SQL', 'SQL', base)
+ cs = serializers.CompositeSerializer(
+ 'Products.ZSQLMethods.SQL', 'SQL', base)
m.setSerializer(cs)
- cs.addSerializer('properties', ZSQLMethodPropertiesSerializer(), 1)
- cs.addSerializer('text', ZSQLMethodSerializer())
- classifier.register('Z SQL Method', 'Products.ZSQLMethods.SQL.SQL', (
+ cs.addSerializer('properties',
+ scripts.ZSQLMethodPropertiesSerializer(), 1)
+ cs.addSerializer('text', scripts.ZSQLMethodSerializer())
+ cfr.register('Z SQL Method', 'Products.ZSQLMethods.SQL.SQL', (
'.sql', ))
# python script mapper
m = root_mapper.addSubMapper('PythonScript') # abbreviated name
- cs = CompositeSerializer('Products.PythonScripts.PythonScript',
- 'PythonScript', base)
+ cs = serializers.CompositeSerializer(
+ 'Products.PythonScripts.PythonScript', 'PythonScript', base)
m.setSerializer(cs)
- cs.addSerializer('body', PythonScriptSerializer())
- classifier.register('Script (Python)', 'PythonScript', ('.py', ))
+ cs.addSerializer('body', scripts.PythonScriptSerializer())
+ cfr.register('Script (Python)', 'PythonScript', ('.py', ))
# user folder mapper
m = root_mapper.addSubMapper('AccessControl.User.UserFolder')
- cs = CompositeSerializer('AccessControl.User', 'UserFolder', base)
+ cs = serializers.CompositeSerializer(
+ 'AccessControl.User', 'UserFolder', base)
m.setSerializer(cs)
- cs.addSerializer('data', UserFolderSerializer())
- classifier.register('User Folder', 'AccessControl.User.UserFolder')
+ cs.addSerializer('data', security.UserFolderSerializer())
+ cfr.register('User Folder', 'AccessControl.User.UserFolder')
# anyfolder mapper
m = root_mapper.addSubMapper('anyfolder')
- cs = AnyObjectSerializer(base)
+ cs = serializers.AnyObjectSerializer(base)
m.setSerializer(cs)
- cs.addSerializer('properties', OptionalSerializer(OFSProperties(), []), 1)
+ cs.addSerializer('properties', serializers.OptionalSerializer(
+ ofsserial.OFSProperties(), []), 1)
cs.addSerializer('items', folder_items_serializer)
- classifier.registerDefaultStorage('(folderish object)', 'anyfolder', 1)
+ cfr.registerDefaultStorage('(folderish object)', 'anyfolder', 1)
# anyfile mapper
m = root_mapper.addSubMapper('anyfile')
- cs = AnyObjectSerializer(base)
+ cs = serializers.AnyObjectSerializer(base)
m.setSerializer(cs)
- cs.addSerializer('properties', OptionalSerializer(OFSProperties(), []), 1)
- classifier.registerDefaultStorage('(fileish object)', 'anyfile', 0)
+ cs.addSerializer('properties', serializers.OptionalSerializer(
+ ofsserial.OFSProperties(), []), 1)
+ cfr.registerDefaultStorage('(fileish object)', 'anyfile', 0)
# application mapper
m = root_mapper.addSubMapper('OFS.Application.Application')
- cs = CompositeSerializer('OFS.Application', 'Application', base_p)
+ cs = serializers.CompositeSerializer(
+ 'OFS.Application', 'Application', base_p)
m.setSerializer(cs)
cs.removeSerializer('id')
cs.addSerializer('items', folder_items_serializer)
- classifier.registerKey(
+ cfr.registerKey(
'Application', 'OFS.Application.Application', app_key)
# Other stuff
- classifier.register('CMF Skins Tool', 'anyfile') # XXX workaround
- classifier.register('Control Panel', 'anyfile') # XXX workaround
+ cfr.register('CMF Skins Tool', 'anyfile') # XXX workaround
+ cfr.register('Control Panel', 'anyfile') # XXX workaround
return root_mapper