pyxsd.xdm ========= .. py:module:: pyxsd.xdm .. autoapi-nested-parse:: Independent, immutable XDM 3.1 values. The package is reusable by XPath, serialization, and other consumers and is independent of stylesheet execution; it does not import :mod:`pyxsd.xslt`. Attributes ---------- .. autoapisummary:: pyxsd.xdm.XdmSequence Classes ------- .. autoapisummary:: pyxsd.xdm.XdmArray pyxsd.xdm.XdmAtomic pyxsd.xdm.XdmFunction pyxsd.xdm.XdmFunctionSignature pyxsd.xdm.XdmItem pyxsd.xdm.XdmMap pyxsd.xdm.XdmSequenceType Functions --------- .. autoapisummary:: pyxsd.xdm.as_xdm Package Contents ---------------- .. py:class:: XdmArray(members = ()) An immutable XDM array whose members are XDM sequences, indexed from one. .. py:property:: members :type: tuple[XdmSequence, ...] .. py:property:: size :type: int .. py:method:: get(index) Return the one-based member at *index*. .. py:class:: XdmAtomic One immutable XDM atomic value with its XSD type identity. .. py:attribute:: value :type: Any .. py:attribute:: type_name :type: str .. py:attribute:: datatype :type: type[Any] | None :value: None .. py:method:: string(value) :classmethod: .. py:method:: integer(value) :classmethod: .. py:method:: decimal(value) :classmethod: .. py:method:: double(value) :classmethod: .. py:method:: float(value) :classmethod: .. py:method:: boolean(value) :classmethod: .. py:method:: untyped_atomic(value) :classmethod: .. py:method:: any_uri(value) :classmethod: .. py:method:: typed(value, datatype) :classmethod: Wrap a value and its XSD datatype at the atomic invariant boundary. List values are not atomic, the payload must carry its actual XSD datatype class (Python storage bases are not accepted), and the payload must be hashable so it can serve as an XDM map key. The function-item layer never constructs an atomic from a mutable Python container. .. py:property:: lexical :type: str The XSD lexical form, including ``INF``/``-INF``/``NaN`` spellings. .. py:property:: string_value :type: str The string value, as computed by ``fn:string`` (F&O 3.1 ยง19.1.1). Numeric and boolean values convert by value rather than by their XSD lexical form: ``xs:double`` 2.0 is ``"2"``, ``xs:decimal`` 2.50 is ``"2.5"``, and values outside ``[1e-6, 1e6)`` use scientific notation. Every other family's XSD lexical form is already its string value. .. py:method:: same_key(other) XDM ``op:same-key`` map-key equality. Numeric keys compare by exact mathematical value with no rounding, so map keys stay transitive and distinct ``xs:decimal``/``xs:double`` values are not collapsed. Strings and their derived types compare by value, QNames compare by expanded name, and two NaNs are the same key even though ``NaN eq NaN`` is false. .. py:method:: cast(type_name) Cast this value to another built-in XSD atomic type. Casting uses the XSD lexical space. Types that require schema or namespace context (for example ``xs:QName``) are rejected rather than approximated. .. py:class:: XdmFunction(implementation, *, arity = None, signature = None, closure = None, name = None, declared_types = None) An immutable XDM function item. ``implementation`` is called as ``implementation(arguments, environment, closure)`` after arity checking and optional signature coercion. It must return an XDM value or a host container convertible by :func:`as_xdm`. The implementation is private to the item and is never exposed as a plain Python call surface. .. py:attribute:: arity :type: tuple[int, int | None] .. py:attribute:: signature :type: XdmFunctionSignature | None .. py:attribute:: closure :type: Any .. py:attribute:: name :type: str | None .. py:attribute:: declared_types :type: XdmFunctionSignature | None .. py:method:: invoke(arguments, environment = None) Invoke with XDM argument sequences and one invocation environment. .. py:class:: XdmFunctionSignature The declared parameter and return sequence types of a function item. .. py:attribute:: parameters :type: tuple[XdmSequenceType, ...] :value: () .. py:attribute:: return_type :type: XdmSequenceType | None :value: None .. py:class:: XdmItem Base class for one XDM item. Concrete items are immutable. Nodes extend this class in ``pyxsd.xdm.nodes``; they are not value items and are never compared by value here. .. py:class:: XdmMap(entries = ()) An immutable XDM map with XDM key equality and update semantics. .. py:method:: empty() :classmethod: .. py:method:: merge(*maps, duplicates = 'use-first') :classmethod: Merge maps with the normative ``map:merge`` duplicate policies. .. py:method:: from_mapping(mapping) :classmethod: Explicit host-dictionary conversion; keys must atomize to one atomic. .. py:property:: entries :type: tuple[tuple[XdmAtomic, XdmSequence], ...] .. py:property:: size :type: int .. py:method:: get(key) .. py:method:: contains(key) .. py:method:: put(key, value) .. py:method:: remove(key) .. py:method:: keys() .. py:method:: values() .. py:type:: XdmSequence :canonical: tuple[XdmItem, ...] an ordered tuple of items, possibly empty. :type: An XDM sequence .. py:class:: XdmSequenceType One XDM sequence type: a type name and an occurrence indicator. .. py:attribute:: type_name :type: str :value: 'item()' .. py:attribute:: occurrence :type: str :value: 'zero-or-more' .. py:function:: as_xdm(value) Convert one host value to an XDM sequence at the explicit seam. An :class:`XdmItem` becomes a one-item sequence. A host list, tuple, or other iterable is a sequence (nested host sequences flatten, since XDM sequences never nest). A mapping is one :class:`XdmMap` item. Strings and byte strings are single atomic items and are never iterated as characters or integers. ``None`` is rejected because the empty sequence is ``()``.