Skip to content

xtr_mime.bundle

The xtr-dependency-injection bundle for xtr-mime.

MIME_TYPE_GUESSER_TAG module-attribute

MIME_TYPE_GUESSER_TAG: Final = 'mime.mime_type_guesser'

The tag a guesser carries to be asked by the container's table.

It takes one optional attribute, priority — an int, higher asked first; without it, the definition's own priority, or 0. A class subclassing MimeTypeGuesserInterface carries it without being told; a bundle tagging one explicitly gives the priority it needs::

services.set(UploadGuesser).add_tag(MIME_TYPE_GUESSER_TAG, priority=10)

AddMimeTypeGuesserPass

Bases: CompilerPassInterface

Registers every service tagged :data:MIME_TYPE_GUESSER_TAG with the table.

The guessers are ordered by priority, highest first, then by the order they were registered in; the table asks them in that order, and answers from the file's extension only when none of them does. Each is offered to the table under a qualifier of its own, mime.guesser.<index>, and the table's factory is handed those qualifiers: it builds the guessers when the table is built, and is never handed the container.

The table is a guesser itself, so autoconfiguration tags its definition; the pass takes that tag off. A service decorating another is asked as the service it decorates, which carries the tag.

process

process(builder: ContainerBuilder) -> None

Offer every tagged guesser to the table.

Raises:

  • LogicError –

    When a tag's priority is not an integer.

MimeBundle

Bases: Bundle[MimeConfig]

Registers the MIME types table and the HTML-to-text converter.

build

build(builder: ContainerBuilder) -> None

Tag every guesser class, and register the pass handing them to the table.

The pass runs after every bundle's process hook, so a guesser a bundle tags there joins too.

load_extension

load_extension(config: MimeConfig, services: ServiceConfigurator, builder: ContainerBuilder) -> None

Register the table, under both its interfaces, and the converter.

MimeConfig dataclass

MimeConfig(extra_map: Mapping[str, Sequence[str]] = dict[str, Sequence[str]]())

How the bundle builds the container's MIME types table.

Buildable with no arguments: an application listing the bundle without configuring it gets the standard library's built-in table.

MimeConfig(extra_map={"application/mbox": ["mbox"]})

Attributes:

  • extra_map (Mapping[str, Sequence[str]]) –

    Extensions by MIME type, each without its leading dot, ranked before the standard table's — what :class:~xtr_mime.MimeTypes takes as extra_map.