]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
pygrub: encode / decode string in Python 3
authorWei Liu <wei.liu2@citrix.com>
Mon, 1 Apr 2019 10:32:37 +0000 (11:32 +0100)
committerWei Liu <wei.liu2@citrix.com>
Tue, 2 Apr 2019 08:50:41 +0000 (09:50 +0100)
String is unicode in 3 but bytes in 2. We need to call encode / decode
function when using Python 3.

Reported-by: M A Young <m.a.young@durham.ac.uk>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
tools/pygrub/src/pygrub

index dbdce315c610a129fc1d290b98482d95758e91a4..ce7ab0eb8cf3c352dfc5ac1726b88cbbf953ff28 100755 (executable)
@@ -457,7 +457,10 @@ class Grub:
         # limit read size to avoid pathological cases
         buf = f.read(FS_READ_MAX)
         del f
-        self.cf.parse(buf)
+        if sys.version_info[0] < 3:
+            self.cf.parse(buf)
+        else:
+            self.cf.parse(buf.decode())
 
     def image_index(self):
         if isinstance(self.cf.default, int):
@@ -960,5 +963,8 @@ if __name__ == "__main__":
         ostring = format_simple(bootcfg["kernel"], bootcfg["ramdisk"], args, "\0")
 
     sys.stdout.flush()
-    os.write(fd, ostring)
+    if sys.version_info[0] < 3:
+        os.write(fd, ostring)
+    else:
+        os.write(fd, ostring.encode())