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