diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index b5a243705a2..23631f657fe 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -726,6 +726,8 @@ class HandlerTests(unittest.TestCase): ("file://ftp.example.com///foo.txt", False), # XXXX bug: fails with OSError, should be URLError ("file://ftp.example.com/foo.txt", False), + ("file://somehost//foo/something.txt", True), + ("file://localhost//foo/something.txt", False), ]: req = Request(url) try: @@ -736,6 +738,7 @@ class HandlerTests(unittest.TestCase): else: self.assertTrue(o.req is req) self.assertEqual(req.type, "ftp") + self.assertEqual(req.type is "ftp", ftp) def test_http(self): diff --git a/Lib/urllib2.py b/Lib/urllib2.py index 40e442751e0..f6f7be9092a 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -1262,7 +1262,8 @@ class FileHandler(BaseHandler): # Use local file or FTP depending on form of URL def file_open(self, req): url = req.get_selector() - if url[:2] == '//' and url[2:3] != '/': + if url[:2] == '//' and url[2:3] != '/' and (req.host and + req.host != 'localhost'): req.type = 'ftp' return self.parent.open(req) else: