From 31b4e8191356aba2fc2604dd0c80f6ff900331e2 2015-01-09 23:41:33 From: Carlos Cordoba Date: 2015-01-09 23:41:33 Subject: [PATCH] Fix ultratb when there are non-ascii filenames present in a traceback This solves the simple problem of running a file with non-ascii chars in its name that contains an error of any kind in it. --- diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index a020dd5..8958be2 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -248,6 +248,7 @@ def fix_frame_records_filenames(records): # Look inside the frame's globals dictionary for __file__, # which should be better. However, keep Cython filenames since # we prefer the source filenames over the compiled .so file. + filename = py3compat.cast_unicode(filename, "utf-8") if not filename.endswith(('.pyx', '.pxd', '.pxi')): better_fn = frame.f_globals.get('__file__', None) if isinstance(better_fn, str): @@ -539,9 +540,9 @@ class ListTB(TBTools): list = [] for filename, lineno, name, line in extracted_list[:-1]: item = ' File %s"%s"%s, line %s%d%s, in %s%s%s\n' % \ - (Colors.filename, filename, Colors.Normal, + (Colors.filename, py3compat.cast_unicode(filename, "utf-8"), Colors.Normal, Colors.lineno, lineno, Colors.Normal, - Colors.name, name, Colors.Normal) + Colors.name, py3compat.cast_unicode(name, "utf-8"), Colors.Normal) if line: item += ' %s\n' % line.strip() list.append(item) @@ -549,9 +550,9 @@ class ListTB(TBTools): filename, lineno, name, line = extracted_list[-1] item = '%s File %s"%s"%s, line %s%d%s, in %s%s%s%s\n' % \ (Colors.normalEm, - Colors.filenameEm, filename, Colors.normalEm, + Colors.filenameEm, py3compat.cast_unicode(filename, "utf-8"), Colors.normalEm, Colors.linenoEm, lineno, Colors.normalEm, - Colors.nameEm, name, Colors.normalEm, + Colors.nameEm, py3compat.cast_unicode(name, "utf-8"), Colors.normalEm, Colors.Normal) if line: item += '%s %s%s\n' % (Colors.line, line.strip(),