mirror of
https://github.com/python/cpython.git
synced 2025-09-25 17:59:57 +00:00
Fix Issue15701 - HTTPError info method call raises AttributeError. Fix that to return headers correctly
This commit is contained in:
parent
cddcafaf6b
commit
f8a6b005fd
3 changed files with 30 additions and 9 deletions
|
@ -1336,7 +1336,7 @@ class RequestTests(unittest.TestCase):
|
||||||
req = Request(url)
|
req = Request(url)
|
||||||
self.assertEqual(req.get_full_url(), url)
|
self.assertEqual(req.get_full_url(), url)
|
||||||
|
|
||||||
def test_HTTPError_interface():
|
def test_HTTPError_interface(self):
|
||||||
"""
|
"""
|
||||||
Issue 13211 reveals that HTTPError didn't implement the URLError
|
Issue 13211 reveals that HTTPError didn't implement the URLError
|
||||||
interface even though HTTPError is a subclass of URLError.
|
interface even though HTTPError is a subclass of URLError.
|
||||||
|
@ -1347,6 +1347,22 @@ def test_HTTPError_interface():
|
||||||
'something bad happened'
|
'something bad happened'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def test_HTTPError_interface_call(self):
|
||||||
|
"""
|
||||||
|
Issue 15701= - HTTPError interface has info method available from URLError.
|
||||||
|
"""
|
||||||
|
err = urllib2.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() failed")
|
||||||
|
self.assertEqual(err.info(), "Content-Length:42")
|
||||||
|
|
||||||
def test_main(verbose=None):
|
def test_main(verbose=None):
|
||||||
from test import test_urllib2
|
from test import test_urllib2
|
||||||
test_support.run_doctest(test_urllib2, verbose)
|
test_support.run_doctest(test_urllib2, verbose)
|
||||||
|
|
|
@ -173,6 +173,9 @@ class HTTPError(URLError, addinfourl):
|
||||||
def reason(self):
|
def reason(self):
|
||||||
return self.msg
|
return self.msg
|
||||||
|
|
||||||
|
def info(self):
|
||||||
|
return self.hdrs
|
||||||
|
|
||||||
# copied from cookielib.py
|
# copied from cookielib.py
|
||||||
_cut_port_re = re.compile(r":\d+$")
|
_cut_port_re = re.compile(r":\d+$")
|
||||||
def request_host(request):
|
def request_host(request):
|
||||||
|
|
|
@ -165,6 +165,8 @@ Library
|
||||||
- Issue #16597: In buffered and text IO, call close() on the underlying stream
|
- Issue #16597: In buffered and text IO, call close() on the underlying stream
|
||||||
if invoking flush() fails.
|
if invoking flush() fails.
|
||||||
|
|
||||||
|
- Issue #15701: Fix HTTPError info method call to return the headers information.
|
||||||
|
|
||||||
- Issue #16646: ftplib.FTP.makeport() might lose socket error details.
|
- Issue #16646: ftplib.FTP.makeport() might lose socket error details.
|
||||||
(patch by Serhiy Storchaka)
|
(patch by Serhiy Storchaka)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue