8000 gh-129965: Add missing MIME types by hugovk · Pull Request #129969 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-129965: Add missing MIME types #129969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 21, 2025
19 changes: 19 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,25 @@ mimetypes

(Contributed by Hugo van Kemenade in :gh:`85957`.)

* More MIME type changes:

* :rfc:`2361`: Change type for ``.avi`` to ``video/vnd.avi``
and for ``.wav`` to ``audio/vnd.wave``
* :rfc:`4337`: Add MPEG-4 ``audio/mp4`` (``.m4a``))
* :rfc:`5334`: Add Ogg media (``.oga``, ``.ogg`` and ``.ogx``)
* :rfc:`9639`: Add FLAC ``audio/flac`` (``.flac``)
* De facto: Add WebM ``audio/webm`` (``.weba``)
* `ECMA-376
<https://ecma-international.org/publications-and-standards/standards/ecma-376/>`__:
Add ``.docx``, ``.pptx`` and ``.xlsx`` types
* `OASIS
<https://docs.oasis-open.org/office/v1.2/cs01/OpenDocument-v1.2-cs01-part1.html#Appendix_C>`__:
Add OpenDocument ``.odg``, ``.odp``, ``.ods`` and ``.odt`` types
* `W3C <https://www.w3.org/TR/epub-33/#app-media-type>`__:
Add EPUB ``application/epub+zip`` (``.epub``)

(Contributed by Hugo van Kemenade in :gh:`129965`.)


multiprocessing
---------------
Expand Down
18 changes: 16 additions & 2 deletions Lib/mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ def _default_mime_types():
types_map = _types_map_default = {
'.js' : 'text/javascript',
'.mjs' : 'text/javascript',
'.epub' : 'application/epub+zip',
'.json' : 'application/json',
'.webmanifest': 'application/manifest+json',
'.doc' : 'application/msword',
Expand All @@ -480,6 +481,7 @@ def _default_mime_types():
'.obj' : 'application/octet-stream',
'.so' : 'application/octet-stream',
'.oda' : 'application/oda',
'.ogx' : 'application/ogg',
'.pdf' : 'application/pdf',
'.p7c' : 'application/pkcs7-mime',
'.ps' : 'application/postscript',
Expand All @@ -496,6 +498,13 @@ def _default_mime_types():
'.ppa' : 'application/vnd.ms-powerpoint',
'.pps' : 'application/vnd.ms-powerpoint',
'.pwz' : 'application/vnd.ms-powerpoint',
'.odg' : 'application/vnd.oasis.opendocument.graphics',
'.odp' : 'application/vnd.oasis.opendocument.presentation',
'.ods' : 'application/vnd.oasis.opendocument.spreadsheet',
'.odt' : 'application/vnd.oasis.opendocument.text',
'.pptx' : 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'.xlsx' : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'.docx' : 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'.wasm' : 'application/wasm',
'.bcpio' : 'application/x-bcpio',
'.cpio' : 'application/x-cpio',
Expand Down Expand Up @@ -546,17 +555,21 @@ def _default_mime_types():
'.ass' : 'audio/aac',
'.au' : 'audio/basic',
'.snd' : 'audio/basic',
'.flac' : 'audio/flac',
'.mka' : 'audio/matroska',
'.m4a' : 'audio/mp4',
'.mp3' : 'audio/mpeg',
'.mp2' : 'audio/mpeg',
'.ogg' : 'audio/ogg',
'.opus' : 'audio/opus',
'.aif' : 'audio/x-aiff',
'.aifc' : 'audio/x-aiff',
'.aiff' : 'audio/x-aiff',
'.ra' : 'audio/x-pn-realaudio',
'.wav' : 'audio/x-wav',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make mimetypes.MimeTypes().guess_extension('audio/x-wav') no longer work. Is that expected?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can only have a single type per extension with this dict implementation (there's also #122632 that proposes dealing with duplicates; I've not looked closely at it).

If we can only choose one, I think handling for the standards-based type is more useful than an x- extension.

Also mimetypes.MimeTypes().guess_type('filename.wav') now gives the preferred result.

This is also a reason why this kind of change is only made as a feature with no backports. But happy to revert this one if you prefer.

'.wav' : 'audio/vnd.wave',
'.otf' : 'font/otf',
'.ttf' : 'font/ttf',
'.weba' : 'audio/webm',
'.woff' : 'font/woff',
'.woff2' : 'font/woff2',
'.avif' : 'image/avif',
Expand Down Expand Up @@ -629,10 +642,11 @@ def _default_mime_types():
'.mpa&# 8000 39; : 'video/mpeg',
'.mpe' : 'video/mpeg',
'.mpg' : 'video/mpeg',
'.ogv' : 'video/ogg',
'.mov' : 'video/quicktime',
'.qt' : 'video/quicktime',
'.webm' : 'video/webm',
'.avi' : 'video/x-msvideo',
'.avi' : 'video/vnd.avi',
'.movie' : 'video/x-sgi-movie',
}

