gh-141018: Update .exe, .dll, .rtf and .jpg mime types in mimetypes (#141023)

This commit is contained in:
Stan Ulbrych 2025-11-17 11:32:00 +00:00 committed by GitHub
parent 7800b78067
commit 31ea3f3c76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 19 deletions

View file

@ -489,8 +489,6 @@ def _default_mime_types():
'.cjs' : 'application/node', '.cjs' : 'application/node',
'.bin' : 'application/octet-stream', '.bin' : 'application/octet-stream',
'.a' : 'application/octet-stream', '.a' : 'application/octet-stream',
'.dll' : 'application/octet-stream',
'.exe' : 'application/octet-stream',
'.o' : 'application/octet-stream', '.o' : 'application/octet-stream',
'.obj' : 'application/octet-stream', '.obj' : 'application/octet-stream',
'.so' : 'application/octet-stream', '.so' : 'application/octet-stream',
@ -501,12 +499,15 @@ def _default_mime_types():
'.p7c' : 'application/pkcs7-mime', '.p7c' : 'application/pkcs7-mime',
'.ps' : 'application/postscript', '.ps' : 'application/postscript',
'.eps' : 'application/postscript', '.eps' : 'application/postscript',
'.rtf' : 'application/rtf',
'.texi' : 'application/texinfo', '.texi' : 'application/texinfo',
'.texinfo': 'application/texinfo', '.texinfo': 'application/texinfo',
'.toml' : 'application/toml', '.toml' : 'application/toml',
'.trig' : 'application/trig', '.trig' : 'application/trig',
'.m3u' : 'application/vnd.apple.mpegurl', '.m3u' : 'application/vnd.apple.mpegurl',
'.m3u8' : 'application/vnd.apple.mpegurl', '.m3u8' : 'application/vnd.apple.mpegurl',
'.dll' : 'application/vnd.microsoft.portable-executable',
'.exe' : 'application/vnd.microsoft.portable-executable',
'.xls' : 'application/vnd.ms-excel', '.xls' : 'application/vnd.ms-excel',
'.xlb' : 'application/vnd.ms-excel', '.xlb' : 'application/vnd.ms-excel',
'.eot' : 'application/vnd.ms-fontobject', '.eot' : 'application/vnd.ms-fontobject',
@ -649,7 +650,6 @@ def _default_mime_types():
'.pl' : 'text/plain', '.pl' : 'text/plain',
'.srt' : 'text/plain', '.srt' : 'text/plain',
'.rtx' : 'text/richtext', '.rtx' : 'text/richtext',
'.rtf' : 'text/rtf',
'.tsv' : 'text/tab-separated-values', '.tsv' : 'text/tab-separated-values',
'.vtt' : 'text/vtt', '.vtt' : 'text/vtt',
'.py' : 'text/x-python', '.py' : 'text/x-python',
@ -682,11 +682,9 @@ def _default_mime_types():
# Please sort these too # Please sort these too
common_types = _common_types_default = { common_types = _common_types_default = {
'.rtf' : 'application/rtf',
'.apk' : 'application/vnd.android.package-archive', '.apk' : 'application/vnd.android.package-archive',
'.midi': 'audio/midi', '.midi': 'audio/midi',
'.mid' : 'audio/midi', '.mid' : 'audio/midi',
'.jpg' : 'image/jpg',
'.pict': 'image/pict', '.pict': 'image/pict',
'.pct' : 'image/pict', '.pct' : 'image/pict',
'.pic' : 'image/pict', '.pic' : 'image/pict',

View file

@ -112,13 +112,12 @@ def test_non_standard_types(self):
eq = self.assertEqual eq = self.assertEqual
# First try strict # First try strict
eq(self.db.guess_file_type('foo.xul', strict=True), (None, None)) eq(self.db.guess_file_type('foo.xul', strict=True), (None, None))
eq(self.db.guess_extension('image/jpg', strict=True), None)
# And then non-strict # And then non-strict
eq(self.db.guess_file_type('foo.xul', strict=False), ('text/xul', None)) eq(self.db.guess_file_type('foo.xul', strict=False), ('text/xul', None))
eq(self.db.guess_file_type('foo.XUL', strict=False), ('text/xul', None)) eq(self.db.guess_file_type('foo.XUL', strict=False), ('text/xul', None))
eq(self.db.guess_file_type('foo.invalid', strict=False), (None, None)) eq(self.db.guess_file_type('foo.invalid', strict=False), (None, None))
eq(self.db.guess_extension('image/jpg', strict=False), '.jpg') eq(self.db.guess_extension('image/jpeg', strict=False), '.jpg')
eq(self.db.guess_extension('image/JPG', strict=False), '.jpg') eq(self.db.guess_extension('image/JPEG', strict=False), '.jpg')
def test_filename_with_url_delimiters(self): def test_filename_with_url_delimiters(self):
# bpo-38449: URL delimiters cases should be handled also. # bpo-38449: URL delimiters cases should be handled also.
@ -179,8 +178,8 @@ def test_guess_all_types(self):
self.assertTrue(set(all) >= {'.bat', '.c', '.h', '.ksh', '.pl', '.txt'}) self.assertTrue(set(all) >= {'.bat', '.c', '.h', '.ksh', '.pl', '.txt'})
self.assertEqual(len(set(all)), len(all)) # no duplicates self.assertEqual(len(set(all)), len(all)) # no duplicates
# And now non-strict # And now non-strict
all = self.db.guess_all_extensions('image/jpg', strict=False) all = self.db.guess_all_extensions('image/jpeg', strict=False)
self.assertEqual(all, ['.jpg']) self.assertEqual(all, ['.jpg', '.jpe', '.jpeg'])
# And now for no hits # And now for no hits
all = self.db.guess_all_extensions('image/jpg', strict=True) all = self.db.guess_all_extensions('image/jpg', strict=True)
self.assertEqual(all, []) self.assertEqual(all, [])
@ -231,6 +230,7 @@ def check_extensions():
("application/ogg", ".ogx"), ("application/ogg", ".ogx"),
("application/pdf", ".pdf"), ("application/pdf", ".pdf"),
("application/postscript", ".ps"), ("application/postscript", ".ps"),
("application/rtf", ".rtf"),
("application/texinfo", ".texi"), ("application/texinfo", ".texi"),
("application/toml", ".toml"), ("application/toml", ".toml"),
("application/vnd.apple.mpegurl", ".m3u"), ("application/vnd.apple.mpegurl", ".m3u"),
@ -281,7 +281,6 @@ def check_extensions():
("model/stl", ".stl"), ("model/stl", ".stl"),
("text/html", ".html"), ("text/html", ".html"),
("text/plain", ".txt"), ("text/plain", ".txt"),
("text/rtf", ".rtf"),
("text/x-rst", ".rst"), ("text/x-rst", ".rst"),
("video/matroska", ".mkv"), ("video/matroska", ".mkv"),
("video/matroska-3d", ".mk3d"), ("video/matroska-3d", ".mk3d"),
@ -372,9 +371,7 @@ def test_keywords_args_api(self):
self.assertEqual(self.db.guess_type( self.assertEqual(self.db.guess_type(
url="scheme:foo.html", strict=True), ("text/html", None)) url="scheme:foo.html", strict=True), ("text/html", None))
self.assertEqual(self.db.guess_all_extensions( self.assertEqual(self.db.guess_all_extensions(
type='image/jpg', strict=True), []) type='image/jpeg', strict=True), ['.jpg', '.jpe', '.jpeg'])
self.assertEqual(self.db.guess_extension(
type='image/jpg', strict=False), '.jpg')
def test_added_types_are_used(self): def test_added_types_are_used(self):
mimetypes.add_type('testing/default-type', '') mimetypes.add_type('testing/default-type', '')
@ -452,15 +449,15 @@ def test_parse_args(self):
args, help_text = mimetypes._parse_args("--invalid") args, help_text = mimetypes._parse_args("--invalid")
self.assertTrue(help_text.startswith("usage: ")) self.assertTrue(help_text.startswith("usage: "))
args, _ = mimetypes._parse_args(shlex.split("-l -e image/jpg")) args, _ = mimetypes._parse_args(shlex.split("-l -e image/jpeg"))
self.assertTrue(args.extension) self.assertTrue(args.extension)
self.assertTrue(args.lenient) self.assertTrue(args.lenient)
self.assertEqual(args.type, ["image/jpg"]) self.assertEqual(args.type, ["image/jpeg"])
args, _ = mimetypes._parse_args(shlex.split("-e image/jpg")) args, _ = mimetypes._parse_args(shlex.split("-e image/jpeg"))
self.assertTrue(args.extension) self.assertTrue(args.extension)
self.assertFalse(args.lenient) self.assertFalse(args.lenient)
self.assertEqual(args.type, ["image/jpg"]) self.assertEqual(args.type, ["image/jpeg"])
args, _ = mimetypes._parse_args(shlex.split("-l foo.webp")) args, _ = mimetypes._parse_args(shlex.split("-l foo.webp"))
self.assertFalse(args.extension) self.assertFalse(args.extension)
@ -491,7 +488,6 @@ def test_multiple_inputs_error(self):
def test_invocation(self): def test_invocation(self):
for command, expected in [ for command, expected in [
("-l -e image/jpg", ".jpg"),
("-e image/jpeg", ".jpg"), ("-e image/jpeg", ".jpg"),
("-l foo.webp", "type: image/webp encoding: None"), ("-l foo.webp", "type: image/webp encoding: None"),
]: ]:

View file

@ -0,0 +1,2 @@
:mod:`mimetypes`: Update ``.exe``, ``.dll``, ``.rtf`` and (when
``strict=False``) ``.jpg`` to their correct IANA mime type.