From 5f0b1b745069b89d7474386de1f21326137dfabf Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 1 Jan 2021 04:06:09 +0100 Subject: [PATCH] Encoding fixes --- src/yunohost/app.py | 15 +++------------ src/yunohost/service.py | 2 +- src/yunohost/utils/password.py | 2 +- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 05580fbe1..d3cf5a11c 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1873,7 +1873,7 @@ def _get_app_settings(app_id): settings = yaml.load(f) # If label contains unicode char, this may later trigger issues when building strings... # FIXME: this should be propagated to read_yaml so that this fix applies everywhere I think... - settings = {k: _encode_string(v) for k, v in settings.items()} + settings = {k: v for k, v in settings.items()} if app_id == settings['id']: return settings except (IOError, TypeError, KeyError): @@ -2300,21 +2300,12 @@ def _value_for_locale(values): for lang in [m18n.locale, m18n.default_locale]: try: - return _encode_string(values[lang]) + return values[lang] except KeyError: continue # Fallback to first value - return _encode_string(values.values()[0]) - - -def _encode_string(value): - """ - Return the string encoded in utf-8 if needed - """ - if isinstance(value, str): - return value.encode('utf8') - return value + return values.values()[0] def _check_manifest_requirements(manifest, app_instance_name): diff --git a/src/yunohost/service.py b/src/yunohost/service.py index 1b1fec81b..89d51b740 100644 --- a/src/yunohost/service.py +++ b/src/yunohost/service.py @@ -358,7 +358,7 @@ def _get_and_format_service_status(service, infos): # that mean that we don't have a translation for this string # that's the only way to test for that for now # if we don't have it, uses the one provided by systemd - if description.decode('utf-8') == translation_key: + if description == translation_key: description = str(raw_status.get("Description", "")) output = { diff --git a/src/yunohost/utils/password.py b/src/yunohost/utils/password.py index e7ff6c275..ac26ae4bf 100644 --- a/src/yunohost/utils/password.py +++ b/src/yunohost/utils/password.py @@ -173,7 +173,7 @@ class PasswordValidator(object): # stdin to avoid it being shown in ps -ef --forest... command = "grep -q -f - %s" % MOST_USED_PASSWORDS p = subprocess.Popen(command.split(), stdin=subprocess.PIPE) - p.communicate(input=password) + p.communicate(input=password.encode('utf-8')) return not bool(p.returncode)