xtr_mime.bundle ¶
The xtr-dependency-injection bundle for xtr-mime.
MIME_TYPE_GUESSER_TAG
module-attribute
¶
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 ¶
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 ¶
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
¶
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.
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.MimeTypestakes asextra_map.