summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2012-12-23 17:00:47 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2012-12-23 17:00:47 (GMT)
commitf8a6b005fdd1b150ae41699de556951a0d3ee26b (patch)
tree3e874ed3cf8a5020f04976c98c430cb93c65a2c6
parentcddcafaf6b11f4da66fdccba20a777ccb55b800b (diff)
downloadcpython-f8a6b005fdd1b150ae41699de556951a0d3ee26b.zip
cpython-f8a6b005fdd1b150ae41699de556951a0d3ee26b.tar.gz
cpython-f8a6b005fdd1b150ae41699de556951a0d3ee26b.tar.bz2
Fix Issue15701 - HTTPError info method call raises AttributeError. Fix that to return headers correctly
-rw-r--r--Lib/test/test_urllib2.py36
-rw-r--r--Lib/urllib2.py3
-rw-r--r--Misc/NEWS2
3 files changed, 31 insertions, 10 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 12263b3..eac9950 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -1336,16 +1336,32 @@ 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 = urllib2.HTTPError(msg='something bad happened', url=None, code=None, hdrs=None, fp=None)
- >>> assert hasattr(err, 'reason')
- >>> err.reason
- 'something bad happened'
- """
+ def test_HTTPError_interface(self):
+ """
+ Issue 13211 reveals that HTTPError didn't implement the URLError
+ interface even though HTTPError is a subclass of URLError.
+
+ >>> err = urllib2.HTTPError(msg='something bad happened', url=None, code=None, hdrs=None, fp=None)
+ >>> assert hasattr(err, 'reason')
+ >>> err.reason
+ 'something bad happened'
+ """
+
+ def test_HTTPError_interface_call(self):
+ """
+ Issue 15701= - HTTPError interface has info method available from URLError.
+ """
+ err = urllib2.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() failed")
+ self.assertEqual(err.info(), "Content-Length:42")
def test_main(verbose=None):
from test import test_urllib2
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index ebf5811..aadeb73 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -173,6 +173,9 @@ class HTTPError(URLError, addinfourl):
def reason(self):
return self.msg
+ def info(self):
+ return self.hdrs
+
# copied from cookielib.py
_cut_port_re = re.compile(r":\d+$")
def request_host(request):
diff --git a/Misc/NEWS b/Misc/NEWS
index babe838..c017257 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -165,6 +165,8 @@ Library
- Issue #16597: In buffered and text IO, call close() on the underlying stream
if invoking flush() fails.
+- Issue #15701: Fix HTTPError info method call to return the headers information.
+
- Issue #16646: ftplib.FTP.makeport() might lose socket error details.
(patch by Serhiy Storchaka)