summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-05-05 12:45:31 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-05-05 12:45:31 (GMT)
commit7c8eaad1bf48f479c0440e6f39b6740b58956520 (patch)
tree9760918800da3d412bbd649b47f7fe611a446263
parent2dd131d5358d155dbc7bea40d6c993b9530f98f3 (diff)
downloadcpython-7c8eaad1bf48f479c0440e6f39b6740b58956520.zip
cpython-7c8eaad1bf48f479c0440e6f39b6740b58956520.tar.gz
cpython-7c8eaad1bf48f479c0440e6f39b6740b58956520.tar.bz2
Merged revisions 80777 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r80777 | victor.stinner | 2010-05-05 14:40:49 +0200 (mer., 05 mai 2010) | 3 lines 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.py9
-rw-r--r--Lib/traceback.py10
-rw-r--r--Misc/NEWS3
3 files changed, 20 insertions, 2 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index 1c067d7..6ef70a6 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -168,6 +168,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 ed0f256..2a77d2c 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -212,8 +212,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):
diff --git a/Misc/NEWS b/Misc/NEWS
index 8ab0508..5d7bd4f 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -33,6 +33,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