Skip to content
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion examples/pod_portforward.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import socket
import time

import six.moves.urllib.request as urllib_request
import urllib.request as urllib_request

from kubernetes import config
from kubernetes.client import Configuration
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This Python package is automatically generated by the [OpenAPI Generator](https:

## Requirements.

Python 2.7 and 3.4+
Python 3.6+

## Installation & Usage
### pip install
Expand Down
23 changes: 6 additions & 17 deletions kubernetes/base/config/kube_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import urllib3
import yaml
from requests_oauthlib import OAuth2Session
from six import PY3

from kubernetes.client import ApiClient, Configuration
from kubernetes.config.exec_provider import ExecProvider
Expand Down Expand Up @@ -413,14 +412,9 @@ def _load_oid_token(self, provider):
# https://tools.ietf.org/html/rfc7515#appendix-C
return

if PY3:
jwt_attributes = json.loads(
base64.urlsafe_b64decode(parts[1] + padding).decode('utf-8')
)
else:
jwt_attributes = json.loads(
base64.b64decode(parts[1] + padding)
)
jwt_attributes = json.loads(
base64.urlsafe_b64decode(parts[1] + padding).decode('utf-8')
)

expire = jwt_attributes.get('exp')

Expand All @@ -442,14 +436,9 @@ def _refresh_oidc(self, provider):
if 'idp-certificate-authority-data' in provider['config']:
ca_cert = tempfile.NamedTemporaryFile(delete=True)

if PY3:
cert = base64.b64decode(
provider['config']['idp-certificate-authority-data']
).decode('utf-8')
else:
cert = base64.b64decode(
provider['config']['idp-certificate-authority-data'] + "=="
)
cert = base64.b64decode(
provider['config']['idp-certificate-authority-data']
).decode('utf-8')

with open(ca_cert.name, 'w') as fh:
fh.write(cert)
Expand Down
9 changes: 2 additions & 7 deletions kubernetes/base/config/kube_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

from unittest import mock
import yaml
from six import PY3, next

from kubernetes.client import Configuration

Expand Down Expand Up @@ -1440,12 +1439,8 @@ def test_list_kube_config_contexts(self):
config_file=config_file)
self.assertDictEqual(self.TEST_KUBE_CONFIG['contexts'][0],
active_context)
if PY3:
self.assertCountEqual(self.TEST_KUBE_CONFIG['contexts'],
contexts)
else:
self.assertItemsEqual(self.TEST_KUBE_CONFIG['contexts'],
contexts)
self.assertCountEqual(self.TEST_KUBE_CONFIG['contexts'],
contexts)

def test_new_client_from_config(self):
config_file = self._create_temp_file(
Expand Down
5 changes: 0 additions & 5 deletions kubernetes/base/dynamic/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import six
import json

from kubernetes import watch
Expand Down Expand Up @@ -57,12 +56,8 @@ def inner(self, *args, **kwargs):
raise api_exception(e)
if serialize_response:
try:
if six.PY2:
return serializer(self, json.loads(resp.data))
return serializer(self, json.loads(resp.data.decode('utf8')))
except ValueError:
if six.PY2:
return resp.data
return resp.data.decode('utf8')
return resp

Expand Down
6 changes: 2 additions & 4 deletions kubernetes/base/dynamic/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

import os
import six
import json
import logging
import hashlib
Expand Down Expand Up @@ -44,8 +43,7 @@ class Discoverer(object):
def __init__(self, client, cache_file):
self.client = client
default_cache_id = self.client.configuration.host
if six.PY3:
default_cache_id = default_cache_id.encode('utf-8')
default_cache_id = default_cache_id.encode('utf-8')
try:
default_cachefile_name = 'osrcp-{0}.json'.format(hashlib.md5(default_cache_id, usedforsecurity=False).hexdigest())
except TypeError:
Expand Down Expand Up @@ -313,7 +311,7 @@ def __iter__(self):
prefix, group, version, rg.preferred)
self._cache['resources'][prefix][group][version] = rg
self.__update_cache = True
for _, resource in six.iteritems(rg.resources):
for _, resource in rg.resources.items():
yield resource
self.__maybe_write_cache()

