[Zope3-checkins] CVS: Packages/ZConfig - SchemaInfo.py:1.1.2.4 SchemaParser.py:1.1.4.3 SectionMatcher.py:1.1.2.2

Fred L. Drake, Jr. fred@zope.com
Mon, 9 Dec 2002 12:58:13 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	SchemaInfo.py SchemaParser.py SectionMatcher.py 
Log Message:
More internal checks; better knitting together of sections.

=== Packages/ZConfig/SchemaInfo.py 1.1.2.3 => 1.1.2.4 ===
--- Packages/ZConfig/SchemaInfo.py:1.1.2.3	Mon Dec  9 12:02:25 2002
+++ Packages/ZConfig/SchemaInfo.py	Mon Dec  9 12:58:12 2002
@@ -65,34 +65,39 @@
 
 
 class SectionInfo(KeyInfo):
-    def __init__(self, name, datatype, minOccurs=0, maxOccurs=1,
-                 handler=None, keytype=None, names=None):
+    def __init__(self, name, datatype, minOccurs, maxOccurs, handler,
+                 keytype, names, nametype):
         assert keytype is not None
         self.keytype = keytype
-        if names is None:
-            names = "*",
         self.names = names
-        self._children = []
+        self.nametype = nametype
+        self._children = [] # list of (name, info) pairs
         KeyInfo.__init__(self, name, datatype, minOccurs, maxOccurs,
                          handler)
 
-    def _add_child(self, thing):
-        for c in self._children:
-            if thing.name == c.name:
-                raise ValueError("child name %s already used" % thing.name)
-        self._children.append(thing)
+    def _add_child(self, name, thing):
+        for n, c in self._children:
+            if name == n:
+                raise ValueError("child name %s already used" % name)
+        self._children.append((name, thing))
 
     def addkey(self, keyinfo):
-        self._add_child(keyinfo)
+        self._add_child(keyinfo.name, keyinfo)
+
+    def addsection(self, name, sectinfo):
+        if name == "*" or name == "+":
+            raise NotImplementedError("sections without a specific name"
+                                      " are not yet supported")
+        self._add_child(name, sectinfo)
 
     def getinfo(self, name):
-        for c in self._children:
-            if c.name == name:
+        for n, c in self._children:
+            if n == name:
                 return c
         return None
 
     def getchildnames(self):
-        return [c.name for c in self._children]
+        return [n for (n, c) in self._children]
 
     def issection(self):
         return True


=== Packages/ZConfig/SchemaParser.py 1.1.4.2 => 1.1.4.3 ===
--- Packages/ZConfig/SchemaParser.py:1.1.4.2	Mon Dec  9 12:02:25 2002
+++ Packages/ZConfig/SchemaParser.py	Mon Dec  9 12:58:12 2002
@@ -100,9 +100,18 @@
         self._prefixes.append(self.get_classname(name or ""))
 
     def start_schema(self, attrs):
-        self.start_section(attrs)
-        assert len(self._stack) == 1
-        self._schema = self._stack[0]
+        self._prefixes.append(attrs.get("prefix", ""))
+        handler = attrs.get("handler")
+        if handler:
+            handler = self.get_classname(handler)
+        if attrs.has_key("keytype"):
+            keytype = ZConfig.DataTypes.get(attrs["keytype"])
+        else:
+            keytype = default_key_type
+        self._schema = SectionInfo(None, None, 1, 1, handler,
+                                   keytype, (), None)
+        self._sections = [self._schema]
+        self._stack = [self._schema]
 
     def end_schema(self):
         del self._prefixes[-1]
@@ -120,21 +129,46 @@
             nametype = ZConfig.DataTypes.get(attrs["nametype"])
         else:
             nametype = default_name_type
+        anyname = anyornoname = False
+        names = []
+        name = None
         if attrs.has_key("names"):
-            names = []
             for s in attrs["names"].split("|"):
                 s = s.strip()
-                if s != "*" and s != "+":
+                if not s:
+                    self.doSchemaError("empty section name not allowed")
+                if s == "*":
+                    if anyname:
+                        self.doSchemaError("cannot specify both '+' and '*'"
+                                           " naming for a section")
+                    if anyornoname:
+                        self.doSchemaError("can specify '*' only once")
+                    anyornoname = True
+                elif s == "+":
+                    if anyornoname:
+                        self.doSchemaError("cannot specify both '*' and '+'"
+                                           " naming for a section")
+                    if anyname:
+                        self.doSchemaError("can specify '+' only once")
+                    anyname = True
+                else:
                     s = nametype.convert(s)
                     if s == "*" or s == "+":
                         self.doSchemaError("nametypes may not convert to"
                                            " '*' or '+'")
+                    name = name or s
                 names.append(s)
         else:
-            names = None
+            names = "*",
         maxOccurs, minOccurs, handler = self.get_common_info(attrs)
-        section = SectionInfo(None, None, minOccurs, maxOccurs, handler,
-                              keytype, names)
+        if self._stack:
+            parent = self._stack[-1]
+        else:
+            parent = self._schema
+        section = SectionInfo(name, None, minOccurs, maxOccurs, handler,
+                              keytype, names, nametype)
+        for n in names:
+            parent.addsection(n, section)
         self._stack.append(section)
         self._sections.append(section)
 


=== Packages/ZConfig/SectionMatcher.py 1.1.2.1 => 1.1.2.2 ===
--- Packages/ZConfig/SectionMatcher.py:1.1.2.1	Mon Dec  9 12:02:25 2002
+++ Packages/ZConfig/SectionMatcher.py	Mon Dec  9 12:58:12 2002
@@ -18,11 +18,11 @@
         self.info = info
         self._values = {}
 
-    def addKeyValue(self, key, value):
+    def addValue(self, key, value):
         keyinfo = self.info.getinfo(key)
         if keyinfo.issection():
             if keyinfo.name:
-                extra = " in %s sections" % `keyinfo.name`
+                extra = " in %s sections" % `self.info.name`
             else:
                 extra = ""
             raise ZConfig.ConfigurationError(