tools/python: fix Python3.4 TypeError in format string

Using the first element of a tuple for a format specifier fails with
python3.4 as included in SLE12:
    b = b"string/%x" % (i, )
TypeError: unsupported operand type(s) for %: 'bytes' and 'tuple'

It happens to work with python 2.7 and 3.6.
To support older Py3, format as strings and explicitly encode as ASCII.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
(cherry picked from commit a27976a108)
This commit is contained in:
Olaf Hering authored and Andrew Cooper committed 2021-07-15 11:55:50 +01:00
1 parent 67f798942c
commit 41f0903e16
1 file changed
+3 -3
+3 -3
View File
@@ -346,9 +346,9 @@ def read_libxl_toolstack(vm, data):
if bytearray(name)[-1] != 0:
raise StreamError("physmap name not NUL terminated")
root = b"physmap/%x" % (phys, )
kv = [root + b"/start_addr", b"%x" % (start, ),
root + b"/size", b"%x" % (size, ),
root = ("physmap/%x" % (phys, )).encode('ascii')
kv = [root + b"/start_addr", ("%x" % (start, )).encode('ascii'),
root + b"/size", ("%x" % (size, )).encode('ascii'),
root + b"/name", name[:-1]]
for key, val in zip(kv[0::2], kv[1::2]):
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.