Correct some codacy errors

This commit is contained in:
Valentin Samir 2016-06-28 00:48:48 +02:00
parent dedc1e34a2
commit 434dcf6e4e
4 changed files with 21 additions and 15 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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)