[Zope-Checkins] CVS: Packages/ZConfig - info.py:1.1.2.3 loader.py:1.1.2.7 matcher.py:1.1.2.4 schema.py:1.1.2.2

Fred L. Drake, Jr. fred@zope.com
Tue, 10 Dec 2002 18:25:02 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	info.py loader.py matcher.py schema.py 
Log Message:
Checkpoint: nested sections still do not get inserted properly, but this
gets checked in to protect against network/power failures while I am away
from the office for a day.


=== Packages/ZConfig/info.py 1.1.2.2 => 1.1.2.3 ===
--- Packages/ZConfig/info.py:1.1.2.2	Tue Dec 10 15:33:11 2002
+++ Packages/ZConfig/info.py	Tue Dec 10 18:25:01 2002
@@ -1,5 +1,7 @@
 """Objects that can describe a ZConfig schema."""
 
+import ZConfig
+
 
 try:
     True
@@ -99,14 +101,16 @@
 
 
 class SectionInfo(KeyInfo):
-    def __init__(self, name, datatype, minOccurs, maxOccurs, handler,
+    def __init__(self, typename, datatype, minOccurs, maxOccurs, handler,
                  attribute, keytype, names, nametype):
         assert keytype is not None
+        self.typename = typename
         self.keytype = keytype
         self.names = names   # '*', '+', or [name1, ...]
         self.nametype = nametype
         self._children = []  # [(name, info), ...]
-        KeyInfo.__init__(self, name, datatype, minOccurs, maxOccurs,
+        self._attrmap = {}   # {attribute: index, ...}
+        KeyInfo.__init__(self, None, datatype, minOccurs, maxOccurs,
                          handler, attribute)
 
     def _add_child(self, name, thing):
@@ -127,15 +131,41 @@
 
     def getinfo(self, name):
         if not name:
-            return None
+            raise ZConfig.ConfigurationError(
+                "cannot match a key without a name")
         for n, info in self._children:
             if n == name:
                 return info
-        else:
-            return None
+        raise ZConfig.ConfigurationError("no key matching " + `name`)
 
     def getchildnames(self):
         return [n for (n,info) in self._children]
+
+    def getsectionindex(self, type, name):
+        index = -1
+        for n, info in self._children:
+            index += 1
+            if n:
+                if n == name:
+                    if not info.issection():
+                        raise ZConfig.ConfigurationError(
+                            "section name %s already in use for key"
+                            % str(n))
+                    if not info.typename == type:
+                        raise ZConfig.ConfigurationError(
+                            "name %s must be used for a %s section"
+                            % (`name`, `info.typename`))
+                    return index
+            elif info.typename == type:
+                if not (name or info.allowUnnamed()):
+                    raise ZConfig.ConfigurationError(
+                        `type` + " sections must be named")
+                return index
+        raise ZConfig.ConfigurationError("no matching section defined")
+
+    def getsectioninfo(self, type, name):
+        i = self.getsectionindex(type, name)
+        return self._children[i][1]
 
     def issection(self):
         return True


=== Packages/ZConfig/loader.py 1.1.2.6 => 1.1.2.7 ===
--- Packages/ZConfig/loader.py:1.1.2.6	Tue Dec 10 16:50:52 2002
+++ Packages/ZConfig/loader.py	Tue Dec 10 18:25:01 2002
@@ -7,6 +7,8 @@
 
 import ZConfig
 
+from ZConfig import matcher
+
 try:
     True
 except NameError:
@@ -74,8 +76,7 @@
         self.schema = schema
 
     def loadResource(self, resource):
-        from ZConfig.matcher import SchemaMatcher
-        sm = SchemaMatcher(self.schema)
+        sm = matcher.SchemaMatcher(self.schema)
         self._parse_resource(sm, resource)
         return sm.finish()
 
@@ -84,10 +85,13 @@
     def startSection(self, parent, type, name, delegatename):
         if delegatename:
             raise NotImpementedError("section delegation is not yet supported")
+        ci = parent.info.getsectioninfo(type, name)
+        return matcher.SectionMatcher(ci, name)
 
     def endSection(self, parent, type, name, delegatename, matcher):
         assert not delegatename
         sectvalue = matcher.finish()
+        parent.addSection(type, name, sectvalue)
 
     def includeConfiguration(self, section, url):
         r = self.openResource(url)


=== Packages/ZConfig/matcher.py 1.1.2.3 => 1.1.2.4 ===
--- Packages/ZConfig/matcher.py:1.1.2.3	Tue Dec 10 15:59:12 2002
+++ Packages/ZConfig/matcher.py	Tue Dec 10 18:25:01 2002
@@ -21,6 +21,10 @@
         self.info = info
         self._values = {}
 
+    def addSection(self, type, name, sectvalue):
+        i = self.info.getsectionindex(type, name)
+        raise NotImpementedError("still working on this...")
+
     def addValue(self, key, value):
         keyinfo = self.info.getinfo(key)
         if keyinfo.issection():


=== Packages/ZConfig/schema.py 1.1.2.1 => 1.1.2.2 ===
--- Packages/ZConfig/schema.py:1.1.2.1	Tue Dec 10 16:50:07 2002
+++ Packages/ZConfig/schema.py	Tue Dec 10 18:25:01 2002
@@ -114,7 +114,7 @@
         self.push_prefix(attrs)
         type = attrs.get("type")
         if not type:
-            self.doSchemaError("section does not specify type")
+            self.doSchemaError("section must specify type")
         if attrs.has_key("keytype"):
             keytype = datatypes.get(attrs["keytype"])
         else:
@@ -129,7 +129,7 @@
             parent = self._stack[-1]
         else:
             parent = self._schema
-        section = info.SectionInfo(None, None, minOccurs, maxOccurs, handler,
+        section = info.SectionInfo(type, None, minOccurs, maxOccurs, handler,
                                    attribute, keytype, names, nametype)
         if any:
             parent.addsection(None, section)