bpo-12707: deprecate info(), geturl(), getcode() methods in favor of headers, url, and status properties for HTTPResponse and addinfourl (GH-11447)
Co-Authored-By: epicfaace <aramaswamis@gmail.com>
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index 8895421..9a6b5f6 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -194,6 +194,15 @@
# by the tearDown() method for the test
self.returned_obj.close()
+ def test_headers(self):
+ self.assertIsInstance(self.returned_obj.headers, email.message.Message)
+
+ def test_url(self):
+ self.assertEqual(self.returned_obj.url, self.pathname)
+
+ def test_status(self):
+ self.assertIsNone(self.returned_obj.status)
+
def test_info(self):
self.assertIsInstance(self.returned_obj.info(), email.message.Message)
diff --git a/Lib/test/test_urllib_response.py b/Lib/test/test_urllib_response.py
index 0eb5942..73d2ef0 100644
--- a/Lib/test/test_urllib_response.py
+++ b/Lib/test/test_urllib_response.py
@@ -42,6 +42,7 @@
def test_addinfo(self):
info = urllib.response.addinfo(self.fp, self.test_headers)
self.assertEqual(info.info(), self.test_headers)
+ self.assertEqual(info.headers, self.test_headers)
def test_addinfourl(self):
url = "http://www.python.org"
@@ -51,6 +52,9 @@
self.assertEqual(infourl.info(), self.test_headers)
self.assertEqual(infourl.geturl(), url)
self.assertEqual(infourl.getcode(), code)
+ self.assertEqual(infourl.headers, self.test_headers)
+ self.assertEqual(infourl.url, url)
+ self.assertEqual(infourl.status, code)
def tearDown(self):
self.sock.close()
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index f6ce9cb..267a90d 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -163,18 +163,10 @@
The *cadefault* parameter is ignored.
- This function always returns an object which can work as a context
- manager and has methods such as
- * geturl() - return the URL of the resource retrieved, commonly used to
- determine if a redirect was followed
-
- * info() - return the meta-information of the page, such as headers, in the
- form of an email.message_from_string() instance (see Quick Reference to
- HTTP Headers)
-
- * getcode() - return the HTTP status code of the response. Raises URLError
- on errors.
+ This function always returns an object which can work as a
+ context manager and has the properties url, headers, and status.
+ See urllib.response.addinfourl for more detail on these properties.
For HTTP and HTTPS URLs, this function returns a http.client.HTTPResponse
object slightly modified. In addition to the three new methods above, the
diff --git a/Lib/urllib/response.py b/Lib/urllib/response.py
index 4778118..5a2c3cc 100644
--- a/Lib/urllib/response.py
+++ b/Lib/urllib/response.py
@@ -73,6 +73,10 @@
self.url = url
self.code = code
+ @property
+ def status(self):
+ return self.code
+
def getcode(self):
return self.code