Skip to content

topmark.processors.bindings

topmark / processors / bindings

Declarative built-in processor binding helpers.

This module defines small value objects and expansion helpers used to declare how HeaderProcessor implementations are associated with file type names in TopMark's built-in registry data.

The bindings are intentionally declarative: they describe built-in registry contents without relying on import-time decorator side effects.

ProcessorBinding dataclass

ProcessorBinding(
    *, file_type_name, processor_class, namespace
)

Declarative association between one file type name and one processor class.

kw_only=True keeps call sites explicit and readable when many bindings are declared together.

Attributes:

Name Type Description
file_type_name str

Local key of the file type the processor should be bound to.

processor_class type[HeaderProcessor]

Concrete HeaderProcessor class associated with that file type.

namespace str

Namespace label identifying the binding source, usually the built-in TopMark namespace or a plugin namespace.

bindings_for

bindings_for(
    processor_class, file_type_names, *, namespace
)

Expand one processor class across multiple file type names.

Parameters:

Name Type Description Default
processor_class type[HeaderProcessor]

Concrete HeaderProcessor class to bind.

required
file_type_names Iterable[str]

File type local keys that should resolve to the same processor class.

required
namespace str

Namespace label identifying the binding source.

required

Returns:

Type Description
ProcessorBinding

Tuple of ProcessorBinding

...

objects preserving the input order of file_type_names.

Source code in src/topmark/processors/bindings.py
def bindings_for(
    processor_class: type[HeaderProcessor],
    file_type_names: Iterable[str],
    *,
    namespace: str,
) -> tuple[ProcessorBinding, ...]:
    """Expand one processor class across multiple file type names.

    Args:
        processor_class: Concrete `HeaderProcessor` class to bind.
        file_type_names: File type local keys that should resolve to the same
            processor class.
        namespace: Namespace label identifying the binding source.

    Returns:
        Tuple of [`ProcessorBinding`][topmark.processors.bindings.ProcessorBinding]
        objects preserving the input order of `file_type_names`.
    """
    return tuple(
        ProcessorBinding(
            file_type_name=file_type_name,
            processor_class=processor_class,
            namespace=namespace,
        )
        for file_type_name in file_type_names
    )