Skip to content

gh-123503: Replace usages of addinfourl and HTTPResponse deprecated attributes with stable ones #132670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/test/test_urllib2.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def getheaders(self, name):
class MockResponse(io.StringIO):
def __init__(self, code, msg, headers, data, url=None):
io.StringIO.__init__(self, data)
self.code, self.msg, self.headers, self.url = code, msg, headers, url
self.status, self.msg, self.headers, self.url = code, msg, headers, url

def info(self):
return self.headers
Expand Down
9 changes: 4 additions & 5 deletions Lib/urllib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def urlretrieve(url, filename=None, reporthook=None, data=None):
url_type, path = _splittype(url)

with contextlib.closing(urlopen(url, data)) as fp:
headers = fp.info()
headers = fp.headers

# Just return the local path and the "headers" for file://
# URLs. No sense in performing a copy unless requested.
Expand Down Expand Up @@ -594,7 +594,7 @@ class HTTPErrorProcessor(BaseHandler):
handler_order = 1000 # after all other processing

def http_response(self, request, response):
code, msg, hdrs = response.code, response.msg, response.info()
code, msg, hdrs = response.status, response.msg, response.headers

# According to RFC 2616, "2xx" code indicates that the client's
# request was successfully received, understood, and accepted.
Expand Down Expand Up @@ -1006,7 +1006,7 @@ def http_request(self, req):

def http_response(self, req, response):
if hasattr(self.passwd, 'is_authenticated'):
if 200 <= response.code < 300:
if 200 <= response.status < 300:
self.passwd.update_authenticated(req.full_url, True)
else:
self.passwd.update_authenticated(req.full_url, False)
Expand Down Expand Up @@ -1338,8 +1338,7 @@ def do_open(self, http_class, req, **http_conn_args):
# This line replaces the .msg attribute of the HTTPResponse
# with .headers, because urllib clients expect the response to
# have the reason in .msg. It would be good to mark this
# attribute is deprecated and get then to use info() or
# .headers.
# attribute is deprecated and get then to use .headers.
r.msg = r.reason
return r

Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,7 @@ Dustin J. Mitchell
Gideon Mitchell
Tim Mitchell
Zubin Mithra
Alexandr Mitin
Florian Mladitsch
Kevin Modzelewski
Doug Moen
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Subsitute internal usages of deprecated attributes :attr:`addinfourl.code
<urllib.response.addinfourl.code>` and :meth:`HTTPResponse.info
<http.client.HTTPResponse.info>` for their recommended equivalents
(:attr:`addinfourl.status <urllib.response.addinfourl.status>` and
:attr::`HTTPResponse.headers <http.client.HTTPResponse.headers>`),
while retaining backwards compatibility.
Loading