Skip to content
This repository was archived by the owner on Mar 19, 2020. It is now read-only.

Commit 0553f05

Browse files
committed
Encoding fixes
Reported-by: Mehdi Laouichi <[email protected]> Signed-off-by: Stéphane Graber <[email protected]>
1 parent dc662b3 commit 0553f05

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lxc/__init__.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,14 @@ def set_config_item(self, key, value):
371371
except KeyError:
372372
old_value = None
373373

374+
# Get everything to unicode with python2
375+
if isinstance(value, str):
376+
value = value.decode()
377+
elif isinstance(value, list):
378+
for i in range(len(value)):
379+
if isinstance(value[i], str):
380+
value[i] = value[i].decode()
381+
374382
# Check if it's a list
375383
def set_key(key, value):
376384
self.clear_config_item(key)
@@ -388,13 +396,13 @@ def set_key(key, value):
388396
if key == "lxc.loglevel":
389397
new_value = value
390398

391-
if (isinstance(value, str) and isinstance(new_value, str) and
399+
if (isinstance(value, unicode) and isinstance(new_value, unicode) and
392400
value == new_value):
393401
return True
394402
elif (isinstance(value, list) and isinstance(new_value, list) and
395403
set(value) == set(new_value)):
396404
return True
397-
elif (isinstance(value, str) and isinstance(new_value, list) and
405+
elif (isinstance(value, unicode) and isinstance(new_value, list) and
398406
set([value]) == set(new_value)):
399407
return True
400408
elif old_value:
@@ -473,7 +481,7 @@ def arch_to_personality(arch):
473481
Determine the process personality corresponding to the architecture
474482
"""
475483
if isinstance(arch, bytes):
476-
arch = str(arch, 'utf-8')
484+
arch = unicode(arch)
477485
return _lxc.arch_to_personality(arch)
478486

479487
# namespace flags (no other python lib exports this)

0 commit comments

Comments
 (0)