Look at slide 89 of last week's presentation.  You can use the mimetypes module from the standard library, instead of rolling your own.
Instead of going just by the file extension, you can have the mimetypes module look at the actual file content to come up with an educated guess:

mimetypes.guess_type(path)[0]

where path is the full path to the file, not just the extension.