File: README.md

package info (click to toggle)
python-pantomime 0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 168 kB
  • sloc: python: 416; makefile: 22; sh: 5
file content (42 lines) | stat: -rw-r--r-- 1,319 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# pantomime

[![build](https://github.com/alephdata/pantomime/actions/workflows/build.yml/badge.svg)](https://github.com/alephdata/pantomime/actions/workflows/build.yml)

``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:

```python
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:

```python
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.