[Zope-CVS] CVS: Products/Ape/lib/apelib/core - mapper.py:1.3.2.1 schemas.py:1.3.2.1 serializers.py:1.2.2.1

Shane Hathaway shane@zope.com
Mon, 7 Jul 2003 18:59:56 -0400


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

Modified Files:
      Tag: ape-newconf-branch
	mapper.py schemas.py serializers.py 
Log Message:
Implemented XML-based configuration.  The filesystem tests pass.

Used an experimental approach for mixing configuration from multiple sources.
Take a look at zope2/apeconf.xml.


=== Products/Ape/lib/apelib/core/mapper.py 1.3 => 1.3.2.1 ===
--- Products/Ape/lib/apelib/core/mapper.py:1.3	Mon May 19 15:32:33 2003
+++ Products/Ape/lib/apelib/core/mapper.py	Mon Jul  7 18:59:21 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.3.2.1 ===
--- Products/Ape/lib/apelib/core/schemas.py:1.3	Sun May 18 00:16:28 2003
+++ Products/Ape/lib/apelib/core/schemas.py	Mon Jul  7 18:59:21 2003
@@ -51,6 +51,10 @@
                 return 1  # Same
         return 0  # Different
 
+    def __ne__(self, other):
+        # XXX shouldn't this be implicit?
+        return not self.__eq__(other)
+
     def __repr__(self):
         return 'FieldSchema(%s, %s, %s)' % (
             repr(self.name), repr(self.type), repr(self.unique))
@@ -88,6 +92,10 @@
                 return 1  # Same
         return 0  # Different
 
+    def __ne__(self, other):
+        # XXX shouldn't this be implicit?
+        return not self.__eq__(other)
+
     def __repr__(self):
         return 'RowSchema(%s)' % repr(self.fields)
 
@@ -111,6 +119,10 @@
                 self.max_rows == other.max_rows):
                 return 1  # Same
         return 0  # Different
+
+    def __ne__(self, other):
+        # XXX shouldn't this be implicit?
+        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.2.2.1 ===
--- Products/Ape/lib/apelib/core/serializers.py:1.2	Mon May 26 15:33:15 2003
+++ Products/Ape/lib/apelib/core/serializers.py	Mon Jul  7 18:59:21 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__()