From 434dcf6e4eae46b29dacd74948db2fc56b060a30 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Tue, 28 Jun 2016 00:48:48 +0200 Subject: [PATCH] Correct some codacy errors --- cas_server/default_settings.py | 8 ++++---- cas_server/federate.py | 11 ++++++----- cas_server/utils.py | 14 +++++++++----- cas_server/views.py | 3 ++- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/cas_server/default_settings.py b/cas_server/default_settings.py index 750a9c9..a773573 100644 --- a/cas_server/default_settings.py +++ b/cas_server/default_settings.py @@ -105,7 +105,7 @@ try: except AttributeError: __CAS_FEDERATE_PROVIDERS_LIST = list(settings.CAS_FEDERATE_PROVIDERS.keys()) - def __CAS_FEDERATE_PROVIDERS_LIST_sort(key): + def __cas_federate_providers_list_sort(key): if len(settings.CAS_FEDERATE_PROVIDERS[key]) > 2: key = settings.CAS_FEDERATE_PROVIDERS[key][2].lower() else: @@ -113,11 +113,11 @@ except AttributeError: if isinstance(key, six.string_types) or isinstance(key, six.text_type): return tuple( int(num) if num else alpha - for num, alpha in __CAS_FEDERATE_PROVIDERS_LIST_sort.tokenize(key) + for num, alpha in __cas_federate_providers_list_sort.tokenize(key) ) else: return key - __CAS_FEDERATE_PROVIDERS_LIST_sort.tokenize = re.compile(r'(\d+)|(\D+)').findall - __CAS_FEDERATE_PROVIDERS_LIST.sort(key=__CAS_FEDERATE_PROVIDERS_LIST_sort) + __cas_federate_providers_list_sort.tokenize = re.compile(r'(\d+)|(\D+)').findall + __CAS_FEDERATE_PROVIDERS_LIST.sort(key=__cas_federate_providers_list_sort) setting_default('CAS_FEDERATE_PROVIDERS_LIST', __CAS_FEDERATE_PROVIDERS_LIST) diff --git a/cas_server/federate.py b/cas_server/federate.py index 3aed3ae..453a778 100644 --- a/cas_server/federate.py +++ b/cas_server/federate.py @@ -46,7 +46,7 @@ class CASFederateValidateUser(object): """test `password` agains the user""" if self.client is None: return False - username, attributs, pgtiou = self.client.verify_ticket(ticket) + username, attributs = self.client.verify_ticket(ticket)[:2] if username is not None: if attributs is None: attributs = {} @@ -73,7 +73,8 @@ class CASFederateValidateUser(object): else: return False - def register_slo(self, username, session_key, ticket): + @staticmethod + def register_slo(username, session_key, ticket): FederateSLO.objects.create( username=username, session_key=session_key, @@ -82,10 +83,10 @@ class CASFederateValidateUser(object): def clean_sessions(self, logout_request): try: - SLOs = self.client.get_saml_slos(logout_request) + slos = self.client.get_saml_slos(logout_request) except NameError: - SLOs = [] - for slo in SLOs: + slos = [] + for slo in slos: try: for federate_slo in FederateSLO.objects.filter(ticket=slo.text): session = SessionStore(session_key=federate_slo.session_key) diff --git a/cas_server/utils.py b/cas_server/utils.py index aa9f8f4..9487ec8 100644 --- a/cas_server/utils.py +++ b/cas_server/utils.py @@ -73,7 +73,9 @@ def reverse_params(url_name, params=None, **kwargs): return url -def copy_params(get_or_post_params, ignore=set()): +def copy_params(get_or_post_params, ignore=None): + if ignore is None: + ignore = set() params = {} for key in get_or_post_params: if key not in ignore and get_or_post_params[key]: @@ -96,7 +98,9 @@ def set_cookie(response, key, value, max_age): ) -def get_current_url(request, ignore_params=set()): +def get_current_url(request, ignore_params=None): + if ignore_params is None: + ignore_params = set() protocol = 'https' if request.is_secure() else "http" service_url = "%s://%s%s" % (protocol, request.get_host(), request.path) if request.GET: @@ -184,11 +188,11 @@ def gen_saml_id(): return _gen_ticket('_') -def get_tuple(tuple, index, default=None): - if tuple is None: +def get_tuple(nuplet, index, default=None): + if nuplet is None: return default try: - return tuple[index] + return nuplet[index] except IndexError: return default diff --git a/cas_server/views.py b/cas_server/views.py index 0d41620..f1434b0 100644 --- a/cas_server/views.py +++ b/cas_server/views.py @@ -193,7 +193,8 @@ class FederateAuth(View): def dispatch(self, request, *args, **kwargs): return super(FederateAuth, self).dispatch(request, *args, **kwargs) - def get_cas_client(self, request, provider): + @staticmethod + def get_cas_client(request, provider): if provider in settings.CAS_FEDERATE_PROVIDERS: service_url = utils.get_current_url(request, {"ticket", "provider"}) return CASFederateValidateUser(provider, service_url)