mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Misc encoding fixes
This commit is contained in:
parent
d3c7d12457
commit
0d58eff6a2
4 changed files with 19 additions and 13 deletions
|
@ -15,7 +15,6 @@ from moulinette.authenticators import BaseAuthenticator
|
|||
|
||||
logger = logging.getLogger("moulinette.authenticator.ldap")
|
||||
|
||||
|
||||
# LDAP Class Implementation --------------------------------------------
|
||||
|
||||
|
||||
|
@ -60,7 +59,7 @@ class Authenticator(BaseAuthenticator):
|
|||
|
||||
def __del__(self):
|
||||
"""Disconnect and free ressources"""
|
||||
if self.con:
|
||||
if hasattr(self, "con") and self.con:
|
||||
self.con.unbind_s()
|
||||
|
||||
# Implement virtual properties
|
||||
|
@ -150,6 +149,19 @@ class Authenticator(BaseAuthenticator):
|
|||
for dn, entry in result:
|
||||
entry["dn"] = [dn]
|
||||
result_list.append(entry)
|
||||
|
||||
def decode(value):
|
||||
if isinstance(value, bytes):
|
||||
value = value.decode('utf-8')
|
||||
return value
|
||||
|
||||
# result_list is for example :
|
||||
# [{'virtualdomain': [b'test.com']}, {'virtualdomain': [b'yolo.test']},
|
||||
for stuff in result_list:
|
||||
if isinstance(stuff, dict):
|
||||
for key, values in stuff.items():
|
||||
stuff[key] = [decode(v) for v in values]
|
||||
|
||||
return result_list
|
||||
|
||||
def add(self, rdn, attr_dict):
|
||||
|
|
|
@ -156,15 +156,11 @@ def pretty_print_dict(d, depth=0):
|
|||
elif isinstance(value, dict):
|
||||
pretty_print_dict({key: value}, depth + 1)
|
||||
else:
|
||||
if isinstance(value, str):
|
||||
value = value.encode("utf-8")
|
||||
elif isinstance(v, date):
|
||||
if isinstance(v, date):
|
||||
v = pretty_date(v)
|
||||
print("{:s}- {}".format(" " * (depth + 1), value))
|
||||
else:
|
||||
if isinstance(v, str):
|
||||
v = v.encode("utf-8")
|
||||
elif isinstance(v, date):
|
||||
if isinstance(v, date):
|
||||
v = pretty_date(v)
|
||||
print("{:s}{}: {}".format(" " * depth, k, v))
|
||||
|
||||
|
@ -532,8 +528,6 @@ class Interface(BaseInterface):
|
|||
Handle the core.MoulinetteSignals.display signal.
|
||||
|
||||
"""
|
||||
if isinstance(message, str):
|
||||
message = message.encode("utf-8")
|
||||
if style == "success":
|
||||
print("{} {}".format(colorize(m18n.g("success"), "green"), message))
|
||||
elif style == "warning":
|
||||
|
|
|
@ -101,7 +101,7 @@ class MoulinetteLogger(Logger):
|
|||
if self.isEnabledFor(SUCCESS):
|
||||
self._log(SUCCESS, msg, args, **kwargs)
|
||||
|
||||
def findCaller(self):
|
||||
def findCaller(self, *args):
|
||||
"""Override findCaller method to consider this source file."""
|
||||
f = logging.currentframe()
|
||||
if f is not None:
|
||||
|
@ -125,7 +125,7 @@ class MoulinetteLogger(Logger):
|
|||
# FIXME: Get real action_id instead of logger/current one
|
||||
extra["action_id"] = _get_action_id()
|
||||
kwargs["extra"] = extra
|
||||
return Logger._log(self, *args, **kwargs)
|
||||
return super()._log(*args, **kwargs)
|
||||
|
||||
|
||||
# Action logging -------------------------------------------------------
|
||||
|
|
|
@ -28,7 +28,7 @@ def check_output(args, stderr=subprocess.STDOUT, shell=True, **kwargs):
|
|||
and use shell by default before calling subprocess.check_output.
|
||||
|
||||
"""
|
||||
return subprocess.check_output(args, stderr=stderr, shell=shell, **kwargs).strip()
|
||||
return subprocess.check_output(args, stderr=stderr, shell=shell, **kwargs).decode('utf-8').strip()
|
||||
|
||||
|
||||
# Call with stream access ----------------------------------------------
|
||||
|
|
Loading…
Add table
Reference in a new issue