[Zodb-checkins] CVS: Packages/ZConfig - loader.py:1.1.2.14

Fred L. Drake, Jr. fred@zope.com
Fri, 13 Dec 2002 16:30:31 -0500


Update of /cvs-repository/Packages/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv11691

Modified Files:
      Tag: zconfig-schema-devel-branch
	loader.py 
Log Message:
Call handlers indirectly via a table.  Especially useful since the
handlers we kept references to were just strings!


=== Packages/ZConfig/loader.py 1.1.2.13 => 1.1.2.14 ===
--- Packages/ZConfig/loader.py:1.1.2.13	Fri Dec 13 15:38:57 2002
+++ Packages/ZConfig/loader.py	Fri Dec 13 16:30:30 2002
@@ -109,7 +109,7 @@
         self.handlers = []
         sm = matcher.SchemaMatcher(self.schema, self.handlers)
         self._parse_resource(sm, resource)
-        return sm.finish(), CompositeHandler(self.handlers)
+        return sm.finish(), CompositeHandler(self.handlers, self.schema)
 
     # parser support API
 
@@ -145,12 +145,28 @@
 
 
 class CompositeHandler:
-    def __init__(self, handlers):
+    def __init__(self, handlers, schema):
         self._handlers = handlers
+        self._convert = schema.registry.get("basic-key")
 
-    def __call__(self):
+    def __call__(self, handlermap):
+        d = {}
+        for name, callback in handlermap.items():
+            n = self._convert(name)
+            if d.has_key(n):
+                raise ZConfig.ConfigurationError(
+                    "handler name not unique when converted to a basic-key: "
+                    + `name`)
+            d[n] = callback
+        L = []
         for handler, value in self._handlers:
-            handler(value)
+            if not d.has_key(handler):
+                L.append(handler)
+        if L:
+            raise ZConfig.ConfigurationError(
+                "undefined handlers: " + ", ".join(L))
+        for handler, value in self._handlers:
+            d[handler](value)
 
     def __len__(self):
         return len(self._handlers)