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) settings = yaml.load(f)
# If label contains unicode char, this may later trigger issues when building strings... # 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... # 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']: if app_id == settings['id']:
return settings return settings
except (IOError, TypeError, KeyError): except (IOError, TypeError, KeyError):
@ -2300,21 +2300,12 @@ def _value_for_locale(values):
for lang in [m18n.locale, m18n.default_locale]: for lang in [m18n.locale, m18n.default_locale]:
try: try:
return _encode_string(values[lang]) return values[lang]
except KeyError: except KeyError:
continue continue
# Fallback to first value # Fallback to first value
return _encode_string(values.values()[0]) return 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
def _check_manifest_requirements(manifest, app_instance_name): 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 mean that we don't have a translation for this string
# that's the only way to test for that for now # that's the only way to test for that for now
# if we don't have it, uses the one provided by systemd # 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", "")) description = str(raw_status.get("Description", ""))
output = { output = {

View file

@ -173,7 +173,7 @@ class PasswordValidator(object):
# stdin to avoid it being shown in ps -ef --forest... # stdin to avoid it being shown in ps -ef --forest...
command = "grep -q -f - %s" % MOST_USED_PASSWORDS command = "grep -q -f - %s" % MOST_USED_PASSWORDS
p = subprocess.Popen(command.split(), stdin=subprocess.PIPE) p = subprocess.Popen(command.split(), stdin=subprocess.PIPE)
p.communicate(input=password) p.communicate(input=password.encode('utf-8'))
return not bool(p.returncode) return not bool(p.returncode)