[Zope3-checkins] CVS: Packages/ZConfig - loader.py:1.16 matcher.py:1.9

Fred L. Drake, Jr. fred@zope.com
Wed, 19 Feb 2003 15:35:39 -0500


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

Modified Files:
	loader.py matcher.py 
Log Message:
Refactor:
- simplify schema matcher construction
- make a matcher responsible for creating "child" matchers; this reduces
  some of the weird data flow previously done by the loader.


=== Packages/ZConfig/loader.py 1.15 => 1.16 ===
--- Packages/ZConfig/loader.py:1.15	Wed Jan 15 14:17:41 2003
+++ Packages/ZConfig/loader.py	Wed Feb 19 15:35:38 2003
@@ -163,11 +163,9 @@
         self.schema = schema
 
     def loadResource(self, resource):
-        self.handlers = []
-        sm = ZConfig.matcher.SchemaMatcher(self.schema, self.handlers)
+        sm = ZConfig.matcher.SchemaMatcher(self.schema)
         self._parse_resource(sm, resource)
-        result = sm.finish(), CompositeHandler(self.handlers, self.schema)
-        del self.handlers
+        result = sm.finish(), CompositeHandler(sm.handlers, self.schema)
         return result
 
     # config parser support API
@@ -180,13 +178,7 @@
             raise ZConfig.ConfigurationError(
                 "concrete sections cannot match abstract section types;"
                 " found abstract type " + `type`)
-        ci = parent.type.getsectioninfo(type, name)
-        assert not ci.isabstract()
-        if not ci.isAllowedName(name):
-            raise ZConfig.ConfigurationError(
-                "%s is not an allowed name for %s sections"
-                % (`name`, `ci.sectiontype.name`))
-        return ZConfig.matcher.SectionMatcher(ci, t, name, self.handlers)
+        return parent.createChildMatcher(t, name)
 
     def endSection(self, parent, type, name, delegatename, matcher):
         assert not delegatename


=== Packages/ZConfig/matcher.py 1.8 => 1.9 ===
--- Packages/ZConfig/matcher.py:1.8	Fri Feb 14 15:24:08 2003
+++ Packages/ZConfig/matcher.py	Wed Feb 19 15:35:38 2003
@@ -28,7 +28,7 @@
         self._sectionnames = {}
         if handlers is None:
             handlers = []
-        self._handlers = handlers
+        self.handlers = handlers
 
     def __repr__(self):
         clsname = self.__class__.__name__
@@ -115,6 +115,15 @@
         else:
             self._values[i] = value
 
+    def createChildMatcher(self, type, name):
+        ci = self.type.getsectioninfo(type.name, name)
+        assert not ci.isabstract()
+        if not ci.isAllowedName(name):
+            raise ZConfig.ConfigurationError(
+                "%s is not an allowed name for %s sections"
+                % (`name`, `ci.sectiontype.name`))
+        return SectionMatcher(ci, type, name, self.handlers)
+
     def finish(self):
         """Check the constraints of the section and convert to an application
         object."""
@@ -202,7 +211,7 @@
                     v = v.convert(ci.datatype)
             values[i] = v
             if ci.handler is not None:
-                self._handlers.append((ci.handler, v))
+                self.handlers.append((ci.handler, v))
         return self.createValue(attrnames)
 
     def createValue(self, attrnames):
@@ -223,8 +232,8 @@
 
 
 class SchemaMatcher(BaseMatcher):
-    def __init__(self, info, handlers=None):
-        BaseMatcher.__init__(self, info, info, handlers)
+    def __init__(self, schema):
+        BaseMatcher.__init__(self, schema, schema, [])
 
     def finish(self):
         # Since there's no outer container to call datatype()
@@ -232,7 +241,7 @@
         v = BaseMatcher.finish(self)
         v = self.type.datatype(v)
         if self.type.handler is not None:
-            self._handlers.append((self.type.handler, v))
+            self.handlers.append((self.type.handler, v))
         return v