[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [PATCH v2] iotests: handle TypeError for Python3 in tes
From: |
Eduardo Habkost |
Subject: |
Re: [Qemu-block] [PATCH v2] iotests: handle TypeError for Python3 in test 242 |
Date: |
Tue, 26 Feb 2019 07:44:19 -0300 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
On Tue, Feb 26, 2019 at 03:42:11AM +0200, Nir Soffer wrote:
> On Mon, Feb 25, 2019 at 10:36 PM Eduardo Habkost <address@hidden>
[...]
> > - 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))
That's perfect. Thanks for the suggestion!
--
Eduardo
- Re: [Qemu-block] [PATCH v2] iotests: handle TypeError for Python3 in test 242, (continued)