Remove six

This is no longer necessary since we only support Python 3.x.

A note is removed from requirements.txt since it's no longer relevant:
pip 20.3+ has a real dependency resolver.

Change-Id: Ie3006813a79fef1f128d388b906e4f1752347fa4
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Co-Authored-By: Grzegorz Grasza <xek@redhat.com>
changes/71/816671/7
Stephen Finucane 2021-11-04 10:33:56 +00:00
parent 11faa0e67d
commit 192a27ae5f
25 changed files with 71 additions and 125 deletions

View File

@ -10,13 +10,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import queue
import threading
import time
from six.moves import queue
class FairSemaphore(object):
"""Semaphore class that notifies in order of request.

View File

@ -14,7 +14,6 @@ import datetime
import logging
import iso8601
import six
def get_logger(name):
@ -38,9 +37,9 @@ def parse_isotime(timestr):
try:
return iso8601.parse_date(timestr)
except iso8601.ParseError as e:
raise ValueError(six.text_type(e))
raise ValueError(str(e))
except TypeError as e:
raise ValueError(six.text_type(e))
raise ValueError(str(e))
def from_utcnow(**timedelta_kwargs):

View File

@ -19,14 +19,11 @@
import abc
import copy
import six
from keystoneauth1 import discover
from keystoneauth1 import exceptions
@six.add_metaclass(abc.ABCMeta)
class ServiceCatalog(object):
class ServiceCatalog(metaclass=abc.ABCMeta):
"""Helper methods for dealing with a Keystone Service Catalog."""
def __init__(self, catalog):

View File

@ -23,10 +23,9 @@ raw data specified in version discovery responses.
import copy
import re
import urllib
import os_service_types
import six
from six.moves import urllib
from keystoneauth1 import _utils as utils
from keystoneauth1 import exceptions
@ -203,7 +202,7 @@ def normalize_version_number(version):
# If it's a non-string iterable, turn it into a string for subsequent
# processing. This ensures at least 1 decimal point if e.g. [1] is given.
if not isinstance(ver, six.string_types):
if not isinstance(ver, str):
try:
ver = '.'.join(map(_str_or_latest, ver))
except TypeError:
@ -214,7 +213,7 @@ def normalize_version_number(version):
# float string. This ensures 1 decimal point.
# If it's a float as a string, don't do that, the split/map below will do
# what we want. (Otherwise, we wind up with 3.20 -> (3, 2))
if isinstance(ver, six.string_types):
if isinstance(ver, str):
# trim the v from a 'v2.0' or similar
ver = ver.lstrip('v')
try:

View File

@ -11,6 +11,7 @@
# under the License.
import datetime
import urllib
import uuid
try:
@ -18,8 +19,6 @@ try:
except ImportError:
etree = None
from six.moves import urllib
from keystoneauth1 import access
from keystoneauth1 import exceptions
from keystoneauth1.extras._saml2.v3 import base

View File

@ -16,7 +16,6 @@ import json
import os
import betamax.serializers.base
import six
import yaml
@ -52,7 +51,7 @@ def _indent_json(val):
return json.dumps(
json.loads(val), indent=2,
separators=(',', ': '), sort_keys=False,
default=six.text_type)
default=str)
def _is_json_body(interaction):
@ -82,7 +81,7 @@ class YamlJsonSerializer(betamax.serializers.base.BaseSerializer):
yaml.representer.BaseRepresenter.represent_scalar = _represent_scalar
MyDumper.add_representer(six.text_type, _unicode_representer)
MyDumper.add_representer(str, _unicode_representer)
return yaml.dump(
cassette_data, Dumper=MyDumper, default_flow_style=False)

View File

@ -17,8 +17,6 @@ import hashlib
import json
import threading
import six
from keystoneauth1 import _utils as utils
from keystoneauth1 import access
from keystoneauth1 import discover
@ -28,8 +26,7 @@ from keystoneauth1 import plugin
LOG = utils.get_logger(__name__)
@six.add_metaclass(abc.ABCMeta)
class BaseIdentityPlugin(plugin.BaseAuthPlugin):
class BaseIdentityPlugin(plugin.BaseAuthPlugin, metaclass=abc.ABCMeta):
# we count a token as valid (not needing refreshing) if it is valid for at
# least this many seconds before the token expiry time
@ -647,9 +644,9 @@ class BaseIdentityPlugin(plugin.BaseAuthPlugin):
for k, v in sorted(elements.items()):
if v is not None:
# NOTE(jamielennox): in python3 you need to pass bytes to hash
if isinstance(k, six.string_types):
if isinstance(k, str):
k = k.encode('utf-8')
if isinstance(v, six.string_types):
if isinstance(v, str):
v = v.encode('utf-8')
hasher.update(k)

View File

@ -11,9 +11,7 @@
# under the License.
import abc
import six
import six.moves.urllib.parse as urlparse
import urllib.parse
from keystoneauth1 import _utils as utils
from keystoneauth1 import discover
@ -24,8 +22,7 @@ from keystoneauth1.identity import base
LOG = utils.get_logger(__name__)
@six.add_metaclass(abc.ABCMeta)
class BaseGenericPlugin(base.BaseIdentityPlugin):
class BaseGenericPlugin(base.BaseIdentityPlugin, metaclass=abc.ABCMeta):
"""An identity plugin that is not version dependent.
Internally we will construct a version dependent plugin with the resolved
@ -144,7 +141,7 @@ class BaseGenericPlugin(base.BaseIdentityPlugin):
'contacting %s. Attempting to parse version from URL.',
self.auth_url)
url_parts = urlparse.urlparse(self.auth_url)
url_parts = urllib.parse.urlparse(self.auth_url)
path = url_parts.path.lower()
if path.startswith('/v2.0'):