Expand Down
22 changes: 19 additions & 3 deletions Lib/test/test_mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,31 @@ def test_guess_known_extensions(self):
def test_preferred_extension(self):
def check_extensions():
for mime_type, ext in (
("application/epub+zip", ".epub"),
("application/octet-stream", ".bin"),
("application/ogg", ".ogx"),
("application/postscript", ".ps"),
("application/vnd.apple.mpegurl", ".m3u"),
("application/vnd.ms-excel", ".xls"),
("application/vnd.ms-fontobject", ".eot"),
("application/vnd.ms-powerpoint", ".ppt"),
("application/vnd.oasis.opendocument.graphics", ".odg"),
("application/vnd.oasis.opendocument.presentation", ".odp"),
("application/vnd.oasis.opendocument.spreadsheet", ".ods"),
("application/vnd.oasis.opendocument.text", ".odt"),
("application/vnd.openxmlformats-officedocument.presentationml.presentation", ".pptx"),
("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", ".xlsx"),
("application/vnd.openxmlformats-officedocument.wordprocessingml.document", ".docx"),
("application/x-texinfo", ".texi"),
("application/x-troff", ".roff"),
("application/xml", ".xsl"),
("audio/flac", ".flac"),
("audio/matroska", ".mka"),
("audio/mp4", ".m4a"),
("audio/mpeg", ".mp3"),
("audio/ogg", ".ogg"),
("audio/vnd.wave", ".wav"),
("audio/webm", ".weba"),
("font/otf", ".otf"),
("font/ttf", ".ttf"),
("font/woff", ".woff"),
Expand All @@ -244,13 +258,13 @@ def check_extensions():
("image/fits", ".fits"),
("image/g3fax", ".g3"),
("image/jp2", ".jp2"),
("image/jpeg", ".jpg"),
("image/jpm", ".jpm"),
("image/t38", ".t38"),
("image/webp", ".webp"),
("image/wmf", ".wmf"),
("image/jpeg", ".jpg"),
("image/tiff", ".tiff"),
("image/tiff-fx", ".tfx"),
("image/webp", ".webp"),
("image/wmf", ".wmf"),
("message/rfc822", ".eml"),
("text/html", ".html"),
("text/plain", ".txt"),
Expand All @@ -259,7 +273,9 @@ def check_extensions():
("video/matroska", ".mkv"),
("video/matroska-3d", ".mk3d"),
("video/mpeg", ".mpeg"),
("video/ogg", ".ogv"),
("video/quicktime", ".mov"),
("video/vnd.avi", ".avi"),
):
with self.subTest(mime_type=mime_type, ext=ext):
self.assertEqual(mimetypes.guess_extension(mime_type), ext)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Update MIME types for ``.avi`` and ``.wav``. Add MIME types for ``.docx``,
``.pptx``, ``.xlsx``, ``.epub``, ``.flac``, ``.m4a``, ``.odg``, ``.odp``,
``.ods``, ``.odt``, ``.oga``, ``.ogg``, ``.ogx`` and ``.weba``. Patch by
Hugo van Kemenade.
Loading
0