All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>,
	Matthias Maier <tamiko@43-1.org>,
	qemu-devel@nongnu.org,
	Arfrever Frehtes Taifersar Arahesis <arfrever.fta@gmail.com>
Subject: Re: [Qemu-devel] [PATCH v3 1/2] qapi: open files in binary mode and use explicit decoding/encoding in common.py
Date: Mon, 18 Jun 2018 19:54:26 +0200	[thread overview]
Message-ID: <87y3fc6kvh.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20180618160430.GG7451@localhost.localdomain> (Eduardo Habkost's message of "Mon, 18 Jun 2018 13:04:30 -0300")

Eduardo Habkost <ehabkost@redhat.com> writes:

> On Mon, Jun 18, 2018 at 07:25:14AM +0200, Markus Armbruster wrote:
>> Matthias Maier <tamiko@43-1.org> 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
>> > [3].
>> 
>> 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.

What I asked for is something else: wrap the version conditional around
open() instead of around the conversion from bytes to str.  Coding up
the (trivial) patch is easier than explaining it in more detail than
"pass encoding='utf-8' to open()", so I did just that.

  reply	other threads:[~2018-06-18 17:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-15 22:02 [Qemu-devel] [PATCH v3 0/2] Fix compilation with python-3 if en_US.UTF-8 is unavailable Matthias Maier
2018-06-15 22:02 ` [Qemu-devel] [PATCH v3 1/2] qapi: open files in binary mode and use explicit decoding/encoding in common.py Matthias Maier
2018-06-18  5:25   ` Markus Armbruster
2018-06-18 14:32     ` Matthias Maier
2018-06-18 16:04     ` Eduardo Habkost
2018-06-18 17:54       ` Markus Armbruster [this message]
2018-06-18 21:17         ` Eduardo Habkost
2018-06-18 21:28           ` Eduardo Habkost
2018-06-15 22:02 ` [Qemu-devel] [PATCH v3 2/2] Revert commit d4e5ec877ca Matthias Maier

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=87y3fc6kvh.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=arfrever.fta@gmail.com \
    --cc=ehabkost@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=tamiko@43-1.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.