pyxsd.schematron.limits

Immutable budget declarations for Schematron compilation and validation.

None leaves a budget unlimited, which preserves the core’s behavior on trusted input. A configured budget is a non-negative integer and the bound is inclusive: observing exactly the configured work count succeeds, and the next unit raises SchematronLimitError. Boolean and non-integer values are rejected rather than coerced. Exhaustion never turns into semantic invalidity.

Compilation and validation limits are separate types because expansion and report-retention bounds differ from XSLT execution bounds. execution reuses the existing ExecutionLimits so one validation charges nested expression work to the same budget contract as the internal XSLT host.

Classes

SchematronCompileLimits

Optional budgets for resolve, expansion, and expression compilation.

SchematronValidationLimits

Optional budgets for one validation invocation.

SchematronBudgetCounter

One stage's running observation of the configured budgets.

Module Contents

class pyxsd.schematron.limits.SchematronCompileLimits

Optional budgets for resolve, expansion, and expression compilation.

max_resources counts admitted source resources, including the root. max_expanded_elements counts source elements produced by include, external-extends, and abstract expansion together, so one value bounds the combined work of both stages rather than each stage on its own. max_expressions counts compiled query expressions. A zero budget admits no unit of that work.

max_resources: int | None = None
max_expanded_elements: int | None = None
max_expressions: int | None = None
class pyxsd.schematron.limits.SchematronValidationLimits

Optional budgets for one validation invocation.

max_outcomes bounds retained outcomes; max_sequence_items bounds any single sequence the driver materializes or retains, in particular a rule/@visit-each result and a schema-parameter default. The check happens on the returned sequence’s length before the driver traverses, charges per-item work for, or previews it, so a large selection raises without multiplying work per item or retaining the sequence. The XPath engine still materializes one dispatch’s result; execution.max_steps cannot interrupt work inside that dispatch, so max_sequence_items is the sequence-size bound, not max_steps.

execution carries the XSLT execution budgets used by the expression host. A zero max_outcomes retains no outcome and therefore raises on the first produced outcome; a zero max_sequence_items rejects any non-empty sequence.

max_outcomes: int | None = None
max_sequence_items: int | None = None
execution: pyxsd.xslt.runtime.frames.ExecutionLimits
class pyxsd.schematron.limits.SchematronBudgetCounter(stage, limits=None)

One stage’s running observation of the configured budgets.

A counter is per compilation or per validation; it counts each budget name independently and never mutates its limits value. stage names the work being charged. The counter accepts only budgets that belong to the supplied limits type, so a validation counter cannot charge a compile-only budget by accident.

Parameters:
property stage: str

The compilation or validation stage this counter charges.

Return type:

str

consume(budget, amount=1)

Record amount units of budget, raising when the bound is crossed.

Parameters:
Return type:

None

observe(budget, observed)

Check observed as a high-water mark without charging the budget.

Repeated observations never accumulate, and a successful observation leaves cumulative consume() counts untouched.

Parameters:
Return type:

None