From 69125bfd07398245480e783415352a2ed0c5ee92 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 17 May 2022 17:22:01 +0900 Subject: Remove six Python 2 is no longer supported, so we no longer need the six library. This change removes usage of the library as well as reference to it (and Python 2) from the documentation. Change-Id: I6328b11dcad54f70f64ecff53eb60708e34351cf --- barbicanclient/tests/test_barbican.py | 6 +++--- barbicanclient/tests/v1/test_containers.py | 3 +-- barbicanclient/tests/v1/test_secrets.py | 12 ++---------- barbicanclient/v1/orders.py | 4 +--- barbicanclient/v1/secrets.py | 21 ++++++++++----------- doc/source/cli/usage.rst | 14 +++++++------- functionaltests/cli/v1/behaviors/base_behaviors.py | 6 +++--- functionaltests/utils.py | 9 ++++----- requirements.txt | 1 - 9 files changed, 31 insertions(+), 45 deletions(-) diff --git a/barbicanclient/tests/test_barbican.py b/barbicanclient/tests/test_barbican.py index c34be55..71ce182 100644 --- a/barbicanclient/tests/test_barbican.py +++ b/barbicanclient/tests/test_barbican.py @@ -12,7 +12,7 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. -import six +import io from barbicanclient import barbican as barb from barbicanclient.barbican import Barbican @@ -26,8 +26,8 @@ class WhenTestingBarbicanCLI(test_client.BaseEntityResource): def setUp(self): self._setUp('barbican') - self.captured_stdout = six.StringIO() - self.captured_stderr = six.StringIO() + self.captured_stdout = io.StringIO() + self.captured_stderr = io.StringIO() self.barbican = Barbican( stdout=self.captured_stdout, stderr=self.captured_stderr diff --git a/barbicanclient/tests/v1/test_containers.py b/barbicanclient/tests/v1/test_containers.py index 3cbdd92..291a07e 100644 --- a/barbicanclient/tests/v1/test_containers.py +++ b/barbicanclient/tests/v1/test_containers.py @@ -17,7 +17,6 @@ from unittest import mock from oslo_serialization import jsonutils from oslo_utils import timeutils -import six from barbicanclient import base from barbicanclient.tests import test_client @@ -524,7 +523,7 @@ class WhenTestingContainers(test_client.BaseEntityResource): # Verify that the names of the secret_refs in the containers are None for container in containers_list: - for name in six.iterkeys(container._secret_refs): + for name in container._secret_refs.keys(): self.assertIsNone(name) def test_should_fail_get_invalid_container(self): diff --git a/barbicanclient/tests/v1/test_secrets.py b/barbicanclient/tests/v1/test_secrets.py index dcc2fdf..ef3f61b 100644 --- a/barbicanclient/tests/v1/test_secrets.py +++ b/barbicanclient/tests/v1/test_secrets.py @@ -93,7 +93,7 @@ class WhenTestingSecrets(test_client.BaseEntityResource): self.assertEqual(self.secret.payload, secret_req['payload']) def test_should_store_binary_type_as_octet_stream(self): - """We use six.binary_type as the canonical binary type. + """We use bytes as the canonical binary type. The client should base64 encode the payload before sending the request. @@ -101,8 +101,6 @@ class WhenTestingSecrets(test_client.BaseEntityResource): data = {'secret_ref': self.entity_href} self.responses.post(self.entity_base + '/', json=data) - # This literal will have type(str) in Python 2, but will have - # type(bytes) in Python 3. It is six.binary_type in both cases. binary_payload = b'F\x130\x89f\x8e\xd9\xa1\x0e\x1f\r\xf67uu\x8b' secret = self.manager.create() @@ -119,12 +117,10 @@ class WhenTestingSecrets(test_client.BaseEntityResource): self.assertNotEqual(binary_payload, secret_req['payload']) def test_should_store_text_type_as_text_plain(self): - """We use six.text_type as the canonical text type.""" + """We use unicode string as the canonical text type.""" data = {'secret_ref': self.entity_href} self.responses.post(self.entity_base + '/', json=data) - # This literal will have type(unicode) in Python 2, but will have - # type(str) in Python 3. It is six.text_type in both cases. text_payload = u'time for an ice cold \U0001f37a' secret = self.manager.create() @@ -448,8 +444,6 @@ class WhenTestingSecrets(test_client.BaseEntityResource): self.test_should_delete_from_object(self.entity_id) def test_should_update_from_manager(self, secret_ref=None): - # This literal will have type(unicode) in Python 2, but will have - # type(str) in Python 3. It is six.text_type in both cases. text_payload = u'time for an ice cold \U0001f37a' secret_ref = secret_ref or self.entity_href @@ -479,8 +473,6 @@ class WhenTestingSecrets(test_client.BaseEntityResource): # Verify the secret has the correct ref for testing updates self.assertEqual(secref_ref, secret.secret_ref) - # This literal will have type(unicode) in Python 2, but will have - # type(str) in Python 3. It is six.text_type in both cases. text_payload = u'time for an ice cold \U0001f37a' self.responses.put(self.entity_href, status_code=204) diff --git a/barbicanclient/v1/orders.py b/barbicanclient/v1/orders.py index aee762a..6b352c9 100644 --- a/barbicanclient/v1/orders.py +++ b/barbicanclient/v1/orders.py @@ -17,7 +17,6 @@ import functools import logging from oslo_utils.timeutils import parse_isotime -import six from barbicanclient import base from barbicanclient import formatter @@ -113,8 +112,7 @@ class CertificateOrderFormatter(formatter.EntityFormatter): return data -@six.add_metaclass(abc.ABCMeta) -class Order(object): +class Order(object, metaclass=abc.ABCMeta): """Base order object to hold common functionality This should be considered an abstract class that should not be diff --git a/barbicanclient/v1/secrets.py b/barbicanclient/v1/secrets.py index f4bc7ad..4a57860 100644 --- a/barbicanclient/v1/secrets.py +++ b/barbicanclient/v1/secrets.py @@ -17,7 +17,6 @@ import functools import logging from oslo_utils.timeutils import parse_isotime -import six from barbicanclient import base from barbicanclient import exceptions @@ -293,7 +292,7 @@ class Secret(SecretFormatter): } if self.payload is not None: - if not isinstance(self.payload, (six.text_type, six.binary_type)): + if not isinstance(self.payload, (str, bytes)): raise exceptions.PayloadException("Invalid Payload Type") if not len(self.payload): @@ -307,7 +306,7 @@ class Secret(SecretFormatter): for backwards compatibility and should be removed in a future release. ''' - if type(self.payload) is six.binary_type: + if type(self.payload) is bytes: secret_dict['payload'] = self.payload.decode('utf-8') else: secret_dict['payload'] = self.payload @@ -315,9 +314,9 @@ class Secret(SecretFormatter): secret_dict['payload_content_encoding'] = ( self.payload_content_encoding ) - elif type(self.payload) is six.binary_type: + elif type(self.payload) is bytes: ''' - six.binary_type is stored as application/octet-stream + bytes is stored as application/octet-stream and it is base64 encoded for a one-step POST ''' secret_dict['payload'] = ( @@ -325,9 +324,9 @@ class Secret(SecretFormatter): ).decode('UTF-8') secret_dict['payload_content_type'] = u'application/octet-stream' secret_dict['payload_content_encoding'] = u'base64' - elif type(self.payload) is six.text_type: + elif type(self.payload) is str: ''' - six.text_type is stored as text/plain + str is stored as text/plain ''' secret_dict['payload'] = self.payload secret_dict['payload_content_type'] = u'text/plain' @@ -350,9 +349,9 @@ class Secret(SecretFormatter): if not self.secret_ref: raise LookupError("Secret is not yet stored.") - if type(self.payload) is six.binary_type: + if type(self.payload) is bytes: headers = {'content-type': "application/octet-stream"} - elif type(self.payload) is six.text_type: + elif type(self.payload) is str: headers = {'content-type': "text/plain"} else: raise exceptions.PayloadException("Invalid Payload Type") @@ -479,9 +478,9 @@ class SecretManager(base.BaseEntityManager): if not secret_ref: raise ValueError('secret_ref is required.') - if type(payload) is six.binary_type: + if type(payload) is bytes: headers = {'content-type': "application/octet-stream"} - elif type(payload) is six.text_type: + elif type(payload) is str: headers = {'content-type': "text/plain"} else: raise exceptions.PayloadException("Invalid Payload Type") diff --git a/doc/source/cli/usage.rst b/doc/source/cli/usage.rst index 418f78b..dbbad60 100644 --- a/doc/source/cli/usage.rst +++ b/doc/source/cli/usage.rst @@ -78,13 +78,13 @@ correct Content Type based on the type of the data that is set on the `Secret.payload` property. The following table summarizes the mapping of Python types to Barbican Secret Content Types: -+-----------------+---------------+---------------+--------------------------+ -| six Type | Python 2 Type | Python 3 Type | Barbican Content Type | -+=================+===============+===============+==========================+ -| six.binary_type | str | bytes | application/octet-stream | -+-----------------+---------------+---------------+--------------------------+ -| six.text_type | unicode | str | text/plain | -+-----------------+---------------+---------------+--------------------------+ ++---------------+--------------------------+ +| Python 3 Type | Barbican Content Type | ++===============+==========================+ +| bytes | application/octet-stream | ++---------------+--------------------------+ +| str | text/plain | ++---------------+--------------------------+ .. WARNING:: Previous versions of python-barbicanclient allowed the user to set the diff --git a/functionaltests/cli/v1/behaviors/base_behaviors.py b/functionaltests/cli/v1/behaviors/base_behaviors.py index 3420cee..aef9831 100644 --- a/functionaltests/cli/v1/behaviors/base_behaviors.py +++ b/functionaltests/cli/v1/behaviors/base_behaviors.py @@ -13,9 +13,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ +import io import logging import re -import six from barbicanclient import barbican from functionaltests.common import config @@ -84,8 +84,8 @@ class BaseBehaviors(object): """ try: - self.cmdline_client.stdout = six.StringIO() - self.cmdline_client.stderr = six.StringIO() + self.cmdline_client.stdout = io.StringIO() + self.cmdline_client.stderr = io.StringIO() self.cmdline_client.run(argv) except SystemExit: pass diff --git a/functionaltests/utils.py b/functionaltests/utils.py index 367dee0..5c5b51a 100644 --- a/functionaltests/utils.py +++ b/functionaltests/utils.py @@ -19,8 +19,7 @@ import time import types import oslotest.base as oslotest -import six -import six.moves.urllib.parse as urlparse +import urllib.parse as urlparse class BaseTestCase(oslotest.BaseTestCase): @@ -43,10 +42,10 @@ def construct_new_test_function(original_func, name, build_params): :return: A new function object """ new_func = types.FunctionType( - six.get_function_code(original_func), - six.get_function_globals(original_func), + original_func.__code__, + original_func.__globals__, name=name, - argdefs=six.get_function_defaults(original_func) + argdefs=original_func.__defaults__ ) # Support either an arg list or kwarg dict for our data diff --git a/requirements.txt b/requirements.txt index 1ce91a6..9c37a45 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,6 @@ # process, which may cause wedges in the gate later. pbr!=2.1.0,>=2.0.0 # Apache-2.0 requests>=2.14.2 # Apache-2.0 -six>=1.10.0 # MIT cliff!=2.9.0,>=2.8.0 # Apache-2.0 keystoneauth1>=3.4.0 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0 -- cgit v1.2.1