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

Fred L. Drake, Jr. fred@zope.com
Fri, 20 Dec 2002 12:37:41 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	datatypes.py 
Log Message:
- Added comments to LogLevelConversion
- Added conversions for inet-address, socket-address


=== Packages/ZConfig/datatypes.py 1.1.2.13 => 1.1.2.14 ===
--- Packages/ZConfig/datatypes.py:1.1.2.13	Thu Dec 19 11:51:27 2002
+++ Packages/ZConfig/datatypes.py	Fri Dec 20 12:37:40 2002
@@ -103,6 +103,10 @@
 
 
 class LogLevelConversion:
+    # This uses the 'logging' package conventions; only makes sense
+    # for Zope 2.7 (and newer) and Zope 3.  Not sure what the
+    # compatibility should be.
+
     _levels = {
         "critical": 50,
         "fatal": 50,
@@ -149,6 +153,35 @@
         raise ValueError("not a valid boolean value: " + repr(s))
 
 
+port_number = RangeCheckedConversion(integer, min=1, max=0xffff).convert
+
+
+def inet_address(s):
+    # returns (host, port) tuple
+    host = ''
+    port = None
+    if ":" in s:
+        host, s = s.split(":", 1)
+        if s:
+            port = port_number(s)
+        host = host.lower()
+    else:
+        try:
+            port = port_number(s)
+        except ValueError:
+            host = s.lower()
+    return host, port
+
+
+def socket_address(s):
+    # returns (family, address) tuple
+    import socket
+    if "/" in s:
+        return socket.AF_UNIX, s
+    else:
+        return socket.AF_INET, inet_address(s)
+
+
 stock_datatypes = {
     "boolean":       asBoolean,
     "integer":       integer,
@@ -156,10 +189,12 @@
     "str":           str,
     "null":          null_conversion,
     "locale":        MemoizedConversion(check_locale).convert,
-    "port-number":   RangeCheckedConversion(int, min=1, max=0xffff).convert,
+    "port-number":   port_number,
     "basic-key":     BasicKeyConversion().convert,
     "identifier":    IdentifierConversion().convert,
     "logging-level": LogLevelConversion().convert,
+    "inet-address":  inet_address,
+    "socket-address":socket_address,
     }
 
 class Registry: