This library implements the content sniffing algorithm described in http://tools.ietf.org/html/draft-abarth-mime-sniff-03, which will eventually become a normative reference in HTML5.
Works well with httplib2:
>>> from mimesniff import Sniffer
>>> from httplib2 import Http
>>> h = Http(".cache")
>>> response, body = h.request("http://wearehugh.com/public/2009/09/feeds/rss10/index.html")
>>> beau = Sniffer(response, body)
>>> beau.official_type
'text/html'
>>> beau.sniffed_type
'application/rss+xml'Also supports IE-compatible encoding aliases and HTML5's replacement encoding tables:
>>> from mimesniff import Sniffer
>>> beau = Sniffer({}, b"<meta charset=X-X-BIG5>")
>>> beau.encoding
"big5"
>>> beau = Sniffer({}, b"<meta charset=iso-8859-1>")
>>> beau.encoding
"windows-1252"Requires Python 3.1 or later.