[Zope-CVS] CVS: Products/AdaptableStorage/gateway_fs - FSAutoId.py:1.3 FSClassificationSection.py:1.5 FSDirectoryItems.py:1.6 FSFileData.py:1.3 FSSectionData.py:1.4
Shane Hathaway
shane@zope.com
Mon, 9 Dec 2002 13:25:59 -0500
Update of /cvs-repository/Products/AdaptableStorage/gateway_fs
In directory cvs.zope.org:/tmp/cvs-serv24698/gateway_fs
Modified Files:
FSAutoId.py FSClassificationSection.py FSDirectoryItems.py
FSFileData.py FSSectionData.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/gateway_fs/FSAutoId.py 1.2 => 1.3 ===
--- Products/AdaptableStorage/gateway_fs/FSAutoId.py:1.2 Fri Dec 6 17:06:50 2002
+++ Products/AdaptableStorage/gateway_fs/FSAutoId.py Mon Dec 9 13:25:27 2002
@@ -16,31 +16,31 @@
$Id$
"""
-from serial_public import IGateway, RecordSchema
+from serial_public import IGateway, FieldSchema
class FSAutoId:
__implements__ = IGateway
- schema = RecordSchema()
- schema.addColumn('id', 'string')
+ schema = FieldSchema('id', 'string')
def getSchema(self):
return self.schema
- def getIdFrom(self, keychain):
- path = keychain[-1]
+ def getIdFrom(self, event):
+ path = event.getKeychain()[-1]
pos = path.rfind('/')
if pos >= 0:
return path[pos + 1:]
else:
return path
- def load(self, object_mapper, keychain):
- id = self.getIdFrom(keychain)
- return ((id,),), id
-
- def store(self, object_mapper, keychain, state):
- id = self.getIdFrom(keychain)
- assert state[0][0] == id, 'Mismatched file ID'
+ def load(self, event):
+ id = self.getIdFrom(event)
+ return id, id
+
+ def store(self, event, state):
+ id = self.getIdFrom(event)
+ assert state == id, 'Mismatched file ID'
return id
+
=== Products/AdaptableStorage/gateway_fs/FSClassificationSection.py 1.4 => 1.5 ===
--- Products/AdaptableStorage/gateway_fs/FSClassificationSection.py:1.4 Sat Dec 7 00:59:12 2002
+++ Products/AdaptableStorage/gateway_fs/FSClassificationSection.py Mon Dec 9 13:25:27 2002
@@ -16,15 +16,14 @@
$Id$
"""
-from serial_public import IGateway, RecordSchema
+from serial_public import IGateway, FieldSchema
class FSClassificationSection:
__implements__ = IGateway
- schema = RecordSchema()
- schema.addColumn('classification', 'classification')
+ schema = FieldSchema('classification', 'classification')
def __init__(self, fs_conn):
self.fs_conn = fs_conn
@@ -32,17 +31,18 @@
def getSchema(self):
return self.schema
- def getIdFrom(self, keychain):
- path = keychain[-1]
+ def getIdFrom(self, event):
+ path = event.getKeychain()[-1]
pos = path.rfind('/')
if pos >= 0:
return path[pos + 1:]
else:
return path
- def load(self, object_mapper, keychain):
+ def load(self, event):
c = self.fs_conn
- text = c.readSection(keychain[-1], 'classification', '')
+ p = event.getKeychain()[-1]
+ text = c.readSection(p, 'classification', '')
classification = {}
if text:
lines = text.split('\n')
@@ -50,12 +50,12 @@
if '=' in line:
k, v = line.split('=', 1)
classification[k.strip()] = v.strip()
- classification['node_type'] = c.readNodeType(keychain[-1])
- classification['filename'] = self.getIdFrom(keychain)
- return ((classification,),), text.strip()
+ classification['node_type'] = c.readNodeType(p)
+ classification['filename'] = self.getIdFrom(event)
+ return classification, text.strip()
- def store(self, object_mapper, keychain, state):
- classification = state[0][0]
+ def store(self, event, state):
+ classification = state
items = classification.items()
items.sort()
text = []
@@ -63,5 +63,6 @@
text.append('%s=%s' % (k, v))
text = '\n'.join(text)
# Write it only if the rest of the subobject is also stored
- self.fs_conn.writeSection(keychain[-1], 'classification', text)
+ p = event.getKeychain()[-1]
+ self.fs_conn.writeSection(p, 'classification', text)
return text.strip()
=== Products/AdaptableStorage/gateway_fs/FSDirectoryItems.py 1.5 => 1.6 ===
--- Products/AdaptableStorage/gateway_fs/FSDirectoryItems.py:1.5 Sat Dec 7 00:59:12 2002
+++ Products/AdaptableStorage/gateway_fs/FSDirectoryItems.py Mon Dec 9 13:25:27 2002
@@ -17,7 +17,7 @@
"""
-from serial_public import IGateway, RecordSchema
+from serial_public import IGateway, RowSequenceSchema
from FSConnection import WRITE_CONDITIONAL
@@ -26,9 +26,9 @@
__implements__ = IGateway
- 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 __init__(self, fs_conn):
self.fs_conn = fs_conn
@@ -36,32 +36,31 @@
def getSchema(self):
return self.schema
- def getSubKeychain(self, keychain, name):
- return keychain[:-1] + ((keychain[-1] + '/%s' % name),)
-
- def load(self, object_mapper, keychain):
+ def load(self, event):
+ p = event.getKeychain()[-1]
c = self.fs_conn
- assert c.readNodeType(keychain[-1]) == 'd'
- names = c.readData(keychain[-1])
+ assert c.readNodeType(p) == 'd'
+ names = c.readData(p)
names.sort()
res = []
for name in names:
- subkeychain = self.getSubKeychain(keychain, name)
- res.append((name, subkeychain))
+ subk = event.makeKeychain(name, 0)
+ res.append((name, subk))
res.sort()
res = tuple(res)
return res, res
- def store(self, object_mapper, keychain, state):
+ def store(self, event, state):
+ p = event.getKeychain()[-1]
c = self.fs_conn
- c.writeNodeType(keychain[-1], 'd')
+ c.writeNodeType(p, 'd')
names = []
state = list(state)
state.sort()
for name, subkeychain in state:
names.append(name)
- assert subkeychain == self.getSubKeychain(keychain, name)
- c.writeData(keychain[-1], names)
+ assert subkeychain == event.makeKeychain(name, 0)
+ c.writeData(p, names)
return tuple(state)
=== Products/AdaptableStorage/gateway_fs/FSFileData.py 1.2 => 1.3 ===
--- Products/AdaptableStorage/gateway_fs/FSFileData.py:1.2 Fri Dec 6 17:06:50 2002
+++ Products/AdaptableStorage/gateway_fs/FSFileData.py Mon Dec 9 13:25:27 2002
@@ -16,14 +16,15 @@
$Id$
"""
-from serial_public import IGateway, RecordSchema
+from types import StringType
+
+from serial_public import IGateway, FieldSchema
class FSFileData:
__implements__ = IGateway
- schema = RecordSchema()
- schema.addColumn('data', 'string')
+ schema = FieldSchema('data', 'string')
def __init__(self, fs_conn):
self.fs_conn = fs_conn
@@ -31,18 +32,19 @@
def getSchema(self):
return self.schema
- def load(self, object_mapper, keychain):
+ def load(self, event):
c = self.fs_conn
- assert c.readNodeType(keychain[-1]) == 'f'
- data = c.readData(keychain[-1], '')
- state = ((data,),)
+ p = event.getKeychain()[-1]
+ assert c.readNodeType(p) == 'f'
+ state = c.readData(p, '')
return state, state
- def store(self, object_mapper, keychain, state):
+ def store(self, event, state):
+ if not isinstance(state, StringType):
+ raise RuntimeError('Not a string: %s' % repr(state))
c = self.fs_conn
- assert len(state) == 1
- assert len(state[0]) == 1
- c.writeNodeType(keychain[-1], 'f')
- c.writeData(keychain[-1], state[0][0])
+ p = event.getKeychain()[-1]
+ c.writeNodeType(p, 'f')
+ c.writeData(p, state)
return state
=== Products/AdaptableStorage/gateway_fs/FSSectionData.py 1.3 => 1.4 ===
--- Products/AdaptableStorage/gateway_fs/FSSectionData.py:1.3 Fri Dec 6 17:06:50 2002
+++ Products/AdaptableStorage/gateway_fs/FSSectionData.py Mon Dec 9 13:25:27 2002
@@ -16,14 +16,15 @@
$Id$
"""
-from serial_public import IGateway, RecordSchema
+from types import StringType
+
+from serial_public import IGateway, FieldSchema
class FSSectionData:
__implements__ = IGateway
- schema = RecordSchema()
- schema.addColumn('data', 'string')
+ schema = FieldSchema('data', 'string')
def __init__(self, fs_conn, section):
self.fs_conn = fs_conn
@@ -32,18 +33,17 @@
def getSchema(self):
return self.schema
- def load(self, object_mapper, keychain):
- c = self.fs_conn
- data = c.readSection(keychain[-1], self.section, '')
- state = ((data,),)
+ def load(self, event):
+ p = event.getKeychain()[-1]
+ state = self.fs_conn.readSection(p, self.section, '').strip()
return state, state
- def store(self, object_mapper, keychain, state):
- if not state:
- return ''
- c = self.fs_conn
- assert len(state) == 1
- assert len(state[0]) == 1
- c.writeSection(keychain[-1], self.section, state[0][0])
+ def store(self, event, state):
+ if not isinstance(state, StringType):
+ raise RuntimeError('Not a string: %s' % repr(state))
+ state = state.strip()
+ if state:
+ p = event.getKeychain()[-1]
+ self.fs_conn.writeSection(p, self.section, state)
return state