diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 1a8ffac1b03..f173aa09dc6 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -684,7 +684,7 @@ def test_file(self): try: data = r.read() headers = r.info() - newurl = r.geturl() + respurl = r.geturl() finally: r.close() stats = os.stat(TESTFN) @@ -695,6 +695,7 @@ def test_file(self): 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/urllib/request.py b/Lib/urllib/request.py index 3293966a198..098630ebcbb 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1216,7 +1216,8 @@ def open_local_file(self, req): host, port = splitport(host) if not host or \ (not port and _safe_gethostbyname(host) in self.get_names()): - return addinfourl(open(localfile, 'rb'), headers, 'file:'+file) + return addinfourl(open(localfile, 'rb'), headers, 'file://'+ + host + file) except OSError as msg: # users shouldn't expect OSErrors coming from urlopen() raise URLError(msg)