Skip to content
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------

Expand Down
27 changes: 26 additions & 1 deletion Lib/mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -665,29 +667,51 @@ 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',
'.h' : 'text/plain',
'.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',
Expand Down Expand Up @@ -718,6 +742,7 @@ def _default_mime_types():
'.pict': 'image/pict',
'.pct' : 'image/pict',
'.pic' : 'image/pict',
'.vcf' : 'text/x-vcard',
'.xul' : 'text/xul',
}

Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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``
Loading