From 0553f05d23b56b59bf3015fa5e45bfbfab9021ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Mon, 25 Aug 2014 15:42:25 -0400 Subject: [PATCH] Encoding fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported-by: Mehdi Laouichi Signed-off-by: Stéphane Graber --- lxc/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lxc/__init__.py b/lxc/__init__.py index 47b25b8..7347a98 100644 --- a/lxc/__init__.py +++ b/lxc/__init__.py @@ -371,6 +371,14 @@ class Container(_lxc.Container): except KeyError: old_value = None + # Get everything to unicode with python2 + if isinstance(value, str): + value = value.decode() + elif isinstance(value, list): + for i in range(len(value)): + if isinstance(value[i], str): + value[i] = value[i].decode() + # Check if it's a list def set_key(key, value): self.clear_config_item(key) @@ -388,13 +396,13 @@ class Container(_lxc.Container): if key == "lxc.loglevel": new_value = value - if (isinstance(value, str) and isinstance(new_value, str) and + if (isinstance(value, unicode) and isinstance(new_value, unicode) and value == new_value): return True elif (isinstance(value, list) and isinstance(new_value, list) and set(value) == set(new_value)): return True - elif (isinstance(value, str) and isinstance(new_value, list) and + elif (isinstance(value, unicode) and isinstance(new_value, list) and set([value]) == set(new_value)): return True elif old_value: @@ -473,7 +481,7 @@ def arch_to_personality(arch): Determine the process personality corresponding to the architecture """ if isinstance(arch, bytes): - arch = str(arch, 'utf-8') + arch = unicode(arch) return _lxc.arch_to_personality(arch) # namespace flags (no other python lib exports this)