import json
import threading
import time
+import six
import bcrypt
from .. import mgr, logger
from ..security import Scope, Permission
-from ..tools import ensure_str
from ..exceptions import RoleAlreadyExists, RoleDoesNotExist, ScopeNotValid, \
PermissionNotValid, RoleIsAssociatedWithUser, \
UserAlreadyExists, UserDoesNotExist, ScopeNotInRole, \
RoleNotInUser
+# replicates tools.ensure_str() to avoid recursive import:
+# ..tools -> .services.auth -> .access_control -> ..tools
+def ensure_str(s, encoding='utf-8', errors='strict'):
+ """Ported from six."""
+ if not isinstance(s, (six.text_type, six.binary_type)):
+ raise TypeError("not expecting type '%s'" % type(s))
+ if six.PY2 and isinstance(s, six.text_type):
+ s = s.encode(encoding, errors)
+ elif six.PY3 and isinstance(s, six.binary_type):
+ s = s.decode(encoding, errors)
+ return s
+
+
# password hashing algorithm
def password_hash(password, salt_password=None):
if not password: