[Zope3-checkins] CVS: Packages/ZConfig - loader.py:1.1.2.25 schema.py:1.1.2.33 url.py:1.1.2.4

Fred L. Drake, Jr. fred@zope.com
Thu, 2 Jan 2003 12:27:02 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	loader.py schema.py url.py 
Log Message:
More consistency in URL handling.  Make sure file: URLs *always* get the
"//" hostpart separator, even with Python 2.1, since urllib2.urlopen()
chokes if that is missing.


=== Packages/ZConfig/loader.py 1.1.2.24 => 1.1.2.25 ===
--- Packages/ZConfig/loader.py:1.1.2.24	Tue Dec 24 15:48:18 2002
+++ Packages/ZConfig/loader.py	Thu Jan  2 12:26:29 2003
@@ -21,7 +21,7 @@
 
 from ZConfig import datatypes
 from ZConfig import matcher
-from ZConfig.url import urldefrag, urljoin, urlsplit, urlunsplit
+from ZConfig.url import urlnormalize, urldefrag, urljoin, urlsplit, urlunsplit
 
 try:
     True
@@ -94,15 +94,12 @@
         if os.path.exists(url):
             url = "file://" + urllib.pathname2url(os.path.abspath(url))
         else:
-            parts = urlsplit(url)
-            if not parts[0]:
-                raise ValueError("invalid URL, or file does not exist:\n"
-                                 + repr(url))
+            url = urlnormalize(url)
         if url and not self.allowFragments():
             url, fragment = urldefrag(url)
             if fragment:
                 raise ZConfig.ConfigurationError(
-                    "fragment identifiers are not currently supported")
+                    "fragment identifiers are not supported")
         return url
 
     def allowFragments(self):


=== Packages/ZConfig/schema.py 1.1.2.32 => 1.1.2.33 ===
--- Packages/ZConfig/schema.py:1.1.2.32	Mon Dec 23 11:21:57 2002
+++ Packages/ZConfig/schema.py	Thu Jan  2 12:26:29 2003
@@ -13,13 +13,13 @@
 ##############################################################################
 """Parser for ZConfig schemas."""
 
-import urlparse
 import xml.sax
 import xml.sax.saxutils
 
 import ZConfig
 
 from ZConfig import info
+from ZConfig import url
 
 
 try:
@@ -116,10 +116,11 @@
         src = attrs.get("src", "").strip()
         if not src:
             self.error("import src may not be omitted or empty")
-        url, fragment = urlparse.urldefrag(src)
+        src = url.urljoin(self._url, src)
+        src, fragment = url.urldefrag(src)
         if fragment:
             self.error("import src many not include a fragment identifier")
-        schema = self._loader.loadURL(urlparse.urljoin(self._url, url))
+        schema = self._loader.loadURL(src)
         for n in schema.gettypenames():
             self._schema.addtype(schema.gettype(n))
 


=== Packages/ZConfig/url.py 1.1.2.3 => 1.1.2.4 ===
--- Packages/ZConfig/url.py:1.1.2.3	Thu Jan  2 10:42:54 2003
+++ Packages/ZConfig/url.py	Thu Jan  2 12:26:29 2003
@@ -4,7 +4,26 @@
 import urlparse as _urlparse
 
 from urllib import splittype as _splittype
-from urlparse import urlunsplit  # part of public API
+
+
+def urlnormalize(url):
+    parts = urlsplit(url)
+    if not parts[0]:
+        raise ValueError("invalid URL, or file does not exist:\n"
+                         + repr(url))
+    url = urlunsplit(parts)
+    if url.startswith("file:/") and not url.startswith("file:///"):
+        url = "file://" + url[5:]
+    return url
+
+
+def urlunsplit(parts):
+    url = _urlparse.urlunsplit(parts)
+    if (  parts[0] == "file"
+          and url.startswith("file:/")
+          and not url.startswith("file:///")):
+        url = "file://" + url[5:]
+    return url
 
 
 def urldefrag(url):
@@ -12,12 +31,17 @@
     if parts[0] == "zconfig":
         return "zconfig:" + parts[2], parts[4]
     else:
-        return _urlparse.urldefrag(url)
+        url, fragment = _urlparse.urldefrag(url)
+        return urlnormalize(url), fragment
 
 
 def urljoin(base, relurl):
-    if _splittype(base)[0] != "zconfig":
-        return _urlparse.urljoin(base, relurl)
+    scheme = _splittype(base)[0]
+    if scheme != "zconfig":
+        url = _urlparse.urljoin(base, relurl)
+        if url.startswith("file:/") and not url.startswith("file:///"):
+            url = "file://" + url[5:]
+        return url
     relscheme = _splittype(relurl)[0]
     if relscheme and relscheme != "zconfig":
         return _urlparse.urljoin(base, relurl)
@@ -67,6 +91,4 @@
         if '?' in path:
             raise ValueError("zconfig: URIs may not contain queries: "
                              + `url`)
-##         import sys
-##         print >>sys.__stderr__, "%r -> %r" % (url, parts)
     return parts