Skip to content

Commit

Permalink
Merge pull request #7408 from ccordoba12/tb-utf8
Browse files Browse the repository at this point in the history
Fix ultratb when there are non-ascii filenames present in a traceback
  • Loading branch information
Carreau committed Jan 11, 2015
2 parents ee56024 + 3206178 commit 70f4d0f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions IPython/core/ultratb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_py2(filename, "utf-8")
if not filename.endswith(('.pyx', '.pxd', '.pxi')):
better_fn = frame.f_globals.get('__file__', None)
if isinstance(better_fn, str):
Expand Down Expand Up @@ -539,19 +540,19 @@ def _format_list(self, extracted_list):
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_py2(filename, "utf-8"), Colors.Normal,
Colors.lineno, lineno, Colors.Normal,
Colors.name, name, Colors.Normal)
Colors.name, py3compat.cast_unicode_py2(name, "utf-8"), Colors.Normal)
if line:
item += ' %s\n' % line.strip()
list.append(item)
# Emphasize the last entry
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_py2(filename, "utf-8"), Colors.normalEm,
Colors.linenoEm, lineno, Colors.normalEm,
Colors.nameEm, name, Colors.normalEm,
Colors.nameEm, py3compat.cast_unicode_py2(name, "utf-8"), Colors.normalEm,
Colors.Normal)
if line:
item += '%s %s%s\n' % (Colors.line, line.strip(),
Expand Down

0 comments on commit 70f4d0f

Please sign in to comment.