[Zodb-checkins] CVS: Zope/lib/python/ZConfig - Common.py:1.1.4.3 Config.py:1.2.4.4 Context.py:1.1.4.5 __init__.py:1.1.4.4

Chris McDonough chrism@zope.com
Sun, 24 Nov 2002 18:29:15 -0500


Update of /cvs-repository/Zope/lib/python/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv6683

Modified Files:
      Tag: chrism-install-branch
	Common.py Config.py Context.py __init__.py 
Log Message:
Merge with head.


=== Zope/lib/python/ZConfig/Common.py 1.1.4.2 => 1.1.4.3 ===
--- Zope/lib/python/ZConfig/Common.py:1.1.4.2	Tue Oct 15 20:53:38 2002
+++ Zope/lib/python/ZConfig/Common.py	Sun Nov 24 18:28:43 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


=== Zope/lib/python/ZConfig/Config.py 1.2.4.3 => 1.2.4.4 ===
--- Zope/lib/python/ZConfig/Config.py:1.2.4.3	Fri Nov 15 20:26:17 2002
+++ Zope/lib/python/ZConfig/Config.py	Sun Nov 24 18:28:43 2002
@@ -75,8 +75,12 @@
             else:
                 return None
 
-    def getChildSections(self):
-        return self._sections[:]
+    def getChildSections(self, type=None):
+        if type is None:
+            return self._sections[:]
+        else:
+            type = type.lower()
+            return [sect for sect in self._sections if sect.type == type]
 
     def addValue(self, key, value):
         key = key.lower()
@@ -151,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 = []


=== Zope/lib/python/ZConfig/Context.py 1.1.4.4 => 1.1.4.5 ===
--- Zope/lib/python/ZConfig/Context.py:1.1.4.4	Fri Nov 15 20:26:17 2002
+++ Zope/lib/python/ZConfig/Context.py	Sun Nov 24 18:28:43 2002
@@ -41,12 +41,21 @@
         from ApacheStyle import Parse
         Parse(file, self, section, url)
 
+    def _normalize_url(self, url):
+        if os.path.exists(url):
+            url = "file://" + urllib.pathname2url(os.path.abspath(url))
+        else:
+            parts = urlparse.urlparse(url)
+            if not parts[0]:
+                raise ValueError("invalid URL, or file does not exist:\n"
+                                 + repr(url))
+        return url
+
     # public API
 
     def load(self, url):
         """Load a resource from a URL or pathname."""
-        if os.path.exists(url):
-            url = "file://" + urllib.pathname2url(os.path.abspath(url))
+        url = self._normalize_url(url)
         top = self.createToplevelSection(url)
         self._all_sections.append(top)
         self._imports = [top]


=== Zope/lib/python/ZConfig/__init__.py 1.1.4.3 => 1.1.4.4 ===
--- Zope/lib/python/ZConfig/__init__.py:1.1.4.3	Sat Nov 16 01:38:39 2002
+++ Zope/lib/python/ZConfig/__init__.py	Sun Nov 24 18:28:43 2002
@@ -31,4 +31,4 @@
 def loadschemafile(file, schema, url=None):
     from SchemaParser import SchemaContext
     return SchemaContext().load(file, url, schema)
-    
+