pyxsd.schemaless ================ .. py:module:: pyxsd.schemaless .. autoapi-nested-parse:: Schemaless XML and native JSON documents with explicit XML projection. Optional JSON Schema and OpenAPI guidance loads only when requested, so the native XML, native JSON, and explicit mapping paths have no optional import. Attributes ---------- .. autoapisummary:: pyxsd.schemaless.NativeJsonValue Exceptions ---------- .. autoapisummary:: pyxsd.schemaless.JsonLimitError pyxsd.schemaless.JsonParseError pyxsd.schemaless.JsonSchemaError pyxsd.schemaless.ScalarTypeError pyxsd.schemaless.SchemalessParseError pyxsd.schemaless.XmlMappingError Classes ------- .. autoapisummary:: pyxsd.schemaless.SchemalessDocument pyxsd.schemaless.JsonDocument pyxsd.schemaless.JsonLimits pyxsd.schemaless.MappingRule pyxsd.schemaless.XmlMapping pyxsd.schemaless.NodeMapping pyxsd.schemaless.DocumentProfile pyxsd.schemaless.PathProfile pyxsd.schemaless.ProfileLimits pyxsd.schemaless.TypeCandidate pyxsd.schemaless.SchemalessElement pyxsd.schemaless.SchemalessRevision pyxsd.schemaless.ScalarAdapter pyxsd.schemaless.TypePolicy Functions --------- .. autoapisummary:: pyxsd.schemaless.from_data pyxsd.schemaless.from_json pyxsd.schemaless.attribute pyxsd.schemaless.child pyxsd.schemaless.children pyxsd.schemaless.text pyxsd.schemaless.parse_xml Package Contents ---------------- .. py:class:: SchemalessDocument(root, source, report, *, source_index = None, capture_source = None, report_current = True, xml_policy = None, xml_limits = None, _xdm_baseline = None, _node_mapping = None) One XML parse with no schema binding. ``root`` is the editable lexical tree, ``report`` is the parse's report (never a validation verdict), ``source`` is the recorded source name, and ``source_index`` is the byte index for that source (``None`` for a caller-built tree). ``report_current`` is true only while the report still describes the tree: a lexical edit or a transform wrapper makes it stale. .. py:attribute:: root :type: pyxsd.schemaless.tree.SchemalessElement .. py:attribute:: source_index :value: None .. py:property:: report_current :type: bool Whether the report still describes the current lexical revision. A successful edit dirties the revision, and a transform wrapper deliberately keeps the old report snapshot, so both report stale until the document is parsed again. .. py:method:: test_type(path, type_ref) Report every matching occurrence that rejects the proposed type. .. py:method:: pin_type(path, type_ref) Install a pin even when some matching values reject the type. Invalid selectors and unknown types or paths are reported but not installed. Successful installation changes neither lexical data nor XDM. .. py:method:: to_xdm() Return the cached, untyped XDM view of this unedited revision. A parsed XML source retains its comments, processing instructions and spans. A caller-built tree instead supplies its XML lexical projection. After an edit, use :meth:`revalidate` to obtain a fresh document. .. py:method:: revalidate() Refresh the current lexical XML in a new document, without a schema. The new parse has its own report, source index, lexical revision and XDM view. Comments and processing instructions omitted by the editable tree do not survive this round trip. Mixin selectors use the paths and lexical values of the new tree. .. py:method:: to_dict(*, typed = True, always_list = False) Returns the lexical tree as a plain dict. ``typed=True`` applies the scalar policy to leaves and attributes. ``typed=False`` exports the lexical strings. .. py:method:: to_data(*, format = 'pyxsd', fidelity = 'best-effort', typed = True, always_list = False) Returns the lexical tree under the native ``pyxsd`` data contract. The schema-directed formats need a compiled schema to choose a layout, so a schemaless document rejects them explicitly. ``typed``, ``always_list``, and ``fidelity`` keep their native meanings. .. py:method:: profile(limits = None) Walk the current lexical revision into an immutable profile. XML rows group occurrences by expanded-name path without same-name occurrence indexes and report attributes separately. Candidate evaluation is evidence only: it never installs a pin, edits lexical data, or adds XDM annotations, and a failing pin still profiles without raising. ``revision_id`` and ``revision_dirty`` record the source revision at snapshot time. .. py:method:: write(dest) Writes the lexical tree to *dest* (a path or a file object). .. py:method:: to_string() Returns the lexical tree serialized as compact XML text. .. py:exception:: JsonLimitError Native JSON input exceeded one of its structural or byte budgets. .. py:exception:: JsonParseError(message, *, line = None, column = None, position = None) Malformed, ambiguous, or non-native JSON input or output. ``line``, ``column``, and ``position`` carry the decoder's one-based text position and zero-based character offset when the failure came from JSON text; value-model failures (duplicate keys, non-finite numbers, unsupported host objects) leave them ``None``. .. py:attribute:: line :value: None .. py:attribute:: column :value: None .. py:attribute:: position :value: None .. py:exception:: JsonSchemaError JSON Schema could not be compiled or evaluated for this document. .. py:exception:: ScalarTypeError(message, *, location) The lexical value at an explicitly pinned location was rejected. .. py:attribute:: location .. py:exception:: SchemalessParseError(message, *, location, open_elements) Malformed XML with a report, exact location, and open expanded names. .. py:attribute:: location .. py:attribute:: open_elements .. py:attribute:: report .. py:exception:: XmlMappingError(report) A native JSON value cannot be projected with the supplied mapping. ``report`` carries the structured diagnostics: each issue names the JSON Pointer, the projected XML path, and any other evidence needed to repair the mapping. Projection stops at the first fatal issue, so a failed projection never returns a partial document. .. py:attribute:: report .. py:class:: JsonDocument(value, *, source = '', types = None) One native JSON value with an optional JSON Schema validation report. ``source`` is the recorded input name (``""`` for anonymous text, bytes, streams, and host data), ``report`` is the document's report, and ``is_valid`` is false once that report records an error. A schema-invalid instance still supports native reads and XDM conversion. ``types`` is the immutable scalar policy; the default is :meth:`~pyxsd.schemaless.types.TypePolicy.native`, and :meth:`pin_type` replaces it for this document only. .. py:attribute:: source :type: str .. py:property:: report :type: pyxsd.validation.ValidationReport The document's report, empty when built without JSON Schema guidance. .. py:property:: is_valid :type: bool Whether the report holds no error-severity issues. .. py:property:: types :type: pyxsd.schemaless.types.TypePolicy The document's immutable scalar policy. .. py:method:: require_valid() Raise :class:`pyxsd.ValidationError` if the report has errors. .. py:method:: value_at(pointer: str, typed: Literal[False] = False) -> pyxsd.schemaless.json_values.NativeJsonValue value_at(pointer: str, typed: bool) -> Any Return the value addressed by an RFC 6901 JSON Pointer. The empty pointer addresses the root. Scalars from the native model are immutable and returned directly; objects and arrays are deep-copied so the caller cannot mutate authoritative storage. ``typed=True`` returns an independent view whose scalar leaves follow the document's policy. Objects stay mappings, arrays stay lists, null stays ``None``, and map keys are never interpreted. A scalar that the policy cannot parse raises :class:`ScalarTypeError` with the failing pointer; the native value itself remains unchanged. .. py:method:: to_data() Return a deep copy of the native value. Parsed integral numbers remain :class:`int`, other parsed numbers remain :class:`Decimal`, and a float remains a float only when host data supplied one. No number passes through float merely to be copied. The type policy affects only :meth:`value_at` and :meth:`to_xdm`. .. py:method:: to_json(indent = None) Serialize the native value as JSON text. ``None`` emits compact containers. An integer supplies spaces and a string supplies JSON whitespace for one level of indentation. A non-whitespace indent raises :class:`JsonParseError`. A type policy never changes the exact native scalar spellings. .. py:method:: to_xml(mapping, *, node_mapping = None) Project this native value into a fresh XML document. *mapping* names the root element and may rename occurrences by RFC 6901 JSON Pointer. Element-first projection turns object properties and array members into elements, strings into escaped character data, numbers and booleans into JSON-compatible lexical text, and null into ``xsi:nil="true"``. The source value is never changed and edits to the derived XML do not write back. The result has no source bytes or source index. Its report is current and holds non-fatal warnings for information the XML shape cannot retain. Invalid names, unusable expanded namespace names, and string characters XML 1.0 cannot represent raise :class:`~pyxsd.schemaless.errors.XmlMappingError` instead of being repaired, escaped around, or dropped. Object member keys are always validated as local names; only explicit mapping names may be expanded. JSON Pointer pins stay on this document: the projected tree starts from a lexical policy. A schema-backed mapping requires a valid instance for its own schema. If validation fails, ``XmlMappingError.report`` contains the JSON Schema diagnostics. Other mappings do not require schema validation. Pass *node_mapping* to add Python mixins to matching projected occurrences; descriptor ``type=`` entries become occurrence pins on the derived document's policy, just as they do for :func:`parse_xml`. .. py:method:: to_xdm() Return this document's native value as an XDM 3.1 sequence. Objects become maps with ``xs:string`` keys, arrays become arrays whose members keep their nesting, and null becomes the empty sequence. A scalar uses an explicit pointer pin, unambiguous schema guidance, conservative string inference, or its exact native atomic kind, in that order. An invalid instance uses only pins and native kinds. A pin that rejects its value raises :class:`ScalarTypeError` with the pointer. Nothing is wrapped in an XML document. .. py:method:: profile(limits = None) Return a bounded, immutable profile of the current native value. Rows use exact RFC 6901 pointers: one ``"value"`` row for every address and one additional ``"array-items"`` row at each array's pointer for aggregate member evidence. Scalar candidates are evaluated as evidence only: the profile never changes the native value, the scalar policy, or any later XDM interpretation. A native document has no revision counter, so the snapshot records ``revision_id=None`` and ``revision_dirty=False``. .. py:method:: test_type(pointer, type_ref) Report whether the JSON scalar at *pointer* accepts a proposed type. Testing never installs a pin. A malformed or absent pointer, a non-scalar value, and an unknown type each report one error and leave the policy unchanged. A scalar that rejects the type also leaves the policy unchanged. .. py:method:: pin_type(pointer, type_ref) Install a pointer pin even when the current value rejects the type. A malformed or absent pointer, a non-scalar value, and an unknown type report an error without changing the policy. A scalar that rejects the type still receives the pin, so later typed reads and XDM conversion raise :class:`ScalarTypeError`. Installing a pin changes neither native storage nor the JSON spelling. .. py:function:: from_data(value, *, limits = None, types = None, json_schema = None, base_uri = None, reference_registry = None, resource_policy = None, format_assertion = False, format_typing = False) Copy host data into a new native JSON document. Mappings with string keys, lists, tuples, strings, booleans, integers, finite floats and ``Decimal`` values, and ``None`` are accepted. Tuples become lists, and the input is copied so later changes to *value* cannot affect the document. Values outside the native model raise :class:`~pyxsd.schemaless.errors.JsonParseError`; structural budgets raise :class:`~pyxsd.schemaless.errors.JsonLimitError`. *types* is the document's scalar policy for typed reads and XDM conversion; the default is :meth:`~pyxsd.schemaless.types.TypePolicy.native`, which preserves every native scalar kind. For the optional schema arguments, see :func:`from_json`. .. py:function:: from_json(source, *, limits = None, types = None, json_schema = None, base_uri = None, reference_registry = None, resource_policy = None, format_assertion = False, format_typing = False) Decode JSON text, bytes, or a stream into a new native JSON document. Integral number tokens become :class:`int` and other number tokens become :class:`Decimal`; no number passes through float. Malformed text, duplicate object keys, non-standard numeric constants, and non-UTF-8 bytes raise :class:`~pyxsd.schemaless.errors.JsonParseError` named for the source: a named stream keeps its ``name`` and every anonymous source is ``""``. An exceeded structural budget raises :class:`~pyxsd.schemaless.errors.JsonLimitError`. *types* is the document's scalar policy for typed reads and XDM conversion; the default is :meth:`~pyxsd.schemaless.types.TypePolicy.native`, which preserves every native scalar kind. Parsed JSON text never changes because of it. *json_schema* accepts a Draft 2020-12 boolean, mapping, or strict JSON text. Relative references use the schema's *base_uri*, not the instance source. External resources must be registered in *reference_registry* or authorized and read by *resource_policy*. Format is an annotation unless *format_assertion* is true. Assertion uses deterministic checks for ``date``, ``date-time``, and ``time`` plus ``uuid``, ``ipv4``, ``ipv6``, ``json-pointer``, ``regex``, ``int32``, ``int64``, ``float``, ``double``, and ``byte``; ``regex`` follows Python ``re`` syntax, and unlisted formats depend on the installed ``jsonschema`` environment. Invalid schemas or unresolved references raise :class:`~pyxsd.schemaless.errors.JsonSchemaError`; instance failures are recorded in the document's report. *format_typing* independently enables supported format and content encoding annotations for typed reads and XDM conversion of valid instances. ``uuid``, ``ipv4``, and ``ipv6`` return standard-library values with canonical ``xs:string`` XDM; ``int32``, ``int64``, ``float``, ``double``, and ``byte`` or ``contentEncoding: base64`` reuse their XSD SimpleTypes. It never changes validation, native storage, or JSON output, and unsupported or rejected values keep their native interpretation. .. py:class:: JsonLimits Optional budgets for one native JSON input. Every structural bound is inclusive and positive: ``max_bytes`` counts the input bytes as supplied (UTF-8 bytes for text, including a leading BOM), ``max_depth`` counts nesting with the root at depth one, and ``max_values`` counts every value (containers and scalars) but not object member names. ``max_diagnostics`` is a non-negative retention budget for diagnostics that later JSON Schema evaluation may attach to the document. ``None`` leaves that budget unset. .. py:attribute:: max_bytes :type: int | None :value: None .. py:attribute:: max_depth :type: int | None :value: None .. py:attribute:: max_values :type: int | None :value: None .. py:attribute:: max_diagnostics :type: int | None :value: None .. py:type:: NativeJsonValue :canonical: bool | int | float | Decimal | str | list['NativeJsonValue'] | dict[str, 'NativeJsonValue'] | None .. py:class:: MappingRule One explicit override for an occurrence addressed by JSON Pointer. ``kind`` overrides the default node kind. ``none`` inlines container children and drops scalar values with a warning. ``name`` and ``item_name`` are local or Clark names; keys used as names must be local. ``namespace`` qualifies a local ``name``; ``prefix`` supplies a lexical binding. Arrays wrap by default. Unwrapped arrays repeat the occurrence name unless ``item_name`` supplies a separate name. ``order`` lists object keys to emit first. By default null emits ``xsi:nil`` for elements and is omitted with a warning for attributes and text. ``type`` formats a scalar's lexical value without annotating the XML or changing the JSON. .. py:attribute:: name :type: str | None :value: None .. py:attribute:: kind :type: str | None :value: None .. py:attribute:: namespace :type: str | None :value: None .. py:attribute:: prefix :type: str | None :value: None .. py:attribute:: array :type: str | None :value: None .. py:attribute:: item_name :type: str | None :value: None .. py:attribute:: null :type: str | None :value: None .. py:attribute:: type :type: pyxsd.schemaless.types.TypeRef | None :value: None .. py:attribute:: order :type: collections.abc.Sequence[str] | None :value: None .. py:class:: XmlMapping(root_name, *, default = 'elements', rules = None) A root name plus per-pointer projection rules. ``rules`` maps RFC 6901 JSON Pointers to :class:`MappingRule` values. A pointer that does not occur in a particular document is simply policy for a possible occurrence; it is not an error, so mapping factories can describe optional schema properties. Use :meth:`compact` to opt into scalar attributes. Rules are checked when their occurrences are projected, because only then are their XML paths known. .. py:property:: root_name :type: str | None The static root name, or None when OpenAPI selects it per instance. .. py:property:: default :type: str ``"elements"`` or ``"compact"``. :type: The projection policy .. py:property:: rules :type: collections.abc.Mapping[str, MappingRule] An immutable view of the JSON Pointer to rule policy. .. py:method:: elements(root_name, *, rules = None) :classmethod: Return the conservative element-first mapping for *root_name*. .. py:method:: compact(root_name, *, rules = None) :classmethod: Map scalar object properties to attributes unless overridden. .. py:method:: from_json_schema(schema, *, root_name, rules = None, base_uri = None, reference_registry = None, resource_policy = None, format_assertion = False, format_typing = False) :classmethod: Compile Draft 2020-12 guidance for an element-first projection. The schema must validate the instance at projection time. ``format_assertion`` checks recognized formats during validation; ``format_typing`` independently formats compatible values through the mapped XSD SimpleTypes or canonical UUID and IP text. Explicit rules take precedence, rejected values keep the native spelling, and schema defaults are not applied. .. py:method:: from_openapi(schema_object, *, root_name = None, rules = None, base_uri = None, reference_registry = None, resource_policy = None, dialect = None, format_assertion = False, format_typing = False) :classmethod: Compile an element-first mapping from an OpenAPI Schema Object. XML Objects on applicable schemas supply node kinds, names, namespaces, and array wrapping. ``root_name`` overrides the annotation's local name. If only an applicator supplies the root name, it is selected at projection time. Explicit rules override individual metadata fields. ``format_assertion`` checks recognized formats during validation; ``format_typing`` independently formats compatible values through the mapped XSD SimpleTypes unless an explicit rule provides a type, and rejected values keep the native spelling. .. py:class:: NodeMapping Register Python mixins for XML element occurrences. Each parse uses the current rules as a snapshot; later registrations do not change existing documents. Later matching rules take precedence, and a mixin matched more than once appears only at its highest priority. Descriptor ``type=`` entries compile into occurrence pins on the same document policy; a later :meth:`~pyxsd.schemaless.document.SchemalessDocument.pin_type` at that path replaces them for descriptor and ordinary reads alike. .. py:method:: register(mixin: None = None, *, path: str | None = None, predicate: _Predicate | None = None) -> collections.abc.Callable[[_Mixin], _Mixin] register(mixin: type, *, path: str | None = None, predicate: _Predicate | None = None) -> None Register a mixin directly or return a decorator for its class. Supply exactly one selector. Paths start at the document root, use Clark names for namespaces, and can specify one-based same-name indexes. If any step is indexed, omitted indexes default to one. A predicate sees the unprojected lexical node and must not edit it. A descriptor ``type=`` requires a path selector because its pin has to name the occurrences it applies to. .. py:function:: attribute(name, *, type = None) Declare one expanded-name attribute field. Reads call ``SchemalessElement.attribute_value`` and therefore follow the document's effective scalar policy; a missing attribute reads as ``None``. Writes format the value through that same adapter and replace only that attribute. *name* is an expanded (Clark) name, not a serialization prefix. .. py:function:: child(name) Declare one child element field by expanded name. The field reads ``None`` when no child has *name*. More than one matching child is ambiguous and raises ``ValueError``, unless the generated mapped class keeps a :func:`children` view for that name declared by the same class as this singular field: the list view then makes the repetition explicit, and the singular field addresses its first element. An inherited pair from one declaring class stays lenient; a list view from another mixin, or one shadowed or replaced in the generated MRO, does not suppress the ambiguity. Navigation fields are read-only. .. py:function:: children(name) Declare all child elements with one expanded name as a tuple. Every read builds a new tuple from the current authoritative child sequence, so the result follows document order after any edit. .. py:function:: text(*, type = None, default = None) Declare the element's leading character data as a scalar field. Reads call ``SchemalessElement.scalar_value`` for present leading text and return *default* when there is none. Mixed content stays mixed content: child tails are never concatenated into this value. Writes replace only the leading text. .. py:function:: parse_xml(source, *, xml_policy = None, xml_limits = None, types = None, node_mapping = None) Read XML from a path, bytes, stream, or caller-built element. Parsed sources retain the same bytes for the source index and XDM capture. A caller-built tree has no original byte spans. Malformed XML raises :class:`SchemalessParseError`; policy and budget errors propagate unchanged. By default scalar reads are lexical; pass *types* to change interpretation. Pass *node_mapping* to add Python mixins to matching lexical occurrences; descriptor ``type=`` entries merge beneath *types* into the document's effective scalar policy as occurrence pins. .. py:class:: DocumentProfile One immutable profile snapshot of a document's current revision. ``revision_id`` is the XML revision identifier and ``revision_dirty`` its edited state at snapshot time; a native JSON document has no revision counter, so it records ``None`` and ``False``. ``rows`` follows document order, and ``complete`` is false whenever a limit truncated evidence. .. py:attribute:: revision_id :type: int | None .. py:attribute:: revision_dirty :type: bool .. py:attribute:: complete :type: bool .. py:attribute:: rows :type: tuple[PathProfile, ...] .. py:method:: at(path, kind = None) Return the row for *path*, preferring its own row over an aggregate. ``kind`` selects one row when a path owns more than one, as a JSON array does with ``"value"`` and ``"array-items"``. Without ``kind`` the first row at the path wins, which is the exact address's own row because an aggregate row always follows the row it aggregates. .. py:class:: PathProfile Bounded evidence for one structural XML path or exact JSON pointer. ``kind`` is ``"element"`` or ``"attribute"`` for XML, ``"value"`` for one exact JSON address, and ``"array-items"`` for the aggregate member evidence of a JSON array at that same pointer. An XML path spells expanded names without same-name occurrence indexes, exactly as a path-wide pin does. ``occurrences`` counts every value at the path; ``parents`` counts the containing occurrences (one document context for a root row) and ``min_occurs``/``max_occurs`` describe how many occurrences each parent holds; ``missing`` counts parents holding none. ``empties`` counts empty elements, empty attributes, empty strings, and empty JSON containers; ``nulls`` counts JSON nulls; ``mixed`` counts XML occurrences that mix character data with element children. ``distinct_values`` and ``samples`` hold bounded lexical text in document order (samples may repeat), ``native_kinds`` holds the observed native JSON kinds, and ``candidates`` holds the ranked built-in scalar types followed by any extra schema-suggested types, with their pass/fail evidence. A row without scalar evidence reports zero candidate counts: an XML occurrence with element children contributes character data only through ``mixed``, and a JSON array aggregate evaluates its scalar members while nulls and containers contribute only kinds and counts. Candidate counts always evaluate the whole lexical value; only the stored value lists are bounded. ``interpretations`` lists the distinct sources of the current interpretation in first-seen order. .. py:attribute:: path :type: str .. py:attribute:: kind :type: str .. py:attribute:: occurrences :type: int .. py:attribute:: parents :type: int .. py:attribute:: min_occurs :type: int .. py:attribute:: max_occurs :type: int .. py:attribute:: missing :type: int :value: 0 .. py:attribute:: nulls :type: int :value: 0 .. py:attribute:: empties :type: int :value: 0 .. py:attribute:: mixed :type: int :value: 0 .. py:attribute:: native_kinds :type: tuple[str, ...] :value: () .. py:attribute:: distinct_values :type: tuple[str, ...] :value: () .. py:attribute:: samples :type: tuple[str, ...] :value: () .. py:attribute:: candidates :type: tuple[TypeCandidate, ...] :value: () .. py:attribute:: interpretations :type: tuple[str, ...] :value: () .. py:attribute:: truncated :type: bool :value: False .. py:property:: candidate_names :type: tuple[str, ...] The ranked candidate names in evaluation order. .. py:method:: candidate(name) Return the candidate named *name*, or raise ``KeyError``. .. py:property:: interpretation :type: str The source of the current interpretation, or ``"mixed"``. A row whose occurrences are interpreted by different sources reports ``"mixed"``. An aggregate row with no scalar members has no source of its own and reports ``"native"``. .. py:class:: ProfileLimits Optional budgets for one profile walk. Every bound is inclusive and positive. ``max_paths`` bounds the number of reported path rows, ``max_distinct`` the distinct-value list of each row, ``max_samples`` the sample list of each row, and ``max_value_bytes`` the UTF-8 length of each stored value. ``None`` leaves that budget unset, which profiles the whole source; supply a bound whenever the source is not trusted. Exceeding a budget during a walk marks the profile incomplete. .. py:attribute:: max_paths :type: int | None :value: None .. py:attribute:: max_distinct :type: int | None :value: None .. py:attribute:: max_samples :type: int | None :value: None .. py:attribute:: max_value_bytes :type: int | None :value: None .. py:class:: TypeCandidate One ranked scalar type evaluated against every value at a path. ``first_failure`` is the first rejecting occurrence in document order, in the same location family the document uses for diagnostics: an XML :class:`~pyxsd.locations.IssueLocation` or a JSON :class:`~pyxsd.locations.DataLocation`. ``from_schema_annotation`` is true when at least one applied JSON Schema annotation suggested the type. .. py:attribute:: name :type: str .. py:attribute:: passed :type: int .. py:attribute:: failed :type: int .. py:attribute:: first_failure :type: pyxsd.locations.IssueLocation | None :value: None .. py:attribute:: from_schema_annotation :type: bool :value: False .. py:class:: SchemalessElement An editable XML element with no schema binding. .. py:property:: revision :type: SchemalessRevision The lexical revision and scalar policy that own this element. .. py:class:: SchemalessRevision One authoritative lexical revision with a replaceable immutable policy. .. py:property:: types :type: pyxsd.schemaless.types.TypePolicy The current immutable scalar policy. .. py:method:: scalar_value(node) .. py:method:: attribute_value(node, expanded_name) .. py:class:: ScalarAdapter Convert lexical strings to Python values and back. The ``parse`` callback rejects invalid input with a ``ValueError``, ``TypeError``, or ``ArithmeticError``. ``format`` takes a typed value and returns its lexical representation. An optional ``xdm`` callback can convert the value to an atomic item; otherwise its formatted string is used. .. py:attribute:: parse :type: collections.abc.Callable[[str], Any] .. py:attribute:: format :type: collections.abc.Callable[[Any], str] .. py:attribute:: xdm :type: collections.abc.Callable[[Any], pyxsd.xdm.values.XdmAtomic] | None :value: None .. py:method:: test(lexical) Return whether this adapter accepts a lexical value. .. py:method:: to_xdm(value) Convert a typed value to an XDM atomic item. .. py:class:: TypePolicy An immutable scalar mode and ordered set of explicit path or pointer pins. .. py:attribute:: mode :type: Literal['lexical', 'native', 'infer'] .. py:attribute:: pins :type: collections.abc.Mapping[str, ScalarAdapter] .. py:method:: lexical() :classmethod: Keep XML scalars lexical unless they are pinned. .. py:method:: native() :classmethod: Keep native scalar kinds unless they are pinned. .. py:method:: infer() :classmethod: Conservatively interpret lexical scalars unless they are pinned. .. py:method:: resolve(type_ref) :staticmethod: Resolve an XSD scalar name or a caller-supplied adapter. .. py:method:: with_pin(path, type_ref) Return a new policy with the adapter pinned at *path*. .. py:method:: json_adapter(pointer, value, *, asserted = None) Resolve the adapter for one native JSON scalar at *pointer*. Precedence is an explicit pointer pin, schema guidance from an evaluated schema, conservative inference of a string leaf, and then the native kind (no adapter). ``asserted`` is the document layer's extension point for a schema that proves this occurrence's type; inference never reinterprets a non-string native value.