Skip to content

Commit 31ea3f3

Browse files
pythongh-141018: Update .exe, .dll, .rtf and .jpg mime types in mimetypes (python#141023)
1 parent 7800b78 commit 31ea3f3

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

Lib/mimetypes.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,6 @@ def _default_mime_types():
489489
'.cjs' : 'application/node',
490490
'.bin' : 'application/octet-stream',
491491
'.a' : 'application/octet-stream',
492-
'.dll' : 'application/octet-stream',
493-
'.exe' : 'application/octet-stream',
494492
'.o' : 'application/octet-stream',
495493
'.obj' : 'application/octet-stream',
496494
'.so' : 'application/octet-stream',
@@ -501,12 +499,15 @@ def _default_mime_types():
501499
'.p7c' : 'application/pkcs7-mime',
502500
'.ps' : 'application/postscript',
503501
'.eps' : 'application/postscript',
502+
'.rtf' : 'application/rtf',
504503
'.texi' : 'application/texinfo',
505504
'.texinfo': 'application/texinfo',
506505
'.toml' : 'application/toml',
507506
'.trig' : 'application/trig',
508507
'.m3u' : 'application/vnd.apple.mpegurl',
509508
'.m3u8' : 'application/vnd.apple.mpegurl',
509+
'.dll' : 'application/vnd.microsoft.portable-executable',
510+
'.exe' : 'application/vnd.microsoft.portable-executable',
510511
'.xls' : 'application/vnd.ms-excel',
511512
'.xlb' : 'application/vnd.ms-excel',
512513
'.eot' : 'application/vnd.ms-fontobject',
@@ -649,7 +650,6 @@ def _default_mime_types():
649650
'.pl' : 'text/plain',
650651
'.srt' : 'text/plain',
651652
'.rtx' : 'text/richtext',
652-
'.rtf' : 'text/rtf',
653653
'.tsv' : 'text/tab-separated-values',
654654
'.vtt' : 'text/vtt',
655655
'.py' : 'text/x-python',
@@ -682,11 +682,9 @@ def _default_mime_types():
682682

683683
# Please sort these too
684684
common_types = _common_types_default = {
685-
'.rtf' : 'application/rtf',
686685
'.apk' : 'application/vnd.android.package-archive',
687686
'.midi': 'audio/midi',
688687
'.mid' : 'audio/midi',
689-
'.jpg' : 'image/jpg',
690688
'.pict': 'image/pict',
691689
'.pct' : 'image/pict',
692690
'.pic' : 'image/pict',

Lib/test/test_mimetypes.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,12 @@ def test_non_standard_types(self):
112112
eq = self.assertEqual
113113
# First try strict
114114
eq(self.db.guess_file_type('foo.xul', strict=True), (None, None))
115-
eq(self.db.guess_extension('image/jpg', strict=True), None)
116115
# And then non-strict
117116
eq(self.db.guess_file_type('foo.xul', strict=False), ('text/xul', None))
118117
eq(self.db.guess_file_type('foo.XUL', strict=False), ('text/xul', None))
119118
eq(self.db.guess_file_type('foo.invalid', strict=False), (None, None))
120-
eq(self.db.guess_extension('image/jpg', strict=False), '.jpg')
121-
eq(self.db.guess_extension('image/JPG', strict=False), '.jpg')
119+
eq(self.db.guess_extension('image/jpeg', strict=False), '.jpg')
120+
eq(self.db.guess_extension('image/JPEG', strict=False), '.jpg')
122121

123122
def test_filename_with_url_delimiters(self):
124123
# bpo-38449: URL delimiters cases should be handled also.
@@ -179,8 +178,8 @@ def test_guess_all_types(self):
179178
self.assertTrue(set(all) >= {'.bat', '.c', '.h', '.ksh', '.pl', '.txt'})
180179
self.assertEqual(len(set(all)), len(all)) # no duplicates
181180
# And now non-strict
182-
all = self.db.guess_all_extensions('image/jpg', strict=False)
183-
self.assertEqual(all, ['.jpg'])
181+
all = self.db.guess_all_extensions('image/jpeg', strict=False)
182+
self.assertEqual(all, ['.jpg', '.jpe', '.jpeg'])
184183
# And now for no hits
185184
all = self.db.guess_all_extensions('image/jpg', strict=True)
186185
self.assertEqual(all, [])
@@ -231,6 +230,7 @@ def check_extensions():
231230
("application/ogg", ".ogx"),
232231
("application/pdf", ".pdf"),
233232
("application/postscript", ".ps"),
233+
("application/rtf", ".rtf"),
234234
("application/texinfo", ".texi"),
235235
("application/toml", ".toml"),
236236
("application/vnd.apple.mpegurl", ".m3u"),
@@ -281,7 +281,6 @@ def check_extensions():
281281
("model/stl", ".stl"),
282282
("text/html", ".html"),
283283
("text/plain", ".txt"),
284-
("text/rtf", ".rtf"),
285284
("text/x-rst", ".rst"),
286285
("video/matroska", ".mkv"),
287286
("video/matroska-3d", ".mk3d"),
@@ -372,9 +371,7 @@ def test_keywords_args_api(self):
372371
self.assertEqual(self.db.guess_type(
373372
url="scheme:foo.html", strict=True), ("text/html", None))
374373
self.assertEqual(self.db.guess_all_extensions(
375-
type='image/jpg', strict=True), [])
376-
self.assertEqual(self.db.guess_extension(
377-
type='image/jpg', strict=False), '.jpg')
374+
type='image/jpeg', strict=True), ['.jpg', '.jpe', '.jpeg'])
378375

379376
def test_added_types_are_used(self):
380377
mimetypes.add_type('testing/default-type', '')
@@ -452,15 +449,15 @@ def test_parse_args(self):
452449
args, help_text = mimetypes._parse_args("--invalid")
453450
self.assertTrue(help_text.startswith("usage: "))
454451

455-
args, _ = mimetypes._parse_args(shlex.split("-l -e image/jpg"))
452+
args, _ = mimetypes._parse_args(shlex.split("-l -e image/jpeg"))
456453
self.assertTrue(args.extension)
457454
self.assertTrue(args.lenient)
458-
self.assertEqual(args.type, ["image/jpg"])
455+
self.assertEqual(args.type, ["image/jpeg"])
459456

460-
args, _ = mimetypes._parse_args(shlex.split("-e image/jpg"))
457+
args, _ = mimetypes._parse_args(shlex.split("-e image/jpeg"))
461458
self.assertTrue(args.extension)
462459
self.assertFalse(args.lenient)
463-
self.assertEqual(args.type, ["image/jpg"])
460+
self.assertEqual(args.type, ["image/jpeg"])
464461

465462
args, _ = mimetypes._parse_args(shlex.split("-l foo.webp"))
466463
self.assertFalse(args.extension)
@@ -491,7 +488,6 @@ def test_multiple_inputs_error(self):
491488

492489
def test_invocation(self):
493490
for command, expected in [
494-
("-l -e image/jpg", ".jpg"),
495491
("-e image/jpeg", ".jpg"),
496492
("-l foo.webp", "type: image/webp encoding: None"),
497493
]:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`mimetypes`: Update ``.exe``, ``.dll``, ``.rtf`` and (when
2+
``strict=False``) ``.jpg`` to their correct IANA mime type.

0 commit comments

Comments
 (0)