[issue4963] mimetypes.guess_extension result changes after mimetypes.init()

Toshio Kuratomi report at bugs.python.org
Mon Apr 14 18:08:18 CEST 2014


Toshio Kuratomi added the comment:

Took a look at this and was able to reproduce it on Fedora Linux 20 and current cpython head.  It is somewhat random though.  I'm able to get reasonably consistent failures using image/jpeg and iterating the test case about 20 times.

Additionally, it looks like the data structure that mimetypes.guess_extensions() is reading its extensions from is a list so it doesn't have to do with dictionary sort order.  It has something to do with the way the extensions are read in from the files and then given to add_type().

Talking to r.david.murray I think that this particular problem can be solved by simply sorting the list of extensions prior to guess_extension taking the first extension off of the list.

The question of what to do when the first extension in the list isn't the best extension should be resolved in Issue1043134.

I'll attach a patch with test case for this problem.

----------
nosy: +a.badger
Added file: http://bugs.python.org/file34821/issue4963.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4963>
_______________________________________


More information about the Python-bugs-list mailing list