MIME type normalisation and labels.
Project description
pantomime
pantomime
is a small library that handles the parsing and normalisation
of internet MIME types in Python. This can be useful to normalise invalid,
or misformatted MIME types emitted by remote web servers.
Usage
The simplest use is to normalise a MIME type:
from pantomime import normalize_mimetype
assert normalize_mimetype('TEXT/PLAIN') == 'text/plain'
assert normalize_mimetype('plain/text') == 'text/plain'
assert normalize_mimetype(None) == 'application/octet-stream'
assert normalize_mimetype('') == 'application/octet-stream'
Internally, pantomime
uses a MIMEType
object to handle parsing. It can
be used to access more specific information, like human readable labels:
from pantomime import parse_mimetype
parsed = parse_mimetype('text/plain')
assert parsed.family == 'text'
assert parsed.subtype == 'plain'
assert parsed.label == 'Plain text'
Open issues
- Internationalisation, i.e. make the human-readable labels available in multiple languages.
- Expand replacements for specific MIME types.
License
Licensed under MIT terms, see the LICENSE
file included in this repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pantomime-0.6.1.tar.gz
(7.5 kB
view hashes)
Built Distribution
Close
Hashes for pantomime-0.6.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ea567dffc2458a174cd624061a1a0efc081c858938d55291e4825e47a4fdb0f |
|
MD5 | 65c7cae24c079a3f025d08bc0ca12424 |
|
BLAKE2b-256 | 9c8d96fcb5db774fbc253a8ec8364b9ee45270ea4bcc8b5cc230cee7a82eb058 |