[Zope-CVS] CVS: Products/AdaptableStorage/serial_ofs - FolderItems.py:1.6 IdAttribute.py:1.2 MetaTypeClassifier.py:1.7
Shane Hathaway
shane@zope.com
Mon, 9 Dec 2002 13:25:59 -0500
Update of /cvs-repository/Products/AdaptableStorage/serial_ofs
In directory cvs.zope.org:/tmp/cvs-serv24698/serial_ofs
Modified Files:
FolderItems.py IdAttribute.py MetaTypeClassifier.py
Log Message:
More sanitization and documentation:
- Renamed RecordSchema to FieldSchema and made the simpler schema classes
usable. This removed the need to always work with record sets when all
that is needed is a single value.
- Finally successfully abstracted away keychain generation. Now gateways
and serializers don't have to duplicate logic.
- Renamed IEventBase to IMapperEvent, created a derivative IAspectEvent, and
moved some of the methods of IMapperEvent to IAspectEvent.
ISerializationEvent and IDeserializationEvent now derive from IAspectEvent.
- Changed IGateways to expect IMapperEvents instead of a (mapper, keychain)
pair.
=== Products/AdaptableStorage/serial_ofs/FolderItems.py 1.5 => 1.6 ===
--- Products/AdaptableStorage/serial_ofs/FolderItems.py:1.5 Mon Dec 9 10:57:24 2002
+++ Products/AdaptableStorage/serial_ofs/FolderItems.py Mon Dec 9 13:25:28 2002
@@ -20,7 +20,7 @@
from Acquisition import aq_base
from OFS.ObjectManager import ObjectManager
-from serial_public import IAspectSerializer, RecordSchema
+from serial_public import IAspectSerializer, RowSequenceSchema
class FolderItems:
@@ -28,16 +28,13 @@
__implements__ = IAspectSerializer
__used_for__ = ObjectManager
- schema = RecordSchema()
- schema.addColumn('id', 'string', 1)
- schema.addColumn('keychain', 'keychain', 0)
+ schema = RowSequenceSchema()
+ schema.addField('id', 'string', 1)
+ schema.addField('keychain', 'keychain', 0)
def getSchema(self):
return self.schema
- def getSubKeychain(self, keychain, name):
- return keychain[:-1] + ((keychain[-1] + '/%s' % name),)
-
def serialize(self, object, event):
assert isinstance(object, ObjectManager)
state = []
@@ -46,7 +43,7 @@
base = aq_base(subob)
keychain = event.identifyObject(base)
if keychain is None:
- keychain = self.getSubKeychain(event.getKeychain(), id)
+ keychain = event.makeKeychain(id, 0)
event.notifySerializedRef(id, base, 1, keychain)
state.append((id, keychain))
return state
=== Products/AdaptableStorage/serial_ofs/IdAttribute.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/serial_ofs/IdAttribute.py:1.1 Wed Nov 27 13:37:07 2002
+++ Products/AdaptableStorage/serial_ofs/IdAttribute.py Mon Dec 9 13:25:28 2002
@@ -18,37 +18,32 @@
from OFS.SimpleItem import Item_w__name__
-from serial_public import IAspectSerializer, RecordSchema
+from serial_public import IAspectSerializer, FieldSchema
class IdAttribute:
__implements__ = IAspectSerializer
- schema = RecordSchema()
- schema.addColumn('id', 'string')
+ schema = FieldSchema('id', 'string')
def getSchema(self):
return self.schema
- def getAttrName(self, object):
+ def getAttrNameFor(self, object):
if isinstance(object, Item_w__name__):
return '__name__'
else:
return 'id'
def serialize(self, object, event):
- attrname = self.getAttrName(object)
+ attrname = self.getAttrNameFor(object)
id = getattr(object, attrname)
assert id, 'ID of %r is %r' % (object, id)
event.notifySerialized(attrname, id, 1)
- return ((id,),)
+ return id
def deserialize(self, object, event, state):
- attrname = self.getAttrName(object)
- assert attrname
- assert len(state) == 1
- assert len(state[0]) == 1
- id = state[0][0]
- setattr(object, attrname, id)
- event.notifyDeserialized(attrname, id)
+ attrname = self.getAttrNameFor(object)
+ setattr(object, attrname, state)
+ event.notifyDeserialized(attrname, state)
=== Products/AdaptableStorage/serial_ofs/MetaTypeClassifier.py 1.6 => 1.7 ===
--- Products/AdaptableStorage/serial_ofs/MetaTypeClassifier.py:1.6 Mon Dec 9 10:57:24 2002
+++ Products/AdaptableStorage/serial_ofs/MetaTypeClassifier.py Mon Dec 9 13:25:28 2002
@@ -92,20 +92,20 @@
return {'meta_type': mt}, mapper_name
- def classifyState(self, mapper, keychain):
+ def classifyState(self, event):
+ keychain = event.getKeychain()
res = self.key_to_res.get(keychain[-1])
if res is not None:
return res
- info, serial = self.gw.load(mapper, keychain)
- classification = info[0][0]
+ classification, serial = self.gw.load(event)
mt = classification.get('meta_type')
if mt is None:
t = classification.get('node_type')
if t == 'd':
# Directory
mt = self.ext_to_mt.get('<directory>', 'Folder')
- elif t == 'd':
- # Some other kind of filesystem node; assume file
+ elif t == 'f':
+ # File
filename = classification.get('filename')
if filename:
name, ext = os.path.splitext(filename)
@@ -122,6 +122,6 @@
return {'meta_type': mt}, mapper_name
- def store(self, mapper, keychain, classification):
- return self.gw.store(mapper, keychain, ((classification,),))
+ def store(self, event, classification):
+ return self.gw.store(event, classification)