[Zope3-checkins] CVS: Packages/ZConfig - datatypes.py:1.1.2.7

Fred L. Drake, Jr. fred@zope.com
Thu, 12 Dec 2002 17:02:27 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	datatypes.py 
Log Message:
Another useful conversion in the Zope world.


=== Packages/ZConfig/datatypes.py 1.1.2.6 => 1.1.2.7 ===
--- Packages/ZConfig/datatypes.py:1.1.2.6	Thu Dec 12 13:11:20 2002
+++ Packages/ZConfig/datatypes.py	Thu Dec 12 17:02:26 2002
@@ -131,6 +131,28 @@
         RegularExpressionConversion.__init__(self, "[_a-zA-Z][_a-zA-Z0-9]*")
 
 
+class LogLevelConversion:
+    _levels = {
+        "critical": 50,
+        "fatal": 50,
+        "error": 40,
+        "warn": 30,
+        "info": 20,
+        "debug": 10,
+        "all": 0,
+        }
+
+    def convert(self, value):
+        s = str(value).lower()
+        if self._levels.has_key(s):
+            return self._levels[s]
+        else:
+            v = int(s)
+            if v < 0 or v > 50:
+                raise ValueError("log level not in range: " + `v`)
+            return v
+
+
 def asBoolean(s):
     """Convert a string value to a boolean value."""
     ss = str(s).lower()
@@ -143,14 +165,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(),
+    "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(),
     }
 
 class Registry: