]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-132054: Add ``application/yaml`` to ``mimetypes`` (#132056)
authorСаша Черных <Kristinita@users.noreply.github.com>
Mon, 21 Apr 2025 09:05:37 +0000 (12:05 +0300)
committerGitHub <noreply@github.com>
Mon, 21 Apr 2025 09:05:37 +0000 (12:05 +0300)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Doc/whatsnew/3.14.rst
Lib/mimetypes.py
Lib/test/test_mimetypes.py
Misc/NEWS.d/next/Library/2025-04-03-20-28-54.gh-issue-132054.c1nlOx.rst [new file with mode: 0644]

index f02ce6bc1d4f2f9ff117efaf9b7b8c1fe96cb77d..51f4286efd6785bdeea766074a16d90f45185284 100644 (file)
@@ -910,6 +910,10 @@ mimetypes
 
   (Contributed by Hugo van Kemenade in :gh:`129965`.)
 
+* Add :rfc:`9512` ``application/yaml`` MIME type for YAML files (``.yaml``
+  and ``.yml``). (Contributed by Sasha "Nelie" Chernykh and Hugo van Kemenade
+  in :gh:`132056`.)
+
 
 multiprocessing
 ---------------
index 7c3e9c0d1159ba3efc866755276c571b8f93f67f..de842eabea80932c3f9608b0ac435d877d5fb5f6 100644 (file)
@@ -544,6 +544,8 @@ def _default_mime_types():
         '.rdf'    : 'application/xml',
         '.wsdl'   : 'application/xml',
         '.xpdl'   : 'application/xml',
+        '.yaml'   : 'application/yaml',
+        '.yml'    : 'application/yaml',
         '.zip'    : 'application/zip',
         '.3gp'    : 'audio/3gpp',
         '.3gpp'   : 'audio/3gpp',
index 261017f832a2af15b55cb32482681c9e29489f25..f2a19c0863570afe3e8bacb7732fa7e5c410b6a7 100644 (file)
@@ -243,6 +243,7 @@ class MimeTypesTestCase(unittest.TestCase):
                 ("application/x-texinfo", ".texi"),
                 ("application/x-troff", ".roff"),
                 ("application/xml", ".xsl"),
+                ("application/yaml", ".yaml"),
                 ("audio/flac", ".flac"),
                 ("audio/matroska", ".mka"),
                 ("audio/mp4", ".m4a"),
@@ -285,6 +286,26 @@ class MimeTypesTestCase(unittest.TestCase):
         mimetypes.init()
         check_extensions()
 
+    def test_guess_file_type(self):
+        def check_file_type():
+            for mime_type, ext in (
+                ("application/yaml", ".yaml"),
+                ("application/yaml", ".yml"),
+                ("audio/mpeg", ".mp2"),
+                ("audio/mpeg", ".mp3"),
+                ("video/mpeg", ".m1v"),
+                ("video/mpeg", ".mpe"),
+                ("video/mpeg", ".mpeg"),
+                ("video/mpeg", ".mpg"),
+            ):
+                with self.subTest(mime_type=mime_type, ext=ext):
+                    result, _ = mimetypes.guess_file_type(f"filename{ext}")
+                    self.assertEqual(result, mime_type)
+
+        check_file_type()
+        mimetypes.init()
+        check_file_type()
+
     def test_init_stability(self):
         mimetypes.init()
 
diff --git a/Misc/NEWS.d/next/Library/2025-04-03-20-28-54.gh-issue-132054.c1nlOx.rst b/Misc/NEWS.d/next/Library/2025-04-03-20-28-54.gh-issue-132054.c1nlOx.rst
new file mode 100644 (file)
index 0000000..b9602c0
--- /dev/null
@@ -0,0 +1,2 @@
+The ``application/yaml`` mime type (:rfc:`9512`) is now supported\r
+by :mod:`mimetypes`. Patch by Sasha "Nelie" Chernykh and Hugo van Kemenade.\r