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:
Wei Liu committed 2019-04-02 09:50:41 +01:00
1 parent 767ba397d3
commit ff915c8cac
1 file changed
+8 -2
+8 -2
View File
@@ -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())
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.