[virt-tools-list] [virt-bootstrap][PATCH 2/7] python3 compat: python3 strings have no decode()

Cédric Bosdonnat cbosdonnat at suse.com
Tue Sep 5 16:41:19 UTC 2017


Since python3 strings are already Unicode-capable, there have no
decode() function. Libguestfs content strings can be either python 2
or 3 strings, only decode them to utf-8 for python2.
---
 src/virtBootstrap/utils.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/virtBootstrap/utils.py b/src/virtBootstrap/utils.py
index 1fb3625..f696471 100644
--- a/src/virtBootstrap/utils.py
+++ b/src/virtBootstrap/utils.py
@@ -168,7 +168,9 @@ class BuildImage(object):
         self.g.mount('/dev/sda', '/')
         success = False
         if self.g.is_file('/etc/shadow'):
-            shadow_content = self.g.read_file('/etc/shadow').decode('utf-8')
+            shadow_content = self.g.read_file('/etc/shadow')
+            if hasattr(shadow_content, 'decode'):
+                shadow_content = shadow_content.decode('utf-8')
             shadow_content = shadow_content.split('\n')
             if shadow_content:
                 # Note: 'shadow_content' is a list, pass-by-reference is used
-- 
2.13.2




More information about the virt-tools-list mailing list