class HTML5Firefox2Hack(object):
"""This is a hack to get HTML 5 to work for Firefox 2. It Sends the xhtml
content-type to all Gecko based browsers where version is less than 1.9,
or "rv:1.9pre" or "rv:1.9a" or "rv:1.9bx" where x is less than 5. I
created this hack based on the information I found on this site,
http://html5doctor.com/how-to-get-html5-working-in-ie-and-firefox-2/."""
def process_response(self, request, response):
status_code = getattr(response, "status_code", None)
meta = getattr(request, "META", None)
user_agent = meta.get('HTTP_USER_AGENT', '')
import re
m = re.search('rv:1\.(([1-8]|9pre|9a|9b[0-4])\.[0-9.]+).*Gecko', user_agent)
if m:
import htmlentitydefs
response['Content-Type']='application/xhtml+xml; charset=utf-8'
for i in htmlentitydefs.name2codepoint.items():
response.content = response.content.replace('&%s;' % i[0], '%s;' % i[1])
return response