summaryrefslogtreecommitdiff
path: root/demoapp
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@dreamhost.com>2013-07-31 12:02:28 -0400
committerDoug Hellmann <doug.hellmann@dreamhost.com>2013-08-12 14:45:23 -0400
commitaa6bb0cfe3bda491aea7293be2ab78ccc40bd061 (patch)
treefbffdf833bf43d5249a50fb1094e0496a1078d0e /demoapp
parent50de738446d5e4e1ad085b6d8faf41c640c6159f (diff)
downloadcliff-aa6bb0cfe3bda491aea7293be2ab78ccc40bd061.tar.gz
Fix default encoding issue with python 2.6
This change addresses issue #38: "fix unicode handling issues". The issue was originally reported against neutron client (https://bugs.launchpad.net/python-neutronclient/+bug/1189112) but was tracked down to the fact that python 2.6 does not set the default encoding for sys.stdout properly. A change to python 2.7 fixes the problem there and later (http://hg.python.org/cpython/rev/e60ef17561dc/), but since cliff supports python 2.6 it needs to handle the case explicitly. Change-Id: Id06507d78c7c82b25f39366ea4a6dfa4ef3a3a97
Diffstat (limited to 'demoapp')
-rw-r--r--demoapp/cliffdemo/encoding.py23
-rw-r--r--demoapp/setup.py1
2 files changed, 24 insertions, 0 deletions
diff --git a/demoapp/cliffdemo/encoding.py b/demoapp/cliffdemo/encoding.py
new file mode 100644
index 0000000..6c6c751
--- /dev/null
+++ b/demoapp/cliffdemo/encoding.py
@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+
+import logging
+
+from cliff.lister import Lister
+
+
+class Encoding(Lister):
+ """Show some unicode text
+ """
+
+ log = logging.getLogger(__name__)
+
+ def take_action(self, parsed_args):
+ messages = [
+ u'pi: π',
+ u'GB18030:鼀丅㐀ٸཌྷᠧꌢ€',
+ ]
+ return (
+ ('UTF-8', 'Unicode'),
+ [(repr(t.encode('utf-8')), t)
+ for t in messages],
+ )
diff --git a/demoapp/setup.py b/demoapp/setup.py
index 33dd73b..330e03e 100644
--- a/demoapp/setup.py
+++ b/demoapp/setup.py
@@ -68,6 +68,7 @@ setup(
'files = cliffdemo.list:Files',
'file = cliffdemo.show:File',
'show file = cliffdemo.show:File',
+ 'unicode = cliffdemo.encoding:Encoding',
],
},