diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index c911c9d2c07..3f781988f5a 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -681,7 +681,7 @@ class HandlerTests(unittest.TestCase): try: data = r.read() headers = r.info() - newurl = r.geturl() + respurl = r.geturl() finally: r.close() stats = os.stat(TESTFN) @@ -692,6 +692,7 @@ class HandlerTests(unittest.TestCase): 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, diff --git a/Lib/urllib2.py b/Lib/urllib2.py index b416913f492..58ef6255874 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -1288,7 +1288,7 @@ class FileHandler(BaseHandler): 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)