[Python-checkins] python/dist/src/Lib urlparse.py,1.45,1.45.4.1

jlgijsbers at users.sourceforge.net jlgijsbers at users.sourceforge.net
Sun Jan 9 16:32:40 CET 2005


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29436

Modified Files:
      Tag: release24-maint
	urlparse.py 
Log Message:
Backport patch #712317: In URLs such as http://www.example.com?query=spam,
treat '?' as a delimiter. Previously, the 'network location' (<authority> in
RFC 2396) would become 'www.example.com?query=spam', while RFC 2396 does not
allow a '?' in <authority>. See bug #548176 for further discussion.


Index: urlparse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urlparse.py,v
retrieving revision 1.45
retrieving revision 1.45.4.1
diff -u -d -r1.45 -r1.45.4.1
--- urlparse.py	29 Jun 2004 04:02:39 -0000	1.45
+++ urlparse.py	9 Jan 2005 15:32:37 -0000	1.45.4.1
@@ -63,6 +63,15 @@
         i = url.find(';')
     return url[:i], url[i+1:]
 
+def _splitnetloc(url, start=0):
+    for c in '/?#': # the order is important!
+        delim = url.find(c, start)
+        if delim >= 0:
+            break
+    else:
+        delim = len(url)
+    return url[start:delim], url[delim:]
+
 def urlsplit(url, scheme='', allow_fragments=1):
     """Parse a URL into 5 components:
     <scheme>://<netloc>/<path>?<query>#<fragment>
@@ -82,13 +91,7 @@
             scheme = url[:i].lower()
             url = url[i+1:]
             if url[:2] == '//':
-                i = url.find('/', 2)
-                if i < 0:
-                    i = url.find('#')
-                    if i < 0:
-                        i = len(url)
-                netloc = url[2:i]
-                url = url[i:]
+                netloc, url = _splitnetloc(url, 2)
             if allow_fragments and '#' in url:
                 url, fragment = url.split('#', 1)
             if '?' in url:
@@ -101,12 +104,8 @@
                 break
         else:
             scheme, url = url[:i].lower(), url[i+1:]
-    if scheme in uses_netloc:
-        if url[:2] == '//':
-            i = url.find('/', 2)
-            if i < 0:
-                i = len(url)
-            netloc, url = url[2:i], url[i:]
+    if scheme in uses_netloc and url[:2] == '//':
+        netloc, url = _splitnetloc(url, 2)
     if allow_fragments and scheme in uses_fragment and '#' in url:
         url, fragment = url.split('#', 1)
     if scheme in uses_query and '?' in url:



More information about the Python-checkins mailing list