2.6.4.4. pycsamt.emtf.xml.parser#

Low-level, namespace-safe helpers for EMTF XML parsing.

Functions

child(node, name)

Return the first direct child matching name.

children(node, name)

Return direct child elements matching name by local name.

element_to_mapping(node)

Convert a small metadata subtree to a loss-preserving Python mapping.

load_xml_root(source)

Parse source and return (root, source_label).

local_name(tag)

Return an XML local name, discarding namespace or prefix.

parse_numeric_text(value, *, complex_)

Parse an FCU-style real or real imag numeric value.

text(node[, name])

Return stripped text from node or one named direct child.

warn(message)

Emit a reader warning with a stable warning category.

Classes

XMLDataTypeSpec(name, tag, data_kind[, ...])

Per-document data-type declaration used while parsing XML.

Exceptions

EMTFXMLParseError

Raised when an EMTF XML document cannot be interpreted safely.

EMTFXMLWarning

Warning emitted for recoverable EMTF XML inconsistencies.

exception pycsamt.emtf.xml.parser.EMTFXMLParseError[source]

Bases: ValueError

Raised when an EMTF XML document cannot be interpreted safely.

exception pycsamt.emtf.xml.parser.EMTFXMLWarning[source]

Bases: UserWarning

Warning emitted for recoverable EMTF XML inconsistencies.

class pycsamt.emtf.xml.parser.XMLDataTypeSpec(name, tag, data_kind, input_kind=None, output_kind=None, units=None, intention='primary', description='', derived_from=None, see_also=(), external_url=None)[source]

Bases: object

Per-document data-type declaration used while parsing XML.

This is deliberately separate from the global scientific registry. EMTF XML files are self-describing and may contain data types unknown to the installed pyCSAMT version; reading one file must not mutate global state.

Parameters:
  • name (str)

  • tag (str)

  • data_kind (str)

  • input_kind (str | None)

  • output_kind (str | None)

  • units (str | None)

  • intention (str)

  • description (str)

  • derived_from (str | None)

  • see_also (tuple[str, ...])

  • external_url (str | None)

name: str
tag: str
data_kind: str
input_kind: str | None = None
output_kind: str | None = None
units: str | None = None
intention: str = 'primary'
description: str = ''
derived_from: str | None = None
see_also: tuple[str, ...] = ()
external_url: str | None = None
property is_scalar: bool[source]
pycsamt.emtf.xml.parser.child(node, name)[source]

Return the first direct child matching name.

Parameters:
Return type:

Element | None

pycsamt.emtf.xml.parser.children(node, name)[source]

Return direct child elements matching name by local name.

Parameters:
Return type:

list[Element]

pycsamt.emtf.xml.parser.element_to_mapping(node)[source]

Convert a small metadata subtree to a loss-preserving Python mapping.

Parameters:

node (Element)

Return type:

dict[str, Any]

pycsamt.emtf.xml.parser.local_name(tag)[source]

Return an XML local name, discarding namespace or prefix.

Parameters:

tag (str)

Return type:

str

pycsamt.emtf.xml.parser.load_xml_root(source)[source]

Parse source and return (root, source_label).

Parameters:

source (str | bytes | PathLike[str] | IO[str] | IO[bytes])

Return type:

tuple[Element, str]

pycsamt.emtf.xml.parser.parse_numeric_text(value, *, complex_)[source]

Parse an FCU-style real or real imag numeric value.

Parameters:
  • value (str | None)

  • complex_ (bool)

Return type:

complex | float

pycsamt.emtf.xml.parser.text(node, name=None)[source]

Return stripped text from node or one named direct child.

Parameters:
Return type:

str | None