[Zope-CVS] CVS: Products/AdaptableStorage/serial_std - PathKeychainGenerator.py:1.1 FixedClassifier.py:1.3 FixedPersistentMapping.py:1.5 FullState.py:1.2 IgnoredAttribute.py:1.2 MappingGateway.py:1.3 RemainingState.py:1.3 StringDataAttribute.py:1.2 public.py:1.5
Shane Hathaway
shane@zope.com
Mon, 9 Dec 2002 13:26:00 -0500
Update of /cvs-repository/Products/AdaptableStorage/serial_std
In directory cvs.zope.org:/tmp/cvs-serv24698/serial_std
Modified Files:
FixedClassifier.py FixedPersistentMapping.py FullState.py
IgnoredAttribute.py MappingGateway.py RemainingState.py
StringDataAttribute.py public.py
Added Files:
PathKeychainGenerator.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.
=== Added File Products/AdaptableStorage/serial_std/PathKeychainGenerator.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Path-based keychain generator
$Id: PathKeychainGenerator.py,v 1.1 2002/12/09 18:25:29 shane Exp $
"""
from serial_public import IKeychainGenerator
class PathKeychainGenerator:
"""Path-based keychain generator
"""
__implements__ = IKeychainGenerator
def makeKeychain(self, event, name, stored):
if name.startswith('.') or '/' in name:
raise ValueError, '%s is not a legal name' % name
parent_keychain = event.getKeychain()
k = parent_keychain[-1]
if k.endswith('/'):
k = k + name
else:
k = '%s/%s' % (k, name)
return parent_keychain[:-1] + (k,)
=== Products/AdaptableStorage/serial_std/FixedClassifier.py 1.2 => 1.3 ===
--- Products/AdaptableStorage/serial_std/FixedClassifier.py:1.2 Mon Dec 9 10:57:24 2002
+++ Products/AdaptableStorage/serial_std/FixedClassifier.py Mon Dec 9 13:25:29 2002
@@ -35,10 +35,10 @@
k = keychain[-1]
return self.key_to_res[k]
- def classifyState(self, mapper, keychain):
- k = keychain[-1]
+ def classifyState(self, event):
+ k = event.getKeychain()[-1]
return self.key_to_res[k]
- def store(self, mapper, keychain, classification):
+ def store(self, event, classification):
pass
=== Products/AdaptableStorage/serial_std/FixedPersistentMapping.py 1.4 => 1.5 ===
--- Products/AdaptableStorage/serial_std/FixedPersistentMapping.py:1.4 Sat Dec 7 00:59:14 2002
+++ Products/AdaptableStorage/serial_std/FixedPersistentMapping.py Mon Dec 9 13:25:29 2002
@@ -16,7 +16,7 @@
$Id$
"""
-from serial_public import IAspectSerializer, RecordSchema
+from serial_public import IAspectSerializer
class FixedPersistentMapping:
=== Products/AdaptableStorage/serial_std/FullState.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/serial_std/FullState.py:1.1 Wed Nov 27 13:37:07 2002
+++ Products/AdaptableStorage/serial_std/FullState.py Mon Dec 9 13:25:29 2002
@@ -16,23 +16,20 @@
$Id$
"""
-from serial_public import IAspectSerializer, RecordSchema
+from serial_public import IAspectSerializer, FieldSchema
class FullState:
__implements__ = IAspectSerializer
- schema = RecordSchema()
- schema.addColumn('data', 'object')
+ schema = FieldSchema('data', 'object')
def getSchema(self):
return self.schema
def serialize(self, object, event):
- return ((object.__getstate__(),),)
+ return object.__getstate__()
def deserialize(self, object, event, state):
- assert len(state) == 1
- assert len(state[0]) == 1
- object.__setstate__(state[0][0])
+ object.__setstate__(state)
=== Products/AdaptableStorage/serial_std/IgnoredAttribute.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/serial_std/IgnoredAttribute.py:1.1 Wed Nov 27 13:37:07 2002
+++ Products/AdaptableStorage/serial_std/IgnoredAttribute.py Mon Dec 9 13:25:29 2002
@@ -17,7 +17,7 @@
"""
-from serial_public import IAspectSerializer, RecordSchema
+from serial_public import IAspectSerializer
class IgnoredAttribute:
=== Products/AdaptableStorage/serial_std/MappingGateway.py 1.2 => 1.3 ===
--- Products/AdaptableStorage/serial_std/MappingGateway.py:1.2 Fri Dec 6 17:06:51 2002
+++ Products/AdaptableStorage/serial_std/MappingGateway.py Mon Dec 9 13:25:29 2002
@@ -32,11 +32,11 @@
def getSchema(self):
return self.schema
- def load(self, object_mapper, keychain):
+ def load(self, event):
# Returns (data, serial)
- return self.data[keychain]
+ return self.data[event.getKeychain()]
- def store(self, object_mapper, keychain, data):
+ def store(self, event, data):
serial = time.time()
- self.data[keychain] = (data, serial)
+ self.data[event.getKeychain()] = (data, serial)
return serial
=== Products/AdaptableStorage/serial_std/RemainingState.py 1.2 => 1.3 ===
--- Products/AdaptableStorage/serial_std/RemainingState.py:1.2 Wed Dec 4 23:18:08 2002
+++ Products/AdaptableStorage/serial_std/RemainingState.py Mon Dec 9 13:25:29 2002
@@ -21,15 +21,14 @@
from types import DictType
from serial_public import \
- IAspectSerializer, RecordSchema, \
+ IAspectSerializer, FieldSchema, \
IFullSerializationEvent, IFullDeserializationEvent
class RemainingState:
__implements__ = IAspectSerializer
- schema = RecordSchema()
- schema.addColumn('data', 'string')
+ schema = FieldSchema('data', 'string')
def getSchema(self):
return self.schema
@@ -46,29 +45,22 @@
del state[attrname]
if not state:
# No data needs to be stored
- return None
+ return ''
outfile = StringIO()
p = Pickler(outfile)
p.persistent_id = event.getInternalReference
p.dump(state)
s = outfile.getvalue()
- return ((s,),)
+ return s
def deserialize(self, object, event, state):
assert IFullDeserializationEvent.isImplementedBy(event)
- if not state:
- return
- assert len(state) == 1
- assert len(state[0]) == 1
- data = state[0][0]
- if not data:
- return
-
- infile = StringIO(data)
- u = Unpickler(infile)
- u.persistent_load = event.loadInternalReference
- state = u.load()
- object.__dict__.update(state)
+ if state:
+ infile = StringIO(state)
+ u = Unpickler(infile)
+ u.persistent_load = event.loadInternalReference
+ s = u.load()
+ object.__dict__.update(s)
=== Products/AdaptableStorage/serial_std/StringDataAttribute.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/serial_std/StringDataAttribute.py:1.1 Wed Nov 27 13:37:07 2002
+++ Products/AdaptableStorage/serial_std/StringDataAttribute.py Mon Dec 9 13:25:29 2002
@@ -18,14 +18,13 @@
from types import StringType
-from serial_public import IAspectSerializer, RecordSchema
+from serial_public import IAspectSerializer, FieldSchema
class StringDataAttribute:
__implements__ = IAspectSerializer
- schema = RecordSchema()
- schema.addColumn('data', 'string')
+ schema = FieldSchema('data', 'string')
def __init__(self, attrname):
self.attrname = attrname
@@ -39,15 +38,12 @@
v = getattr(object, attrname)
assert isinstance(v, StringType)
event.notifySerialized(attrname, v, 1)
- return ((v,),)
+ return v
def deserialize(self, object, event, state):
attrname = self.attrname
assert attrname
- assert len(state) == 1
- assert len(state[0]) == 1
- v = state[0][0]
- assert isinstance(v, StringType)
- setattr(object, attrname, v)
- event.notifyDeserialized(attrname, v)
+ assert isinstance(state, StringType)
+ setattr(object, attrname, state)
+ event.notifyDeserialized(attrname, state)
=== Products/AdaptableStorage/serial_std/public.py 1.4 => 1.5 ===
--- Products/AdaptableStorage/serial_std/public.py:1.4 Sat Dec 7 00:59:14 2002
+++ Products/AdaptableStorage/serial_std/public.py Mon Dec 9 13:25:29 2002
@@ -21,6 +21,7 @@
from FullState import FullState
from IgnoredAttribute import IgnoredAttribute
from MappingGateway import MappingGateway
+from PathKeychainGenerator import PathKeychainGenerator
from RemainingState import RemainingState
from RollCall import RollCall
from StringDataAttribute import StringDataAttribute