[Zope3-checkins] CVS: Packages/ZConfig - SchemaParser.py:1.1.4.9 info.py:1.1.2.2 loader.py:1.1.2.4 matcher.py:1.1.2.2

Fred L. Drake, Jr. fred@zope.com
Tue, 10 Dec 2002 15:33:12 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	SchemaParser.py info.py loader.py matcher.py 
Log Message:
Stitch more of the components together.

=== Packages/ZConfig/SchemaParser.py 1.1.4.8 => 1.1.4.9 ===
--- Packages/ZConfig/SchemaParser.py:1.1.4.8	Tue Dec 10 14:17:55 2002
+++ Packages/ZConfig/SchemaParser.py	Tue Dec 10 15:33:11 2002
@@ -100,8 +100,7 @@
             keytype = datatypes.get(attrs["keytype"])
         else:
             keytype = default_key_type
-        self._schema = info.SectionInfo(None, None, 1, 1, handler, None,
-                                        keytype, (), None)
+        self._schema = info.SchemaInfo(handler, keytype)
         self._sections = [self._schema]
         self._stack = [self._schema]
 


=== Packages/ZConfig/info.py 1.1.2.1 => 1.1.2.2 ===
--- Packages/ZConfig/info.py:1.1.2.1	Tue Dec 10 14:17:55 2002
+++ Packages/ZConfig/info.py	Tue Dec 10 15:33:11 2002
@@ -1,6 +1,13 @@
 """Objects that can describe a ZConfig schema."""
 
 
+try:
+    True
+except NameError:
+    True = 1
+    False = 0
+
+
 class UnboundedThing:
     def __lt__(self, other):
         return False
@@ -145,3 +152,15 @@
             return self.names == "*"
         else:
             return name in self.names
+
+
+class SchemaInfo(SectionInfo):
+    def __init__(self, handler, keytype):
+        SectionInfo.__init__(self, None, None, 1, 1, handler, None,
+                             keytype, (), None)
+
+    def allowUnnamed(self):
+        return True
+
+    def isAllowedName(self, name):
+        return False


=== Packages/ZConfig/loader.py 1.1.2.3 => 1.1.2.4 ===
--- Packages/ZConfig/loader.py:1.1.2.3	Tue Dec 10 14:50:03 2002
+++ Packages/ZConfig/loader.py	Tue Dec 10 15:33:11 2002
@@ -74,7 +74,23 @@
         self.schema = schema
 
     def loadResource(self, resource):
-        raise NotImpementedError
+        from ZConfig.matcher import SchemaMatcher
+        sm = SchemaMatcher(self.schema)
+        self._parse_resource(sm, resource)
+        return sm.finish()
+
+    def nestSection(self, section, type, name, delegatename):
+        if delegatename:
+            raise NotImpementedError("section delegation is not yet supported")
+
+    def includeConfiguration(self, section, url):
+        r = self.openResource(url)
+        self._parse_resource(section, r)
+
+    def _parse_resource(self, matcher, resource):
+        from ZConfig.cfgparser import ZConfigParser
+        parser = ZConfigParser(resource, self)
+        parser.parse(matcher)
 
 
 class Resource:


=== Packages/ZConfig/matcher.py 1.1.2.1 => 1.1.2.2 ===
--- Packages/ZConfig/matcher.py:1.1.2.1	Tue Dec 10 14:17:55 2002
+++ Packages/ZConfig/matcher.py	Tue Dec 10 15:33:11 2002
@@ -2,6 +2,7 @@
 
 import ZConfig
 
+
 class SectionMatcher:
     def __init__(self, info, name=None):
         if name is not None:
@@ -32,9 +33,8 @@
             L = []
         if keyinfo.maxOccurs is None:
             L.append(value)
-        elif len(L) = keyinfo.maxOccurs:
-            raise ZConfig.ConfigurationError(
-                "too many values for " + `name`)
+        elif len(L) == keyinfo.maxOccurs:
+            raise ZConfig.ConfigurationError("too many values for " + `name`)
         else:
             L.append(value)
         self._values[key] = L
@@ -53,6 +53,7 @@
                         % (`key`, len(L), ci.minOccurs))
             else:
                 L = ci.getdefault()
+        return self.constuct()
 
     def constuct(self):
         keys = self.info.getchildnames()
@@ -62,7 +63,7 @@
             ci = self.info.getinfo(name)
             keys[i] = ci.attribute
             if self._values.has_key(name):
-                L = self._values[key]
+                L = self._values[name]
             elif ci.ismulti():
                 L = ci.getdefault()
             else:
@@ -79,6 +80,11 @@
         if self.info.handler:
             v = self.info.handler(v)
         return v
+
+
+class SchemaMatcher(SectionMatcher):
+    def __init__(self, info):
+        SectionMatcher.__init__(self, info, None)
 
 
 class SectionValue: