From 5dd2bf5fb635bbb8f762103257b6aeefa73b436e Mon Sep 17 00:00:00 2001 From: Ivan Kolodyazhny Date: Wed, 8 Jan 2020 22:38:31 +0200 Subject: [PATCH] Remove six usage from openstack_auth package We don't support Python 2 anymore so we don't need this compatibility library. Change-Id: I0ecd706af1b4432fe439472189444141853c9d0b --- openstack_auth/plugin/base.py | 4 +--- openstack_auth/user.py | 3 +-- openstack_auth/utils.py | 16 ++++++++-------- openstack_auth/views.py | 7 +++---- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/openstack_auth/plugin/base.py b/openstack_auth/plugin/base.py index 215b5fd708..011c06bae1 100644 --- a/openstack_auth/plugin/base.py +++ b/openstack_auth/plugin/base.py @@ -17,7 +17,6 @@ import re from django.utils.translation import ugettext_lazy as _ from keystoneauth1 import exceptions as keystone_exceptions from keystoneclient.v3 import client as v3_client -import six from openstack_auth import exceptions from openstack_auth import utils @@ -26,8 +25,7 @@ LOG = logging.getLogger(__name__) __all__ = ['BasePlugin'] -@six.add_metaclass(abc.ABCMeta) -class BasePlugin(object): +class BasePlugin(object, metaclass=abc.ABCMeta): """Base plugin to provide ways to log in to dashboard. Provides a framework for keystoneclient plugins that can be used with the diff --git a/openstack_auth/user.py b/openstack_auth/user.py index ebc2ba1cc9..94f3385f2a 100644 --- a/openstack_auth/user.py +++ b/openstack_auth/user.py @@ -17,7 +17,6 @@ import logging from django.contrib.auth import models from django.db import models as db_models from keystoneauth1 import exceptions as keystone_exceptions -import six from openstack_auth import utils @@ -379,7 +378,7 @@ class User(models.AbstractBaseUser, models.AnonymousUser): if not perm_list: return True for perm in perm_list: - if isinstance(perm, six.string_types): + if isinstance(perm, str): # check that the permission matches if not self.has_perm(perm, obj): return False diff --git a/openstack_auth/utils.py b/openstack_auth/utils.py index 21d2d9bfe0..331ef98172 100644 --- a/openstack_auth/utils.py +++ b/openstack_auth/utils.py @@ -14,6 +14,7 @@ import datetime import logging import re +from urllib import parse from django.conf import settings from django.contrib import auth @@ -23,7 +24,6 @@ from keystoneauth1.identity import v3 as v3_auth from keystoneauth1 import session from keystoneauth1 import token_endpoint from keystoneclient.v3 import client as client_v3 -from six.moves.urllib import parse as urlparse from openstack_auth import defaults @@ -252,7 +252,7 @@ def get_websso_url(request, auth_url, websso_auth): def has_in_url_path(url, subs): """Test if any of `subs` strings is present in the `url` path.""" - scheme, netloc, path, query, fragment = urlparse.urlsplit(url) + scheme, netloc, path, query, fragment = parse.urlsplit(url) return any([sub in path for sub in subs]) @@ -264,17 +264,17 @@ def url_path_replace(url, old, new, count=None): occurrences are replaced. """ args = [] - scheme, netloc, path, query, fragment = urlparse.urlsplit(url) + scheme, netloc, path, query, fragment = parse.urlsplit(url) if count is not None: args.append(count) - return urlparse.urlunsplit(( + return parse.urlunsplit(( scheme, netloc, path.replace(old, new, *args), query, fragment)) def url_path_append(url, suffix): - scheme, netloc, path, query, fragment = urlparse.urlsplit(url) + scheme, netloc, path, query, fragment = parse.urlsplit(url) path = (path + suffix).replace('//', '/') - return urlparse.urlunsplit((scheme, netloc, path, query, fragment)) + return parse.urlunsplit((scheme, netloc, path, query, fragment)) def _augment_url_with_version(auth_url): @@ -316,8 +316,8 @@ def clean_up_auth_url(auth_url): # NOTE(mnaser): This drops the query and fragment because we're only # trying to extract the Keystone URL. - scheme, netloc, path, query, fragment = urlparse.urlsplit(auth_url) - return urlparse.urlunsplit(( + scheme, netloc, path, query, fragment = parse.urlsplit(auth_url) + return parse.urlunsplit(( scheme, netloc, re.sub(r'/auth.*', '', path), '', '')) diff --git a/openstack_auth/views.py b/openstack_auth/views.py index 339f81b1af..571b0e3819 100644 --- a/openstack_auth/views.py +++ b/openstack_auth/views.py @@ -30,7 +30,6 @@ from django.views.decorators.csrf import csrf_protect from django.views.decorators.debug import sensitive_post_parameters from django.views.generic import edit as edit_views from keystoneauth1 import exceptions as keystone_exceptions -import six from openstack_auth import exceptions from openstack_auth import forms @@ -174,7 +173,7 @@ def websso(request): if utils.is_websso_default_redirect(): res = django_http.HttpResponseRedirect(settings.LOGIN_ERROR) else: - msg = 'Login failed: %s' % six.text_type(exc) + msg = 'Login failed: %s' % exc res = django_http.HttpResponseRedirect(settings.LOGIN_URL) res.set_cookie('logout_reason', msg, max_age=10) return res @@ -337,7 +336,7 @@ def switch_keystone_provider(request, keystone_provider=None, unscoped_auth_ref = current_plugin.get_access_info(unscoped_auth) except exceptions.KeystoneAuthException as exc: msg = 'Switching to Keystone Provider %s has failed. %s' \ - % (keystone_provider, (six.text_type(exc))) + % (keystone_provider, exc) messages.error(request, msg) if unscoped_auth_ref: @@ -346,7 +345,7 @@ def switch_keystone_provider(request, keystone_provider=None, request, auth_url=unscoped_auth.auth_url, token=unscoped_auth_ref.auth_token) except exceptions.KeystoneAuthException as exc: - msg = 'Keystone provider switch failed: %s' % six.text_type(exc) + msg = 'Keystone provider switch failed: %s' % exc res = django_http.HttpResponseRedirect(settings.LOGIN_URL) res.set_cookie('logout_reason', msg, max_age=10) return res