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.4434052
Marked as misclassified No
Message-id <1232107494.83.0.0570958889295.issue4963@psf.upfronthosting.co.za>
In-reply-to
Content
Asking mimetypes to reload mime.types can cause guess_extension() to
return a different result if multiple extensions are mapped to that mime
type:

>>> import mimetypes
>>> mimetypes.guess_extension('image/jpeg')
'.jpe'
>>> mimetypes.init()
>>> mimetypes.guess_extension('image/jpeg')
'.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.
History
Date User Action Args
2009-01-16 12:04:55sionasetrecipients: + siona
2009-01-16 12:04:54sionasetmessageid: <1232107494.83.0.0570958889295.issue4963@psf.upfronthosting.co.za>
2009-01-16 12:04:53sionalinkissue4963 messages
2009-01-16 12:04:52sionacreate