View File

@ -12,8 +12,6 @@
import abc
import six
from keystoneauth1 import _utils as utils
from keystoneauth1 import access
from keystoneauth1 import exceptions
@ -22,8 +20,7 @@ from keystoneauth1.identity import base
_logger = utils.get_logger(__name__)
@six.add_metaclass(abc.ABCMeta)
class Auth(base.BaseIdentityPlugin):
class Auth(base.BaseIdentityPlugin, metaclass=abc.ABCMeta):
"""Identity V2 Authentication Plugin.
:param string auth_url: Identity service endpoint for authorization.

View File

@ -13,8 +13,6 @@
import abc
import json
import six
from keystoneauth1 import _utils as utils
from keystoneauth1 import access
from keystoneauth1 import exceptions
@ -25,8 +23,7 @@ _logger = utils.get_logger(__name__)
__all__ = ('Auth', 'AuthMethod', 'AuthConstructor', 'BaseAuth')
@six.add_metaclass(abc.ABCMeta)
class BaseAuth(base.BaseIdentityPlugin):
class BaseAuth(base.BaseIdentityPlugin, metaclass=abc.ABCMeta):
"""Identity V3 Authentication Plugin.
:param string auth_url: Identity service endpoint for authentication.
@ -223,8 +220,7 @@ class Auth(BaseAuth):
return params
@six.add_metaclass(abc.ABCMeta)
class AuthMethod(object):
class AuthMethod(metaclass=abc.ABCMeta):
"""One part of a V3 Authentication strategy.
V3 Tokens allow multiple methods to be presented when authentication
@ -283,8 +279,7 @@ class AuthMethod(object):
raise NotImplementedError()
@six.add_metaclass(abc.ABCMeta)
class AuthConstructor(Auth):
class AuthConstructor(Auth, metaclass=abc.ABCMeta):
"""Abstract base class for creating an Auth Plugin.
The Auth Plugin created contains only one authentication method. This

View File

@ -12,16 +12,13 @@
import abc
import six
from keystoneauth1.identity.v3 import base
from keystoneauth1.identity.v3 import token
__all__ = ('FederationBaseAuth',)
@six.add_metaclass(abc.ABCMeta)
class _Rescoped(base.BaseAuth):
class _Rescoped(base.BaseAuth, metaclass=abc.ABCMeta):
"""A plugin that is always going to go through a rescope process.
The original keystone plugins could simply pass a project or domain to

View File

@ -10,8 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from keystoneauth1 import access
from keystoneauth1 import exceptions
from keystoneauth1.identity.v3 import federation
@ -119,7 +117,7 @@ class Keystone2Keystone(federation._Rescoped):
if not resp.text:
raise exceptions.InvalidResponse(resp)
return six.text_type(resp.text)
return str(resp.text)
def _send_service_provider_ecp_authn_response(self, session, sp_url,
sp_auth_url):

View File

@ -13,8 +13,6 @@
import abc
import warnings
import six
from keystoneauth1 import _utils as utils
from keystoneauth1 import access
from keystoneauth1 import exceptions
@ -28,8 +26,7 @@ __all__ = ('OidcAuthorizationCode',
'OidcAccessToken')
@six.add_metaclass(abc.ABCMeta)
class _OidcBase(federation.FederationBaseAuth):
class _OidcBase(federation.FederationBaseAuth, metaclass=abc.ABCMeta):
"""Base class for different OpenID Connect based flows.
The OpenID Connect specification can be found at::

