Encoding fixes

This commit is contained in:
Alexandre Aubin 2021-01-01 04:06:09 +01:00
parent 86a612fab1
commit 5f0b1b7450
3 changed files with 5 additions and 14 deletions

View file

@ -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):

View file

@ -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 = {

View file

@ -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)