There was an error while loading. Please reload this page.
1 parent d947267 commit a5bbf20Copy full SHA for a5bbf20
1 file changed
Lib/linecache.py
@@ -7,7 +7,7 @@
7
8
import sys
9
import os
10
-import tokenize
+import re
11
12
__all__ = ["getline", "clearcache", "checkcache"]
13
@@ -121,11 +121,27 @@ def updatecache(filename, module_globals=None):
121
pass
122
else:
123
# No luck
124
+## print '*** Cannot stat', filename, ':', msg
125
return []
- with open(fullname, 'rb') as fp:
126
- coding, line = tokenize.detect_encoding(fp.readline)
127
- with open(fullname, 'r', encoding=coding) as fp:
+## print("Refreshing cache for %s..." % fullname)
+ try:
128
+ fp = open(fullname, 'rU')
129
lines = fp.readlines()
130
+ fp.close()
131
+ except Exception as msg:
132
+## print '*** Cannot open', fullname, ':', msg
133
+ return []
134
+ coding = "utf-8"
135
+ for line in lines[:2]:
136
+ m = re.search(r"coding[:=]\s*([-\w.]+)", line)
137
+ if m:
138
+ coding = m.group(1)
139
+ break
140
141
+ lines = [line if isinstance(line, str) else str(line, coding)
142
+ for line in lines]
143
+ except:
144
+ pass # Hope for the best
145
size, mtime = stat.st_size, stat.st_mtime
146
cache[filename] = size, mtime, lines, fullname
147
return lines
0 commit comments