[Zope-CVS] CVS: Products/AdaptableStorage/mapper_std - OptionalAspect.py:1.1 FixedPersistentMapping.py:1.2 FullState.py:1.2 IgnoredAttribute.py:1.2 RollCall.py:1.2 StringDataAttribute.py:1.2 public.py:1.2
Shane Hathaway
shane@zope.com
Mon, 6 Jan 2003 10:37:21 -0500
Update of /cvs-repository/Products/AdaptableStorage/mapper_std
In directory cvs.zope.org:/tmp/cvs-serv31552/mapper_std
Modified Files:
FixedPersistentMapping.py FullState.py IgnoredAttribute.py
RollCall.py StringDataAttribute.py public.py
Added Files:
OptionalAspect.py
Log Message:
Added OptionalAspect, a wrapper that disables an aspect if it can't
serialize the object. This involved refactoring the IAspectSerializer
and IObjectSerializer interfaces. Thanks, Christian, for discovering
the need for this.
=== Added File Products/AdaptableStorage/mapper_std/OptionalAspect.py ===
##############################################################################
#
# Copyright (c) 2002, 2003 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.
#
##############################################################################
"""Optional data aspect wrapper
$Id: OptionalAspect.py,v 1.1 2003/01/06 15:36:47 shane Exp $
"""
from mapper_public import IAspectSerializer
class OptionalAspect:
"""
"""
__implements__ = IAspectSerializer
def __init__(self, aspect, default_state=None):
self._aspect = aspect
self._default_state = default_state
def getSchema(self):
return self._aspect.getSchema()
def canSerialize(self, object):
return 1
def serialize(self, object, event):
if self._aspect.canSerialize(object):
return self._aspect.serialize(object, event)
else:
return self._default_state
def deserialize(self, object, event, state):
if self._aspect.canSerialize(object):
self._aspect.deserialize(object, event, state)
else:
if state is not None and state != self._default_state:
raise DeserializationError(
"Optional aspect unable to install state %s into %s" %
(repr(state), repr(object)))
=== Products/AdaptableStorage/mapper_std/FixedPersistentMapping.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/mapper_std/FixedPersistentMapping.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/FixedPersistentMapping.py Mon Jan 6 10:36:47 2003
@@ -17,6 +17,7 @@
"""
from mapper_public import IAspectSerializer
+from Persistence import PersistentMapping
class FixedPersistentMapping:
@@ -31,6 +32,9 @@
def getSchema(self):
return None # No storage
+
+ def canSerialize(self, object):
+ return isinstance(object, PersistentMapping)
def serialize(self, object, event):
names = object.keys()
=== Products/AdaptableStorage/mapper_std/FullState.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/mapper_std/FullState.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/FullState.py Mon Jan 6 10:36:47 2003
@@ -27,6 +27,9 @@
def getSchema(self):
return self.schema
+ def canSerialize(self, object):
+ return 1
+
def serialize(self, object, event):
return object.__getstate__()
=== Products/AdaptableStorage/mapper_std/IgnoredAttribute.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/mapper_std/IgnoredAttribute.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/IgnoredAttribute.py Mon Jan 6 10:36:47 2003
@@ -29,6 +29,9 @@
def getSchema(self):
return None # No storage
+ def canSerialize(self, object):
+ return 1
+
def serialize(self, object, event):
event.ignoreAttribute(self.attrname)
return None
=== Products/AdaptableStorage/mapper_std/RollCall.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/mapper_std/RollCall.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/RollCall.py Mon Jan 6 10:36:47 2003
@@ -30,6 +30,9 @@
def getSchema(self):
return None # No storage
+ def canSerialize(self, object):
+ return 1
+
def serialize(self, object, tracker):
assert IFullSerializationEvent.isImplementedBy(tracker)
attrs = tracker.getSerializedAttributeNames()
=== Products/AdaptableStorage/mapper_std/StringDataAttribute.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/mapper_std/StringDataAttribute.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/StringDataAttribute.py Mon Jan 6 10:36:47 2003
@@ -32,6 +32,9 @@
def getSchema(self):
return self.schema
+ def canSerialize(self, object):
+ return 1
+
def serialize(self, object, event):
attrname = self.attrname
assert attrname
=== Products/AdaptableStorage/mapper_std/public.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/mapper_std/public.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/public.py Mon Jan 6 10:36:47 2003
@@ -22,6 +22,7 @@
from FullState import FullState
from IgnoredAttribute import IgnoredAttribute
from MappingGateway import MappingGateway
+from OptionalAspect import OptionalAspect
from PathKeychainGenerator import PathKeychainGenerator
from RollCall import RollCall
from StringDataAttribute import StringDataAttribute