[Zope-Checkins] CVS: Packages/ZConfig - url.py:1.4

Fred L. Drake, Jr. fred@zope.com
Wed, 8 Jan 2003 00:42:48 -0500


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

Modified Files:
	url.py 
Log Message:
Get urlsplit() and urlunsplit() right, and implemented for Python 2.1.


=== Packages/ZConfig/url.py 1.3 => 1.4 ===
--- Packages/ZConfig/url.py:1.3	Fri Jan  3 18:01:07 2003
+++ Packages/ZConfig/url.py	Wed Jan  8 00:42:45 2003
@@ -21,7 +21,23 @@
 import urlparse as _urlparse
 
 from urllib import splittype as _splittype
-from urlparse import urlsplit
+
+try:
+    from urlparse import urlsplit
+except ImportError:
+    def urlsplit(url):
+        # Check for the fragment here, since Python 2.1.3 didn't get
+        # it right for things like "http://www.python.org#frag".
+        if '#' in url:
+            url, fragment = url.split('#', 1)
+        else:
+            fragment = ''
+        parts = list(_urlparse.urlparse(url))
+        parts[-1] = fragment
+        param = parts.pop(3)
+        if param:
+            parts[2] += ";" + param
+        return tuple(parts)
 
 
 def urlnormalize(url):
@@ -36,7 +52,9 @@
 
 
 def urlunsplit(parts):
-    url = _urlparse.urlunsplit(parts)
+    parts = list(parts)
+    parts.insert(3, '')
+    url = _urlparse.urlunparse(tuple(parts))
     if (  parts[0] == "file"
           and url.startswith("file:/")
           and not url.startswith("file:///")):