Leo Shklovskii <l...@thermopylae.net> added the comment:

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.

----------
nosy: +leos
versions: +Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue1043134>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to