diff --git a/modoboa/core/password_hashers/__init__.py b/modoboa/core/password_hashers/__init__.py index 80a5a8529..661251784 100644 --- a/modoboa/core/password_hashers/__init__.py +++ b/modoboa/core/password_hashers/__init__.py @@ -36,7 +36,7 @@ def get_dovecot_schemes(): """Return schemes supported by dovecot""" supported_schemes = None try: - code, schemes = doveadm_cmd("pw -l") + _, schemes = doveadm_cmd("pw -l") except OSError: pass else: diff --git a/modoboa/core/password_hashers/base.py b/modoboa/core/password_hashers/base.py index 88652de13..ccf2f9f2d 100644 --- a/modoboa/core/password_hashers/base.py +++ b/modoboa/core/password_hashers/base.py @@ -17,8 +17,27 @@ from random import Random from django.utils.crypto import constant_time_compare from django.utils.encoding import force_bytes, force_text +from six import with_metaclass -class PasswordHasher(object): + +class MetaHasher(type): + """ + PasswordHasher Metaclass + + Allow classmethod to be properties + """ + @property + def name(cls): + """Returns the name of the hasher""" + return cls.__name__.rstrip('Hasher').lower() + + @property + def label(cls): + """Returns the label of the hasher""" + return cls.name if not cls._weak else "{} (weak)".format(cls.name) + + +class PasswordHasher(with_metaclass(MetaHasher, object)): """ Base class of all hashers. """ @@ -27,16 +46,6 @@ class PasswordHasher(object): def __init__(self, target="local"): self._target = target - class __metaclass__(type): - """class properties""" - @property - def name(cls): - return cls.__name__.rstrip('Hasher').lower() - - @property - def label(cls): - return cls.name if not cls._weak else "{} (weak)".format(cls.name) - def _encrypt(self, clearvalue, salt=None): raise NotImplementedError diff --git a/modoboa/lib/sysutils.py b/modoboa/lib/sysutils.py index a363643fc..868eddcf8 100644 --- a/modoboa/lib/sysutils.py +++ b/modoboa/lib/sysutils.py @@ -46,7 +46,8 @@ def exec_cmd(cmd, sudo_user=None, pinput=None, capture_output=True, **kwargs): return process.returncode, output -def doveadm_cmd(params, sudo_user=None, pinput=None, capture_output=True, **kwargs): +def doveadm_cmd(params, sudo_user=None, pinput=None, + capture_output=True, **kwargs): """Execute doveadm command. Run doveadm command using the current user. Set :keyword:`sudo_user` if