[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [Qemu-devel] [PATCH v2] iotests: handle TypeError for P
From: |
Eric Blake |
Subject: |
Re: [Qemu-block] [Qemu-devel] [PATCH v2] iotests: handle TypeError for Python3 in test 242 |
Date: |
Tue, 26 Feb 2019 08:06:10 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 |
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.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
- [Qemu-block] [PATCH v2] iotests: handle TypeError for Python3 in test 242, Andrey Shinkevich, 2019/02/22
- Re: [Qemu-block] [PATCH v2] iotests: handle TypeError for Python3 in test 242, Eric Blake, 2019/02/22
- Re: [Qemu-block] [Qemu-devel] [PATCH v2] iotests: handle TypeError for Python3 in test 242, Cleber Rosa, 2019/02/22
- Re: [Qemu-block] [PATCH v2] iotests: handle TypeError for Python3 in test 242, Vladimir Sementsov-Ogievskiy, 2019/02/23
- Re: [Qemu-block] [PATCH v2] iotests: handle TypeError for Python3 in test 242, Eduardo Habkost, 2019/02/25
- Re: [Qemu-block] [PATCH v2] iotests: handle TypeError for Python3 in test 242, Eduardo Habkost, 2019/02/26