##// END OF EJS Templates
Fixes for producing unicode tracebacks.
Thomas Kluyver -
Show More
@@ -102,6 +102,7 b' from IPython.utils import io'
102 102 from IPython.utils import path as util_path
103 103 from IPython.utils import py3compat
104 104 from IPython.utils import pyfile
105 from IPython.utils import ulinecache
105 106 from IPython.utils.data import uniq_stable
106 107 from IPython.utils.warn import info, error
107 108
@@ -230,7 +231,6 b' def fix_frame_records_filenames(records):'
230 231
231 232
232 233 def _fixed_getinnerframes(etb, context=1,tb_offset=0):
233 import linecache
234 234 LNUM_POS, LINES_POS, INDEX_POS = 2, 4, 5
235 235
236 236 records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
@@ -252,7 +252,7 b' def _fixed_getinnerframes(etb, context=1,tb_offset=0):'
252 252 maybeStart = lnum-1 - context//2
253 253 start = max(maybeStart, 0)
254 254 end = start + context
255 lines = linecache.getlines(file)[start:end]
255 lines = ulinecache.getlines(file)[start:end]
256 256 buf = list(records[i])
257 257 buf[LNUM_POS] = lnum
258 258 buf[INDEX_POS] = lnum - 1 - start
@@ -826,7 +826,7 b' class VerboseTB(TBTools):'
826 826 # Look up the corresponding source file.
827 827 file = pyfile.source_from_cache(file)
828 828
829 def linereader(file=file, lnum=[lnum], getline=linecache.getline):
829 def linereader(file=file, lnum=[lnum], getline=ulinecache.getline):
830 830 line = getline(file, lnum[0])
831 831 lnum[0] += 1
832 832 return line
@@ -21,13 +21,18 b' else:'
21 21 def getlines(filename, module_globals=None):
22 22 """Get the lines (as unicode) for a file from the cache.
23 23 Update the cache if it doesn't contain an entry for this file already."""
24 linesb = linecache.getlines(filename, module_globals=module_globals)
25 readline = openpy._list_readline(linesb)
24 lines = linecache.getlines(filename, module_globals=module_globals)
25
26 # The bits we cache ourselves can be unicode.
27 if (not lines) or isinstance(lines[0], unicode):
28 return lines
29
30 readline = openpy._list_readline(lines)
26 31 try:
27 32 encoding, _ = openpy.detect_encoding(readline)
28 33 except SyntaxError:
29 34 encoding = 'ascii'
30 return [l.decode(encoding, 'replace') for l in linesb]
35 return [l.decode(encoding, 'replace') for l in lines]
31 36
32 37 # This is a straight copy of linecache.getline
33 38 def getline(filename, lineno, module_globals=None):
General Comments 0
You need to be logged in to leave comments. Login now