revert r67713. it causes build problems

This commit is contained in:
Benjamin Peterson 2008-12-12 02:02:24 +00:00
parent d947267283
commit a5bbf20017
1 changed files with 20 additions and 4 deletions

View File

@ -7,7 +7,7 @@ that name.
import sys import sys
import os import os
import tokenize import re
__all__ = ["getline", "clearcache", "checkcache"] __all__ = ["getline", "clearcache", "checkcache"]
@ -121,11 +121,27 @@ def updatecache(filename, module_globals=None):
pass pass
else: else:
# No luck # No luck
## print '*** Cannot stat', filename, ':', msg
return [] return []
with open(fullname, 'rb') as fp: ## print("Refreshing cache for %s..." % fullname)
coding, line = tokenize.detect_encoding(fp.readline) try:
with open(fullname, 'r', encoding=coding) as fp: fp = open(fullname, 'rU')
lines = fp.readlines() lines = fp.readlines()
fp.close()
except Exception as msg:
## print '*** Cannot open', fullname, ':', msg
return []
coding = "utf-8"
for line in lines[:2]:
m = re.search(r"coding[:=]\s*([-\w.]+)", line)
if m:
coding = m.group(1)
break
try:
lines = [line if isinstance(line, str) else str(line, coding)
for line in lines]
except:
pass # Hope for the best
size, mtime = stat.st_size, stat.st_mtime size, mtime = stat.st_size, stat.st_mtime
cache[filename] = size, mtime, lines, fullname cache[filename] = size, mtime, lines, fullname
return lines return lines