Issue #8313: traceback.format_exception_only() encodes unicode message to
ASCII with backslashreplace error handler if str(value) failed
This commit is contained in:
parent
f3c157f639
commit
926fd4ee32
|
@ -159,6 +159,15 @@ def test():
|
||||||
err = traceback.format_exception_only(None, None)
|
err = traceback.format_exception_only(None, None)
|
||||||
self.assertEqual(err, ['None\n'])
|
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):
|
class TracebackFormatTests(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -211,8 +211,14 @@ def _format_final_exc_line(etype, value):
|
||||||
def _some_str(value):
|
def _some_str(value):
|
||||||
try:
|
try:
|
||||||
return str(value)
|
return str(value)
|
||||||
except:
|
except Exception:
|
||||||
return '<unprintable %s object>' % type(value).__name__
|
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):
|
def print_exc(limit=None, file=None):
|
||||||
|
|
|
@ -39,6 +39,9 @@ Core and Builtins
|
||||||
Library
|
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
|
- Issue #8567: Fix precedence of signals in Decimal module: when a
|
||||||
Decimal operation raises multiple signals and more than one of those
|
Decimal operation raises multiple signals and more than one of those
|
||||||
signals is trapped, the specification determines the order in which
|
signals is trapped, the specification determines the order in which
|
||||||
|
|
Loading…
Reference in New Issue