[Python-checkins] bpo-45639: Add webp and avif image formats to mimetypes (#29259)

JelleZijlstra webhook-mailer at python.org
Tue May 3 17:18:01 EDT 2022


https://github.com/python/cpython/commit/6dee69577ac22506d3fa59dcc13c9e0cb9ee3e8a
commit: 6dee69577ac22506d3fa59dcc13c9e0cb9ee3e8a
branch: main
author: kixorz <kixorz at users.noreply.github.com>
committer: JelleZijlstra <jelle.zijlstra at gmail.com>
date: 2022-05-03T15:17:57-06:00
summary:

bpo-45639: Add webp and avif image formats to mimetypes (#29259)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra at gmail.com>

files:
A Misc/NEWS.d/next/Library/2022-02-02-04-51-39.bpo-45639.N8XrGO.rst
M Lib/mimetypes.py
M Lib/test/test_mimetypes.py

diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py
index 1aa32467e278a..f6c43b3b92bc5 100644
--- a/Lib/mimetypes.py
+++ b/Lib/mimetypes.py
@@ -517,6 +517,7 @@ def _default_mime_types():
         '.aiff'   : 'audio/x-aiff',
         '.ra'     : 'audio/x-pn-realaudio',
         '.wav'    : 'audio/x-wav',
+        '.avif'   : 'image/avif',
         '.bmp'    : 'image/bmp',
         '.gif'    : 'image/gif',
         '.ief'    : 'image/ief',
@@ -589,6 +590,7 @@ def _default_mime_types():
         '.pict': 'image/pict',
         '.pct' : 'image/pict',
         '.pic' : 'image/pict',
+        '.webp': 'image/webp',
         '.xul' : 'text/xul',
         }
 
diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py
index f2b103693a9b2..d64aee71fc48b 100644
--- a/Lib/test/test_mimetypes.py
+++ b/Lib/test/test_mimetypes.py
@@ -96,12 +96,14 @@ def test_non_standard_types(self):
         # First try strict
         eq(self.db.guess_type('foo.xul', strict=True), (None, None))
         eq(self.db.guess_extension('image/jpg', strict=True), None)
+        eq(self.db.guess_extension('image/webp', strict=True), None)
         # And then non-strict
         eq(self.db.guess_type('foo.xul', strict=False), ('text/xul', None))
         eq(self.db.guess_type('foo.XUL', strict=False), ('text/xul', None))
         eq(self.db.guess_type('foo.invalid', strict=False), (None, None))
         eq(self.db.guess_extension('image/jpg', strict=False), '.jpg')
         eq(self.db.guess_extension('image/JPG', strict=False), '.jpg')
+        eq(self.db.guess_extension('image/webp', strict=False), '.webp')
 
     def test_filename_with_url_delimiters(self):
         # bpo-38449: URL delimiters cases should be handled also.
@@ -180,6 +182,7 @@ def check_extensions():
             self.assertEqual(mimetypes.guess_extension('application/x-troff'), '.roff')
             self.assertEqual(mimetypes.guess_extension('application/xml'), '.xsl')
             self.assertEqual(mimetypes.guess_extension('audio/mpeg'), '.mp3')
+            self.assertEqual(mimetypes.guess_extension('image/avif'), '.avif')
             self.assertEqual(mimetypes.guess_extension('image/jpeg'), '.jpg')
             self.assertEqual(mimetypes.guess_extension('image/tiff'), '.tiff')
             self.assertEqual(mimetypes.guess_extension('message/rfc822'), '.eml')
diff --git a/Misc/NEWS.d/next/Library/2022-02-02-04-51-39.bpo-45639.N8XrGO.rst b/Misc/NEWS.d/next/Library/2022-02-02-04-51-39.bpo-45639.N8XrGO.rst
new file mode 100644
index 0000000000000..332008bf9c472
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-02-02-04-51-39.bpo-45639.N8XrGO.rst
@@ -0,0 +1 @@
+``image/avif`` and ``image/webp`` were added to :mod:`mimetypes`.



More information about the Python-checkins mailing list