pyxsd.resource_policy ===================== .. py:module:: pyxsd.resource_policy .. autoapi-nested-parse:: Opt-in resource loading and XML parser hooks, without optional dependencies. A policy is trusted application code, not a sandbox. Every dependency read uses the same policy. Denials should raise ResourcePolicyError, not OSError (which schema composition treats as an unavailable resource). Attributes ---------- .. autoapisummary:: pyxsd.resource_policy.ResourcePurpose Exceptions ---------- .. autoapisummary:: pyxsd.resource_policy.ResourcePolicyError Classes ------- .. autoapisummary:: pyxsd.resource_policy.ResourceData pyxsd.resource_policy.ResourcePolicy Functions --------- .. autoapisummary:: pyxsd.resource_policy.validate_purpose pyxsd.resource_policy.new_validation_report pyxsd.resource_policy.source_identifier pyxsd.resource_policy.is_root_read_source pyxsd.resource_policy.policy_compilation pyxsd.resource_policy.reject_parser_override pyxsd.resource_policy.read_resource pyxsd.resource_policy.record_declarations Module Contents --------------- .. py:data:: ResourcePurpose .. py:function:: validate_purpose(purpose) Return *purpose* if it is a known resource purpose, else raise. Internal callers pass the purpose of a read through several layers; an unknown value is a programming error rather than an authorization decision, so it is rejected before a policy can act on it. .. py:exception:: ResourcePolicyError A resource/parser policy refused input; never a missing-resource hint. .. py:class:: ResourceData Original bytes and their canonical source name, before tree rewriting. .. py:attribute:: source_id :type: str .. py:attribute:: content :type: bytes .. py:class:: ResourcePolicy Application-controlled loading and parsing for a schema and its instances. Source IDs are canonical strings: a local path (including a virtual path a policy defines, such as ``/workspace/...``), an absolute remote URI, or ```` for an anonymous stream. A dependency's base is its including document, not its directory: a policy resolves a remote base with URI semantics and any other base with its own filesystem semantics. ``purpose`` is a :data:`ResourcePurpose`: ``"schema"`` for an explicitly supplied schema, a caller's namespace mapping, and an ordinary schema dependency; ``"schema-hint"`` for a schema an instance document selected through ``xsi:schemaLocation`` or ``xsi:noNamespaceSchemaLocation``; and ``"instance"`` for an instance document. Parsers must populate the supplied namespace context. Anonymous streams use ```` and have no implicit filesystem base. .. py:method:: read(source, *, base, purpose) Authorize and read a named resource, retaining its original bytes. .. py:method:: parse(data, context) Parse admitted bytes and record namespace evidence. .. py:function:: new_validation_report(policy) Use a policy's optional report budget, preserving unlimited core defaults. .. py:function:: source_identifier(source) Name a path or named stream without substituting the process cwd. .. py:function:: is_root_read_source(source) Whether *source* is an explicit path whose first policy read is the root. An anonymous stream has no implicit base, so a policy compilation entered for it must still let its dependencies authorize local-to-remote loading. .. py:function:: policy_compilation(policy, *, root_read) Enter a policy's optional per-compilation closure scope. :class:`~pyxsd.remote.RemoteResourcePolicy` advertises the hook through the private ``_pyxsd_compilation_scope`` capability marker, not through the public ``compilation()`` method's spelling, so a custom policy may define an unrelated ``compilation`` attribute without breaking compilation. A policy that wants the same per-compilation state publishes the marker itself. ``root_read`` is false for an anonymous stream schema, whose dependencies must still authorize local-to-remote loading. .. py:function:: reject_parser_override(resource_policy, xml_policy, xml_limits) Refuse parser arguments that a trusted ResourcePolicy would swallow. Shared by every schema compiler so a policy/parser combination is rejected identically, before any input is read. .. py:function:: read_resource(source, policy, *, purpose, base = None) Load paths through the policy; streams still pass through its parser. .. py:function:: record_declarations(root, source, origins) Record original declaration addresses before composition moves nodes.