diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2012-12-23 17:04:24 (GMT) |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2012-12-23 17:04:24 (GMT) |
commit | 41e66a26b0b86291f5fb846ffe2dc641b5ced65a (patch) | |
tree | 9812deaeb24350f851a355f7dc3ec96dbb75d71c | |
parent | 3cbdaa3fee9489570124c368c94ff84718c81dae (diff) | |
download | cpython-41e66a26b0b86291f5fb846ffe2dc641b5ced65a.zip cpython-41e66a26b0b86291f5fb846ffe2dc641b5ced65a.tar.gz cpython-41e66a26b0b86291f5fb846ffe2dc641b5ced65a.tar.bz2 |
Fix Issue15701 - HTTPError info method call raises AttributeError. Fix that to return headers correctly
-rw-r--r-- | Lib/test/test_urllib2.py | 36 | ||||
-rw-r--r-- | Lib/urllib/error.py | 4 | ||||
-rw-r--r-- | Misc/NEWS | 2 |
3 files changed, 32 insertions, 10 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index d8c302b..5eab30a 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1438,16 +1438,32 @@ class RequestTests(unittest.TestCase): req = Request(url) self.assertEqual(req.get_full_url(), url) -def test_HTTPError_interface(): - """ - Issue 13211 reveals that HTTPError didn't implement the URLError - interface even though HTTPError is a subclass of URLError. - - >>> err = urllib.error.HTTPError(msg='something bad happened', url=None, code=None, hdrs=None, fp=None) - >>> assert hasattr(err, 'reason') - >>> err.reason - 'something bad happened' - """ + def test_HTTPError_interface(self): + """ + Issue 13211 reveals that HTTPError didn't implement the URLError + interface even though HTTPError is a subclass of URLError. + + >>> err = urllib.error.HTTPError(msg='something bad happened', url=None, code=None, hdrs=None, fp=None) + >>> assert hasattr(err, 'reason') + >>> err.reason + 'something bad happened' + """ + + def test_HTTPError_interface_call(self): + """ + Issue 15701 - HTTPError interface has info method available from URLError + """ + err = urllib.request.HTTPError(msg="something bad happened", url=None, + code=None, hdrs='Content-Length:42', fp=None) + self.assertTrue(hasattr(err, 'reason')) + assert hasattr(err, 'reason') + assert hasattr(err, 'info') + assert callable(err.info) + try: + err.info() + except AttributeError: + self.fail('err.info call failed.') + self.assertEqual(err.info(), "Content-Length:42") def test_main(verbose=None): from test import test_urllib2 diff --git a/Lib/urllib/error.py b/Lib/urllib/error.py index 40add41..eb14c1d 100644 --- a/Lib/urllib/error.py +++ b/Lib/urllib/error.py @@ -58,6 +58,10 @@ class HTTPError(URLError, urllib.response.addinfourl): def reason(self): return self.msg + def info(self): + return self.hdrs + + # exception raised when downloaded size does not match content-length class ContentTooShortError(URLError): def __init__(self, message, content): @@ -179,6 +179,8 @@ Core and Builtins Library ------- +- Issue #15701: Fix HTTPError info method call to return the headers information. + - Issue #16646: ftplib.FTP.makeport() might lose socket error details. (patch by Serhiy Storchaka) |