Expand Down
20 changes: 10 additions & 10 deletions kubernetes/base/stream/ws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
import threading
import time

import six
import yaml


from six.moves.urllib.parse import urlencode, urlparse, urlunparse
from six import StringIO, BytesIO
from urllib.parse import urlencode, urlparse, urlunparse
from io import StringIO, BytesIO

from websocket import WebSocket, ABNF, enableTrace, WebSocketConnectionClosedException
from base64 import urlsafe_b64decode
Expand All @@ -40,6 +39,7 @@
ERROR_CHANNEL = 3
RESIZE_CHANNEL = 4


class _IgnoredIO:
def write(self, _x):
pass
Expand Down Expand Up @@ -109,12 +109,12 @@ def readline_channel(self, channel, timeout=None):
def write_channel(self, channel, data):
"""Write data to a channel."""
# check if we're writing binary data or not
binary = six.PY3 and type(data) == six.binary_type
binary = type(data) is bytes
opcode = ABNF.OPCODE_BINARY if binary else ABNF.OPCODE_TEXT

channel_prefix = chr(channel)
if binary:
channel_prefix = six.binary_type(channel_prefix, "ascii")
channel_prefix = channel_prefix.encode("ascii")

payload = channel_prefix + data
self.sock.send(payload, opcode=opcode)
Expand Down Expand Up @@ -200,11 +200,11 @@ def update(self, timeout=0):
return
elif op_code == ABNF.OPCODE_BINARY or op_code == ABNF.OPCODE_TEXT:
data = frame.data
if six.PY3 and not self.binary:
if not self.binary:
data = data.decode("utf-8", "replace")
if len(data) > 1:
channel = data[0]
if six.PY3 and not self.binary:
if not self.binary:
channel = ord(channel)
data = data[1:]
if data:
Expand Down Expand Up @@ -303,7 +303,7 @@ def __init__(self, ix, port_number):
# The remote port number
self.port_number = port_number
# The websocket channel byte number for this port
self.channel = six.int2byte(ix * 2)
self.channel = bytes([ix * 2])
# A socket pair is created to provide a means of translating the data flow
# between the python application and the kubernetes websocket. The self.python
# half of the socket pair is used by the _proxy method to receive and send data
Expand Down Expand Up @@ -388,7 +388,7 @@ def _proxy(self):
if opcode == ABNF.OPCODE_BINARY:
if not frame.data:
raise RuntimeError("Unexpected frame data size")
channel = six.byte2int(frame.data)
channel = frame.data[0] if frame.data else None
if channel >= len(channel_ports):
raise RuntimeError("Unexpected channel number: %s" % channel)
port = channel_ports[channel]
Expand All @@ -405,7 +405,7 @@ def _proxy(self):
raise RuntimeError(
"Unexpected initial channel frame data size"
)
port_number = six.byte2int(frame.data[1:2]) + (six.byte2int(frame.data[2:3]) * 256)
port_number = frame.data[1] + (frame.data[2] * 256)
if port_number != port.port_number:
raise RuntimeError(
"Unexpected port number in initial channel frame: %s" % port_number
Expand Down
4 changes: 1 addition & 3 deletions kubernetes/client/api/admissionregistration_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import re # noqa: F401

# python 2 and python 3 compatibility library
import six

from kubernetes.client.api_client import ApiClient
from kubernetes.client.exceptions import ( # noqa: F401
Expand Down Expand Up @@ -97,7 +95,7 @@ def get_api_group_with_http_info(self, **kwargs): # noqa: E501
]
)

for key, val in six.iteritems(local_var_params['kwargs']):
for key, val in local_var_params['kwargs'].items():
if key not in all_params:
raise ApiTypeError(
"Got an unexpected keyword argument '%s'"
Expand Down
Loading