Merged revisions 82780 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r82780 | senthil.kumaran | 2010-07-11 08:42:43 +0530 (Sun, 11 Jul 2010) | 3 lines

  Stricter verification for file based url scheme and reliance on ftp protocol.
........
This commit is contained in:
Senthil Kumaran 2010-07-11 03:18:51 +00:00
parent 9d8c456696
commit 87ed31a414
2 changed files with 5 additions and 1 deletions

View File

@ -726,6 +726,8 @@ class HandlerTests(unittest.TestCase):
("file://ftp.example.com///foo.txt", False), ("file://ftp.example.com///foo.txt", False),
# XXXX bug: fails with OSError, should be URLError # XXXX bug: fails with OSError, should be URLError
("file://ftp.example.com/foo.txt", False), ("file://ftp.example.com/foo.txt", False),
("file://somehost//foo/something.txt", True),
("file://localhost//foo/something.txt", False),
]: ]:
req = Request(url) req = Request(url)
try: try:
@ -736,6 +738,7 @@ class HandlerTests(unittest.TestCase):
else: else:
self.assertTrue(o.req is req) self.assertTrue(o.req is req)
self.assertEqual(req.type, "ftp") self.assertEqual(req.type, "ftp")
self.assertEqual(req.type is "ftp", ftp)
def test_http(self): def test_http(self):

View File

@ -1262,7 +1262,8 @@ class FileHandler(BaseHandler):
# Use local file or FTP depending on form of URL # Use local file or FTP depending on form of URL
def file_open(self, req): def file_open(self, req):
url = req.get_selector() 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' req.type = 'ftp'
return self.parent.open(req) return self.parent.open(req)
else: else: