[Zope3-checkins] CVS: Packages/ZConfig - info.py:1.1.2.12 loader.py:1.1.2.12 schema.py:1.1.2.13

Fred L. Drake, Jr. fred@zope.com
Fri, 13 Dec 2002 10:16:58 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	info.py loader.py schema.py 
Log Message:
More changes that the previous commit relied on.

=== Packages/ZConfig/info.py 1.1.2.11 => 1.1.2.12 ===
--- Packages/ZConfig/info.py:1.1.2.11	Thu Dec 12 17:50:48 2002
+++ Packages/ZConfig/info.py	Fri Dec 13 10:16:57 2002
@@ -176,19 +176,44 @@
         self._types = {}
 
     def addtype(self, typeinfo):
-        if self._types.has_key(typeinfo.name):
+        n = typeinfo.name.lower()
+        if self._types.has_key(n):
             raise ZConfig.ConfigurationError("type name cannot be redefined: "
                                              + `typeinfo.name`)
-        self._types[typeinfo.name] = typeinfo
+        self._types[n] = typeinfo
 
     def gettype(self, name):
+        n = name.lower()
         try:
-            return self._types[name]
+            return self._types[n]
         except KeyError:
             raise ZConfig.ConfigurationError("unknown type name: " + `name`)
 
     def gettypenames(self):
         return self._types.keys()
+
+    def finish(self):
+        if not self._types:
+            raise ZConfig.ConfigurationError(
+                "sectiongroup must contain at least on sectiontype")
+        # This tries to make sure the datatype gets set to the right
+        # thing.  If each child type has the same datatype object,
+        # that is used, otherwise one gets added that maps to the
+        # datatype specified by the actual type of the value passed to
+        # convert().
+        types = self._types.values()
+        dt = types[0].datatype
+        for t in types[1:]:
+            if t.datatype is not dt:
+                self.datatype = GroupConversion()
+                break
+        else:
+            self.datatype = dt
+
+
+class GroupConversion:
+    def convert(self, value):
+        return value.__type__.datatype.convert(value)
 
 
 class GroupType(TypeContainer):


=== Packages/ZConfig/loader.py 1.1.2.11 => 1.1.2.12 ===
--- Packages/ZConfig/loader.py:1.1.2.11	Fri Dec 13 00:05:43 2002
+++ Packages/ZConfig/loader.py	Fri Dec 13 10:16:57 2002
@@ -116,7 +116,7 @@
             raise ZConfig.ConfigurationError(
                 "%s is not an allowed name for %s sections"
                 % (`name`, `ci.sectiontype.name`))
-        return matcher.SectionMatcher(ci, name)
+        return matcher.SectionMatcher(ci, self.schema.gettype(type), name)
 
     def endSection(self, parent, type, name, delegatename, matcher):
         assert not delegatename


=== Packages/ZConfig/schema.py 1.1.2.12 => 1.1.2.13 ===
--- Packages/ZConfig/schema.py:1.1.2.12	Thu Dec 12 17:50:48 2002
+++ Packages/ZConfig/schema.py	Fri Dec 13 10:16:57 2002
@@ -187,7 +187,7 @@
     def end_sectiongroup(self):
         del self._prefixes[-1]
         self._group = None
-        self._stack.pop()
+        self._stack.pop().finish()
 
     def start_key(self, attrs):
         name = attrs.get("name")