From: Senthil Kumaran Date: Sat, 27 Oct 2012 09:48:21 +0000 (-0700) Subject: Issue #16250: Fix URLError invocation with proper args X-Git-Tag: v3.3.1rc1~741 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cc2f0421c70d6a68e026d074b7d1c7fa4d96e6b8;p=python Issue #16250: Fix URLError invocation with proper args --- cc2f0421c70d6a68e026d074b7d1c7fa4d96e6b8 diff --cc Lib/test/test_urllib.py index 22ada56d0c,3fc499ec07..623eb5ef2f --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@@ -268,6 -268,41 +268,39 @@@ Content-Type: text/html; charset=iso-88 finally: self.unfakehttp() + def test_missing_localfile(self): + # Test for #10836 - with self.assertRaises(urllib.error.URLError) as e: ++ # 3.3 - URLError is not captured, explicit IOError is raised. ++ with self.assertRaises(IOError): + urlopen('file://localhost/a/file/which/doesnot/exists.py') - self.assertTrue(e.exception.filename) - self.assertTrue(e.exception.reason) + + def test_file_notexists(self): + fd, tmp_file = tempfile.mkstemp() + tmp_fileurl = 'file://localhost/' + tmp_file.replace(os.path.sep, '/') + try: + self.assertTrue(os.path.exists(tmp_file)) + with urlopen(tmp_fileurl) as fobj: + self.assertTrue(fobj) + finally: + os.close(fd) + os.unlink(tmp_file) + self.assertFalse(os.path.exists(tmp_file)) - with self.assertRaises(urllib.error.URLError): ++ # 3.3 - IOError instead of URLError ++ with self.assertRaises(IOError): + urlopen(tmp_fileurl) + + def test_ftp_nohost(self): + test_ftp_url = 'ftp:///path' - with self.assertRaises(urllib.error.URLError) as e: ++ # 3.3 - IOError instead of URLError ++ with self.assertRaises(IOError): + urlopen(test_ftp_url) - self.assertFalse(e.exception.filename) - self.assertTrue(e.exception.reason) + + def test_ftp_nonexisting(self): - with self.assertRaises(urllib.error.URLError) as e: ++ # 3.3 - IOError instead of URLError ++ with self.assertRaises(IOError): + urlopen('ftp://localhost/a/file/which/doesnot/exists.py') - self.assertFalse(e.exception.filename) - self.assertTrue(e.exception.reason) + + def test_userpass_inurl(self): self.fakehttp(b"HTTP/1.0 200 OK\r\n\r\nHello!") try: @@@ -298,10 -333,6 +331,10 @@@ finally: self.unfakehttp() + def test_URLopener_deprecation(self): + with support.check_warnings(('',DeprecationWarning)): - warn = urllib.request.URLopener() ++ urllib.request.URLopener() + class urlretrieve_FileTests(unittest.TestCase): """Test urllib.urlretrieve() on local files""" diff --cc Misc/NEWS index da227f7382,a7af2ccf3d..e0a54cbe01 --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -49,10 -132,10 +49,12 @@@ Core and Builtin Library ------- + - Issue #16250: Fix URLError invocation with proper args. + -- Issue #16305: Fix a segmentation fault occurring when interrupting - math.factorial. +- Issue #16116: Fix include and library paths to be correct when building C + extensions in venvs. + +- Issue #16245: Fix the value of a few entities in html.entities.html5. - Issue #14398: Fix size truncation and overflow bugs in the bz2 module.