]> git.apps.os.sepia.ceph.com Git - ceph.git/commit
ceph-volume: terminal: encode unicode when writing to stdout 27148/head
authorKefu Chai <kchai@redhat.com>
Sun, 24 Mar 2019 09:11:31 +0000 (17:11 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 27 Mar 2019 14:41:24 +0000 (22:41 +0800)
commit77912c0c71874a23785d3bdd109ad61e4f4c0e28
treea8727915706ac6987df971ab7a1c682154ed0f5f
parentcdba92a1e3cb64f503c1ed753c4a74e8616fa1f6
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>
src/ceph-volume/ceph_volume/terminal.py
src/ceph-volume/ceph_volume/tests/test_terminal.py