pyxsd.schematron.limits ======================= .. py:module:: pyxsd.schematron.limits .. autoapi-nested-parse:: 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 :class:`~pyxsd.schematron.errors.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 :class:`~pyxsd.xslt.runtime.frames.ExecutionLimits` so one validation charges nested expression work to the same budget contract as the internal XSLT host. Classes ------- .. autoapisummary:: pyxsd.schematron.limits.SchematronCompileLimits pyxsd.schematron.limits.SchematronValidationLimits pyxsd.schematron.limits.SchematronBudgetCounter Module Contents --------------- .. py:class:: 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. .. py:attribute:: max_resources :type: int | None :value: None .. py:attribute:: max_expanded_elements :type: int | None :value: None .. py:attribute:: max_expressions :type: int | None :value: None .. py:class:: 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. .. py:attribute:: max_outcomes :type: int | None :value: None .. py:attribute:: max_sequence_items :type: int | None :value: None .. py:attribute:: execution :type: pyxsd.xslt.runtime.frames.ExecutionLimits .. py:class:: 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. .. py:property:: stage :type: str The compilation or validation stage this counter charges. .. py:method:: consume(budget, amount = 1) Record *amount* units of *budget*, raising when the bound is crossed. .. py:method:: observe(budget, observed) Check *observed* as a high-water mark without charging the budget. Repeated observations never accumulate, and a successful observation leaves cumulative :meth:`consume` counts untouched.