diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_urllib2.py | 6 | ||||
-rw-r--r-- | Lib/urllib/error.py | 8 |
2 files changed, 13 insertions, 1 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 2261d57..33042ed 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1539,11 +1539,15 @@ def test_HTTPError_interface(): interface even though HTTPError is a subclass of URLError. >>> msg = 'something bad happened' - >>> url = code = hdrs = fp = None + >>> url = code = fp = None + >>> hdrs = 'Content-Length: 42' >>> err = urllib.error.HTTPError(url, code, msg, hdrs, fp) >>> assert hasattr(err, 'reason') >>> err.reason 'something bad happened' + >>> assert hasattr(err, 'headers') + >>> err.headers + 'Content-Length: 42' """ def test_main(verbose=None): diff --git a/Lib/urllib/error.py b/Lib/urllib/error.py index c1dfc40..237ed6b 100644 --- a/Lib/urllib/error.py +++ b/Lib/urllib/error.py @@ -61,6 +61,14 @@ class HTTPError(URLError, urllib.response.addinfourl): def reason(self): return self.msg + @property + def headers(self): + return self.hdrs + + @headers.setter + def headers(self, headers): + self.hdrs = headers + # exception raised when downloaded size does not match content-length class ContentTooShortError(URLError): def __init__(self, message, content): |