Skip to content

Commit 36cea8d

Browse files
Add support for urllib3 version 2.0
1 parent a2e148d commit 36cea8d

14 files changed

+359
-365
lines changed

cloudinary/api_client/execute_request.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ def execute_request(http_connector, method, params, headers, auth, api_url, **op
6363
processed_params = process_params(params)
6464

6565
api_url = smart_escape(unquote(api_url))
66-
6766
try:
68-
response = http_connector.request(method.upper(), api_url, processed_params, req_headers, **kw)
67+
response = http_connector.request(method=method.upper(), url=api_url, fields=processed_params, headers=req_headers, **kw)
6968
body = response.data
7069
except HTTPError as e:
7170
raise GeneralError("Unexpected error %s" % str(e))

cloudinary/http_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _http_client(self):
2424

2525
def get_json(self, url):
2626
try:
27-
response = self._http_client.request("GET", url, timeout=self.timeout)
27+
response = self._http_client.request(method="GET", url=url, timeout=self.timeout)
2828
body = response.data
2929
except HTTPError as e:
3030
raise GeneralError("Unexpected error %s" % str(e))

cloudinary/uploader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def call_api(action, params, http_headers=None, return_error=False, unsigned=Fal
506506

507507
code = 200
508508
try:
509-
response = _http.request("POST", api_url, param_list, headers, **kw)
509+
response = _http.request(method="POST", url=api_url, fields=param_list, headers=headers, **kw)
510510
except HTTPError as e:
511511
raise Error("Unexpected error - {0!r}".format(e))
512512
except socket.error as e:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
test_suite="test",
6161
install_requires=[
6262
"six",
63-
"urllib3>=1.26.5,<2",
63+
"urllib3>=1.26.5",
6464
"certifi"
6565
],
6666
tests_require=[

test/helper_test.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@
4444

4545
ON_SUCCESS_STR = 'current_asset.update({tags: ["autocaption"]});'
4646

47+
try:
48+
# urllib3 2.x support
49+
# noinspection PyProtectedMember
50+
import urllib3._request_methods
51+
URLLIB3_REQUEST = "urllib3._request_methods.RequestMethods.request"
52+
except ImportError:
53+
URLLIB3_REQUEST = "urllib3.request.RequestMethods.request"
54+
55+
4756
class UTC(tzinfo):
4857
"""UTC"""
4958

@@ -58,22 +67,18 @@ def dst(self, dt):
5867

5968

6069
def get_method(mocker):
61-
return mocker.call_args[0][0]
62-
63-
64-
def get_request_url(mocker):
65-
return mocker.call_args[0][1]
70+
return mocker.call_args[1]["method"]
6671

6772

68-
def get_uri(args):
69-
return args[1]
73+
def get_uri(mocker):
74+
return mocker.call_args[1]["url"]
7075

7176

72-
def get_headers(args):
73-
return args[3] if len(args) > 3 else tuple()
77+
def get_headers(mocker):
78+
return mocker.call_args[1]["headers"]
7479

7580

76-
def get_params(args):
81+
def get_params(mocker):
7782
"""
7883
Extracts query parameters from mocked urllib3.request `fields` param.
7984
Supports both list and dict values of `fields`. Returns params as dictionary.
@@ -82,11 +87,12 @@ def get_params(args):
8287
- [("urls[]", "http://host1"), ("urls[]", "http://host2")]
8388
In both cases the result would be {"urls": ["http://host1", "http://host2"]}
8489
"""
85-
if not args or not args[2]:
90+
if not mocker.call_args[1].get("fields"):
8691
return {}
8792
params = {}
8893
reg = re.compile(r'^(.*)\[\d*]$')
89-
fields = args[2].items() if isinstance(args[2], dict) else args[2]
94+
fields = mocker.call_args[1].get("fields")
95+
fields = fields.items() if isinstance(fields, dict) else fields
9096
for k, v in fields:
9197
match = reg.match(k)
9298
if match:
@@ -110,8 +116,7 @@ def get_param(mocker, name):
110116
:param name: the name of the parameter
111117
:return: the value of the parameter if present or None
112118
"""
113-
args, kargs = mocker.call_args
114-
params = get_params(args)
119+
params = get_params(mocker)
115120
return params.get(name)
116121

117122

0 commit comments

Comments
 (0)