File: mime.py

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 (21 lines) | stat: -rw-r--r-- 752 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
from typing import Optional
from pantomime.parse import MIMEType
from pantomime.types import DEFAULT, PLAIN


def parse_mimetype(text: Optional[str], default: str = DEFAULT) -> MIMEType:
    """Parse a MIME type into a structured object."""
    return MIMEType.parse(text, default=default)


def normalize_mimetype(text: Optional[str], default: str = DEFAULT) -> str:
    """Normalize the spelling of a MIME type."""
    return parse_mimetype(text, default=default).normalized or default


def useful_mimetype(text: Optional[str]) -> bool:
    """Check to see if the given mime type is a MIME type
    which is useful in terms of how to treat this file.
    """
    mimetype = normalize_mimetype(text)
    return mimetype not in [DEFAULT, PLAIN, None]