Use context manager for reading addon headers

This commit is contained in:
Campbell Barton 2015-06-08 21:21:54 +10:00
parent 07d51141ae
commit d63615272c

View File

@ -80,6 +80,7 @@ def modules_refresh(module_cache=addons_fake_modules):
print("Error opening file %r: %s" % (mod_path, e))
return None
with file_mod:
if speedy:
lines = []
line_iter = iter(file_mod)
@ -91,7 +92,6 @@ def modules_refresh(module_cache=addons_fake_modules):
if not error_encoding:
error_encoding = True
print("Error reading file as UTF-8:", mod_path, e)
file_mod.close()
return None
if len(l) == 0:
@ -104,15 +104,13 @@ def modules_refresh(module_cache=addons_fake_modules):
if not error_encoding:
error_encoding = True
print("Error reading file as UTF-8:", mod_path, e)
file_mod.close()
return None
data = "".join(lines)
else:
data = file_mod.read()
file_mod.close()
del file_mod
try:
ast_data = ast.parse(data, filename=mod_path)