if get_declaration(line1) or get_declaration(line2):
# the file does have an encoding declaration, so trust it
- infile.close()
return False
# check the whole file for non utf-8 characters
if infile is None:
return False
- line = infile.readline()
- infile.close()
+ with infile:
+ line = infile.readline()
if binary_re.search(line):
# file appears to be binary
if infile is None:
return False
- code = infile.read()
- infile.close()
+ with infile:
+ code = infile.read()
try:
compile(code, fullpath, "exec")