summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2017-12-06 17:23:39 +0100
committerArmin Ronacher <armin.ronacher@active-4.com>2017-12-06 17:23:39 +0100
commit9bd66b397fd85f11330afd19ab72390616b2bf48 (patch)
treef0f568e71be1809535c75453751654e4c11b6bed
parentebcbef923d3b9f118d1f21fd3d21645b52099e87 (diff)
downloadclick-9bd66b397fd85f11330afd19ab72390616b2bf48.tar.gz
Fixed unicode behavior for exceptions
-rw-r--r--CHANGES3
-rw-r--r--click/exceptions.py12
2 files changed, 12 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index 6c49ad4..fb2022f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -14,6 +14,9 @@ Version 6.8
- Fix crash on Windows console, see #744.
- Fix bashcompletion on chained commands. See #754.
- Fix option naming routine to match documentation. See #793
+- Fixed the behavior of click error messages with regards to unicode on 2.x
+ and 3.x respectively. Message is now always unicode and the str and unicode
+ special methods work as you expect on that platform.
Version 6.7
-----------
diff --git a/click/exceptions.py b/click/exceptions.py
index 74a4542..148730b 100644
--- a/click/exceptions.py
+++ b/click/exceptions.py
@@ -9,15 +9,21 @@ class ClickException(Exception):
exit_code = 1
def __init__(self, message):
- if PY2:
- if message is not None:
- message = message.encode('utf-8')
Exception.__init__(self, message)
self.message = message
def format_message(self):
return self.message
+ def __str__(self):
+ return self.message
+
+ if PY2:
+ __unicode__ = __str__
+
+ def __str__(self):
+ return self.message.encode('utf-8')
+
def show(self, file=None):
if file is None:
file = get_text_stderr()