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
........
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 _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):