]> git.ipfire.org Git - thirdparty/patchwork.git/commit
pwclient: Fix encoding problems
authorRobin Jarry <robin.jarry@6wind.com>
Thu, 15 Dec 2016 16:56:18 +0000 (17:56 +0100)
committerStephen Finucane <stephen@that.guru>
Sun, 18 Dec 2016 22:31:39 +0000 (22:31 +0000)
commitcdeeaa79743bf1a9117532ca94f68b5c78a74d43
treef50fdeb8a26ceb2f2c67054f8e9d28f325dd171e
parentcfe8b7b1159aaec950a765abd4165fcae9aa83d9
pwclient: Fix encoding problems

All data returned by the xmlrpc object is unicode decoded with 'utf-8' (on
python 3, unicode == str). Add from __future__ import unicode_literals
to make sure that everything is unicode and avoid surprises.

On python 2, printing unicode to stdout causes it to be encoded to str
(byte string) with the 'ascii' codec:

  >>> print some_unicode_string
  ...
  UnicodeEncodeError: 'ascii' codec can't encode character u'\u0142'
  in position 468: ordinal not in range(128)

Work around ths by avoiding any explicit call to unicode() and by
replacing sys.stdout and sys.stderr by unicode-aware file objects (as
returned by io.open()).

Guess the encoding of stdout and stderr by looking at (in that order):
sys.stdout.encoding, locale.getpreferredencoding(), the PYTHONIOENCODING
environment variable. If no encoding is defined, assume 'utf-8' as
output encoding.

Conflicts:
    patchwork/bin/pwclient

Tested-by: Thomas Monjalon <thomas.monjalon@6wind.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
(cherry picked from commit 046419a3bf8f012fcb019c3ec8d78653da685908)
patchwork/bin/pwclient