On Tue, Feb 26, 2019 at 03:42:11AM +0200, Nir Soffer wrote:
> On Mon, Feb 25, 2019 at 10:36 PM Eduardo Habkost <ehabk...@redhat.com>
[...]
> > -        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

Reply via email to