diff options
author | Flaper Fesp <flaper87@gmail.com> | 2013-02-27 14:47:44 +0100 |
---|---|---|
committer | Flaper Fesp <flaper87@gmail.com> | 2013-03-29 13:50:48 +0100 |
commit | 03a4806d972ac150e717451566e9c4c35a141d8f (patch) | |
tree | b5079ee0b75eb9d184449913ac71691ba7a4f6c0 /cinderclient/shell.py | |
parent | 7369310622224073ecbef4ab84a48c2a873a56b9 (diff) | |
download | python-cinderclient-1.0.3.tar.gz |
Decodes input and encodes output1.0.3
Currently cinderclient doesn't handle properly incoming and outgoing
encode / decode process. As a solution for this, this patch implements a
decoding process for all data incoming from the user side and encodes
everything going out of the client, i.e: http requests, prints, etc.
This patch introduces a new module (strutils.py) taken from
oslo-incubator in order to use 2 of the functions present in it:
About safe_(decode|encode):
Both functions try to encode / decode the incoming text using the
stdin encoding, fallback to python's default encoding if that
returns None or to UTF-8 as the last option.
In both functions only basestring objects are accepted and they both
raise TypeError if an object of another type is passed.
About the general cinderclient changes:
In order to better support non-ASCII characters, it is a good
practice to use unicode interanlly and encode everything that has to
go out. This patch aims to do that and introduces this behaviour in
the client.
Testing:
A good test (besides using tox) is to use cinder client with and
without setting any locale (export LANG=).
Fixes bug: 1130572
Change-Id: Idb7d06954c29e003f68a0c4aa0b80ecc7017cbc9
Diffstat (limited to 'cinderclient/shell.py')
-rw-r--r-- | cinderclient/shell.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/cinderclient/shell.py b/cinderclient/shell.py index b163d70..c080564 100644 --- a/cinderclient/shell.py +++ b/cinderclient/shell.py @@ -30,6 +30,7 @@ import logging from cinderclient import client from cinderclient import exceptions as exc import cinderclient.extension +from cinderclient.openstack.common import strutils from cinderclient import utils from cinderclient.v1 import shell as shell_v1 from cinderclient.v2 import shell as shell_v2 @@ -486,13 +487,16 @@ class OpenStackHelpFormatter(argparse.HelpFormatter): def main(): try: - OpenStackCinderShell().main(sys.argv[1:]) + OpenStackCinderShell().main(map(strutils.safe_decode, sys.argv[1:])) except KeyboardInterrupt: print >> sys.stderr, "... terminating cinder client" sys.exit(130) except Exception, e: logger.debug(e, exc_info=1) - print >> sys.stderr, "ERROR: %s" % e.message + message = e.message + if not isinstance(message, basestring): + message = str(message) + print >> sys.stderr, "ERROR: %s" % strutils.safe_encode(message) sys.exit(1) |