betty.media_type package¶
Submodules¶
Module contents¶
Provide media type handling utilities.
- exception betty.media_type.InvalidMediaType¶
Bases:
ValueErrorRaised when an identifier is not a valid media type.
- final class betty.media_type.MediaType¶
-
Define a media type.
Media types are also commonly known as content types or MIME types.
- dump() PortableData¶
Dump the instance to portable data.
- Raises:
betty.portable.error.NotPortable – Raised if any part of the data is not portable.
- property extensions: Sequence[str]¶
The file extensions associated with this media type.
Extensions must include a leading dot, and are returned in order of decreasing priority.
- classmethod load(portable: PortableData, /) Self¶
Create a new instance from portable data.
- Raises:
betty.exception.HumanFacingException – Raised if the portable data is invalid.
- property parameters: Mapping[str, str]¶
The parameters, e.g.
{"charset": "UTF-8"}for"text/html; charset=UTF-8".
- property subtype: str¶
The subtype, e.g.
"vnd.oasis.opendocument.text"for"application/vnd.oasis.opendocument.text".
- final class betty.media_type.MediaTypeDefinition¶
Bases:
HumanFacingDefinition,OrderedPluginDefinitionThe media type plugin type.
Plugin type ID
media-typeDefinition
Built-in media types:
- __init__(plugin_id: ResolvableMachineName, *, label: ResolvableLocalizable, description: ResolvableLocalizable | None = None, media_type: MediaType, after: Order[MediaTypeDefinition] = (), auto: bool = True, before: Order[MediaTypeDefinition] = ())¶
- static type() PluginTypeDefinition[Self]¶
The plugin type definition.
- exception betty.media_type.UnsupportedMediaType¶
Bases:
RuntimeErrorRaised when a media type is not supported.
- __init__(media_type: MediaTypeIndicator)¶
- betty.media_type.match_extension(source: StrPath, media_types: Iterable[MediaType], /) tuple[MediaType, str]¶
Match a file extension indicator against available media types.