topmark.pipeline.adapters¶
Adapters bridging between high-level ProcessingContext and lightweight view protocols.
This module provides helper classes and functions that adapt a full
topmark.pipeline.context.model.ProcessingContext into protocol-compatible
view objects such as topmark.filetypes.model.PreInsertContextView.
These adapters allow downstream components like InsertChecker or other
file-type-specific validation utilities to operate without depending on the
entire pipeline internals.
The design ensures a stable and memory-efficient interface by exposing only the minimal attributes or iterators required for read-only inspection of file contents and metadata.
All adapters defined here are intentionally lightweight and immutable within their lifecycle.
PreInsertViewAdapter
dataclass
¶
Adapter that exposes a ProcessingContext as a PreInsertContextView.
This class extracts only the fields required by the
topmark.filetypes.model.PreInsertContextView protocol and
presents them through lightweight, read-only attributes.
Attributes:
| Name | Type | Description |
|---|---|---|
lines |
Iterable[str]
|
Streaming access to the file lines as provided by the ProcessingContext image view. |
newline_style |
str
|
Detected newline style ("LF", "CR", "CRLF"). |
header_processor |
HeaderProcessor | None
|
The file-type-specific HeaderProcessor instance. |
file_type |
FileType | None
|
The resolved FileType instance or |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
ProcessingContext
|
The processing context to wrap. |
required |
Source code in src/topmark/pipeline/adapters.py
as_sequence ¶
Convert an iterable or sequence of lines into a list.
This utility ensures that downstream components expecting a concrete
list[str] receive one, while gracefully handling None and
already-list inputs without unnecessary copying.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lines
|
Sequence[str] | Iterable[str] | None
|
The source of line strings, which may be a list, tuple, generator, or |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: A list of line strings. Returns an empty list when |
list[str]
|
|