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 dlchambers
Recipients dlchambers
Date 2012-06-27.16:03:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1340813009.36.0.80214060404.issue15207@psf.upfronthosting.co.za>
In-reply-to
Content
The current mimetypes.read_windows_registry() enums the values under HKCR\MIME\Database\Content Type
However, this is the key for mimetype to extension lookups, NOT for extension to mimetype lookups.
As a result, when >1 MIME types are mapped to a particular extension, the last-found entry is used.
For example, both "image/png" and "image/x-png" map to the ".png" file extension.
Unfortunately, what happens is this code finds "image/png", then later finds "image/x-png" and this steals the ".png" extension.


The solution is to use the correct regkey, which is the HKCR root.
This is the correct location for extension-to-mimetype lookups.
What we should do is enum the HKCR root, find all subkeys that start with a dot (i.e. file extensions), then inspect those for a 'Content Type' value.


The attached ZIP contains:
mimetype_flaw_demo.py  - this demonstrates the error (due to wrong regkey) and my fix (uses the correct regkey)
mimetypes_fixed.py   -   My suggested fix to the standard mimetypes.py module.
History
Date User Action Args
2012-06-27 16:03:29dlchamberssetrecipients: + dlchambers
2012-06-27 16:03:29dlchamberssetmessageid: <1340813009.36.0.80214060404.issue15207@psf.upfronthosting.co.za>
2012-06-27 16:03:28dlchamberslinkissue15207 messages
2012-06-27 16:03:28dlchamberscreate