Skip to content

Commit cfcacf3

Browse files
authored
Make python code compatible with urllib3 v2.6.0+ (#22520)
openapi-generator still uses methods that have been removed from urllib3 v2.6.0. The solution is as described in urllib3's changelog: > Removed the HTTPResponse.getheaders() method in favor of > HTTPResponse.headers. Removed the HTTPResponse.getheader(name, > default) method in favor of HTTPResponse.headers.get(name, default). > (#3622) See https://urllib3.readthedocs.io/en/latest/changelog.html Close #22514
1 parent 5a6fcd3 commit cfcacf3

File tree

28 files changed

+154
-226
lines changed

28 files changed

+154
-226
lines changed

modules/openapi-generator/src/main/resources/python/api_client.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ class ApiClient:
321321
return_data = self.__deserialize_file(response_data)
322322
elif response_type is not None:
323323
match = None
324-
content_type = response_data.getheader('content-type')
324+
content_type = response_data.headers.get('content-type')
325325
if content_type is not None:
326326
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
327327
encoding = match.group(1) if match else "utf-8"
@@ -338,7 +338,7 @@ class ApiClient:
338338
return ApiResponse(
339339
status_code = response_data.status,
340340
data = return_data,
341-
headers = response_data.getheaders(),
341+
headers = response_data.headers,
342342
raw_data = response_data.data
343343
)
344344

@@ -719,7 +719,7 @@ class ApiClient:
719719
os.close(fd)
720720
os.remove(path)
721721

722-
content_disposition = response.getheader("Content-Disposition")
722+
content_disposition = response.headers.get("Content-Disposition")
723723
if content_disposition:
724724
m = re.search(
725725
r'filename=[\'"]?([^\'"\s]+)[\'"]?',

modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@ class RESTResponse(io.IOBase):
3131
self.data = await self.response.read()
3232
return self.data
3333

34+
@property
35+
def headers(self):
36+
"""Returns a CIMultiDictProxy of response headers."""
37+
return self.response.headers
38+
3439
def getheaders(self):
35-
"""Returns a CIMultiDictProxy of the response headers."""
40+
"""Returns a CIMultiDictProxy of the response headers; use ``headers`` instead."""
3641
return self.response.headers
3742

3843
def getheader(self, name, default=None):
39-
"""Returns a given response header."""
44+
"""Returns a given response header; use ``headers.get()`` instead."""
4045
return self.response.headers.get(name, default)
4146

4247

modules/openapi-generator/src/main/resources/python/exceptions.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ApiException(OpenApiException):
119119
self.body = http_resp.data.decode('utf-8')
120120
except Exception:
121121
pass
122-
self.headers = http_resp.getheaders()
122+
self.headers = http_resp.headers
123123

124124
@classmethod
125125
def from_response(

modules/openapi-generator/src/main/resources/python/httpx/rest.mustache

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ class RESTResponse(io.IOBase):
2828
self.data = await self.response.aread()
2929
return self.data
3030

31+
@property
32+
def headers(self):
33+
"""Returns a CIMultiDictProxy of response headers."""
34+
return self.response.headers
35+
3136
def getheaders(self):
32-
"""Returns a CIMultiDictProxy of the response headers."""
37+
"""Returns a CIMultiDictProxy of the response headers; use ``headers`` instead."""
3338
return self.response.headers
3439

3540
def getheader(self, name, default=None):
36-
"""Returns a given response header."""
41+
"""Returns a given response header; use ``headers`` instead."""
3742
return self.response.headers.get(name, default)
3843

3944

modules/openapi-generator/src/main/resources/python/rest.mustache

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ class RESTResponse(io.IOBase):
3939
self.data = self.response.data
4040
return self.data
4141

42+
@property
43+
def headers(self):
44+
"""Returns a dictionary of response headers."""
45+
return self.response.headers
46+
4247
def getheaders(self):
43-
"""Returns a dictionary of the response headers."""
48+
"""Returns a dictionary of the response headers; use ``headers`` instead."""
4449
return self.response.headers
4550

4651
def getheader(self, name, default=None):
47-
"""Returns a given response header."""
52+
"""Returns a given response header; use ``headers.get()`` instead."""
4853
return self.response.headers.get(name, default)
4954

5055

modules/openapi-generator/src/main/resources/python/tornado/rest.mustache

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ class RESTResponse(io.IOBase):
3030
self.data = self.response.body
3131
return self.data
3232

33+
@property
34+
def headers(self):
35+
"""Returns a CIMultiDictProxy of response headers."""
36+
return self.response.headers
37+
3338
def getheaders(self):
34-
"""Returns a CIMultiDictProxy of the response headers."""
39+
"""Returns a CIMultiDictProxy of the response headers; use ``headers`` instead."""
3540
return self.response.headers
3641

3742
def getheader(self, name, default=None):
38-
"""Returns a given response header."""
43+
"""Returns a given response header; use ``headers`` instead."""
3944
return self.response.headers.get(name, default)
4045

4146

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def response_deserialize(
313313
return_data = self.__deserialize_file(response_data)
314314
elif response_type is not None:
315315
match = None
316-
content_type = response_data.getheader('content-type')
316+
content_type = response_data.headers.get('content-type')
317317
if content_type is not None:
318318
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
319319
encoding = match.group(1) if match else "utf-8"
@@ -330,7 +330,7 @@ def response_deserialize(
330330
return ApiResponse(
331331
status_code = response_data.status,
332332
data = return_data,
333-
headers = response_data.getheaders(),
333+
headers = response_data.headers,
334334
raw_data = response_data.data
335335
)
336336

@@ -702,7 +702,7 @@ def __deserialize_file(self, response):
702702
os.close(fd)
703703
os.remove(path)
704704

705-
content_disposition = response.getheader("Content-Disposition")
705+
content_disposition = response.headers.get("Content-Disposition")
706706
if content_disposition:
707707
m = re.search(
708708
r'filename=[\'"]?([^\'"\s]+)[\'"]?',

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def __init__(
129129
self.body = http_resp.data.decode('utf-8')
130130
except Exception:
131131
pass
132-
self.headers = http_resp.getheaders()
132+
self.headers = http_resp.headers
133133

134134
@classmethod
135135
def from_response(

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/rest.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@ def read(self):
4949
self.data = self.response.data
5050
return self.data
5151

52+
@property
53+
def headers(self):
54+
"""Returns a dictionary of response headers."""
55+
return self.response.headers
56+
5257
def getheaders(self):
53-
"""Returns a dictionary of the response headers."""
58+
"""Returns a dictionary of the response headers; use ``headers`` instead."""
5459
return self.response.headers
5560

5661
def getheader(self, name, default=None):
57-
"""Returns a given response header."""
62+
"""Returns a given response header; use ``headers.get()`` instead."""
5863
return self.response.headers.get(name, default)
5964

6065

samples/client/echo_api/python/openapi_client/api_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def response_deserialize(
313313
return_data = self.__deserialize_file(response_data)
314314
elif response_type is not None:
315315
match = None
316-
content_type = response_data.getheader('content-type')
316+
content_type = response_data.headers.get('content-type')
317317
if content_type is not None:
318318
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
319319
encoding = match.group(1) if match else "utf-8"
@@ -330,7 +330,7 @@ def response_deserialize(
330330
return ApiResponse(
331331
status_code = response_data.status,
332332
data = return_data,
333-
headers = response_data.getheaders(),
333+
headers = response_data.headers,
334334
raw_data = response_data.data
335335
)
336336

@@ -702,7 +702,7 @@ def __deserialize_file(self, response):
702702
os.close(fd)
703703
os.remove(path)
704704

705-
content_disposition = response.getheader("Content-Disposition")
705+
content_disposition = response.headers.get("Content-Disposition")
706706
if content_disposition:
707707
m = re.search(
708708
r'filename=[\'"]?([^\'"\s]+)[\'"]?',

0 commit comments

Comments
 (0)