mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
pygrub: encode / decode string in Python 3
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>
This commit is contained in:
1 parent
767ba397d3
commit
ff915c8cac
1 file changed
+8
-2
@@ -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())
|
||||
|
||||