Show More
@@ -40,6 +40,7 b' from IPython.testing.skipdoctest import skip_doctest' | |||
|
40 | 40 | from IPython.utils import io |
|
41 | 41 | from IPython.utils.jsonutil import json_clean |
|
42 | 42 | from IPython.utils.process import arg_split |
|
43 | from IPython.utils import py3compat | |
|
43 | 44 | from IPython.utils.traitlets import Instance, Type, Dict, CBool, CBytes |
|
44 | 45 | from IPython.utils.warn import warn, error |
|
45 | 46 | from IPython.zmq.displayhook import ZMQShellDisplayHook, _encode_binary |
@@ -436,6 +437,27 b' class KernelMagics(Magics):' | |||
|
436 | 437 | error("Could not start qtconsole: %r" % e) |
|
437 | 438 | return |
|
438 | 439 | |
|
440 | def safe_unicode(e): | |
|
441 | """unicode(e) with various fallbacks. Used for exceptions, which may not be | |
|
442 | safe to call unicode() on. | |
|
443 | """ | |
|
444 | try: | |
|
445 | return unicode(e) | |
|
446 | except UnicodeError: | |
|
447 | pass | |
|
448 | ||
|
449 | try: | |
|
450 | return py3compat.str_to_unicode(str(e)) | |
|
451 | except UnicodeError: | |
|
452 | pass | |
|
453 | ||
|
454 | try: | |
|
455 | return py3compat.str_to_unicode(repr(e)) | |
|
456 | except UnicodeError: | |
|
457 | pass | |
|
458 | ||
|
459 | return u'Unrecoverably corrupt evalue' | |
|
460 | ||
|
439 | 461 | |
|
440 | 462 | class ZMQInteractiveShell(InteractiveShell): |
|
441 | 463 | """A subclass of InteractiveShell for ZMQ.""" |
@@ -514,7 +536,7 b' class ZMQInteractiveShell(InteractiveShell):' | |||
|
514 | 536 | exc_content = { |
|
515 | 537 | u'traceback' : stb, |
|
516 | 538 | u'ename' : unicode(etype.__name__), |
|
517 | u'evalue' : unicode(evalue) | |
|
539 | u'evalue' : safe_unicode(evalue) | |
|
518 | 540 | } |
|
519 | 541 | |
|
520 | 542 | dh = self.displayhook |
General Comments 0
You need to be logged in to leave comments.
Login now