code: def get_ctype_charset (text):
      
      for param in text.lower().split(';'):
          param = param.strip()
          if param.startswith('charset='):
              charset = param[8:].strip()
              try:
                  codecs.lookup(charset)
                  return charset
              except (LookupError, ValueError):
                  pass
      return None
docs: Extract charset information from mime content type string, eg.
      "text/html; charset=iso8859-1".