[Zope3-checkins] CVS: StandaloneZConfig/ZConfig - info.py:1.23 schema.py:1.35

Fred L. Drake, Jr. fred at zope.com
Wed Apr 14 23:49:13 EDT 2004


Update of /cvs-repository/StandaloneZConfig/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv24282

Modified Files:
	info.py schema.py 
Log Message:
desparately try to clean up someo of the internal logic so fixing really
obscure bugs is easier


=== StandaloneZConfig/ZConfig/info.py 1.22 => 1.23 ===
--- StandaloneZConfig/ZConfig/info.py:1.22	Mon Apr 12 11:27:00 2004
+++ StandaloneZConfig/ZConfig/info.py	Wed Apr 14 23:49:12 2004
@@ -99,14 +99,14 @@
         return False
 
 
-class KeyInfo(BaseInfo):
+class BaseKeyInfo(BaseInfo):
+
     def __init__(self, name, datatype, minOccurs, maxOccurs, handler,
                  attribute):
         assert minOccurs is not None
         BaseInfo.__init__(self, name, datatype, minOccurs, maxOccurs,
                           handler, attribute)
         self._finished = False
-        self._default = None
 
     def finish(self):
         if self._finished:
@@ -126,50 +126,63 @@
             raise ZConfig.SchemaError(
                 "unexpected key for default value")
 
-        value = ValueInfo(value, position)
-        if self.maxOccurs > 1:
-            if self.name == "+":
-                # This is a keyed value, not a simple value:
-                if self._default is None:
-                    self._default = {key: [value]}
-                else:
-                    if key in self._default:
-                        self._default[key].append(value)
-                    else:
-                        self._default[key] = [value]
-            elif self._default is None:
-                self._default = [value]
-            else:
-                self._default.append(value)
-        elif self.name == "+":
-            if self._default is None:
-                self._default = {key: value}
-            else:
-                if self._default.has_key(key):
-                    raise ZConfig.SchemaError(
-                        "duplicate default value for key %s" % `key`)
-                self._default[key] = value
+        self.add_valueinfo(ValueInfo(value, position), key)
+
+
+class KeyInfo(BaseKeyInfo):
+
+    _default = None
+
+    def __init__(self, name, datatype, minOccurs, handler, attribute):
+        BaseKeyInfo.__init__(self, name, datatype, minOccurs, 1,
+                             handler, attribute)
+        if self.name == "+":
+            self._default = {}
+
+    def add_valueinfo(self, vi, key):
+        if self.name == "+":
+            if self._default.has_key(key):
+                # not ideal: we're presenting the unconverted
+                # version of the key
+                raise ZConfig.SchemaError(
+                    "duplicate default value for key %s" % `key`)
+            self._default[key] = vi
         elif self._default is not None:
             raise ZConfig.SchemaError(
                 "cannot set more than one default to key with maxOccurs == 1")
         else:
-            self._default = value
+            self._default = vi
 
     def getdefault(self):
-        if not self._finished:
-            raise ZConfig.SchemaError(
-                "cannot get default value of key before KeyInfo"
-                " has been completely initialized")
-        if self._default is None:
-            if self.name == "+":
-                return {}
-            elif self.maxOccurs > 1:
-                return []
+        # Use copy.copy() to make sure we don't allow polution of
+        # our internal data without having to worry about both the
+        # list and dictionary cases:
+        return copy.copy(self._default)
+
+
+class MultiKeyInfo(BaseKeyInfo):
+
+    def __init__(self, name, datatype, minOccurs, maxOccurs, handler,
+                 attribute):
+        BaseKeyInfo.__init__(self, name, datatype, minOccurs, maxOccurs,
+                             handler, attribute)
+        if self.name == "+":
+            self._default = {}
         else:
-            # Use copy.copy() to make sure we don't allow polution of
-            # our internal data without having to worry about both the
-            # list and dictionary cases:
-            return copy.copy(self._default)
+            self._default = []
+
+    def add_valueinfo(self, vi, key):
+        if self.name == "+":
+            # This is a keyed value, not a simple value:
+            if key in self._default:
+                self._default[key].append(vi)
+            else:
+                self._default[key] = [vi]
+        else:
+            self._default.append(vi)
+
+    def getdefault(self):
+        return copy.copy(self._default)
 
 
 class SectionInfo(BaseInfo):


=== StandaloneZConfig/ZConfig/schema.py 1.34 => 1.35 ===
--- StandaloneZConfig/ZConfig/schema.py:1.34	Mon Apr 12 11:27:00 2004
+++ StandaloneZConfig/ZConfig/schema.py	Wed Apr 14 23:49:12 2004
@@ -395,7 +395,7 @@
     def start_key(self, attrs):
         name, datatype, handler, attribute = self.get_key_info(attrs, "key")
         min = self.get_required(attrs) and 1 or 0
-        key = info.KeyInfo(name, datatype, min, 1, handler, attribute)
+        key = info.KeyInfo(name, datatype, min, handler, attribute)
         if attrs.has_key("default"):
             if min:
                 self.error("required key cannot have a default value")
@@ -418,7 +418,7 @@
         name, datatype, handler, attribute = self.get_key_info(attrs,
                                                                "multikey")
         min, max = self.get_ordinality(attrs)
-        key = info.KeyInfo(name, datatype, min, max, handler, attribute)
+        key = info.MultiKeyInfo(name, datatype, min, max, handler, attribute)
         self._stack[-1].addkey(key)
         self._stack.append(key)
 




More information about the Zope3-Checkins mailing list