From 9cd7379abb0219d03947c50f7971d7753034e66a Mon Sep 17 00:00:00 2001 From: Alexandr Mitin Date: Fri, 30 Aug 2024 21:45:12 +0600 Subject: [PATCH 1/6] Replacing deprecated members from urllib/request --- Lib/urllib/request.py | 5 ++--- Misc/ACKS | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index bc35d8a80e5d03..e92241f84ee698 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -596,7 +596,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. @@ -1336,8 +1336,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 diff --git a/Misc/ACKS b/Misc/ACKS index b031eb7c11f73f..129f952de6b580 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1252,6 +1252,7 @@ Dustin J. Mitchell Gideon Mitchell Tim Mitchell Zubin Mithra +Alexandr Mitin Florian Mladitsch Kevin Modzelewski Doug Moen From 343cd787c1b586431603a599e373851c9c2617f5 Mon Sep 17 00:00:00 2001 From: Alexandr Mitin Date: Fri, 30 Aug 2024 23:32:21 +0600 Subject: [PATCH 2/6] Fix error with tests --- Lib/test/test_urllib2.py | 5 +++-- Lib/urllib/request.py | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 19179fdc9508ca..812c93ddc3befe 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -301,9 +301,10 @@ def getheaders(self, name): class MockResponse(io.StringIO): - def __init__(self, code, msg, headers, data, url=None): + def __init__(self, status, 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 = status, msg, headers, url + def info(self): return self.headers diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index e92241f84ee698..816138d4631ba5 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -596,13 +596,13 @@ class HTTPErrorProcessor(BaseHandler): handler_order = 1000 # after all other processing def http_response(self, request, response): - code, msg, hdrs = response.status, response.msg, response.headers + status, 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. - if not (200 <= code < 300): + if not (200 <= status < 300): response = self.parent.error( - 'http', request, response, code, msg, hdrs) + 'http', request, response, status, msg, hdrs) return response @@ -1007,7 +1007,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) From fe3bb0e34a96db6432b40f97e931488645272b68 Mon Sep 17 00:00:00 2001 From: Alexandr Mitin Date: Fri, 30 Aug 2024 23:39:00 +0600 Subject: [PATCH 3/6] Rename some literals --- Lib/test/test_urllib2.py | 4 ++-- Lib/urllib/request.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 812c93ddc3befe..8a4bee9a037f5b 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -301,9 +301,9 @@ def getheaders(self, name): class MockResponse(io.StringIO): - def __init__(self, status, msg, headers, data, url=None): + def __init__(self, code, msg, headers, data, url=None): io.StringIO.__init__(self, data) - self.status, self.msg, self.headers, self.url = status, msg, headers, url + self.status, self.msg, self.headers, self.url = code, msg, headers, url def info(self): diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 816138d4631ba5..bd13172ad316fa 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -596,13 +596,13 @@ class HTTPErrorProcessor(BaseHandler): handler_order = 1000 # after all other processing def http_response(self, request, response): - status, msg, hdrs = response.status, response.msg, response.headers + 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. - if not (200 <= status < 300): + if not (200 <= code < 300): response = self.parent.error( - 'http', request, response, status, msg, hdrs) + 'http', request, response, code, msg, hdrs) return response From 1be4238c6dbee5d02d65c71a5a628ac89ce0a279 Mon Sep 17 00:00:00 2001 From: Alexandr Mitin Date: Sat, 31 Aug 2024 01:16:50 +0600 Subject: [PATCH 4/6] Work with info() --- Lib/urllib/request.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index bd13172ad316fa..bf5d101d2a39ea 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -212,7 +212,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. @@ -1788,14 +1788,14 @@ def retrieve(self, url, filename=None, reporthook=None, data=None): if filename is None and (not type or type == 'file'): try: fp = self.open_local_file(url1) - hdrs = fp.info() + hdrs = fp.status fp.close() return url2pathname(_splithost(url1)[1]), hdrs except OSError: pass fp = self.open(url, data) try: - headers = fp.info() + headers = fp.status if filename: tfp = open(filename, 'wb') else: From e22fc32209fff280c88c828aef2c9a8a22ac70fb Mon Sep 17 00:00:00 2001 From: Alexandr Mitin Date: Sat, 31 Aug 2024 02:07:07 +0600 Subject: [PATCH 5/6] Fix --- Lib/urllib/request.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index bf5d101d2a39ea..2f1ce396e4e51d 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1788,14 +1788,14 @@ def retrieve(self, url, filename=None, reporthook=None, data=None): if filename is None and (not type or type == 'file'): try: fp = self.open_local_file(url1) - hdrs = fp.status + hdrs = fp.headers fp.close() return url2pathname(_splithost(url1)[1]), hdrs except OSError: pass fp = self.open(url, data) try: - headers = fp.status + headers = fp.headers if filename: tfp = open(filename, 'wb') else: From 8e00b4b855ff373ec4ed519c7c15ee2e87fb0d72 Mon Sep 17 00:00:00 2001 From: Alexandr Mitin <64941904+Alexandr153@users.noreply.github.com> Date: Sat, 31 Aug 2024 12:48:53 +0600 Subject: [PATCH 6/6] Update Lib/test/test_urllib2.py Co-authored-by: Kirill Podoprigora --- Lib/test/test_urllib2.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 8a4bee9a037f5b..e3fc9446bbe09c 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -305,7 +305,6 @@ def __init__(self, code, msg, headers, data, url=None): io.StringIO.__init__(self, data) self.status, self.msg, self.headers, self.url = code, msg, headers, url - def info(self): return self.headers