From: Eric Blake <eblake@redhat.com>
To: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>,
Nir Soffer <nsoffer@redhat.com>,
Eduardo Habkost <ehabkost@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
Denis Lunev <den@virtuozzo.com>,
qemu-block <qemu-block@nongnu.org>,
philmd@redhat.com, QEMU Developers <qemu-devel@nongnu.org>,
Max Reitz <mreitz@redhat.com>, Cleber Rosa <crosa@redhat.com>
Subject: Re: [Qemu-devel] [Qemu-block] [PATCH v2] iotests: handle TypeError for Python3 in test 242
Date: Tue, 26 Feb 2019 08:06:10 -0600 [thread overview]
Message-ID: <d335bcf4-fae8-108d-2e24-9cfba80b5c2c@redhat.com> (raw)
In-Reply-To: <a8ca5f99-43d0-610b-ea09-28b2655f5cda@virtuozzo.com>
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
next prev parent reply other threads:[~2019-02-26 14:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-22 11:26 [Qemu-devel] [PATCH v2] iotests: handle TypeError for Python3 in test 242 Andrey Shinkevich
2019-02-22 14:53 ` Eric Blake
2019-02-25 8:51 ` Andrey Shinkevich
2019-02-22 15:20 ` Cleber Rosa
2019-02-25 8:51 ` Andrey Shinkevich
2019-02-23 9:19 ` Vladimir Sementsov-Ogievskiy
2019-02-25 20:26 ` Eduardo Habkost
2019-02-26 1:42 ` [Qemu-devel] [Qemu-block] " Nir Soffer
2019-02-26 10:39 ` Andrey Shinkevich
2019-02-26 14:06 ` Eric Blake [this message]
2019-02-26 14:08 ` Andrey Shinkevich
2019-02-26 10:44 ` Eduardo Habkost
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d335bcf4-fae8-108d-2e24-9cfba80b5c2c@redhat.com \
--to=eblake@redhat.com \
--cc=andrey.shinkevich@virtuozzo.com \
--cc=crosa@redhat.com \
--cc=den@virtuozzo.com \
--cc=ehabkost@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=nsoffer@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).