[Zodb-checkins] CVS: Packages/ZConfig - matcher.py:1.1.2.25 schema.py:1.1.2.28

Fred L. Drake, Jr. fred@zope.com
Thu, 19 Dec 2002 10:19:00 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	matcher.py schema.py 
Log Message:
Basic support for supporting arbitrary keys as <key name="+".../>
(also multikeys).


=== Packages/ZConfig/matcher.py 1.1.2.24 => 1.1.2.25 ===
--- Packages/ZConfig/matcher.py:1.1.2.24	Thu Dec 19 09:12:46 2002
+++ Packages/ZConfig/matcher.py	Thu Dec 19 10:18:29 2002
@@ -55,13 +55,18 @@
 
     def addValue(self, key, value):
         length = len(self.type)
+        arbkey_info = None
         for i in range(length):
             k, ci = self.type[i]
             if k == key:
                 break
+            if ci.name == "+" and not ci.issection():
+                arbkey_info = i, k, ci
         else:
-            raise ZConfig.ConfigurationError(
-                `key` + " is not a known key name")
+            if arbkey_info is None:
+                raise ZConfig.ConfigurationError(
+                    `key` + " is not a known key name")
+            i, k, ci = arbkey_info
         if ci.issection():
             if ci.name:
                 extra = " in %s sections" % `self.type.name`
@@ -70,19 +75,33 @@
             raise ZConfig.ConfigurationError(
                 "%s is not a valid key name%s" % (`key`, extra))
 
+        ismulti = ci.ismulti()
         v = self._values[i]
         if v is None:
-            if ci.ismulti():
+            if k == '+':
+                v = {}
+            elif ismulti:
                 v = []
-                self._values[i] = v
-        elif not ci.ismulti():
-            raise ZConfig.ConfigurationError(
-                `key` + " does not support multiple values")
+            self._values[i] = v
+        elif not ismulti:
+            if k != '+':
+                raise ZConfig.ConfigurationError(
+                    `key` + " does not support multiple values")
         elif len(v) == ci.maxOccurs:
             raise ZConfig.ConfigurationError(
                 "too many values for " + `name`)
 
-        if ci.ismulti():
+        if k == '+':
+            if ismulti:
+                if v.has_key(key):
+                    v[key].append(value)
+                else:
+                    v[key] = [value]
+            else:
+                if v.has_key(key):
+                    raise ZConfig.ConfigurationError("too many")
+                v[key] = value
+        elif ismulti:
             v.append(value)
         else:
             self._values[i] = value
@@ -97,6 +116,9 @@
             key, ci = self.type[i]
             attrnames[i] = ci.attribute or key
             v = values[i]
+            if v is None and ci.name == '+' and not ci.issection():
+                v = {}
+                values[i] = v
             if v is None and ci.minOccurs:
                 default = ci.getdefault()
                 if default is None:
@@ -130,10 +152,18 @@
             if ci.ismulti():
                 if ci.issection():
                     v = [s.__type__.datatype(s) for s in values[i]]
+                elif ci.name == '+':
+                    v = values[i]
+                    for key, val in v.items():
+                        v[key] = [ci.datatype(s) for s in val]
                 else:
                     v = [ci.datatype(s) for s in values[i]]
             elif ci.issection():
                 v = values[i].__type__.datatype(values[i])
+            elif name == '+':
+                v = values[i]
+                for key, val in v.items():
+                    v[key] = ci.datatype(val)
             else:
                 v = ci.datatype(values[i])
             values[i] = v


=== Packages/ZConfig/schema.py 1.1.2.27 => 1.1.2.28 ===
--- Packages/ZConfig/schema.py:1.1.2.27	Thu Dec 19 09:15:07 2002
+++ Packages/ZConfig/schema.py	Thu Dec 19 10:18:29 2002
@@ -254,7 +254,7 @@
             self.error(element + " name may not be omitted or empty")
         datatype = self.get_datatype(attrs, "datatype", "str")
         handler = self.get_handler(attrs)
-        return name, datatype, handler, attribute
+        return name or any, datatype, handler, attribute
 
     def start_key(self, attrs):
         name, datatype, handler, attribute = self.get_key_info(attrs, "key")