def get_file_encoding(content):
 encoding = None
 try:
  lines_to_check = content.split(u'\n', 2)
  for index in range(2):
   if (len(lines_to_check) > index):
    line_encoding = _search_coding_line(lines_to_check[index])
    if line_encoding:
     encoding = line_encoding
     break
 except UnicodeDecodeError as error:
  print error
 if (encoding is None):
  encoding = u'UTF-8'
 return encoding

def get_file_encoding ( content ) : encoding = None try : lines_to_check = content . split ( u'\n' , 2 ) for index in range ( 2 ) : if ( len ( lines_to_check ) > index ) : line_encoding = _search_coding_line ( lines_to_check [ index ] ) if line_encoding : encoding = line_encoding break except UnicodeDecodeError as error : print error if ( encoding is None ) : encoding = u'UTF-8' return encoding
try to get the encoding of the file using the pep 0263 rules search the first or the second line of the file returns the encoding or the default utf-8 .