diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-05 12:40:49 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-05 12:40:49 (GMT) |
commit | 926fd4ee32de00ddb44df111f830678e2bcc6524 (patch) | |
tree | a6e5cda549defe46bae0ff2e520b09fd2c7c81ac | |
parent | f3c157f639f3da24ccfc532aabe01af1ba0111c5 (diff) | |
download | cpython-926fd4ee32de00ddb44df111f830678e2bcc6524.zip cpython-926fd4ee32de00ddb44df111f830678e2bcc6524.tar.gz cpython-926fd4ee32de00ddb44df111f830678e2bcc6524.tar.bz2 |
Issue #8313: traceback.format_exception_only() encodes unicode message to
ASCII with backslashreplace error handler if str(value) failed
-rw-r--r-- | Lib/test/test_traceback.py | 9 | ||||
-rw-r--r-- | Lib/traceback.py | 10 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 20 insertions, 2 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index c79961e..811feac 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -159,6 +159,15 @@ def test(): err = traceback.format_exception_only(None, None) self.assertEqual(err, ['None\n']) + def test_unicode(self): + err = AssertionError('\xff') + lines = traceback.format_exception_only(type(err), err) + self.assertEqual(lines, ['AssertionError: \xff\n']) + + err = AssertionError(u'\xe9') + lines = traceback.format_exception_only(type(err), err) + self.assertEqual(lines, ['AssertionError: \\xe9\n']) + class TracebackFormatTests(unittest.TestCase): diff --git a/Lib/traceback.py b/Lib/traceback.py index 8d28afc..8cb9e28 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -211,8 +211,14 @@ def _format_final_exc_line(etype, value): def _some_str(value): try: return str(value) - except: - return '<unprintable %s object>' % type(value).__name__ + except Exception: + pass + try: + value = unicode(value) + return value.encode("ascii", "backslashreplace") + except Exception: + pass + return '<unprintable %s object>' % type(value).__name__ def print_exc(limit=None, file=None): @@ -39,6 +39,9 @@ Core and Builtins Library ------- +- Issue #8313: traceback.format_exception_only() encodes unicode message to + ASCII with backslashreplace error handler if str(value) failed + - Issue #8567: Fix precedence of signals in Decimal module: when a Decimal operation raises multiple signals and more than one of those signals is trapped, the specification determines the order in which |