Command Line Interface Formulation Framework
Go to file
John Dennis 132c948aed Fix codec error when format=csv
The Py2 version of the csv module cannot accept unicode text. In Py2
we replaced the csv module with the unicodecsv module which encodes
unicode text prior to calling the standard Py2 csv module. Thus when
the cvs formatted output is emitted on stdout it is presented as a
encoded byte stream. But stdout has been replaced with a StreamWriter
which encodes to the desired encoding. The problem is the StreamWriter
attempts to encode all objects passed to it's write function,
including str objects. Instead it should only encode unicode text objects
and allow bytes to pass through unmodified.

This patch adds an override of the codecs.getwriter function which
only encodes unicode text objects. In addtion we pass the encoding
value obtained from the stream to the unicodecsv writer.

The patch fixes the codec error when outputing csv formated text that
contains a non-ASCII character. The unicodecsv implmentation will emit
byte encoded str objects to the stream. When the core StreamWriter
attempts to encode a str object Python will first promote the str
object to a unicode object. The promotion of str to unicode requires
the str bytes to be decoded. However the encoding associated with the
str object is not known therefore Python applies the default-encoding
which is ASCII. In the case where the str object contains utf-8
encoded non-ASCII characters a decoding error is raised. By not
attempting to encode a byte stream we avoid this error.

A more complete discussion of the above issues can be found here:

https://github.com/fedora-infra/kitchen/blob/develop/kitchen2/docs/unicode-frustrations.rst#frustration-4-now-it-doesnt-take-byte-strings

Conflicts:
    cliff/tests/test_app.py

Change-Id: I22b5ad8bf0e227ec75a2a36986f0487191f7cbc2
Closes-Bug: 1720115
Signed-off-by: John Dennis <jdennis@redhat.com>
(cherry picked from commit c61cc30060)
2017-12-06 13:58:54 +00:00
cliff Fix codec error when format=csv 2017-12-06 13:58:54 +00:00
demoapp Fix cliff URLs in doc and demoapp 2016-07-28 16:08:47 +09:00
doc [doc]Fix URL for 'setuptools entry points' 2016-09-07 21:41:54 +09:00
integration-tests Remove tox environments that no longer work 2017-01-04 08:54:20 +11:00
.gitignore Sort the fuzzy matches 2015-04-14 08:17:04 -06:00
.gitreview Update .gitreview for stable/ocata 2017-01-31 20:53:35 +00:00
.travis.yml add pypy test env configuration 2013-09-23 15:45:31 -04:00
CONTRIBUTING.rst Workflow documentation is now in infra-manual 2014-12-05 03:30:36 +00:00
LICENSE change to apache license 2012-04-20 10:06:58 -07:00
MANIFEST.in remove the other traces of distribute 2013-06-11 14:01:31 -04:00
Makefile Correct path to docs 2015-11-12 13:52:05 +00:00
README.rst Show team and repo badges on README 2016-11-26 12:04:54 +01:00
openstack-common.conf remove openstack-common.conf 2016-01-15 12:53:44 +08:00
requirements.txt Updated from global requirements 2017-07-26 16:11:13 +00:00
setup.cfg Merge "Add Python 3.5 classifier and venv" 2016-11-15 22:23:34 +00:00
setup.py Updated from global requirements 2015-11-19 15:44:19 +00:00
test-requirements.txt Updated from global requirements 2016-10-22 01:18:07 +00:00
tox.ini Remove tox environments that no longer work 2017-01-04 08:54:20 +11:00

README.rst

Team and repository tags

image

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.