def get_coding(text):
 for line in text.splitlines()[:2]:
  try:
   result = CODING_RE.search(to_text_string(line))
  except UnicodeDecodeError:
   pass
  else:
   if result:
    codec = result.group(1)
    if (codec in CODECS):
     return codec
 if is_binary_string(text):
  detector = UniversalDetector()
  for line in text.splitlines()[:2]:
   detector.feed(line)
   if detector.done:
    break
  detector.close()
  return detector.result['encoding']
 return None

def get_coding ( text ) : for line in text . splitlines ( ) [ : 2 ] : try : result = CODING_RE . search ( to_text_string ( line ) ) except UnicodeDecodeError : pass else : if result : codec = result . group ( 1 ) if ( codec in CODECS ) : return codec if is_binary_string ( text ) : detector = UniversalDetector ( ) for line in text . splitlines ( ) [ : 2 ] : detector . feed ( line ) if detector . done : break detector . close ( ) return detector . result [ 'encoding' ] return None
function to get the coding of a text .