pyxsd.resource_policy¶
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¶
Exceptions¶
A resource/parser policy refused input; never a missing-resource hint. |
Classes¶
Original bytes and their canonical source name, before tree rewriting. |
|
Application-controlled loading and parsing for a schema and its instances. |
Functions¶
|
Return purpose if it is a known resource purpose, else raise. |
|
Use a policy's optional report budget, preserving unlimited core defaults. |
|
Name a path or named stream without substituting the process cwd. |
|
Whether source is an explicit path whose first policy read is the root. |
|
Enter a policy's optional per-compilation closure scope. |
|
Refuse parser arguments that a trusted ResourcePolicy would swallow. |
|
Load paths through the policy; streams still pass through its parser. |
|
Record original declaration addresses before composition moves nodes. |
Module Contents¶
- pyxsd.resource_policy.ResourcePurpose¶
- pyxsd.resource_policy.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.
- Parameters:
purpose (str)
- Return type:
- exception pyxsd.resource_policy.ResourcePolicyError¶
A resource/parser policy refused input; never a missing-resource hint.
- class pyxsd.resource_policy.ResourceData¶
Original bytes and their canonical source name, before tree rewriting.
- class pyxsd.resource_policy.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<memory>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.purposeis aResourcePurpose:"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 throughxsi:schemaLocationorxsi:noNamespaceSchemaLocation; and"instance"for an instance document. Parsers must populate the supplied namespace context. Anonymous streams use<memory>and have no implicit filesystem base.- read(source, *, base, purpose)¶
Authorize and read a named resource, retaining its original bytes.
- Parameters:
source (str)
base (str | None)
purpose (ResourcePurpose)
- Return type:
- parse(data, context)¶
Parse admitted bytes and record namespace evidence.
- Parameters:
data (ResourceData)
context (pyxsd.namespaces.NamespaceContext)
- Return type:
- pyxsd.resource_policy.new_validation_report(policy)¶
Use a policy’s optional report budget, preserving unlimited core defaults.
- Parameters:
policy (ResourcePolicy | None)
- Return type:
- pyxsd.resource_policy.source_identifier(source)¶
Name a path or named stream without substituting the process cwd.
- pyxsd.resource_policy.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.
- pyxsd.resource_policy.policy_compilation(policy, *, root_read)¶
Enter a policy’s optional per-compilation closure scope.
RemoteResourcePolicyadvertises the hook through the private_pyxsd_compilation_scopecapability marker, not through the publiccompilation()method’s spelling, so a custom policy may define an unrelatedcompilationattribute without breaking compilation. A policy that wants the same per-compilation state publishes the marker itself.root_readis false for an anonymous stream schema, whose dependencies must still authorize local-to-remote loading.- Parameters:
policy (ResourcePolicy | None)
root_read (bool)
- Return type:
collections.abc.Iterator[None]
- pyxsd.resource_policy.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.
- Parameters:
resource_policy (ResourcePolicy | None)
xml_policy (pyxsd.xml_policy.XmlParserPolicy | None)
xml_limits (pyxsd.xml_policy.XmlLimits | None)
- Return type:
None
- pyxsd.resource_policy.read_resource(source, policy, *, purpose, base=None)¶
Load paths through the policy; streams still pass through its parser.
- Parameters:
source (str | os.PathLike[str] | IO[str] | IO[bytes] | xml.etree.ElementTree.Element)
policy (ResourcePolicy)
purpose (ResourcePurpose)
base (str | None)
- Return type:
- pyxsd.resource_policy.record_declarations(root, source, origins)¶
Record original declaration addresses before composition moves nodes.
- Parameters:
source (str | None)
origins (weakref.WeakKeyDictionary[xml.etree.ElementTree.Element, pyxsd.locations.IssueLocation])
- Return type:
None