[Python-Dev] standard library mimetypes module pathologically broken?

Jacob Rus jacobolus at gmail.com
Sun Aug 2 06:03:12 CEST 2009


Brett Cannon wrote:
> Jacob Rus wrote:
>> At the very least, I
>> think some changes can be made to this code without altering its basic
>> function, which would clean up the actual mime types it returns,
>> comment the exceptions to Apache and explain why they're there, and
>> make the code flow understandable to someone reading the code.
>
> That all sounds reasonable.

Okay, as a start, I did a simple code cleanup that I think fixes some
potential bugs (any code using its own instance of the MimeTypes class
should now be insulated from other same-process users of the module),
chops out 80 or 90 lines, removes some redundant code paths, clarifies
some of the micro level behavior of some chunks of code, adds a bit
more to the docstring at the top of the file, and makes the program
flow somewhat clearer … *without* changing the semantics of the module
or its included list of MIME types.

Here's a diff:
http://pastie.textmate.org/568329

And here's the whole file:
http://pastie.textmate.org/568333

This change does require any tests that previously called
_default_mime_types() to instead call init().

Any thoughts?
Jacob Rus


More information about the Python-Dev mailing list