[Zope-Checkins] CVS: Products/AdaptableStorage/mapper_std - NullClassifier.py:1.1 NullKeychainGenerator.py:1.1 FixedClassifier.py:1.2 PathKeychainGenerator.py:1.2 public.py:1.3
Shane Hathaway
shane@zope.com
Mon, 6 Jan 2003 18:18:23 -0500
Update of /cvs-repository/Products/AdaptableStorage/mapper_std
In directory cvs.zope.org:/tmp/cvs-serv1755/mapper_std
Modified Files:
FixedClassifier.py PathKeychainGenerator.py public.py
Added Files:
NullClassifier.py NullKeychainGenerator.py
Log Message:
- Added a user folder mapper for the filesystem. SQL version coming
soon. (SQL tests fail at the moment.)
- Added unwriteData() to FSConnection. I may remove it later, since it turned
out I didn't need it.
- Made configuration errors easier to read.
- Added null implementations of certain interfaces.
- Added a default for FixedClassifier.
=== 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 2003/01/06 23:17:48 shane 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 2003/01/06 23:17:48 shane 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")
=== Products/AdaptableStorage/mapper_std/FixedClassifier.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/mapper_std/FixedClassifier.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/FixedClassifier.py Mon Jan 6 18:17:48 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/PathKeychainGenerator.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/mapper_std/PathKeychainGenerator.py:1.1 Tue Dec 31 16:47:47 2002
+++ Products/AdaptableStorage/mapper_std/PathKeychainGenerator.py Mon Jan 6 18:17:48 2003
@@ -33,3 +33,4 @@
else:
k = '%s/%s' % (k, name)
return parent_keychain[:-1] + (k,)
+
=== Products/AdaptableStorage/mapper_std/public.py 1.2 => 1.3 ===
--- Products/AdaptableStorage/mapper_std/public.py:1.2 Mon Jan 6 10:36:47 2003
+++ Products/AdaptableStorage/mapper_std/public.py Mon Jan 6 18:17:48 2003
@@ -22,6 +22,8 @@
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