[Zope-CVS] CVS: Products/Ape/lib/apelib/core - exceptions.py:1.3 gateways.py:1.6 mapper.py:1.4 schemas.py:1.4 serializers.py:1.3

Shane Hathaway shane@zope.com
Wed, 9 Jul 2003 11:40:36 -0400


Update of /cvs-repository/Products/Ape/lib/apelib/core
In directory cvs.zope.org:/tmp/cvs-serv4933/lib/apelib/core

Modified Files:
	exceptions.py gateways.py mapper.py schemas.py serializers.py 
Log Message:
Merged ape-newconf-branch.  Mappers are now configured using XML.


=== Products/Ape/lib/apelib/core/exceptions.py 1.2 => 1.3 ===
--- Products/Ape/lib/apelib/core/exceptions.py:1.2	Tue Apr 29 18:11:50 2003
+++ Products/Ape/lib/apelib/core/exceptions.py	Wed Jul  9 11:39:59 2003
@@ -25,6 +25,12 @@
 class DeserializationError(MappingError):
     """Error during deserialization"""
 
+class StoreError(MappingError):
+    """Error while storing"""
+
+class LoadError(MappingError):
+    """Error while loading"""
+
 class NoStateFoundError(MappingError):
     """No state is there to load"""
 


=== Products/Ape/lib/apelib/core/gateways.py 1.5 => 1.6 ===
--- Products/Ape/lib/apelib/core/gateways.py:1.5	Mon May 19 15:32:33 2003
+++ Products/Ape/lib/apelib/core/gateways.py	Wed Jul  9 11:39:59 2003
@@ -19,7 +19,7 @@
 import time
 
 from interfaces import IGateway
-from exceptions import NoStateFoundError
+import exceptions
 
 
 class CompositeGateway:
@@ -111,7 +111,7 @@
         try:
             return self.data[keychain]
         except KeyError:
-            raise NoStateFoundError(keychain)
+            raise exceptions.NoStateFoundError(keychain)
 
     def store(self, event, data):
         h = time.time()


=== Products/Ape/lib/apelib/core/mapper.py 1.3 => 1.4 ===
--- Products/Ape/lib/apelib/core/mapper.py:1.3	Mon May 19 15:32:33 2003
+++ Products/Ape/lib/apelib/core/mapper.py	Wed Jul  9 11:39:59 2003
@@ -16,6 +16,8 @@
 $Id$
 """
 
+from types import DictType
+
 import interfaces
 from exceptions import ConfigurationError
 
@@ -41,6 +43,9 @@
 
     # IConfigurableMapper implementation
 
+    def setParent(self, p):
+        self._parent = p
+
     def setSerializer(self, s):
         self._serializer = s
 
@@ -80,28 +85,53 @@
             raise ConfigurationError(
                 'Not an IGateway: %s' % repr(g))
         if s.getSchema() != g.getSchema():
+            # Try to show a descriptive error
+            ss = s.getSchema()
+            gs = g.getSchema()
+            msg = None
+            if isinstance(ss, DictType) and isinstance(gs, DictType):
+                for key in ss.keys():
+                    if not gs.has_key(key):
+                        msg = 'No gateway provided for serializer "%s"' % key
+                        break
+                    elif ss[key] != gs[key]:
+                        msg = 'Mismatch on name "%s". %s != %s' % (
+                            key, ss[key], gs[key])
+                        break
+                if msg is None:
+                    for key in gs.keys():
+                        if not ss.has_key(key):
+                            msg = ('No serializer provided for gateway "%s"'
+                                   % key)
+                            break
+            if msg is None:
+                msg = '%s != %s' % (ss, gs)
             raise ConfigurationError(
-                'Mismatched schemas in mapper %s: %s != %s' % (
-                repr(path), s.getSchema(), g.getSchema()))
+                'Mismatched schemas in mapper "%s": %s' % (path, msg))
         if self._parent is None:
             if self._classifier is None:
                 raise ConfigurationError('No root classifier configured')
-            if not interfaces.IClassifier.isImplementedBy(self._classifier):
-                raise ConfigurationError(
-                    'Not an IClassifier: %s' % repr(self._classifier))
             if self._kgen is None:
                 raise ConfigurationError(
                     'No root keychain generator configured')
-            if not interfaces.IKeychainGenerator.isImplementedBy(self._kgen):
-                raise ConfigurationError(
-                    'Not an IKeychainGenerator: %s' % repr(self._kgen))
         else:
             if not interfaces.IMapper.isImplementedBy(self._parent):
                 raise ConfigurationError(
                     'Not an IMapper: %s' % repr(self._parent))
+        if (self._classifier is not None
+            and not interfaces.IClassifier.isImplementedBy(self._classifier)):
+            raise ConfigurationError(
+                'Not an IClassifier: %s' % repr(self._classifier))
+        if (self._kgen is not None
+            and not interfaces.IKeychainGenerator.isImplementedBy(self._kgen)):
+            raise ConfigurationError(
+                'Not an IKeychainGenerator: %s' % repr(self._kgen))
 
         if recursive:
             for n, m in self._sub_mappers.items():
+                if not interfaces.IMapper.isImplementedBy(m):
+                    raise ConfigurationError(
+                        'Not an IMapper: %s' % repr(m))
                 m.checkConfiguration(('%s/%s' % (path, n)), recursive)
 
     # IMapper implementation


=== Products/Ape/lib/apelib/core/schemas.py 1.3 => 1.4 ===
--- Products/Ape/lib/apelib/core/schemas.py:1.3	Sun May 18 00:16:28 2003
+++ Products/Ape/lib/apelib/core/schemas.py	Wed Jul  9 11:39:59 2003
@@ -51,6 +51,9 @@
                 return 1  # Same
         return 0  # Different
 
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
     def __repr__(self):
         return 'FieldSchema(%s, %s, %s)' % (
             repr(self.name), repr(self.type), repr(self.unique))
@@ -88,6 +91,9 @@
                 return 1  # Same
         return 0  # Different
 
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
     def __repr__(self):
         return 'RowSchema(%s)' % repr(self.fields)
 
@@ -111,6 +117,9 @@
                 self.max_rows == other.max_rows):
                 return 1  # Same
         return 0  # Different
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
 
     def __repr__(self):
         return 'RowSequenceSchema(%s, min_rows=%s, max_rows=%s)' % (


=== Products/Ape/lib/apelib/core/serializers.py 1.2 => 1.3 ===
--- Products/Ape/lib/apelib/core/serializers.py:1.2	Mon May 26 15:33:15 2003
+++ Products/Ape/lib/apelib/core/serializers.py	Wed Jul  9 11:39:59 2003
@@ -121,7 +121,15 @@
             # This serializer can't do anything without the classification.
             return None
         cn = classification['class_name']
-        module, name = cn.split(':', 1)
+        if ':' in cn:
+            # Old spelling
+            module, name = cn.split(':', 1)
+        else:
+            pos = cn.rfind('.')
+            if pos < 0:
+                raise ValueError, "class_name must include the module"
+            module = cn[:pos]
+            name = cn[pos + 1:]
         c = class_factory.getClass(module, name)
         return c.__basicnew__()