Author leos
Recipients BreamoreBoy, ajaksu2, elesbom, eric.araujo, jlgijsbers, josiahcarlson, kxroberto, lambacck, leos, ptarjan, sandro.tosi, skrah
Date 2011-09-07.08:20:05
SpamBayes Score 1.30512e-12
Marked as misclassified No
Message-id <>
I'm running into a similar issue with this function. My bug is that get_type('foo.png') returns image/x-png. This occurs on windows because there are mappings to both image/png and image/x-png in the registry (as there should be, since that key is actually a reverse mapping) and the code simply picks the first key that it enumerates over. This issue strikes in both directions.

Chris and others bring up a valid issue: how to decide what the winning result is?

I think the answer is pretty clear - you use the common_types mapping already in the file and expand it as appropriate. If the mimetype can't be found, only then do you go to the windows registry. The behavior on Linux is even stranger to me (now we'll dig through an arbitrary list of files that might contain MIME info or may have completely irrelevant data) but it's a pragmatic solution.

If someone needs to customize what guess_type returns, they can simply wrap the guess_type function in their own code or monkey patch if they don't have access to the source they're running. Changing such a mime type is a really advanced and unusual operation. If that's unacceptable, the code can provide a hook for an 'apache MIME config' file on windows in a standard place (either pythonpath, or %system% or wherever) that it will check before going to common_types or to the registry.

Making this change doesn't require changing the API at all, just the implementation changes.
Date User Action Args
2011-09-07 08:20:07leossetrecipients: + leos, jlgijsbers, josiahcarlson, kxroberto, ajaksu2, eric.araujo, lambacck, skrah, ptarjan, sandro.tosi, BreamoreBoy, elesbom
2011-09-07 08:20:06leossetmessageid: <>
2011-09-07 08:20:06leoslinkissue1043134 messages
2011-09-07 08:20:05leoscreate