rigging.model
Models are the core datatypes for structured parsing.
CommaDelimitedAnswer
#
DelimitedAnswer
#
Model
#
Bases: BaseXmlModel
from_text(content: str) -> list[tuple[ModelT, slice]]
classmethod
#
The core parsing method which attempts to extract and parse as many valid instances of a model from semi-structured text.
Parameters:
-
content
(str
) –The text content to parse.
Returns:
-
list[tuple[ModelT, slice]]
–A list of tuples containing the extracted models and their corresponding slices.
Raises:
-
MissingModelError
–If the specified model tags are not found in the message.
-
ValidationError
–If an error occurs while parsing the content.
Source code in rigging/model.py
is_simple() -> bool
classmethod
#
Check if the model is "simple", meaning it has a single field with a basic datatype.
Until we refactor our XML parsing, this helps make the parsing more consistent for models which can support it.
Returns:
-
bool
–True if the model is simple, False otherwise.
Source code in rigging/model.py
one_from_text(content: str, *, fail_on_many: bool = False) -> tuple[ModelT, slice]
classmethod
#
Finds and returns a single match from the given text content.
Parameters:
-
content
(str
) –The text content to search for matches.
-
fail_on_many
(bool
, default:False
) –If True, raises a ValidationError if multiple matches are found.
Returns:
-
tuple[ModelT, slice]
–A tuple containing the matched model and the slice indicating the match location.
Raises:
-
ValidationError
–If multiple matches are found and fail_on_many is True.
Source code in rigging/model.py
to_pretty_xml() -> str
#
Converts the model to a pretty XML string with indents and newlines.
Returns:
-
str
–The pretty XML representation of the model.
Source code in rigging/model.py
xml_end_tag() -> str
classmethod
#
xml_example() -> str
classmethod
#
Returns an example XML representation of the given class.
Models should typically override this method to provide a more complex example.
By default, this method returns a hollow XML scaffold one layer deep.
Returns:
-
str
–A string containing the XML representation of the class.
Source code in rigging/model.py
xml_start_tag() -> str
classmethod
#
NewlineDelimitedAnswer
#
QuestionAnswer
#
YesNoAnswer
#
make_primitive(name: str, type_: type[PrimitiveT] = str, *, tag: str | None = None, doc: str | None = None, validator: t.Callable[[str], str | None] | None = None, strip_content: bool = True) -> type[Primitive[PrimitiveT]]
#
Helper to create a simple primitive model with an optional content validator.
Note
This API is experimental and may change in the future.
Parameters:
-
name
(str
) –The name of the model.
-
tag
(str | None
, default:None
) –The XML tag for the model.
-
doc
(str | None
, default:None
) –The documentation for the model.
-
validator
(Callable[[str], str | None] | None
, default:None
) –An optional content validator for the model.
-
strip_content
(bool
, default:True
) –Whether to strip the content string before pydantic validation.
Returns:
-
type[Primitive[PrimitiveT]]
–The primitive model class.