View File

@ -12,16 +12,13 @@
import abc
import six
from keystoneauth1 import _utils as utils
from keystoneauth1 import plugin
LOG = utils.get_logger(__name__)
@six.add_metaclass(abc.ABCMeta)
class TokenlessAuth(plugin.BaseAuthPlugin):
class TokenlessAuth(plugin.BaseAuthPlugin, metaclass=abc.ABCMeta):
"""A plugin for authenticating with Tokenless Auth.
This is for Tokenless Authentication. Scoped information

View File

@ -12,7 +12,6 @@
import abc
import six
import stevedore
from keystoneauth1 import exceptions
@ -99,8 +98,7 @@ def get_plugin_options(name):
return get_plugin_loader(name).get_options()
@six.add_metaclass(abc.ABCMeta)
class BaseLoader(object):
class BaseLoader(metaclass=abc.ABCMeta):
@property
def plugin_class(self):

View File

@ -20,11 +20,10 @@ import platform
import socket
import sys
import time
import urllib
import uuid
import requests
import six
from six.moves import urllib
import keystoneauth1
from keystoneauth1 import _utils as utils
@ -92,18 +91,11 @@ def _sanitize_headers(headers):
"""Ensure headers are strings and not bytes."""
str_dict = {}
for k, v in headers.items():
if six.PY3:
# requests expects headers to be str type in python3, which means
# if we get a bytes we need to decode it into a str
k = k.decode('ASCII') if isinstance(k, six.binary_type) else k
if v is not None:
v = v.decode('ASCII') if isinstance(v, six.binary_type) else v
else:
# requests expects headers to be str type in python2, which means
# if we get a unicode we need to encode it to ASCII into a str
k = k.encode('ASCII') if isinstance(k, six.text_type) else k
if v is not None:
v = v.encode('ASCII') if isinstance(v, six.text_type) else v
# requests expects headers to be str type in python3, which means
# if we get a bytes we need to decode it into a str
k = k.decode('ASCII') if isinstance(k, bytes) else k
if v is not None:
v = v.decode('ASCII') if isinstance(v, bytes) else v
str_dict[k] = v
return str_dict
@ -126,9 +118,9 @@ class _JSONEncoder(json.JSONEncoder):
if isinstance(o, datetime.datetime):
return o.isoformat()
if isinstance(o, uuid.UUID):
return six.text_type(o)
return str(o)
if netaddr and isinstance(o, netaddr.IPAddress):
return six.text_type(o)
return str(o)
return super(_JSONEncoder, self).default(o)
@ -485,7 +477,7 @@ class Session(object):
# so we need to actually check that this is False.
if self.verify is False:
string_parts.append('--insecure')
elif isinstance(self.verify, six.string_types):
elif isinstance(self.verify, str):
string_parts.append('--cacert "%s"' % self.verify)
if method:
@ -509,7 +501,7 @@ class Session(object):
if json:
data = self._json.encode(json)
if data:
if isinstance(data, six.binary_type):
if isinstance(data, bytes):
try:
data = data.decode("ascii")
except UnicodeDecodeError:

View File

@ -13,7 +13,6 @@
import uuid
from oauthlib import oauth1
import six
from testtools import matchers
from keystoneauth1.extras import oauth1 as ksa_oauth1
@ -47,7 +46,7 @@ class OAuth1AuthTests(test_utils.TestCase):
self.assertEqual('HMAC-SHA1', parameters['oauth_signature_method'])
self.assertEqual('1.0', parameters['oauth_version'])
self.assertIsInstance(parameters['oauth_nonce'], six.string_types)
self.assertIsInstance(parameters['oauth_nonce'], str)
self.assertEqual(oauth_client.client_key,
parameters['oauth_consumer_key'])
if oauth_client.resource_owner_key:

View File

@ -10,10 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import urllib
import uuid
from lxml import etree
from six.moves import urllib
from keystoneauth1 import exceptions
from keystoneauth1.extras import _saml2 as saml2

View File

@ -12,11 +12,9 @@
import abc
import collections
import urllib
import uuid
import six
from six.moves import urllib
from keystoneauth1 import _utils
from keystoneauth1 import access
from keystoneauth1 import adapter
@ -76,8 +74,7 @@ class FakeServiceEndpoints(object):
return url
@six.add_metaclass(abc.ABCMeta)
class CommonIdentityTests(object):
class CommonIdentityTests(metaclass=abc.ABCMeta):
PROJECT_ID = uuid.uuid4().hex
TEST_ROOT_URL = 'http://127.0.0.1:5000/'

View File

@ -13,8 +13,6 @@
import copy
import uuid
import six
from keystoneauth1 import access
from keystoneauth1 import exceptions
from keystoneauth1 import fixture
@ -144,7 +142,7 @@ class K2KAuthPluginTest(utils.TestCase):
self.requests_mock.register_uri(
'POST',
self.REQUEST_ECP_URL,
content=six.b(k2k_fixtures.ECP_ENVELOPE),
content=bytes(k2k_fixtures.ECP_ENVELOPE, 'latin-1'),
headers={'Content-Type': 'application/vnd.paos+xml'},
status_code=200)
@ -152,7 +150,7 @@ class K2KAuthPluginTest(utils.TestCase):
self.requests_mock.register_uri(
'POST',
self.SP_URL,
content=six.b(k2k_fixtures.TOKEN_BASED_ECP),
content=bytes(k2k_fixtures.TOKEN_BASED_ECP, 'latin-1'),
headers={'Content-Type': 'application/vnd.paos+xml'},
status_code=redirect_code)
@ -195,7 +193,7 @@ class K2KAuthPluginTest(utils.TestCase):
self.requests_mock.register_uri(
'POST', self.REQUEST_ECP_URL,
headers={'Content-Type': 'application/vnd.paos+xml'},
content=six.b(''), status_code=200)
content=b'', status_code=200)
self.assertRaises(exceptions.InvalidResponse,
self.k2kplugin._get_ecp_assertion,
@ -210,7 +208,7 @@ class K2KAuthPluginTest(utils.TestCase):
self.requests_mock.register_uri(
'POST', self.REQUEST_ECP_URL,
headers={'Content-Type': uuid.uuid4().hex},
content=six.b(''), status_code=200)
content=b'', status_code=200)
self.assertRaises(exceptions.InvalidResponse,
self.k2kplugin._get_ecp_assertion,
@ -259,7 +257,7 @@ class K2KAuthPluginTest(utils.TestCase):
self.requests_mock.register_uri(
'POST',
self.REQUEST_ECP_URL,
content=six.b(k2k_fixtures.ECP_ENVELOPE),
content=bytes(k2k_fixtures.ECP_ENVELOPE, 'latin-1'),
headers={'Content-Type': 'application/vnd.paos+xml'},
status_code=200)
@ -267,7 +265,7 @@ class K2KAuthPluginTest(utils.TestCase):
self.requests_mock.register_uri(
'POST',
self.SP_URL,
content=six.b(k2k_fixtures.TOKEN_BASED_ECP),
content=bytes(k2k_fixtures.TOKEN_BASED_ECP, 'latin-1'),
headers={'Content-Type': 'application/vnd.paos+xml'},
status_code=302)

View File

@ -10,11 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import urllib
import uuid
import warnings
from six.moves import urllib
from keystoneauth1 import exceptions
from keystoneauth1.identity.v3 import oidc
from keystoneauth1 import session

View File

@ -10,11 +10,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import queue
from threading import Thread
from timeit import default_timer as timer
from unittest import mock
from six.moves import queue
import testtools
from keystoneauth1 import _fair_semaphore

View File

@ -11,6 +11,7 @@
# under the License.
import datetime
import io
import itertools
import json
import logging
@ -21,7 +22,6 @@ import uuid
from oslo_utils import encodeutils
import requests
import requests.auth
import six
from testtools import matchers
from keystoneauth1 import adapter
@ -1258,8 +1258,8 @@ class SessionAuthTests(utils.TestCase):
logger.setLevel(logging.DEBUG)
logger.propagate = False
io = six.StringIO()
handler = logging.StreamHandler(io)
string_io = io.StringIO()
handler = logging.StreamHandler(string_io)
logger.addHandler(handler)
auth = AuthPlugin()
@ -1273,7 +1273,7 @@ class SessionAuthTests(utils.TestCase):
resp = sess.get(self.TEST_URL, logger=logger)
self.assertEqual(response, resp.json())
output = io.getvalue()
output = string_io.getvalue()
self.assertIn(self.TEST_URL, output)
self.assertIn(list(response.keys())[0], output)
@ -1289,14 +1289,14 @@ class SessionAuthTests(utils.TestCase):
logger = logging.getLogger(logger_name)
logger.setLevel(logging.DEBUG)
io = six.StringIO()
handler = logging.StreamHandler(io)
string_io = io.StringIO()
handler = logging.StreamHandler(string_io)
logger.addHandler(handler)
return io
return string_io
io = {}
io_dict = {}
for name in ('request', 'body', 'response', 'request-id'):
io[name] = get_logger_io(name)
io_dict[name] = get_logger_io(name)
auth = AuthPlugin()
sess = client_session.Session(auth=auth, split_loggers=True)
@ -1322,10 +1322,10 @@ class SessionAuthTests(utils.TestCase):
self.assertEqual(response, resp.json())
request_output = io['request'].getvalue().strip()
response_output = io['response'].getvalue().strip()
body_output = io['body'].getvalue().strip()
id_output = io['request-id'].getvalue().strip()
request_output = io_dict['request'].getvalue().strip()
response_output = io_dict['response'].getvalue().strip()
body_output = io_dict['body'].getvalue().strip()
id_output = io_dict['request-id'].getvalue().strip()
self.assertIn('curl -g -i -X GET {url}'.format(url=self.TEST_URL),
request_output)
@ -1607,8 +1607,8 @@ class AdapterTest(utils.TestCase):
logger.setLevel(logging.DEBUG)
logger.propagate = False
io = six.StringIO()
handler = logging.StreamHandler(io)
string_io = io.StringIO()
handler = logging.StreamHandler(string_io)
logger.addHandler(handler)
auth = AuthPlugin()
@ -1623,7 +1623,7 @@ class AdapterTest(utils.TestCase):
resp = adpt.get(self.TEST_URL, logger=logger)
self.assertEqual(response, resp.json())
output = io.getvalue()
output = string_io.getvalue()
self.assertIn(self.TEST_URL, output)
self.assertIn(list(response.keys())[0], output)

View File

@ -13,12 +13,12 @@
import json as jsonutils
import logging
import time
import urllib.parse
import uuid
import fixtures
import requests
from requests_mock.contrib import fixture
from six.moves.urllib import parse as urlparse
import testtools
@ -80,9 +80,11 @@ class TestCase(testtools.TestCase):
The qs parameter should be of the format \'foo=bar&abc=xyz\'
"""
expected = urlparse.parse_qs(qs, keep_blank_values=True)
parts = urlparse.urlparse(self.requests_mock.last_request.url)
querystring = urlparse.parse_qs(parts.query, keep_blank_values=True)
expected = urllib.parse.parse_qs(qs, keep_blank_values=True)
parts = urllib.parse.urlparse(self.requests_mock.last_request.url)
querystring = urllib.parse.parse_qs(
parts.query, keep_blank_values=True,
)
self.assertEqual(expected, querystring)
def assertQueryStringContains(self, **kwargs):
@ -95,8 +97,8 @@ class TestCase(testtools.TestCase):
verified is that the parameter is present.
"""
parts = urlparse.urlparse(self.requests_mock.last_request.url)
qs = urlparse.parse_qs(parts.query, keep_blank_values=True)
parts = urllib.parse.urlparse(self.requests_mock.last_request.url)
qs = urllib.parse.parse_qs(parts.query, keep_blank_values=True)
for k, v in kwargs.items():
self.assertIn(k, qs)

View File

@ -2,10 +2,6 @@
# date but we do not test them so no guarantee of having them all correct. If
# you find any incorrect lower bounds, let us know or propose a fix.
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
# All additions to this file must have significant justification.
# NOTE(morgan) At no time may any oslo library be added to the keystoneauth
@ -18,6 +14,5 @@
pbr!=2.1.0,>=2.0.0 # Apache-2.0
iso8601>=0.1.11 # MIT
requests>=2.14.2 # Apache-2.0
six>=1.10.0 # MIT
stevedore>=1.20.0 # Apache-2.0
os-service-types>=1.2.0 # Apache-2.0