This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author siona
Recipients siona
Date 2009-01-16.12:04:52
SpamBayes Score 0.443405
Marked as misclassified No
Message-id <>
Asking mimetypes to reload mime.types can cause guess_extension() to
return a different result if multiple extensions are mapped to that mime

>>> import mimetypes
>>> mimetypes.guess_extension('image/jpeg')
>>> mimetypes.init()
>>> mimetypes.guess_extension('image/jpeg')

This is because both the forward (extension to type) and inverse (type
to extension) type mapping dicts are populated by iterating through the
existing forward (extension to type) dict (types_map), then supplemented
by reading from mime.types (or any other files given to init()). The
fully populated forward dict becomes the new types_map. Initially,
types_map is hard-coded, but when the type mapping dicts are
repopulated, by explicitly or implicitly calling init() again, it is
done by iterating over the types_map created by the first init() call,
not the hard-coded one. If the iteration order for a set of extensions
with the same type is different in these two versions of the forward
dict, the order of extensions appearing for that type in the inverse
dict will change. And so the behavior of guess_all_extensions() and
hence guess_extension() will change.
Date User Action Args
2009-01-16 12:04:55sionasetrecipients: + siona
2009-01-16 12:04:54sionasetmessageid: <>
2009-01-16 12:04:53sionalinkissue4963 messages
2009-01-16 12:04:52sionacreate