From: Wei Liu Date: Mon, 1 Apr 2019 10:32:37 +0000 (+0100) Subject: pygrub: encode / decode string in Python 3 X-Git-Tag: archive/raspbian/4.14.0+80-gd101b417b7-1+rpi1^2~63^2~2420 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=ff915c8cacc264ae1380d51fea07267b8308d7ba;p=xen.git 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 Signed-off-by: Wei Liu Acked-by: Andrew Cooper --- diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub index dbdce315c6..ce7ab0eb8c 100755 --- a/tools/pygrub/src/pygrub +++ b/tools/pygrub/src/pygrub @@ -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())