[Zodb-checkins] CVS: Packages/ZConfig - Common.py:1.4 Config.py:1.9 StorageTypes.py:1.3

Fred L. Drake, Jr. fred@zope.com
Fri, 22 Nov 2002 13:13:32 -0500


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

Modified Files:
	Common.py Config.py StorageTypes.py 
Log Message:
Refactor: move string->boolean conversion to a helper that gets shared.

=== Packages/ZConfig/Common.py 1.3 => 1.4 ===
--- Packages/ZConfig/Common.py:1.3	Thu Oct 10 17:43:37 2002
+++ Packages/ZConfig/Common.py	Fri Nov 22 13:13:32 2002
@@ -11,6 +11,17 @@
     False = 0
 
 
+def asBoolean(s):
+    """Convert a string value to a boolean value."""
+    ss = str(s).lower()
+    if ss in ('yes', 'true', 'on'):
+        return True
+    elif ss in ('no', 'false', 'off'):
+        return False
+    else:
+        raise ValueError("not a valid boolean value: " + repr(s))
+
+
 class ConfigurationError(Exception):
     def __init__(self, msg):
         self.message = msg


=== Packages/ZConfig/Config.py 1.8 => 1.9 ===
--- Packages/ZConfig/Config.py:1.8	Fri Nov 22 12:09:39 2002
+++ Packages/ZConfig/Config.py	Fri Nov 22 13:13:32 2002
@@ -155,20 +155,13 @@
             else:
                 return self.delegate.get(key, default)
 
-    _boolean_values = {
-         'true': True,  'yes': True,   'on': True,
-        'false': False,  'no': False, 'off': False,
-        } 
-
     def getbool(self, key, default=None):
         missing = []
         s = self.get(key, missing)
         if s is missing:
             return default
-        try:
-            return self._boolean_values[s.lower()]
-        except KeyError:
-            raise ValueError("%s is not a valid boolean value" % repr(s))
+        else:
+            return asBoolean(s)
 
     def getfloat(self, key, default=None, min=None, max=None):
         missing = []


=== Packages/ZConfig/StorageTypes.py 1.2 => 1.3 ===
--- Packages/ZConfig/StorageTypes.py:1.2	Fri Nov 22 12:35:24 2002
+++ Packages/ZConfig/StorageTypes.py	Fri Nov 22 13:13:32 2002
@@ -18,17 +18,7 @@
 
 import re
 
-
-def asBoolean(s):
-    if not s:
-        return 0
-    ss = str(s).lower()
-    if ss in ('yes', 'true', 'on'):
-        return 1
-    elif ss in ('no', 'false', 'off'):
-        return 0
-    else:
-        raise ValueError, 'Not a boolean value: %s' % s
+from ZConfig.Common import asBoolean
 
 
 def convertFileStorageArgs(quota=None, stop=None, **kw):