[Zodb-checkins] CVS: Packages/ZConfig - Context.py:1.10

Fred L. Drake, Jr. fred@zope.com
Fri, 22 Nov 2002 14:50:56 -0500


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

Modified Files:
	Context.py 
Log Message:
Refactor: abstract out filename normalization.


=== Packages/ZConfig/Context.py 1.9 => 1.10 ===
--- Packages/ZConfig/Context.py:1.9	Thu Nov  7 15:05:24 2002
+++ Packages/ZConfig/Context.py	Fri Nov 22 14:50:55 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.urlsplit(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]