Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
2 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77912c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tchaikov
If I'm still using python2, how to solve the problem?