Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 132b6bc

Browse files
KristinitaAA-Turnerhugovk
authored
gh-132054: Add application/yaml to mimetypes (#132056)
Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent fee8089 commit 132b6bc

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

Doc/whatsnew/3.14.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,10 @@ mimetypes
910910

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

913+
* Add :rfc:`9512` ``application/yaml`` MIME type for YAML files (``.yaml``
914+
and ``.yml``). (Contributed by Sasha "Nelie" Chernykh and Hugo van Kemenade
915+
in :gh:`132056`.)
916+
913917

914918
multiprocessing
915919
---------------

Lib/mimetypes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,8 @@ def _default_mime_types():
544544
'.rdf' : 'application/xml',
545545
'.wsdl' : 'application/xml',
546546
'.xpdl' : 'application/xml',
547+
'.yaml' : 'application/yaml',
548+
'.yml' : 'application/yaml',
547549
'.zip' : 'application/zip',
548550
'.3gp' : 'audio/3gpp',
549551
'.3gpp' : 'audio/3gpp',

Lib/test/test_mimetypes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def check_extensions():
243243
("application/x-texinfo", ".texi"),
244244
("application/x-troff", ".roff"),
245245
("application/xml", ".xsl"),
246+
("application/yaml", ".yaml"),
246247
("audio/flac", ".flac"),
247248
("audio/matroska", ".mka"),
248249
("audio/mp4", ".m4a"),
@@ -285,6 +286,26 @@ def check_extensions():
285286
mimetypes.init()
286287
check_extensions()
287288

289+
def test_guess_file_type(self):
290+
def check_file_type():
291+
for mime_type, ext in (
292+
("application/yaml", ".yaml"),
293+
("application/yaml", ".yml"),
294+
("audio/mpeg", ".mp2"),
295+
("audio/mpeg", ".mp3"),
296+
("video/mpeg", ".m1v"),
297+
("video/mpeg", ".mpe"),
298+
("video/mpeg", ".mpeg"),
299+
("video/mpeg", ".mpg"),
300+
):
301+
with self.subTest(mime_type=mime_type, ext=ext):
302+
result, _ = mimetypes.guess_file_type(f"filename{ext}")
303+
self.assertEqual(result, mime_type)
304+
305+
check_file_type()
306+
mimetypes.init()
307+
check_file_type()
308+
288309
def test_init_stability(self):
289310
mimetypes.init()
290311

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The ``application/yaml`` mime type (:rfc:`9512`) is now supported
2+
by :mod:`mimetypes`. Patch by Sasha "Nelie" Chernykh and Hugo van Kemenade.

0 commit comments

Comments
 (0)