mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
Fix Issue15701 : add .headers attribute to urllib.error.HTTPError
This commit is contained in:
parent
8e5a8296cc
commit
5962cce050
4 changed files with 23 additions and 1 deletions
|
@ -45,6 +45,13 @@ The following exceptions are raised by :mod:`urllib.error` as appropriate:
|
||||||
|
|
||||||
This is usually a string explaining the reason for this error.
|
This is usually a string explaining the reason for this error.
|
||||||
|
|
||||||
|
.. attribute:: headers
|
||||||
|
|
||||||
|
The HTTP response headers for the HTTP request that cause the
|
||||||
|
:exc:`HTTPError`.
|
||||||
|
|
||||||
|
.. versionadded:: 3.4
|
||||||
|
|
||||||
.. exception:: ContentTooShortError(msg, content)
|
.. exception:: ContentTooShortError(msg, content)
|
||||||
|
|
||||||
This exception is raised when the :func:`urlretrieve` function detects that
|
This exception is raised when the :func:`urlretrieve` function detects that
|
||||||
|
|
|
@ -1539,11 +1539,15 @@ def test_HTTPError_interface():
|
||||||
interface even though HTTPError is a subclass of URLError.
|
interface even though HTTPError is a subclass of URLError.
|
||||||
|
|
||||||
>>> msg = 'something bad happened'
|
>>> 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)
|
>>> err = urllib.error.HTTPError(url, code, msg, hdrs, fp)
|
||||||
>>> assert hasattr(err, 'reason')
|
>>> assert hasattr(err, 'reason')
|
||||||
>>> err.reason
|
>>> err.reason
|
||||||
'something bad happened'
|
'something bad happened'
|
||||||
|
>>> assert hasattr(err, 'headers')
|
||||||
|
>>> err.headers
|
||||||
|
'Content-Length: 42'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def test_main(verbose=None):
|
def test_main(verbose=None):
|
||||||
|
|
|
@ -61,6 +61,14 @@ class HTTPError(URLError, urllib.response.addinfourl):
|
||||||
def reason(self):
|
def reason(self):
|
||||||
return self.msg
|
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
|
# exception raised when downloaded size does not match content-length
|
||||||
class ContentTooShortError(URLError):
|
class ContentTooShortError(URLError):
|
||||||
def __init__(self, message, content):
|
def __init__(self, message, content):
|
||||||
|
|
|
@ -163,6 +163,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #15701: Add a .headers attribute to urllib.error.HTTPError. Patch
|
||||||
|
contributed by Berker Peksag.
|
||||||
|
|
||||||
- Issue #15872: Fix 3.3 regression introduced by the new fd-based shutil.rmtree
|
- Issue #15872: Fix 3.3 regression introduced by the new fd-based shutil.rmtree
|
||||||
that caused it to not ignore certain errors when ignore_errors was set.
|
that caused it to not ignore certain errors when ignore_errors was set.
|
||||||
Patch by Alessandro Moura and Serhiy Storchaka.
|
Patch by Alessandro Moura and Serhiy Storchaka.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue