Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > mimetypes oddity

Reply
Thread Tools

mimetypes oddity

 
 
Sion Arrowsmith
Guest
Posts: n/a
 
      01-15-2009
>>> ge = mimetypes.guess_extension
>>> ge('image/jpeg')

'.jpe'
>>> ge('image/jpeg')

'.jpeg'
>>>


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

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 -- http://www.velocityreviews.com/forums/(E-Mail Removed) -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
 
Reply With Quote
 
 
 
 
Sion Arrowsmith
Guest
Posts: n/a
 
      01-16-2009
In article <(E-Mail Removed)>,
<(E-Mail Removed)> wrote:
> [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.)

--
\S -- (E-Mail Removed) -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
 
Reply With Quote
 
 
 
 
Terry Reedy
Guest
Posts: n/a
 
      01-16-2009
Sion Arrowsmith wrote:
> In article <(E-Mail Removed)>,
> <(E-Mail Removed)> wrote:
>> [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'))

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mimetypes.guess_type broken in windows on py2.7 and python 3.X Gelonida N Python 0 09-26-2012 08:54 AM
Re: mimeTypes.rdf problems in Firefox 3.0.7 Rom Firefox 0 03-15-2009 02:04 AM
Re: mimeTypes.rdf problems in Firefox 3.0.7 Peter Potamus the Purple Hippo Firefox 0 03-14-2009 01:11 AM
navigator.mimeTypes Aaron Gray Javascript 3 03-10-2007 07:11 AM
propose extension of mimetypes GHUM Python 0 05-28-2006 04:57 PM



Advertisments