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.

classification
Title: mimetypes module does not recognize jp2 type
Type: enhancement Stage:
Components: Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: iritkatriel, naro
Priority: normal Keywords:

Created on 2020-09-15 04:31 by naro, last changed 2022-04-11 14:59 by admin.

Messages (5)
msg376927 - (view) Author: Radim Novotny (naro) Date: 2020-09-15 04:31
Even if jp2 is in the official list of types https://www.iana.org/assignments/media-types/media-types.xhtml it's not recognized by the MimeTypes.guess_type:

   >>> from mimetypes import MimeTypes
   >>> MimeTypes().guess_type('test.jp2')
   (None, None)

The same example works in Python 3.7 and returns 'image/jp2'
msg377074 - (view) Author: Andrés Delfino (adelfino) * (Python triager) Date: 2020-09-17 23:25
Hi, Radim!

I've tested with 3.7.8 and got (None, None). I'm curious on how you got that 'image/jp2' output.

It seems jp2 was never supported by looking into the git history of Lib/mimetypes.py.

Would you like to open a PR to support it? :)
msg377086 - (view) Author: Radim Novotny (naro) Date: 2020-09-18 05:41
Hi Andrés,

tried again and the difference is between 3.7.4 and 3.7.5
The jp2 mimetype is read from /etc/apache2/mime.types (see knownfiles in mimetypes.py) so the mime type does not have to be in the mimetypes.py hardcoded, but in version 3.7.5 it stopped working. 

I think it's because of using _types_map_default instead of types_map in some places.

Since jp2 is an official mime type it should be added to the list but I also think we should try to identify the issue with _types_map_default.

Seems to be related to https://bugs.python.org/issue4963

I will have look if I can find out what was changed and why.

Cheers,
Radim
msg377113 - (view) Author: Andrés Delfino (adelfino) * (Python triager) Date: 2020-09-18 12:27
Nice debugging!
msg410860 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-18 13:10
It is found by the module-level guess_type but not by the MimeType class's guess_type:

>>> from mimetypes import MimeTypes
>>> MimeTypes().guess_type('test.jp2')
(None, None)
>>> mimetypes.guess_type('test.jp2')
('image/jp2', None)
>>> 

That difference is the subject of Issue38656.

What remains to decide here is whether jp2 should be added to the builtin list of mimetypes.
History
Date User Action Args
2022-04-11 14:59:35adminsetgithub: 85957
2022-01-19 00:38:51adelfinosetnosy: - adelfino
2022-01-18 13:10:00iritkatrielsetversions: + Python 3.11, - Python 3.8
nosy: + iritkatriel

messages: + msg410860

type: behavior -> enhancement
2020-09-18 12:27:11adelfinosetmessages: + msg377113
2020-09-18 05:41:01narosetmessages: + msg377086
2020-09-17 23:25:35adelfinosetnosy: + adelfino
messages: + msg377074
2020-09-15 04:31:47narocreate