From: Senthil Kumaran Date: Sun, 11 Jul 2010 03:12:43 +0000 (+0000) Subject: Stricter verification for file based url scheme and reliance on ftp protocol. X-Git-Tag: v3.2a1~236 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2ef16328e82ae9b9715251e41b8abf4b95ae6f20;p=thirdparty%2FPython%2Fcpython.git Stricter verification for file based url scheme and reliance on ftp protocol. --- diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 080daa4f2733..4d117c731975 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -731,6 +731,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: @@ -741,6 +743,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/urllib/request.py b/Lib/urllib/request.py index f7c7416f34c1..c6767d0b2660 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1188,7 +1188,8 @@ class FileHandler(BaseHandler): # Use local file or FTP depending on form of URL def file_open(self, req): url = req.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: