Skip to content

Commit

Permalink
Quick fix for ipython#1688, traceback-unicode issue
Browse files Browse the repository at this point in the history
By importing unicode_literals from __future__ and casting to unicode at
two locations a simple case now works. However I have not audited the code
to find other locations where casts may be necessary. No new failures were
noted when running the testsuite.
  • Loading branch information
jstenar committed Aug 27, 2012
1 parent 011222a commit 660787d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 4 additions & 9 deletions IPython/core/ultratb.py
Expand Up @@ -69,7 +69,7 @@
# the file COPYING, distributed as part of this software.
#*****************************************************************************

from __future__ import with_statement
from __future__ import unicode_literals

import inspect
import keyword
Expand Down Expand Up @@ -99,6 +99,7 @@
from IPython.core.excolors import exception_colors
from IPython.utils import PyColorize
from IPython.utils import io
from IPython.utils import path as util_path
from IPython.utils import py3compat
from IPython.utils import pyfile
from IPython.utils.data import uniq_stable
Expand Down Expand Up @@ -282,12 +283,7 @@ def _format_traceback_lines(lnum, index, lines, Colors, lvals=None,scheme=None):
_line_format = _parser.format2

for line in lines:
# FIXME: we need to ensure the source is a pure string at this point,
# else the coloring code makes a royal mess. This is in need of a
# serious refactoring, so that all of the ultratb and PyColorize code
# is unicode-safe. So for now this is rather an ugly hack, but
# necessary to at least have readable tracebacks. Improvements welcome!
line = py3compat.cast_bytes_py2(line, 'utf-8')
line = py3compat.cast_unicode(line)

new_line, err = _line_format(line, 'str', scheme)
if not err: line = new_line
Expand Down Expand Up @@ -779,7 +775,6 @@ def nullrepr(value, repr=text_repr): return ''
abspath = os.path.abspath
for frame, file, lnum, func, lines, index in records:
#print '*** record:',file,lnum,func,lines,index # dbg

if not file:
file = '?'
elif not(file.startswith("<") and file.endswith(">")):
Expand All @@ -791,7 +786,7 @@ def nullrepr(value, repr=text_repr): return ''
# Not sure if this can still happen: abspath now works with
# file names like <string>
pass

file = py3compat.cast_unicode(file, util_path.fs_encoding)
link = tpl_link % file
args, varargs, varkw, locals = inspect.getargvalues(frame)

Expand Down
2 changes: 2 additions & 0 deletions IPython/utils/PyColorize.py
Expand Up @@ -30,6 +30,8 @@
"""
from __future__ import print_function

from __future__ import unicode_literals

__all__ = ['ANSICodeColors','Parser']

_scheme_default = 'Linux'
Expand Down

0 comments on commit 660787d

Please sign in to comment.