[Zope-CVS] CVS: Products/AdaptableStorage/mapper_std - NullClassifier.py:1.1.2.1 NullKeychainGenerator.py:1.1.2.1 OptionalAspect.py:1.2.2.1 FixedClassifier.py:1.1.2.1 FixedPersistentMapping.py:1.1.2.1 FullState.py:1.1.2.1 IgnoredAttribute.py:1.1.2.1 MappingGateway.py:1.1.2.1 PathKeychainGenerator.py:1.1.2.1 RollCall.py:1.1.2.1 StringDataAttribute.py:1.1.2.1 public.py:1.1.2.1
Christian Zagrodnick
cz@gocept.com
Mon, 13 Jan 2003 14:47:17 -0500
Update of /cvs-repository/Products/AdaptableStorage/mapper_std
In directory cvs.zope.org:/tmp/cvs-serv23278
Modified Files:
Tag: zagy-patches
FixedClassifier.py FixedPersistentMapping.py FullState.py
IgnoredAttribute.py MappingGateway.py PathKeychainGenerator.py
RollCall.py StringDataAttribute.py public.py
Added Files:
Tag: zagy-patches
NullClassifier.py NullKeychainGenerator.py OptionalAspect.py
Log Message:
merging HEAD into zagy-patches branch
=== Added File Products/AdaptableStorage/mapper_std/NullClassifier.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.
#
##############################################################################
"""Null classifier.
$Id: NullClassifier.py,v 1.1.2.1 2003/01/13 19:47:11 zagy Exp $
"""
import os
from mapper_public import IClassifier, SerializationError, DeserializationError
class NullClassifier:
"""A null classifier refuses to classify anything."""
__implements__ = IClassifier
def classifyObject(self, value, keychain):
raise SerializationError("Null classifier")
def classifyState(self, event):
raise DeserializationError("Null classifier")
def store(self, event, classification):
pass
=== Added File Products/AdaptableStorage/mapper_std/NullKeychainGenerator.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.
#
##############################################################################
"""Null keychain generator.
$Id: NullKeychainGenerator.py,v 1.1.2.1 2003/01/13 19:47:11 zagy Exp $
"""
import os
from mapper_public import IKeychainGenerator, MappingError
class NullKeychainGenerator:
"""A null keychain generator refuses to generate any keychains."""
__implements__ = IKeychainGenerator
def makeKeychain(self, event, name, stored):
raise MappingError("Null keychain generator")
=== 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.2.2.1 2003/01/13 19:47:11 zagy Exp $
"""
from mapper_public import IAspectSerializer
class OptionalAspect:
"""Aspect wrapper. Disables the aspect if it can't serialize the object.
"""
__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/FixedClassifier.py 1.1 => 1.1.2.1 ===
--- Products/AdaptableStorage/mapper_std/FixedClassifier.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/FixedClassifier.py Mon Jan 13 14:47:11 2003
@@ -18,26 +18,38 @@
import os
-from mapper_public import IClassifier, DeserializationError
+from mapper_public import IClassifier
class FixedClassifier:
+ """Classifies objects based purely on the keychain."""
__implements__ = IClassifier
def __init__(self):
- self.key_to_res = {}
+ self._key_to_res = {}
+ self._default_res = None
def register(self, key, mapper_name):
- self.key_to_res[key] = ({}, mapper_name)
+ self._key_to_res[key] = ({}, mapper_name)
+
+ def registerDefault(self, mapper_name):
+ self._default_res = ({}, mapper_name)
+
+ def getResult(self, k):
+ res = self._key_to_res.get(k)
+ if res is None:
+ res = self._default_res
+ if res is None:
+ raise KeyError("Key %s is not known to fixed classifier %s" %
+ (repr(k), repr(self)))
+ return res
def classifyObject(self, value, keychain):
- k = keychain[-1]
- return self.key_to_res[k]
+ return self.getResult(keychain[-1])
def classifyState(self, event):
- k = event.getKeychain()[-1]
- return self.key_to_res[k]
+ return self.getResult(event.getKeychain()[-1])
def store(self, event, classification):
pass
=== Products/AdaptableStorage/mapper_std/FixedPersistentMapping.py 1.1 => 1.1.2.1 ===
--- Products/AdaptableStorage/mapper_std/FixedPersistentMapping.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/FixedPersistentMapping.py Mon Jan 13 14:47:11 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.1.2.1 ===
--- Products/AdaptableStorage/mapper_std/FullState.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/FullState.py Mon Jan 13 14:47:11 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.1.2.1 ===
--- Products/AdaptableStorage/mapper_std/IgnoredAttribute.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/IgnoredAttribute.py Mon Jan 13 14:47:11 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/MappingGateway.py 1.1 => 1.1.2.1 ===
--- Products/AdaptableStorage/mapper_std/MappingGateway.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/MappingGateway.py Mon Jan 13 14:47:11 2003
@@ -18,7 +18,7 @@
import time
-from mapper_public import IGateway
+from mapper_public import IGateway, NoStateFoundError
class MappingGateway:
"""Stores data in a mapping."""
@@ -34,7 +34,11 @@
def load(self, event):
# Returns (data, serial)
- return self.data[event.getKeychain()]
+ keychain = event.getKeychain()
+ try:
+ return self.data[keychain]
+ except KeyError:
+ raise NoStateFoundError(keychain)
def store(self, event, data):
serial = time.time()
=== Products/AdaptableStorage/mapper_std/PathKeychainGenerator.py 1.1 => 1.1.2.1 ===
--- Products/AdaptableStorage/mapper_std/PathKeychainGenerator.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/PathKeychainGenerator.py Mon Jan 13 14:47:11 2003
@@ -33,3 +33,4 @@
else:
k = '%s/%s' % (k, name)
return parent_keychain[:-1] + (k,)
+
=== Products/AdaptableStorage/mapper_std/RollCall.py 1.1 => 1.1.2.1 ===
--- Products/AdaptableStorage/mapper_std/RollCall.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/RollCall.py Mon Jan 13 14:47:11 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.1.2.1 ===
--- Products/AdaptableStorage/mapper_std/StringDataAttribute.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/StringDataAttribute.py Mon Jan 13 14:47:11 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.1.2.1 ===
--- Products/AdaptableStorage/mapper_std/public.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/public.py Mon Jan 13 14:47:11 2003
@@ -22,6 +22,9 @@
from FullState import FullState
from IgnoredAttribute import IgnoredAttribute
from MappingGateway import MappingGateway
+from NullClassifier import NullClassifier
+from NullKeychainGenerator import NullKeychainGenerator
+from OptionalAspect import OptionalAspect
from PathKeychainGenerator import PathKeychainGenerator
from RollCall import RollCall
from StringDataAttribute import StringDataAttribute