Additional mimetype utils

This commit is contained in:
Matthew Tretter 2012-04-20 23:27:35 -04:00
parent 7b34716d9e
commit b466ff3723

View file

@ -122,6 +122,19 @@ def _format_to_extension(format):
return None
def extension_to_mimetype(ext):
try:
filename = 'a%s' % (ext or '') # guess_type requires a full filename, not just an extension
mimetype = mimetypes.guess_type(filename)[0]
except IndexError:
mimetype = None
return mimetype
def format_to_mimetype(format):
return extension_to_mimetype(format_to_extension(format))
def extension_to_format(extension):
"""Returns the format that corresponds to the provided extension.