def IsPythonFile(filename):
 if (os.path.splitext(filename)[1] == '.py'):
  return True
 try:
  with open(filename, 'rb') as fd:
   encoding = tokenize.detect_encoding(fd.readline)[0]
  with py3compat.open_with_encoding(filename, mode='r', encoding=encoding) as fd:
   fd.read()
 except UnicodeDecodeError:
  encoding = 'latin-1'
 except (IOError, SyntaxError):
  return False
 try:
  with py3compat.open_with_encoding(filename, mode='r', encoding=encoding) as fd:
   first_line = fd.readlines()[0]
 except (IOError, IndexError):
  return False
 return re.match('^#!.*\\bpython[23]?\\b', first_line)

def IsPythonFile ( filename ) : if ( os . path . splitext ( filename ) [ 1 ] == '.py' ) : return True try : with open ( filename , 'rb' ) as fd : encoding = tokenize . detect_encoding ( fd . readline ) [ 0 ] with py3compat . open_with_encoding ( filename , mode = 'r' , encoding = encoding ) as fd : fd . read ( ) except UnicodeDecodeError : encoding = 'latin-1' except ( IOError , SyntaxError ) : return False try : with py3compat . open_with_encoding ( filename , mode = 'r' , encoding = encoding ) as fd : first_line = fd . readlines ( ) [ 0 ] except ( IOError , IndexError ) : return False return re . match ( '^#!.*\\bpython[23]?\\b' , first_line )
return true if filename is a python file .