[Zope3-checkins] CVS: Packages/ZConfig - info.py:1.1.2.9 matcher.py:1.1.2.13 schema.py:1.1.2.10

Fred L. Drake, Jr. fred@zope.com
Thu, 12 Dec 2002 13:48:59 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	info.py matcher.py schema.py 
Log Message:
Refactor: KeyInfo and SectionInfo now derive from a common base, and
SectionInfo no longer carries the extra baggage of managing default values
since that is all key-specific.


=== Packages/ZConfig/info.py 1.1.2.8 => 1.1.2.9 ===
--- Packages/ZConfig/info.py:1.1.2.8	Thu Dec 12 13:36:36 2002
+++ Packages/ZConfig/info.py	Thu Dec 12 13:48:58 2002
@@ -48,7 +48,7 @@
 Unbounded = UnboundedThing()
 
 
-class KeyInfo:
+class BaseInfo:
     """Information about a single configuration key."""
 
     def __init__(self, name, datatype, minOccurs, maxOccurs, handler,
@@ -64,8 +64,21 @@
         self.maxOccurs = maxOccurs
         self.handler = handler
         self.attribute = attribute
-        self._default = None
+
+    def ismulti(self):
+        return self.maxOccurs > 1
+
+    def issection(self):
+        return False
+
+
+class KeyInfo(BaseInfo):
+    def __init__(self, name, datatype, minOccurs, maxOccurs, handler,
+                 attribute):
+        BaseInfo.__init__(self, name, datatype, minOccurs, maxOccurs,
+                          handler, attribute)
         self._finished = False
+        self._default = None
 
     def finish(self):
         if self._finished:
@@ -100,14 +113,8 @@
         else:
             return self._default
 
-    def ismulti(self):
-        return self.maxOccurs > 1
-
-    def issection(self):
-        return False
-
 
-class SectionInfo(KeyInfo):
+class SectionInfo(BaseInfo):
     def __init__(self, name, sectiontype, minOccurs, maxOccurs, handler,
                  attribute):
         # name        - name of the section; one of '*', '+', or name1
@@ -127,8 +134,8 @@
                 raise ZConfig.ConfigurationError(
                     "sections which can occur more than once must"
                     " specify a target attribute name")
-        KeyInfo.__init__(self, name, sectiontype.datatype,
-                         minOccurs, maxOccurs, handler, attribute)
+        BaseInfo.__init__(self, name, sectiontype.datatype,
+                          minOccurs, maxOccurs, handler, attribute)
         self.sectiontype = sectiontype
 
     def issection(self):


=== Packages/ZConfig/matcher.py 1.1.2.12 => 1.1.2.13 ===
--- Packages/ZConfig/matcher.py:1.1.2.12	Thu Dec 12 13:11:20 2002
+++ Packages/ZConfig/matcher.py	Thu Dec 12 13:48:58 2002
@@ -106,7 +106,9 @@
                         "not enough values for %s; %d found, %d required"
                         % (`key`, len(L), ci.minOccurs))
             if v is None:
-                if ci.ismulti():
+                if ci.issection():
+                    v = []
+                elif ci.ismulti():
                     v = ci.getdefault()[:]
                 else:
                     v = ci.getdefault()


=== Packages/ZConfig/schema.py 1.1.2.9 => 1.1.2.10 ===
--- Packages/ZConfig/schema.py:1.1.2.9	Thu Dec 12 13:32:13 2002
+++ Packages/ZConfig/schema.py	Thu Dec 12 13:48:58 2002
@@ -156,7 +156,6 @@
         self._stack.pop()
 
     def start_section(self, attrs):
-        self.push_prefix(attrs)
         type = attrs.get("type")
         if not type:
             self.doSchemaError("section must specify type")
@@ -169,8 +168,7 @@
         self._stack.append(section)
 
     def end_section(self):
-        del self._prefixes[-1]
-        self._stack.pop().finish()
+        self._stack.pop()
 
     def start_sectiongroup(self, attrs):
         self.push_prefix(attrs)