madam.vector module
- class madam.vector.SVGContext(processor: SVGProcessor, tree: ET.ElementTree[ET.Element])[source]
Bases:
ProcessingContextDeferred in-memory state for an SVG processing run.
Holds a live
xml.etree.ElementTree.ElementTreeso that consecutive SVG operators can transform the document without intermediate serialise/parse cycles. Callmaterialize()to produce the final encodedAsset.Instances are created by
SVGProcessorand passed toexecute_run(). Custom operator implementations can traverse or mutatetreein place before the result is serialised.- Variables:
tree (xml.etree.ElementTree.ElementTree) – The live element tree being transformed. Operators may modify its nodes in place or replace child elements. The root element must remain a valid
<svg>element.
Added in version 1.0.
- __init__(processor: SVGProcessor, tree: ET.ElementTree[ET.Element]) None[source]
- property processor: SVGProcessor
The
Processorthat owns this context.
- class madam.vector.SVGMetadataProcessor(config: Mapping[str, Any] | None = None)[source]
Bases:
MetadataProcessorRepresents a metadata processor that handles Scalable Vector Graphics (SVG) data.
It is assumed that the SVG XML uses UTF-8 encoding.
- __init__(config: Mapping[str, Any] | None = None) None[source]
Initializes a new SVGMetadataProcessor.
- Parameters:
config – Mapping with settings.
- combine(file: IO, metadata: Mapping[str, Mapping]) IO[source]
Returns a byte stream whose contents represent the specified file where the specified metadata was added.
- Parameters:
metadata (Mapping) – Mapping of the metadata format to the metadata dict
file (IO) – Container file
- Returns:
file-like object with combined content
- Return type:
IO
- read(file: IO) Mapping[str, Mapping][source]
Reads the file and returns the metadata.
The metadata that is returned is grouped by type. The keys are specified by
format.- Parameters:
file (IO) – File-like object to be read
- Returns:
Metadata contained in the file
- Return type:
Mapping
- Raises:
UnsupportedFormatError – if the data is corrupt or its format is not supported
- class madam.vector.SVGProcessor(config: Mapping[str, Any] | None = None)[source]
Bases:
ProcessorRepresents a processor that handles Scalable Vector Graphics (SVG) data.
- __init__(config: Mapping[str, Any] | None = None) None[source]
Initializes a new SVGProcessor.
- Parameters:
config – Mapping with settings.
- can_read(file: IO) bool[source]
Returns whether the specified MIME type is supported by this processor.
- Parameters:
file (IO) – file-like object to be tested
- Returns:
whether the data format of the specified file is supported or not
- Return type:
- execute_run(steps: list[Callable], asset_or_context: Asset | SVGContext) Asset | SVGContext[source]
Apply a group of consecutive SVG operators in a single parse/serialise cycle.
The input
Asset(or incomingSVGContextfrom a prior run) is parsed once. Each step’s XML transform is applied in memory via a_transform_*method. The result is returned as anSVGContextfor the pipeline to serialise at the processor boundary or pipeline end.
- read(file: IO) Asset[source]
Returns an
Assetobject whose essence is identical to the contents of the specified file.- Parameters:
file (IO) – file-like object to be read
- Returns:
Asset with essence
- Return type:
- Raises:
UnsupportedFormatError – if the specified data format is not supported