[Zodb-checkins] CVS: Packages/ZConfig - datatypes.py:1.1.2.18

Fred L. Drake, Jr. fred@zope.com
Fri, 20 Dec 2002 15:39:43 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	datatypes.py 
Log Message:
Change the helper classes so that instances are valid conversion
functions.  We still use bound methods for efficiency, but doing so is
not required.


=== Packages/ZConfig/datatypes.py 1.1.2.17 => 1.1.2.18 ===
--- Packages/ZConfig/datatypes.py:1.1.2.17	Fri Dec 20 15:21:20 2002
+++ Packages/ZConfig/datatypes.py	Fri Dec 20 15:39:43 2002
@@ -30,7 +30,7 @@
         self._memo = {}
         self._conversion = conversion
 
-    def convert(self, value):
+    def __call__(self, value):
         try:
             return self._memo[value]
         except KeyError:
@@ -47,7 +47,7 @@
         self._max = max
         self._conversion = conversion
 
-    def convert(self, value):
+    def __call__(self, value):
         v = self._conversion(value)
         if self._min is not None and v < self._min:
             raise ValueError("%s is below lower bound (%s)"
@@ -62,7 +62,7 @@
     def __init__(self, regex):
         self._rx = re.compile(regex)
 
-    def convert(self, value):
+    def __call__(self, value):
         m = self._rx.match(value)
         if m and m.group() == value:
             return value
@@ -92,9 +92,9 @@
     def __init__(self):
         RegularExpressionConversion.__init__(self, "[a-zA-Z][-._a-zA-Z0-9]*")
 
-    def convert(self, value):
+    def __call__(self, value):
         value = str(value)
-        return RegularExpressionConversion.convert(self, value).lower()
+        return RegularExpressionConversion.__call__(self, value).lower()
 
 
 class IdentifierConversion(RegularExpressionConversion):
@@ -117,7 +117,7 @@
         "all": 0,
         }
 
-    def convert(self, value):
+    def __call__(self, value):
         s = str(value).lower()
         if self._levels.has_key(s):
             return self._levels[s]
@@ -153,7 +153,7 @@
         raise ValueError("not a valid boolean value: " + repr(s))
 
 
-port_number = RangeCheckedConversion(integer, min=1, max=0xffff).convert
+port_number = RangeCheckedConversion(integer, min=1, max=0xffff).__call__
 
 
 def inet_address(s):
@@ -191,15 +191,15 @@
 
 stock_datatypes = {
     "boolean":       asBoolean,
-    "identifier":    IdentifierConversion().convert,
+    "identifier":    IdentifierConversion().__call__,
     "integer":       integer,
     "float":         float_conversion,
     "str":           str,
     "null":          null_conversion,
-    "locale":        MemoizedConversion(check_locale).convert,
+    "locale":        MemoizedConversion(check_locale).__call__,
     "port-number":   port_number,
-    "basic-key":     BasicKeyConversion().convert,
-    "logging-level": LogLevelConversion().convert,
+    "basic-key":     BasicKeyConversion().__call__,
+    "logging-level": LogLevelConversion().__call__,
     "inet-address":  inet_address,
     "socket-address":socket_address,
     }