[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v3 1/2] qapi: open files in binary mode and use
Re: [Qemu-devel] [PATCH v3 1/2] qapi: open files in binary mode and use explicit decoding/encoding in common.py
Mon, 18 Jun 2018 18:28:13 -0300
On Mon, Jun 18, 2018 at 06:17:04PM -0300, Eduardo Habkost wrote:
> On Mon, Jun 18, 2018 at 07:54:26PM +0200, Markus Armbruster wrote:
> > Eduardo Habkost <address@hidden> writes:
> > > On Mon, Jun 18, 2018 at 07:25:14AM +0200, Markus Armbruster wrote:
> > >> Matthias Maier <address@hidden> writes:
> > >>
> > >> > This is a different approach to fix the locale dependent encode/decode
> > >> > problem in common.py utilizing the binary read/write mode [1,2], and
> > >> > (if
> > >> > a python 3 interpreter is used) with explicit decode/encode arguments
> > >> > .
> > >>
> > >> Why can't we simply pass encoding='utf-8' to open()?
> > >
> > > This wouldn't work in Python 2.7 (where the `open()` builtin
> > > doesn't support the `encoding` parameter).
> > >
> > > io.open(..., encoding='utf-8') should work, though.
> > This falls apart because then f.read() returns objects of type 'unicode'
> > in Python 2, breaking isinstance(..., str) predicates in several places.
> If the existing code already works with Python 3, we can import
> Python 3 string semantics in Python 2.7 so we have just one
> string API to care about.
> This should do it:
> from __future__ import unicode_literals
> from builtins import str
> from builtins import open
Oops, I just noticed that this needs the 'future' package to be
I will submit a patch series later requiring python-future on
./configure. In the meantime, probably your series is good
[Qemu-devel] [PATCH v3 2/2] Revert commit d4e5ec877ca, Matthias Maier, 2018/06/15