Mior fixes to reduce the amount of warnings

* Close the file after reading so no more ResourceWarings
* When testing mime types, the __file__ could be a .pyc