Kaydet (Commit) 26da1871 authored tarafından Benjamin Peterson's avatar Benjamin Peterson

simplify and modernize updatecache()

üst b9e7c012
...@@ -72,13 +72,13 @@ def updatecache(filename, module_globals=None): ...@@ -72,13 +72,13 @@ def updatecache(filename, module_globals=None):
if filename in cache: if filename in cache:
del cache[filename] del cache[filename]
if not filename or filename[0] + filename[-1] == '<>': if not filename or (filename.startswith('<') and filename.endswith('>')):
return [] return []
fullname = filename fullname = filename
try: try:
stat = os.stat(fullname) stat = os.stat(fullname)
except os.error, msg: except OSError:
basename = filename basename = filename
# Try for a __loader__, if available # Try for a __loader__, if available
...@@ -115,20 +115,18 @@ def updatecache(filename, module_globals=None): ...@@ -115,20 +115,18 @@ def updatecache(filename, module_globals=None):
fullname = os.path.join(dirname, basename) fullname = os.path.join(dirname, basename)
except (TypeError, AttributeError): except (TypeError, AttributeError):
# Not sufficiently string-like to do anything useful with. # Not sufficiently string-like to do anything useful with.
continue
try:
stat = os.stat(fullname)
break
except os.error:
pass pass
else:
try:
stat = os.stat(fullname)
break
except os.error:
pass
else: else:
return [] return []
try: try:
fp = open(fullname, 'rU') with open(fullname, 'rU') as fp:
lines = fp.readlines() lines = fp.readlines()
fp.close() except IOError:
except IOError, msg:
return [] return []
if lines and not lines[-1].endswith('\n'): if lines and not lines[-1].endswith('\n'):
lines[-1] += '\n' lines[-1] += '\n'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment