FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

revert r67713. it causes build problems · python/cpython@a5bbf20 · GitHub

Repository navigation

Commit a5bbf20

Browse files
committed
revert r67713. it causes build problems
1 parent d947267 commit a5bbf20

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

‎Lib/linecache.py‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import sys
99
import os
10-
import tokenize
10+
import re
1111

1212
__all__ = ["getline", "clearcache", "checkcache"]
1313

@@ -121,11 +121,27 @@ def updatecache(filename, module_globals=None):
121121
pass
122122
else:
123123
# No luck
124+
## print '*** Cannot stat', filename, ':', msg
124125
return []
125-
with open(fullname, 'rb') as fp:
126-
coding, line = tokenize.detect_encoding(fp.readline)
127-
with open(fullname, 'r', encoding=coding) as fp:
126+
## print("Refreshing cache for %s..." % fullname)
127+
try:
128+
fp = open(fullname, 'rU')
128129
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+
try:
141+
lines = [line if isinstance(line, str) else str(line, coding)
142+
for line in lines]
143+
except:
144+
pass # Hope for the best
129145
size, mtime = stat.st_size, stat.st_mtime
130146
cache[filename] = size, mtime, lines, fullname
131147
return lines

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL