Use six to import urlparse
Add text/plain and other image formats to acceptable_content_types
Rename and move content type regex to the top of the file so we only compile it once
Don't check the encoding or the data, and switch charset and encoding to non-capturing subpatterns