diff --git a/IPython/kernel/zmq/zmqshell.py b/IPython/kernel/zmq/zmqshell.py index 3dc43cf..b3ab8d8 100644 --- a/IPython/kernel/zmq/zmqshell.py +++ b/IPython/kernel/zmq/zmqshell.py @@ -472,27 +472,6 @@ class KernelMagics(Magics): else: print("Autosave disabled") -def safe_unicode(e): - """unicode(e) with various fallbacks. Used for exceptions, which may not be - safe to call unicode() on. - """ - try: - return unicode(e) - except UnicodeError: - pass - - try: - return py3compat.str_to_unicode(str(e)) - except UnicodeError: - pass - - try: - return py3compat.str_to_unicode(repr(e)) - except UnicodeError: - pass - - return u'Unrecoverably corrupt evalue' - class ZMQInteractiveShell(InteractiveShell): """A subclass of InteractiveShell for ZMQ.""" @@ -572,7 +551,7 @@ class ZMQInteractiveShell(InteractiveShell): exc_content = { u'traceback' : stb, u'ename' : unicode(etype.__name__), - u'evalue' : safe_unicode(evalue) + u'evalue' : py3compat.safe_unicode(evalue), } dh = self.displayhook diff --git a/IPython/utils/py3compat.py b/IPython/utils/py3compat.py index 6f7a19c..9731368 100644 --- a/IPython/utils/py3compat.py +++ b/IPython/utils/py3compat.py @@ -50,6 +50,27 @@ def _modify_str_or_docstring(str_change_func): return doc return wrapper +def safe_unicode(e): + """unicode(e) with various fallbacks. Used for exceptions, which may not be + safe to call unicode() on. + """ + try: + return unicode(e) + except UnicodeError: + pass + + try: + return py3compat.str_to_unicode(str(e)) + except UnicodeError: + pass + + try: + return py3compat.str_to_unicode(repr(e)) + except UnicodeError: + pass + + return u'Unrecoverably corrupt evalue' + if sys.version_info[0] >= 3: PY3 = True