[Zodb-checkins] CVS: Packages/ZConfig - datatypes.py:1.1.2.8 matcher.py:1.1.2.19 schema.py:1.1.2.15

Fred L. Drake, Jr. fred@zope.com
Fri, 13 Dec 2002 12:28:12 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	datatypes.py matcher.py schema.py 
Log Message:
Change the datatype converters to not be special objects, but any callable
that takes one argument.


=== Packages/ZConfig/datatypes.py 1.1.2.7 => 1.1.2.8 ===
--- Packages/ZConfig/datatypes.py:1.1.2.7	Thu Dec 12 17:02:26 2002
+++ Packages/ZConfig/datatypes.py	Fri Dec 13 12:28:11 2002
@@ -22,18 +22,6 @@
     False = 0
 
 
-class NullConversion:
-    def convert(self, value):
-        return value
-
-
-class TrivialConversion:
-    """Datatype that exposes a conversion implemented as a function."""
-
-    def __init__(self, conversion):
-        self.convert = conversion
-
-
 class MemoizedConversion:
     """Conversion helper that caches the results of expensive conversions."""
 
@@ -165,15 +153,15 @@
 
 
 stock_datatypes = {
-    "boolean":       TrivialConversion(asBoolean),
-    "integer":       TrivialConversion(int),
-    "float":         TrivialConversion(float),
-    "str":           TrivialConversion(str),
-    "locale":        MemoizedConversion(Locale().convert),
-    "port-number":   RangeCheckedConversion(int, min=1, max=0xffff),
-    "basic-key":     BasicKeyConversion(),
-    "identifier":    IdentifierConversion(),
-    "logging-level": LogLevelConversion(),
+    "boolean":       asBoolean,
+    "integer":       int,
+    "float":         float,
+    "str":           str,
+    "locale":        MemoizedConversion(Locale().convert).convert,
+    "port-number":   RangeCheckedConversion(int, min=1, max=0xffff).convert,
+    "basic-key":     BasicKeyConversion().convert,
+    "identifier":    IdentifierConversion().convert,
+    "logging-level": LogLevelConversion().convert,
     }
 
 class Registry:
@@ -214,9 +202,8 @@
             except AttributeError:
                 n = '.'.join(modulenames)
                 package = __import__(n, g, g, component)
-        datatype = package()
-        self._other[name] = datatype
-        return datatype
+        self._other[name] = package
+        return package
 
 
 _r = Registry()


=== Packages/ZConfig/matcher.py 1.1.2.18 => 1.1.2.19 ===
--- Packages/ZConfig/matcher.py:1.1.2.18	Fri Dec 13 10:41:52 2002
+++ Packages/ZConfig/matcher.py	Fri Dec 13 12:28:11 2002
@@ -126,14 +126,14 @@
             name, ci = self.type[i]
             if ci.ismulti():
                 if ci.issection():
-                    values[i] = [s.__type__.datatype.convert(s)
+                    values[i] = [s.__type__.datatype(s)
                                  for s in values[i]]
                 else:
-                    values[i] = [ci.datatype.convert(s) for s in values[i]]
+                    values[i] = [ci.datatype(s) for s in values[i]]
             elif ci.issection():
-                values[i] = values[i].__type__.datatype.convert(values[i])
+                values[i] = values[i].__type__.datatype(values[i])
             else:
-                values[i] = ci.datatype.convert(values[i])
+                values[i] = ci.datatype(values[i])
         v = self.createValue(attrnames)
         # XXX  Really should delay this until after all the
         # XXX  sibling SectionValue instances have been created and
@@ -164,10 +164,10 @@
         BaseMatcher.__init__(self, info, info)
 
     def finish(self):
-        # Since there's no outer container to call datatype.convert()
+        # Since there's no outer container to call datatype()
         # for the schema, we convert on the way out.
         v = BaseMatcher.finish(self)
-        return self.type.datatype.convert(v)
+        return self.type.datatype(v)
 
 
 class SectionValue:


=== Packages/ZConfig/schema.py 1.1.2.14 => 1.1.2.15 ===
--- Packages/ZConfig/schema.py:1.1.2.14	Fri Dec 13 12:12:59 2002
+++ Packages/ZConfig/schema.py	Fri Dec 13 12:28:11 2002
@@ -34,9 +34,11 @@
 default_value_type = datatypes.get("str")
 default_key_type = datatypes.get("basic-key")
 default_name_type = default_key_type
-default_section_type = datatypes.NullConversion()
 
-_identifier = datatypes.get("identifier").convert
+def default_section_type(value):
+    return value
+
+_identifier = datatypes.get("identifier")
 
 
 class SchemaParser(xml.sax.ContentHandler):
@@ -194,7 +196,7 @@
         if not name:
             self.doSchemaError("key name may not be omitted or empty")
         # run the keytype converter to make sure this is a valid key
-        name = self._stack[-1].keytype.convert(name)
+        name = self._stack[-1].keytype(name)
         datatype = datatypes.get(attrs.get("datatype"))
         maxOccurs, minOccurs, handler = self.get_common_info(attrs)
         attribute = attrs.get("attribute")