[Python-3000-checkins] r65680 - in python/branches/py3k/Lib: test/test_urlparse.py urllib/parse.py

facundo.batista python-3000-checkins at python.org
Thu Aug 14 18:55:14 CEST 2008


Author: facundo.batista
Date: Thu Aug 14 18:55:14 2008
New Revision: 65680

Log:

Issue 1432. Fixes a bug caused because of the evolution
of the RFC that describes the behaviour. Note that we now
have the same behaviour than the current browsers.


Modified:
   python/branches/py3k/Lib/test/test_urlparse.py
   python/branches/py3k/Lib/urllib/parse.py

Modified: python/branches/py3k/Lib/test/test_urlparse.py
==============================================================================
--- python/branches/py3k/Lib/test/test_urlparse.py	(original)
+++ python/branches/py3k/Lib/test/test_urlparse.py	Thu Aug 14 18:55:14 2008
@@ -6,6 +6,7 @@
 
 RFC1808_BASE = "http://a/b/c/d;p?q#f"
 RFC2396_BASE = "http://a/b/c/d;p?q"
+RFC3986_BASE = "http://a/b/c/d;p?q"
 
 class UrlParseTestCase(unittest.TestCase):
 
@@ -167,8 +168,6 @@
     def test_RFC2396(self):
         # cases from RFC 2396
 
-        self.checkJoin(RFC2396_BASE, '?y', 'http://a/b/c/?y')
-        self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x')
 
         self.checkJoin(RFC2396_BASE, 'g:h', 'g:h')
         self.checkJoin(RFC2396_BASE, 'g', 'http://a/b/c/g')
@@ -210,6 +209,14 @@
         self.checkJoin(RFC2396_BASE, 'g#s/./x', 'http://a/b/c/g#s/./x')
         self.checkJoin(RFC2396_BASE, 'g#s/../x', 'http://a/b/c/g#s/../x')
 
+        #The following scenarios have been updated in RFC3986
+        #self.checkJoin(RFC2396_BASE, '?y', 'http://a/b/c/?y')
+        #self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x')
+
+    def test_RFC3986(self):
+        self.checkJoin(RFC3986_BASE, '?y','http://a/b/c/d;p?y')
+        self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x')
+
     def test_urldefrag(self):
         for url, defrag, frag in [
             ('http://python.org#frag', 'http://python.org', 'frag'),

Modified: python/branches/py3k/Lib/urllib/parse.py
==============================================================================
--- python/branches/py3k/Lib/urllib/parse.py	(original)
+++ python/branches/py3k/Lib/urllib/parse.py	Thu Aug 14 18:55:14 2008
@@ -219,9 +219,18 @@
     if path[:1] == '/':
         return urlunparse((scheme, netloc, path,
                            params, query, fragment))
-    if not (path or params or query):
-        return urlunparse((scheme, netloc, bpath,
-                           bparams, bquery, fragment))
+    if not path:
+        path = bpath
+        if not params:
+            params = bparams
+        else:
+            path = path[:-1]
+            return urlunparse((scheme, netloc, path,
+                                params, query, fragment))
+        if not query:
+            query = bquery
+        return urlunparse((scheme, netloc, path,
+                           params, query, fragment))
     segments = bpath.split('/')[:-1] + path.split('/')
     # XXX The stuff below is bogus in various ways...
     if segments[-1] == '.':


More information about the Python-3000-checkins mailing list