mirror of https://github.com/python/cpython
merge from 3.2
Fix Issue15701 - HTTPError info method call raises AttributeError. Fix that to return headers correctly
This commit is contained in:
commit
0a6b9eca68
|
@ -1495,7 +1495,7 @@ class RequestTests(unittest.TestCase):
|
|||
req = Request(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
|
||||
interface even though HTTPError is a subclass of URLError.
|
||||
|
@ -1508,6 +1508,22 @@ def test_HTTPError_interface():
|
|||
'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
|
||||
support.run_doctest(test_urllib2, verbose)
|
||||
|
|
|
@ -61,6 +61,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):
|
||||
|
|
|
@ -114,6 +114,8 @@ Core and Builtins
|
|||
Library
|
||||
-------
|
||||
|
||||
- Issue #15701: Fix HTTPError info method call to return the headers information.
|
||||
|
||||
- Issue #16752: Add a missing import to modulefinder. Patch by Berker Peksag.
|
||||
|
||||
- Issue #16646: ftplib.FTP.makeport() might lose socket error details.
|
||||
|
|
Loading…
Reference in New Issue