aas_core3_2.xmlrpc

Read and write the JSON-able values as a subset of XML-RPC.

JSON prescribes no XML representation of its own, so we borrow the one of XML-RPC for it: a value is written as a single discriminator element – <nil>, <boolean>, <double>, <string>, <array> or <struct> – which says what the value is. XML-RPC itself knows no null, so we follow the widespread extension, and write a JSON null as an empty <nil/>.

This module knows nothing of the meta-model beyond the JSON-able types, and it drives no document of its own. The caller hands over the very stream of (event, element) tuples, or the very aas_core3_2.xmlcommon.Writer, with which the enclosing document is being read or written, so that a JSON-able property is read and written in the same pass as everything around it.

These elements reside in no namespace at all, as the XML-RPC specification prescribes, and not in the namespace of the enclosing document. The outermost one therefore undeclares the default namespace with xmlns="", and the elements nested in it inherit that.

aas_core3_2.xmlrpc.read_value_content(element: Element, iterator: Iterator[Tuple[str, Element]]) → Union[None, bool, int, float, str, Sequence[Any], Mapping[str, Any]][source]

Read the content of element as a JSON-able value.

The content is a single discriminator element – <nil>, <boolean>, <double>, <string>, <array> or <struct> – which says what the value is.

The end element corresponding to element will be read as well.

Parameters
  • element – start element enclosing the discriminator

  • iterator – Input stream of (event, element) coming from xml.etree.ElementTree.iterparse() with the argument events=["start", "end"]

Raise

DeserializationException if unexpected input

Returns

parsed JSON-able value

aas_core3_2.xmlrpc.read_array_body(element: Element, iterator: Iterator[Tuple[str, Element]]) → Sequence[Any][source]

Read the content of element as a <data> of <value>’s.

The end element corresponding to element will be read as well.

Parameters
  • element – start element enclosing the <data>

  • iterator – Input stream of (event, element) coming from xml.etree.ElementTree.iterparse() with the argument events=["start", "end"]

Raise

DeserializationException if unexpected input

Returns

parsed JSON-able array

aas_core3_2.xmlrpc.read_value_element(element: Element, iterator: Iterator[Tuple[str, Element]]) → Union[None, bool, int, float, str, Sequence[Any], Mapping[str, Any]][source]

Read element, which has to be a <value>, as a JSON-able value.

The end element corresponding to element will be read as well.

Parameters
  • element – start element, expected to be a <value>

  • iterator – Input stream of (event, element) coming from xml.etree.ElementTree.iterparse() with the argument events=["start", "end"]

Raise

DeserializationException if unexpected input

Returns

parsed JSON-able value

aas_core3_2.xmlrpc.read_struct_body(element: Element, iterator: Iterator[Tuple[str, Element]]) → Mapping[str, Any][source]

Read the content of element as a sequence of <member>’s.

The end element corresponding to element will be read as well.

Parameters
  • element – start element enclosing the members

  • iterator – Input stream of (event, element) coming from xml.etree.ElementTree.iterparse() with the argument events=["start", "end"]

Raise

DeserializationException if unexpected input

Returns

parsed JSON-able object

aas_core3_2.xmlrpc.write_discriminator(value: Union[None, bool, int, float, str, Sequence[Any], Mapping[str, Any]], writer: Writer) → None[source]

Write value as one of the six XML-RPC discriminators.

Parameters
  • value – to be serialized

  • writer – to write to

Raise

SerializationException if the value could not be written

aas_core3_2.xmlrpc.write_array_body(value: Sequence[Any], writer: Writer) → None[source]

Write the <data> of the JSON-able array value.

The path of a failure points into value, and not into the document, which is only half written when the failure is raised: it is the value which the caller holds and can look at.

Parameters
  • value – to be serialized

  • writer – to write to

Raise

SerializationException if the value could not be written

aas_core3_2.xmlrpc.write_struct_body(value: Mapping[str, Any], writer: Writer) → None[source]

Write the <member>’s of the JSON-able object value.

The path of a failure points into value, and not into the document, which is only half written when the failure is raised: it is the value which the caller holds and can look at.

Parameters
  • value – to be serialized

  • writer – to write to

Raise

SerializationException if the value could not be written