Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
aa204dbe
Commit
aa204dbe
authored
Nov 07, 2011
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #13211: Add .reason attribute to HTTPError to implement parent class (URLError) interface.
parent
a90e364e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
0 deletions
+17
-0
Lib/test/test_urllib2.py
Lib/test/test_urllib2.py
+11
-0
Lib/urllib/error.py
Lib/urllib/error.py
+6
-0
No files found.
Lib/test/test_urllib2.py
View file @
aa204dbe
...
...
@@ -1409,6 +1409,17 @@ 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_main
(
verbose
=
None
):
from
test
import
test_urllib2
support
.
run_doctest
(
test_urllib2
,
verbose
)
...
...
Lib/urllib/error.py
View file @
aa204dbe
...
...
@@ -52,6 +52,12 @@ class HTTPError(URLError, urllib.response.addinfourl):
def
__str__
(
self
):
return
'HTTP Error %s: %s'
%
(
self
.
code
,
self
.
msg
)
# since URLError specifies a .reason attribute, HTTPError should also
# provide this attribute. See issue13211 for discussion.
@
property
def
reason
(
self
):
return
self
.
msg
# exception raised when downloaded size does not match content-length
class
ContentTooShortError
(
URLError
):
def
__init__
(
self
,
message
,
content
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment