Browse Source

Merged fix for #13211 from 3.2

pull/2332/head
Jason R. Coombs 15 years ago
parent
commit
0612e8c2a2
  1. 11
      Lib/test/test_urllib2.py
  2. 6
      Lib/urllib/error.py

11
Lib/test/test_urllib2.py

@ -1449,6 +1449,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)

6
Lib/urllib/error.py

@ -55,6 +55,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):

Loading…
Cancel
Save