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

Fred L. Drake, Jr. fred@zope.com
Fri, 20 Dec 2002 13:42:48 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	datatypes.py 
Log Message:
Tighten up the float datatype so it's more portable.


=== Packages/ZConfig/datatypes.py 1.1.2.14 => 1.1.2.15 ===
--- Packages/ZConfig/datatypes.py:1.1.2.14	Fri Dec 20 12:37:40 2002
+++ Packages/ZConfig/datatypes.py	Fri Dec 20 13:42:47 2002
@@ -182,16 +182,23 @@
         return socket.AF_INET, inet_address(s)
 
 
+def float_conversion(v):
+    if isinstance(v, type('')) or isinstance(v, type(u'')):
+        if v.lower() in ["inf", "-inf", "nan"]:
+            raise ValueError(`v` + " is not a portable float representation")
+    return float(v)
+
+
 stock_datatypes = {
     "boolean":       asBoolean,
+    "identifier":    IdentifierConversion().convert,
     "integer":       integer,
-    "float":         float,
+    "float":         float_conversion,
     "str":           str,
     "null":          null_conversion,
     "locale":        MemoizedConversion(check_locale).convert,
     "port-number":   port_number,
     "basic-key":     BasicKeyConversion().convert,
-    "identifier":    IdentifierConversion().convert,
     "logging-level": LogLevelConversion().convert,
     "inet-address":  inet_address,
     "socket-address":socket_address,