From c1aec0230d20f1bd0fc519d82e601656c0a76a95 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Mon, 20 Sep 2021 16:37:56 +0200 Subject: [PATCH 30/59] misc: fix no-else-raise pylint error (#56982) --- src/authentic2/attributes_ng/engine.py | 23 +++++++++++------------ src/authentic2/forms/authentication.py | 3 +-- src/authentic2/hashers.py | 17 +++++++++-------- src/authentic2_auth_saml/adapters.py | 3 +-- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/authentic2/attributes_ng/engine.py b/src/authentic2/attributes_ng/engine.py index fd3d67e2..bf23a2c6 100644 --- a/src/authentic2/attributes_ng/engine.py +++ b/src/authentic2/attributes_ng/engine.py @@ -63,18 +63,17 @@ def topological_sort(source_and_instances, ctx, raise_on_unsortable=False): elif count_sorted == len(sorted_list): # no progress ! if raise_on_unsortable: raise UnsortableError(sorted_list, unsorted) - else: - logger = logging.getLogger(__name__) - for source, instance in unsorted: - dependencies = set(source.get_dependencies(instance, ctx)) - sorted_list.append((source, instance)) - logger.debug( - 'missing dependencies for instance %r of %r: %s', - instance, - source, - list(dependencies - variables), - ) - break + logger = logging.getLogger(__name__) + for source, instance in unsorted: + dependencies = set(source.get_dependencies(instance, ctx)) + sorted_list.append((source, instance)) + logger.debug( + 'missing dependencies for instance %r of %r: %s', + instance, + source, + list(dependencies - variables), + ) + break return sorted_list diff --git a/src/authentic2/forms/authentication.py b/src/authentic2/forms/authentication.py index bae4cff1..2608c98d 100644 --- a/src/authentic2/forms/authentication.py +++ b/src/authentic2/forms/authentication.py @@ -127,8 +127,7 @@ class AuthenticationForm(auth_forms.AuthenticationForm): code='invalid_login', params={'username': self.username_field.verbose_name}, ) - else: - self.confirm_login_allowed(self.user_cache) + self.confirm_login_allowed(self.user_cache) return self.cleaned_data diff --git a/src/authentic2/hashers.py b/src/authentic2/hashers.py index 9d32c800..65cf8ed8 100644 --- a/src/authentic2/hashers.py +++ b/src/authentic2/hashers.py @@ -238,17 +238,18 @@ class JoomlaPasswordHasher(CommonPasswordHasher): def from_joomla(cls, encoded): if encoded.startswith('$P$'): raise NotImplementedError - elif encoded.startswith('$'): + if encoded.startswith('$'): raise NotImplementedError - elif encoded.startswith('{SHA256}'): + if encoded.startswith('{SHA256}'): raise NotImplementedError + + if ':' in encoded: + h, salt = encoded.split(':', 1) else: - if ':' in encoded: - h, salt = encoded.split(':', 1) - else: - h, salt = encoded, '' - salt = force_text(hexlify(force_bytes(salt)), encoding='ascii') - return '%s$md5$%s$%s' % (cls.algorithm, salt, h) + h, salt = encoded, '' + salt = force_text(hexlify(force_bytes(salt)), encoding='ascii') + + return '%s$md5$%s$%s' % (cls.algorithm, salt, h) @classmethod def to_joomla(cls, encoded): diff --git a/src/authentic2_auth_saml/adapters.py b/src/authentic2_auth_saml/adapters.py index a7e3e12a..427c2d0b 100644 --- a/src/authentic2_auth_saml/adapters.py +++ b/src/authentic2_auth_saml/adapters.py @@ -141,8 +141,7 @@ class AuthenticAdapter(DefaultAdapter): if mandatory: # it's mandatory, provisionning should fail completely raise e - else: - logger.warning('auth_saml: mapping action failed: %s', e) + logger.warning('auth_saml: mapping action failed: %s', e) return user_modified def action_rename(self, user, idp, saml_attributes, mapping): -- 2.30.2