]> granicus.if.org Git - python/commitdiff
Fix localhost checking in FileHandler. Raised in #21970.
authorSenthil Kumaran <senthil@uthcode.com>
Tue, 22 Jul 2014 07:15:20 +0000 (00:15 -0700)
committerSenthil Kumaran <senthil@uthcode.com>
Tue, 22 Jul 2014 07:15:20 +0000 (00:15 -0700)
Lib/test/test_urllib2.py
Lib/urllib/request.py

index 6b73723a6e321a02b60965b6a6c521d7a2fcea6f..76208768a5bf06ad38dd53b6461bff3143feed39 100644 (file)
@@ -678,7 +678,7 @@ class HandlerTests(unittest.TestCase):
             self.assertEqual(int(headers["Content-length"]), len(data))
 
     def test_file(self):
-        import email.utils, socket
+        import email.utils
         h = urllib.request.FileHandler()
         o = h.parent = MockOpener()
 
@@ -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",
             "file://%s:80%s/%s" % (socket.gethostbyname('localhost'),
                                    os.getcwd(), TESTFN),
             "file://somerandomhost.ontheinternet.com%s/%s" %
index 72e91dd5f4cc3bf2169e2653817d1eb8dc222a80..0389f5e853c24f92360c867ce46c13dc83a6d290 100644 (file)
@@ -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():
+            if not req.host in self.get_names():
                 raise URLError("file:// scheme is supported only on localhost")
         else:
             return self.open_local_file(req)