Fix an issue with __metaclass__ in python3

improve code quality
This commit is contained in:
Anthony Bourguignon
2018-10-14 12:41:59 +02:00
parent e2f7b47b47
commit bb05f502cf
3 changed files with 23 additions and 13 deletions
+1 -1
View File
@@ -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:
+20 -11
View File
@@ -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
+2 -1
View File
@@ -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