diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index 4c90b509a6381df..e32df7eb6fc7875 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -1259,6 +1259,11 @@ mimetypes undotted extensions raise a :exc:`ValueError`. (Contributed by Nikita Sobolev in :gh:`149720`.) +* Add more built-in MIME types. The ``.vcf`` extension now maps to + ``text/vcard``. Passing ``strict=False`` to :func:`mimetypes.guess_extension` + still returns ``.vcf`` for the legacy ``text/x-vcard`` type. + (Contributed by Charlie Lin in :gh:`146344`.) + shutil ------ diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py index 561b99a92c8d16b..0c403f7c687fdb9 100644 --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -497,6 +497,7 @@ def _default_mime_types(): '.dcm' : 'application/dicom', '.efi' : 'application/efi', '.epub' : 'application/epub+zip', + '.gml' : 'application/gml+xml', '.gz' : 'application/gzip', '.json' : 'application/json', '.webmanifest': 'application/manifest+json', @@ -590,6 +591,7 @@ def _default_mime_types(): '.rdf' : 'application/xml', '.wsdl' : 'application/xml', '.xpdl' : 'application/xml', + '.ent' : 'application/xml-external-parsed-entity', '.yaml' : 'application/yaml', '.yml' : 'application/yaml', '.zip' : 'application/zip', @@ -665,13 +667,22 @@ def _default_mime_types(): '.gltf' : 'model/gltf+json', '.glb' : 'model/gltf-binary', '.stl' : 'model/stl', + '.appcache': 'text/cache-manifest', + '.ics' : 'text/calendar', + '.ifb' : 'text/calendar', + '.cql' : 'text/cql', '.css' : 'text/css', '.csv' : 'text/csv', + '.csvs' : 'text/csv-schema', + '.gff3' : 'text/gff3', '.html' : 'text/html', '.htm' : 'text/html', + '.cnd' : 'text/jcr-cnd', '.md' : 'text/markdown', '.markdown': 'text/markdown', + '.miz' : 'text/mizar', '.n3' : 'text/n3', + '.org' : 'text/org', '.txt' : 'text/plain', '.bat' : 'text/plain', '.c' : 'text/plain', @@ -679,15 +690,28 @@ def _default_mime_types(): '.ksh' : 'text/plain', '.pl' : 'text/plain', '.srt' : 'text/plain', + '.provn' : 'text/provenance-notation', '.rtx' : 'text/richtext', + '.shaclc' : 'text/shaclc', + '.shc' : 'text/shaclc', + '.shex' : 'text/shex', + '.spdx' : 'text/spdx', '.tsv' : 'text/tab-separated-values', + '.ttl' : 'text/turtle', + '.uri' : 'text/uri-list', + '.uris' : 'text/uri-list', + '.vcf' : 'text/vcard', + '.vcard' : 'text/vcard', + '.ascii' : 'text/vnd.ascii-art', + '.curl' : 'text/vnd.curl', + '.gv' : 'text/vnd.graphviz', '.vtt' : 'text/vtt', + '.wgsl' : 'text/wgsl', '.py' : 'text/x-python', '.rst' : 'text/x-rst', '.etx' : 'text/x-setext', '.sgm' : 'text/x-sgml', '.sgml' : 'text/x-sgml', - '.vcf' : 'text/x-vcard', '.xml' : 'text/xml', '.mkv' : 'video/matroska', '.mk3d' : 'video/matroska-3d', @@ -718,6 +742,7 @@ def _default_mime_types(): '.pict': 'image/pict', '.pct' : 'image/pict', '.pic' : 'image/pict', + '.vcf' : 'text/x-vcard', '.xul' : 'text/xul', } diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py index 8e39552dba8aa89..159a148b67a9246 100644 --- a/Lib/test/test_mimetypes.py +++ b/Lib/test/test_mimetypes.py @@ -385,6 +385,14 @@ def test_default_data(self): eq(self.db.guess_file_type("foo.tar.Z"), ("application/x-tar", "compress")) eq(self.db.guess_file_type("foo.tar.bz2"), ("application/x-tar", "bzip2")) eq(self.db.guess_file_type("foo.tar.xz"), ("application/x-tar", "xz")) + eq(self.db.guess_file_type("foo.vcf"), ("text/vcard", None)) + eq(self.db.guess_file_type("foo.vcard"), ("text/vcard", None)) + eq(self.db.guess_extension("text/vcard"), ".vcf") + eq(self.db.guess_file_type("foo.gml"), ("application/gml+xml", None)) + eq(self.db.guess_file_type("foo.ent"), + ("application/xml-external-parsed-entity", None)) + eq(self.db.guess_file_type("foo.appcache"), ("text/cache-manifest", None)) + eq(self.db.guess_file_type("foo.manifest"), (None, None)) def test_data_urls(self): eq = self.assertEqual @@ -412,6 +420,8 @@ def test_non_standard_types(self): eq(self.db.guess_file_type('foo.invalid', strict=False), (None, None)) eq(self.db.guess_extension('image/jpeg', strict=False), '.jpg') eq(self.db.guess_extension('image/JPEG', strict=False), '.jpg') + eq(self.db.guess_file_type('foo.vcf', strict=False), ('text/vcard', None)) + eq(self.db.guess_extension('text/x-vcard', strict=False), '.vcf') def test_filename_with_url_delimiters(self): # bpo-38449: URL delimiters cases should be handled also. diff --git a/Misc/NEWS.d/next/Library/2026-03-23-20-37-02.gh-issue-146343.JnXJVB.rst b/Misc/NEWS.d/next/Library/2026-03-23-20-37-02.gh-issue-146343.JnXJVB.rst new file mode 100644 index 000000000000000..f48a18653b707d9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-03-23-20-37-02.gh-issue-146343.JnXJVB.rst @@ -0,0 +1,22 @@ +Add the following MIME types with file extensions: +``.appcache`` for ``text/cache-manifest`` +``.ics`` and ``.ifb`` for ``text/calendar`` +``.cql`` for ``text/cql`` +``.csvs`` for ``text/csv-schema`` +``.gff3`` for ``text/gff3`` +``.cnd`` for ``text/jcr-cnd`` +``.miz`` for ``text/mizar`` +``.org`` for ``text/org`` +``.provn`` for ``text/provenance-notation`` +``.shaclc`` and ``.shc`` for ``text/shaclc`` +``.shex`` for ``text/shex`` +``.spdx`` for ``text/spdx`` +``.ttl`` for ``text/turtle`` +``.uri`` and ``.uris`` for ``text/uri-list`` +``.vcf`` and ``.vcard`` for ``text/vcard`` +``.ascii`` for ``text/vnd.ascii-art`` +``.curl`` for ``text/vnd.curl`` +``.gml`` for ``application/gml+xml`` +``.gv`` for ``text/vnd.graphviz`` +``.wgsl`` for ``text/wgsl`` +``.ent`` for ``application/xml-external-parsed-entity``