cpython: 4b98961748f1 (original) (raw)
Mercurial > cpython
changeset 91755:4b98961748f1 3.4
Fix localhost checking in FileHandler. Raised in #21970. [#21970]
Senthil Kumaran senthil@uthcode.com | |
---|---|
date | Tue, 22 Jul 2014 00:15:20 -0700 |
parents | 4dac45f88d45 |
children | 2c660948bb41 a74c48aa43eb |
files | Lib/test/test_urllib2.py Lib/urllib/request.py |
diffstat | 2 files changed, 3 insertions(+), 2 deletions(-)[+] [-] Lib/test/test_urllib2.py 3 Lib/urllib/request.py 2 |
line wrap: on
line diff
--- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -678,7 +678,7 @@ class HandlerTests(unittest.TestCase): self.assertEqual(int(headers["Content-length"]), len(data)) def test_file(self):
import email.utils, socket[](#l1.7)
import email.utils[](#l1.8) h = urllib.request.FileHandler()[](#l1.9) o = h.parent = MockOpener()[](#l1.10)
@@ -725,6 +725,7 @@ class HandlerTests(unittest.TestCase): for url in [ "file://localhost:80%s" % urlpath, "file:///file_does_not_exist.txt",
"file://not-a-local-host.com//dir/file.txt",[](#l1.16) "file://%s:80%s/%s" % (socket.gethostbyname('localhost'),[](#l1.17) os.getcwd(), TESTFN),[](#l1.18) "file://somerandomhost.ontheinternet.com%s/%s" %[](#l1.19)
--- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1315,7 +1315,7 @@ class FileHandler(BaseHandler): url = req.selector if url[:2] == '//' and url[2:3] != '/' and (req.host and req.host != 'localhost'):
if not req.host is self.get_names():[](#l2.7)
if not req.host in self.get_names():[](#l2.8) raise URLError("file:// scheme is supported only on localhost")[](#l2.9) else:[](#l2.10) return self.open_local_file(req)[](#l2.11)