qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] iotests: handle TypeError for Python3 in test 2


From: Philippe Mathieu-Daudé
Subject: Re: [Qemu-devel] [PATCH] iotests: handle TypeError for Python3 in test 242
Date: Mon, 18 Feb 2019 22:25:12 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0

On 2/18/19 9:05 PM, Eric Blake wrote:
> [adding Eduardo for some python 2-vs-3 advice]

And Cleber.

> 
> On 2/18/19 1:59 PM, Andrey Shinkevich wrote:
>> To write one byte to disk, Python2 may use 'chr' type.
>> In Python3, conversion to 'byte' type is required.
>>
>> Signed-off-by: Andrey Shinkevich <address@hidden>
>> ---
>>  tests/qemu-iotests/242 | 9 +++++++--
>>  1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/tests/qemu-iotests/242 b/tests/qemu-iotests/242
>> index 16c65ed..6b1f7b8 100755
>> --- a/tests/qemu-iotests/242
>> +++ b/tests/qemu-iotests/242
>> @@ -65,9 +65,14 @@ 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)
>> +        toggled = ord(c) ^ bitmap_flag_unknown
>>          f.seek(-1, 1)
>> -        f.write(toggled)
>> +        try:
>> +            # python2
>> +            f.write(chr(toggled))
>> +        except TypeError:
>> +            # python3
>> +            f.write(bytes([toggled]))
> 
> Looks like it works, but I'm not enough of a python expert to know if
> there is a more Pythonic elegant approach.
> 
> If someone else picks it up before my next NBD pull request,
> Acked-by: Eric Blake <address@hidden>
> 



reply via email to

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