def get_encoding(headers, content):
 encoding = None
 content_type = headers.get('content-type')
 if content_type:
  (_, params) = cgi.parse_header(content_type)
  if ('charset' in params):
   encoding = params['charset'].strip('\'"')
 if (not encoding):
  content = (utils.pretty_unicode(content[:1000]) if six.PY3 else content)
  charset_re = re.compile('<meta.*?charset=["\\\']*(.+?)["\\\'>]', flags=re.I)
  pragma_re = re.compile('<meta.*?content=["\\\']*;?charset=(.+?)["\\\'>]', flags=re.I)
  xml_re = re.compile('^<\\?xml.*?encoding=["\\\']*(.+?)["\\\'>]')
  encoding = ((charset_re.findall(content) + pragma_re.findall(content)) + xml_re.findall(content))
  encoding = ((encoding and encoding[0]) or None)
 return encoding

def get_encoding ( headers , content ) : encoding = None content_type = headers . get ( 'content-type' ) if content_type : ( _ , params ) = cgi . parse_header ( content_type ) if ( 'charset' in params ) : encoding = params [ 'charset' ] . strip ( '\'"' ) if ( not encoding ) : content = ( utils . pretty_unicode ( content [ : 1000 ] ) if six . PY3 else content ) charset_re = re . compile ( '<meta.*?charset=["\\\']*(.+?)["\\\'>]' , flags = re . I ) pragma_re = re . compile ( '<meta.*?content=["\\\']*;?charset=(.+?)["\\\'>]' , flags = re . I ) xml_re = re . compile ( '^<\\?xml.*?encoding=["\\\']*(.+?)["\\\'>]' ) encoding = ( ( charset_re . findall ( content ) + pragma_re . findall ( content ) ) + xml_re . findall ( content ) ) encoding = ( ( encoding and encoding [ 0 ] ) or None ) return encoding
returns the unicode encoding type .