On 26/02/2019 17:06, Eric Blake wrote: > On 2/26/19 4:39 AM, Andrey Shinkevich wrote: > >>> +++ b/tests/qemu-iotests/242 >>> @@ -64,10 +64,12 @@ def write_to_disk(offset, size): >>> def toggle_flag(offset): >>> with open(disk, "r+b") as f: >>> f.seek(offset, 0) >>> - c = f.read(1) >>> - toggled = chr(ord(c) ^ bitmap_flag_unknown) >>> + # The casts to bytearray() below are only necessary >>> + # for Python 2 compatibility >>> + c = bytearray(f.read(1))[0] >>> >>> >>> This is simpler and makes the intent of the code more clear: >>> >>> flag, = struct.unpack("B", f.read(1)) >>> >>> + toggled = c ^ bitmap_flag_unknown >>> f.seek(-1, 1) >>> - f.write(toggled) >>> + f.write(bytearray([toggled])) >>> >>> >>> For consistency, we can use struct.pack here: >>> >>> f.write(struct.pack("B", toggled)) >>> >>> Nir >>> >> >> Thank you all. I am OK with this approach. >> Will wait for Eric's response. > > That looks better. Peter hasn't applied my pull request yet, so you have > time to submit a formal v3 (making it easier for me to 'git am' it > rather than reconstruct from this email), and then I will update my pull > request to use this improved version. > Noted
-- With the best regards, Andrey Shinkevich