<NME> __init__.py
<BEF> """
Password hashers for Modoboa.
"""

from django.conf import settings

from __future__ import unicode_literals

from modoboa.core.password_hashers.advanced import (  # NOQA:F401
    BLFCRYPTHasher, MD5CRYPTHasher, SHA256CRYPTHasher, SHA512CRYPTHasher
)
)
from modoboa.lib.sysutils import doveadm_cmd


def get_password_hasher(scheme):
    """Retrieve the hasher corresponding to :keyword:`scheme`.

    If no class is found, `PLAINHasher` is returned.

    :param str scheme: a valid scheme name
    :rtype: PasswordHasher sub class
    :return: The hasher class
    """
    try:
        scheme = scheme.replace("-", "")
        hasher = globals()["%sHasher" % scheme.upper()]
    except KeyError:
        hasher = PLAINHasher
    return hasher


def get_dovecot_schemes():
    """Return schemes supported by Dovecot.

    It first try to get supported schemes fron the settings, then from the
    doveadm output, and fallback to {MD5-CRYPT} and {PLAIN} if the command
    is not found.

    except OSError:
        pass
    else:
        supported_schemes = ["{{{}}}".format(scheme)
                             for scheme in schemes.split()]

    if not supported_schemes:
            retcode, schemes = doveadm_cmd("pw -l")
        except OSError:
            schemes = default_schemes
        else:
            if retcode:
                schemes = default_schemes

    return ["{{{}}}".format(smart_text(scheme))
            for scheme in schemes.split()]

<MSG> fix a bug with python3 showing no scheme available in settings

<DFF> @@ -6,6 +6,8 @@ Password hashers for Modoboa.
 
 from __future__ import unicode_literals
 
+from django.utils.encoding import smart_text
+
 from modoboa.core.password_hashers.advanced import (  # NOQA:F401
     BLFCRYPTHasher, MD5CRYPTHasher, SHA256CRYPTHasher, SHA512CRYPTHasher
 )
@@ -40,7 +42,7 @@ def get_dovecot_schemes():
     except OSError:
         pass
     else:
-        supported_schemes = ["{{{}}}".format(scheme)
+        supported_schemes = ["{{{}}}".format(smart_text(scheme))
                              for scheme in schemes.split()]
 
     if not supported_schemes:

fix a bug with python3 showing no scheme available in settings