]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
ceph-volume: terminal: encode unicode when writing to stdout
authorKefu Chai <kchai@redhat.com>
Sun, 24 Mar 2019 09:11:31 +0000 (17:11 +0800)
committerJan Fajerski <jfajerski@suse.com>
Mon, 12 Aug 2019 12:24:43 +0000 (14:24 +0200)
commit47b02f2e5197428f631e1b5b5e6c11def257c5e0
treee65a19953d956963eb5489dbd6e884e77864eacb
parent75b82403d554c5af2e2479fbd945e6729ed9a289
ceph-volume: terminal: encode unicode when writing to stdout

python determins the encoding of stdout and stderr based on the LC_CTYPE
and PYTHONIOENCODING env variable, by default, python3's sys.stdout uses
'utf-8' as its encoding, so it will be able to write unicode string even
the stdout is not attached to a tty device. but when it comes to
python2, it will default to ascii if neither of these variabls is set.
so, if we are writing unicode using `_Write` in an environment where
LC_CTYPE and/or PYTHONIOENCODING are using non UTF-8 encoding, it chokes
by raising `UnicodeEncodeError` exception.

in this change, we add a wrapper around `_Write._writer` so it is able
to write unicode string in such a non-unicode-friendly environment.

for more info related the encoding of stdout and stderr, see
https://docs.python.org/3/using/cmdline.html#envvar-PYTHONIOENCODING .

Signed-off-by: Alfredo Deza <adeza@redhat.com>
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 77912c0c71874a23785d3bdd109ad61e4f4c0e28)
src/ceph-volume/ceph_volume/terminal.py
src/ceph-volume/ceph_volume/tests/test_terminal.py