[Zope-CVS] CVS: Products/AdaptableStorage - Zope2FS.py:1.9
Shane Hathaway
shane@zope.com
Mon, 9 Dec 2002 15:27:38 -0500
Update of /cvs-repository/Products/AdaptableStorage
In directory cvs.zope.org:/tmp/cvs-serv10661
Modified Files:
Zope2FS.py
Log Message:
Added two mappers to Zope2FS for serializing any kind of object. If no mapper
is provided for a class, the database falls back to a default mapper--either
the "fileish" or the "folderish" mapper.
... which is *really cool*. :-) I've been trying to achieve this in a clean
way for months. (Deeeeep, loooonnnnnggggg sigh of relief!)
=== Products/AdaptableStorage/Zope2FS.py 1.8 => 1.9 ===
--- Products/AdaptableStorage/Zope2FS.py:1.8 Mon Dec 9 13:25:27 2002
+++ Products/AdaptableStorage/Zope2FS.py Mon Dec 9 15:27:08 2002
@@ -21,10 +21,10 @@
import ObjectSerializer, ObjectGateway, ObjectMapper
from serial_std.public \
import RollCall, FixedPersistentMapping, IgnoredAttribute, \
- RemainingState, PathKeychainGenerator
+ RemainingState, PathKeychainGenerator, AnyObjectSerializer
from serial_ofs.public import FolderItems, MetaTypeClassifier, IdAttribute
from gateway_fs.public import FSConnection, FSDirectoryItems, FSAutoId, \
- FSSectionData, FSClassificationSection
+ FSSectionData, FSClassificationSection, FSFileData
def createMapper(basepath, volatile=1):
@@ -40,18 +40,31 @@
s.addAspect('items', FolderItems())
s.addAspect('id', IdAttribute())
s.addAspect('remainder', RemainingState())
- object_serializers['OFS/Folder'] = s
+ object_serializers['OFS.Folder.Folder'] = s
+
+ # anyfolder serializer
+ s = AnyObjectSerializer()
+ s.addAspect('items', FolderItems())
+ s.addAspect('id', IdAttribute())
+ s.addAspect('remainder', RemainingState())
+ object_serializers['anyfolder'] = s
+
+ # anyfile serializer
+ s = AnyObjectSerializer()
+ s.addAspect('id', IdAttribute())
+ s.addAspect('data', RemainingState())
+ object_serializers['anyfile'] = s
# application serializer
s = ObjectSerializer('OFS.Application', 'Application')
s.addAspect('items', FolderItems())
s.addAspect('remainder', RemainingState())
- object_serializers['OFS/Application'] = s
+ object_serializers['OFS.Application.Application'] = s
# root serializer
s = ObjectSerializer('Persistence', 'PersistentMapping')
aspect = FixedPersistentMapping()
- aspect.add('Application', ('/',), ('OFS/Application',))
+ aspect.add('Application', ('/',), ('OFS.Application.Application',))
s.addAspect('items', aspect)
s.addAspect('roll_call', RollCall())
root_serializer = s
@@ -63,13 +76,26 @@
g.addGateway('items', FSDirectoryItems(fs_conn))
g.addGateway('id', FSAutoId())
g.addGateway('remainder', FSSectionData(fs_conn, 'remainder'))
- object_gateways['OFS/Folder'] = g
+ object_gateways['OFS.Folder.Folder'] = g
+
+ # anyfolder object gateway
+ g = ObjectGateway()
+ g.addGateway('items', FSDirectoryItems(fs_conn))
+ g.addGateway('id', FSAutoId())
+ g.addGateway('remainder', FSSectionData(fs_conn, 'remainder'))
+ object_gateways['anyfolder'] = g
+
+ # anyfile object gateway
+ g = ObjectGateway()
+ g.addGateway('id', FSAutoId())
+ g.addGateway('data', FSFileData(fs_conn))
+ object_gateways['anyfile'] = g
# application gateway
g = ObjectGateway()
g.addGateway('items', FSDirectoryItems(fs_conn))
g.addGateway('remainder', FSSectionData(fs_conn, 'remainder'))
- object_gateways['OFS/Application'] = g
+ object_gateways['OFS.Application.Application'] = g
# root gateway (no storage)
g = ObjectGateway()
@@ -84,8 +110,10 @@
# Put everything together
classifier = MetaTypeClassifier(FSClassificationSection(fs_conn))
- classifier.registerDefaultLoader('Folder', 'OFS/Folder', 1)
- classifier.registerKey('Application', 'OFS/Application', '/')
+ classifier.registerDefaultLoader('Folder', 'OFS.Folder.Folder', 1)
+ classifier.registerDefaultStorage('(folderish object)', 'anyfolder', 1)
+ classifier.registerDefaultStorage('(fileish object)', 'anyfile', 0)
+ classifier.registerKey('Application', 'OFS.Application.Application', '/')
keychain_gen = PathKeychainGenerator()
rm = ObjectMapper(
None, root_serializer, root_gateway, classifier, keychain_gen)