mimetypes oddity

S

Sion Arrowsmith

ge = mimetypes.guess_extension
I actually discovered this through explicitly calling mimetypes.init
to reload an edited mime.types file between calls to guess_extension,
but I think the above scenario makes for more disturbing reading :cool:

The problem is that mimetools initialises its type mapping dict
before adding new type mappings from a file by iterating through the
existing type mapping dict. This process is bootstrapped by a hard-
coded dict which gets shadowed by the first file read, so the second
file read uses a dict initialsed from the dict created by the first
file read (got that?) which has a different iteration order to the
hard-coded dict. So the mappings get added in a different order the
second time around, and where there are multiple mappings like this
you get a different answer.

Is this a bug? If I want to be sure of a consistent result, do I
need to use sorted(mimetools.guess_all_extensions(t))[0] (or [-1])?
 
S

Sion Arrowsmith

[mimetype weirdness reported]
Sion> Is this a bug?
Might be. Can you file a bug report in the Python issue tracker with a
small script that demonstrates the behavior?

http://bugs.python.org/issue4963

(It's tagged as being 2.4 and 2.5 because those are the versions I
have to hand to confirm it on, but I'd be rather surprised if it's
not still like this in 2.6.)
 
T

Terry Reedy

Sion said:
[mimetype weirdness reported]
Sion> Is this a bug?
Might be. Can you file a bug report in the Python issue tracker with a
small script that demonstrates the behavior?

http://bugs.python.org/issue4963

(It's tagged as being 2.4 and 2.5 because those are the versions I
have to hand to confirm it on, but I'd be rather surprised if it's
not still like this in 2.6.)

Trying to reproduce a bug, as this report requires, is easier if you
give code that can be copy and pasted into the interpreter or even into
an edit window (as with IDLE) to be run from there. (3.0 version)

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top