def is_python_file(filename):
 if filename.endswith(u'.py'):
  return True
 try:
  with open_with_encoding(filename) as f:
   first_line = f.readlines(1)[0]
 except (IOError, IndexError):
  return False
 if (not PYTHON_SHEBANG_REGEX.match(first_line)):
  return False
 return True

def is_python_file ( filename ) : if filename . endswith ( u'.py' ) : return True try : with open_with_encoding ( filename ) as f : first_line = f . readlines ( 1 ) [ 0 ] except ( IOError , IndexError ) : return False if ( not PYTHON_SHEBANG_REGEX . match ( first_line ) ) : return False return True
return true if filename is python file .