[Zope-Checkins] CVS: Packages/ZConfig - Context.py:1.2

Fred L. Drake, Jr. fdrake@acm.org
Thu, 10 Oct 2002 16:42:25 -0400


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

Modified Files:
	Context.py 
Log Message:
Allow ZContext.load() to take filesnames as well as URLs, by changing the
underlying Context.load() method.


=== Packages/ZConfig/Context.py 1.1 => 1.2 ===
--- Packages/ZConfig/Context.py:1.1	Tue Oct  8 17:42:17 2002
+++ Packages/ZConfig/Context.py	Thu Oct 10 16:42:24 2002
@@ -1,6 +1,8 @@
 """Top-level configuration handle."""
 
+import os
 import urllib2
+import urlparse
 
 from Common import *
 from Config import Configuration, ImportingConfiguration
@@ -40,6 +42,14 @@
     # public API
 
     def load(self, url):
+        """Load a resource from a URL or pathname."""
+        parts = urlparse.urlsplit(url)
+        if not parts[0]:
+            # must be a filename
+            path = os.path.abspath(url)
+            if os.sep != "/":
+                path = path.replace(os.sep, "/")
+            url = "file://" + path
         top = self.createToplevelSection(url)
         self._imports = [top]
         self._parse_url(url, top)