Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions kubernetes/client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ def __call_api(
if _return_http_data_only:
return (return_data)
else:
return (return_data, response_data.status,
response_data.getheaders())
return (return_data, response_data.status, response_data.headers)

def sanitize_for_serialization(self, obj):
"""Builds a JSON POST object.
Expand Down Expand Up @@ -547,7 +546,7 @@ def __deserialize_file(self, response):
os.close(fd)
os.remove(path)

content_disposition = response.getheader("Content-Disposition")
content_disposition = response.headers.get("Content-Disposition")
if content_disposition:
filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
content_disposition).group(1)
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/client/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__(self, status=None, reason=None, http_resp=None):
self.status = http_resp.status
self.reason = http_resp.reason
self.body = http_resp.data
self.headers = http_resp.getheaders()
self.headers = http_resp.headers
else:
self.status = status
self.reason = reason
Expand Down
12 changes: 9 additions & 3 deletions kubernetes/client/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import logging
import re
import ssl
import warnings

import certifi
# python 2 and python 3 compatibility library
Expand All @@ -39,13 +40,18 @@ def __init__(self, resp):
self.reason = resp.reason
self.data = resp.data

def getheaders(self):
def headers(self):
"""Returns a dictionary of the response headers."""
return self.urllib3_response.getheaders()
return self.urllib3_response.headers

def getheader(self, name, default=None):
"""Returns a given response header."""
return self.urllib3_response.getheader(name, default)
warnings.warn(
'RESTResponse.getheader() has been deprecated in favour of '
'RESTResponse.headers.get(name, default)',
DeprecationWarning,
)
return self.urllib3_response.headers.get(name, default)


class RESTClientObject(object):
Expand Down
70 changes: 70 additions & 0 deletions scripts/rest_urllib_3x.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
diff --git a/kubernetes/client/api_client.py b/kubernetes/client/api_client.py
index 814ee8be4..1bb97047c 100644
--- a/kubernetes/client/api_client.py
+++ b/kubernetes/client/api_client.py
@@ -196,8 +196,7 @@ class ApiClient(object):
if _return_http_data_only:
return (return_data)
else:
- return (return_data, response_data.status,
- response_data.getheaders())
+ return (return_data, response_data.status, response_data.headers)

def sanitize_for_serialization(self, obj):
"""Builds a JSON POST object.
@@ -547,7 +546,7 @@ class ApiClient(object):
os.close(fd)
os.remove(path)

- content_disposition = response.getheader("Content-Disposition")
+ content_disposition = response.headers.get("Content-Disposition")
if content_disposition:
filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
content_disposition).group(1)
diff --git a/kubernetes/client/exceptions.py b/kubernetes/client/exceptions.py
index 51856fac2..398d88a50 100644
--- a/kubernetes/client/exceptions.py
+++ b/kubernetes/client/exceptions.py
@@ -88,7 +88,7 @@ class ApiException(OpenApiException):
self.status = http_resp.status
self.reason = http_resp.reason
self.body = http_resp.data
- self.headers = http_resp.getheaders()
+ self.headers = http_resp.headers
else:
self.status = status
self.reason = reason
diff --git a/kubernetes/client/rest.py b/kubernetes/client/rest.py
index bb97dfe3c..d56c4bf04 100644
--- a/kubernetes/client/rest.py
+++ b/kubernetes/client/rest.py
@@ -17,6 +17,7 @@ import json
import logging
import re
import ssl
+import warnings

import certifi
# python 2 and python 3 compatibility library
@@ -39,13 +40,18 @@ class RESTResponse(io.IOBase):
self.reason = resp.reason
self.data = resp.data

- def getheaders(self):
+ def headers(self):
"""Returns a dictionary of the response headers."""
- return self.urllib3_response.getheaders()
+ return self.urllib3_response.headers

def getheader(self, name, default=None):
"""Returns a given response header."""
- return self.urllib3_response.getheader(name, default)
+ warnings.warn(
+ 'RESTResponse.getheader() has been deprecated in favour of '
+ 'RESTResponse.headers.get(name, default)',
+ DeprecationWarning,
+ )
+ return self.urllib3_response.headers.get(name, default)


class RESTClientObject(object):
13 changes: 0 additions & 13 deletions scripts/rest_urllib_headers.diff

This file was deleted.

7 changes: 3 additions & 4 deletions scripts/update-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ git apply "${SCRIPT_ROOT}/rest_client_patch.diff"
# once we upgrade to a version of swagger-codegen that includes it (version>= 6.6.0).
# See https://github.com/OpenAPITools/openapi-generator/pull/15283
git apply "${SCRIPT_ROOT}/rest_sni_patch.diff"
# The following is commented out due to:
# AttributeError: 'RESTResponse' object has no attribute 'headers'
# OpenAPI client generator prior to 6.4.0 uses deprecated urllib3 APIs.
# git apply "${SCRIPT_ROOT}/rest_urllib_headers.diff"
# This patch removes use of deprecated functionality in urllib 3.x. Once again,
# this won't be necessary once we bump swagger-codegen.
git apply "${SCRIPT_ROOT}/rest_urllib_3x.diff"

echo ">>> generating docs..."
pushd "${DOC_ROOT}" > /dev/null
Expand Down