50d67088ea
Unicode must be encoded/decoded for text I/O streams, the correct encoding for the stream must be selected and it must be capable of handling the set of characters in the stream or Python will raise a codec error. The correct codec is selected based on the locale. Python2 uses the locales encoding but only when the I/O stream is attached to a terminal (TTY) otherwise it uses the default ASCII encoding. The effect is internationalized text written to the terminal works as expected but if command line output is redirected (file or pipe) the ASCII codec is used and the program aborts with a codec error. The default I/O streams stdin, stdout and stderr can be wrapped in a codec based on the locale thus assuring the users desired encoding is always used no matter the I/O destination. Python3 does this by default. If the caller supplies an I/O stream we use it unmodified on the assumption the caller has taken all responsibility for the stream. But with Python2 if the caller allows us to default the I/O streams to sys.stdin, sys.stdout and sys.stderr we apply the locales encoding just as Python3 would do. We also check to make sure the main Python program has not already already wrapped sys.stdin, sys.stdout and sys.stderr as this is a common recommendation. Note, the unit test enhancement included in this patch is limited to assuring the I/O streams passed to the App constructor are wrapped or not wrapped as expected. No attempt is made to assure codec errors will not occur in a terminal because of the difficulty of constructing such a test. Properly testing this probably would require spawing a subshell but one can't use Python's subcommand because the I/O streams are not attached to a TTY. One could set up a ptty (pseudo-terminal) but experience has shown ptty's to be non-portable across operating systems and environments, getting a ptty to work correctly in all testing environments would be more work and hassle than is justified. Change-Id: I8e85936dff0d5db29a66337c9ce60c70a8dee10a Closes-Bug: 1603210 Signed-off-by: John Dennis <jdennis@redhat.com> |
||
---|---|---|
cliff | ||
demoapp | ||
doc | ||
integration-tests | ||
.gitignore | ||
.gitreview | ||
.travis.yml | ||
CONTRIBUTING.rst | ||
LICENSE | ||
MANIFEST.in | ||
Makefile | ||
README.rst | ||
openstack-common.conf | ||
requirements.txt | ||
setup.cfg | ||
setup.py | ||
test-requirements.txt | ||
tox.ini |
README.rst
cliff -- Command Line Interface Formulation Framework
cliff is a framework for building command line programs. It uses setuptools entry points to provide subcommands, output formatters, and other extensions.
- Free software: Apache license
- Documentation: http://docs.openstack.org/developer/cliff
- Source: http://git.openstack.org/cgit/openstack/cliff
- Bugs: https://bugs.launchpad.net/python-cliff