Update mimetype overrides

See https://github.com/python/cpython/commits/main/Lib/mimetypes.py
This commit is contained in:
Florian Bruhin 2024-10-13 16:44:59 +02:00
parent eb8121ffd5
commit 088b5973eb
2 changed files with 37 additions and 7 deletions

View File

@ -38,6 +38,12 @@ Added
- **Planned:** Full support for Python 3.13, with Windows/macOS binaries using
it if possible.
Changed
~~~~~~~
- Updated mimetype information for getting a suitable extension when downloading
a `data:` URL.
[[v3.3.1]]
v3.3.1 (2024-10-12)

View File

@ -777,14 +777,38 @@ def mimetype_extension(mimetype: str) -> Optional[str]:
This mostly delegates to Python's mimetypes.guess_extension(), but backports some
changes (via a simple override dict) which are missing from earlier Python versions.
Most likely, this can be dropped once the minimum Python version is raised to 3.10.
"""
overrides = {
# Added in 3.10.0
"application/x-hdf5": ".h5",
# Added in 3.9.0
"application/manifest+json": ".webmanifest",
}
overrides = {}
if sys.version_info[:2] < (3, 13):
overrides.update({
"text/rtf": ".rtf",
"text/markdown": ".md",
"text/x-rst": ".rst",
})
if sys.version_info[:2] < (3, 12):
overrides.update({
"text/javascript": ".js",
})
if sys.version_info[:2] < (3, 11):
overrides.update({
"application/n-quads": ".nq",
"application/n-triples": ".nt",
"application/trig": ".trig",
"image/avif": ".avif",
"image/webp": ".webp",
"text/n3": ".n3",
"text/vtt": ".vtt",
})
if sys.version_info[:2] < (3, 10):
overrides.update({
"application/x-hdf5": ".h5",
"audio/3gpp": ".3gp",
"audio/3gpp2": ".3g2",
"audio/aac": ".aac",
"audio/opus": ".opus",
"image/heic": ".heic",
"image/heif": ".heif",
})
if mimetype in overrides:
return overrides[mimetype]
return mimetypes.guess_extension(mimetype, strict=False)