Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue15207] mimetypes.read_windows_registry() uses the wrong regkey, creates wrong mappings

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Aug 10, 2013, 9:13 AM

Post #1 of 4 (17 views)
Permalink
[issue15207] mimetypes.read_windows_registry() uses the wrong regkey, creates wrong mappings

Tim Golden added the comment:

I attach a patch against 3.3; this is substantially Dave Chambers' original patch with a trivial test added and a doc change. This means that HKCR is scanned to determine extensions and these will override anything in the mimetypes db. The doc change highlights the possibility of overriding this by passing files=[].

I can't see an easy solution for this which will suit everyone but I've sat on it waay too long already. The module startup time is increased but, for bugfix releases, I can't see any other solution which won't break compatibility somewhere.

I'm taking the simplest view which says that: .jpg => image/pjpeg is broken but that the winreg code has been in place for too long to simply back it out altogether.

I'll commit appropriate versions of this within the next day to 2.7, 3.3 and 3.4 unless anyone objects. Please understand: this *is* a compromise; but I don't think there's a perfect solution for this, short of the rethink which mimetypes needs per MALs suggestion or otherwise.

----------
Added file: http://bugs.python.org/file31217/issue15207.33.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15207>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2013, 12:43 PM

Post #2 of 4 (10 views)
Permalink
[issue15207] mimetypes.read_windows_registry() uses the wrong regkey, creates wrong mappings [In reply to]

Ben Hoyt added the comment:

Thanks, Tim! Works for me! A couple of code review comments:

1) On 2.7, guess_type(s)[0] is a byte string as usual if the type doesn't exist in the registry, but it's a unicode string if it came from the registry. Seems like it should be a byte string in all cases (the mime type can only be ASCII char). I would say .encode('ascii') and if it raises UnicodeError, ignore that key.

2) Would 'subkeyname[0] == "."' be better as subkeyname.startswith(".")? More idiomatic, and won't bomb out if subkeyname is zero length (though that probably can't happen). Relatedly, "not subkeyname.startswith()" with an early-continue would avoid an indent and is what the rest of the code does.

3) I believe the default_encoding variable is not needed anymore. That was used in the old registry code.

4) Super-minor: "raises EnvironmentError" would be the Pythonic way to say "throws EnvironmentError".

5) Would it be worth adding a test for 'foo.png' as well, as that was another super-common type that was wrong?

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15207>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 12, 2013, 2:05 PM

Post #3 of 4 (2 views)
Permalink
[issue15207] mimetypes.read_windows_registry() uses the wrong regkey, creates wrong mappings [In reply to]

Tim Golden added the comment:

Thanks for the review, Ben. Updated patches attached.

1 & 3) default_encoding -- Your two points appear to contradict each
other slightly. What's in the updated patches is: 3.x has no encoding
(because everything's unicode end-to-end); 2.7 attempts to apply the
default encoding -- which is probably ascii -- to the extension and the
mimetype and continues on error. I'm not 100% sure about this because it
seems possible if unlikely to have a non-ascii extension / mimetype, but
this seems like the best compromise (and is no worse than what was there
before). Does that seem to fit the bill?

2) subkeyname[0] -- done

4) "throws EnvironmentError" -- done

5) test for .png -- done

----------
Added file: http://bugs.python.org/file31259/issue15207.27.2.patch
Added file: http://bugs.python.org/file31260/issue15207.33.2.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15207>
_______________________________________
Attachments: issue15207.27.2.patch (3.01 KB)
  issue15207.33.2.patch (2.55 KB)


report at bugs

Aug 12, 2013, 3:23 PM

Post #4 of 4 (2 views)
Permalink
[issue15207] mimetypes.read_windows_registry() uses the wrong regkey, creates wrong mappings [In reply to]

Ben Hoyt added the comment:

All looks great. I like what you've done with default_encoding now. Thanks, Tim (and Dave for the original report).

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15207>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.