[Python-checkins] r80953 - in python/trunk/Lib: test/test_urllib2.py urllib2.py

senthil.kumaran python-checkins at python.org
Sat May 8 05:11:50 CEST 2010


Author: senthil.kumaran
Date: Sat May  8 05:11:50 2010
New Revision: 80953

Log:
Fix Issue8656 - urllib2 mangles file://-scheme URLs



Modified:
   python/trunk/Lib/test/test_urllib2.py
   python/trunk/Lib/urllib2.py

Modified: python/trunk/Lib/test/test_urllib2.py
==============================================================================
--- python/trunk/Lib/test/test_urllib2.py	(original)
+++ python/trunk/Lib/test/test_urllib2.py	Sat May  8 05:11:50 2010
@@ -679,7 +679,7 @@
                 try:
                     data = r.read()
                     headers = r.info()
-                    newurl = r.geturl()
+                    respurl = r.geturl()
                 finally:
                     r.close()
                 stats = os.stat(TESTFN)
@@ -690,6 +690,7 @@
             self.assertEqual(headers["Content-type"], "text/plain")
             self.assertEqual(headers["Content-length"], "13")
             self.assertEqual(headers["Last-modified"], modified)
+            self.assertEqual(respurl, url)
 
         for url in [
             "file://localhost:80%s" % urlpath,

Modified: python/trunk/Lib/urllib2.py
==============================================================================
--- python/trunk/Lib/urllib2.py	(original)
+++ python/trunk/Lib/urllib2.py	Sat May  8 05:11:50 2010
@@ -1291,7 +1291,7 @@
             if not host or \
                 (not port and socket.gethostbyname(host) in self.get_names()):
                 return addinfourl(open(localfile, 'rb'),
-                                  headers, 'file:'+file)
+                                  headers, 'file://'+ host + file)
         except OSError, msg:
             # urllib2 users shouldn't expect OSErrors coming from urlopen()
             raise URLError(msg)


More information about the Python-checkins mailing list