qemu-block
[Top][All Lists]
Advanced

[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: Andrey Shinkevich
Subject: Re: [Qemu-block] [Qemu-devel] [PATCH v2] iotests: handle TypeError for Python3 in test 242
Date: Tue, 26 Feb 2019 14:08:36 +0000


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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]