LockedXmlTraits

class wwt_data_formats.LockedXmlTraits(**kwargs)[source]

Bases: wwt_data_formats.LockedDownTraits

A base class for LockedDownTraits objects that can also be serialized to and from XML.

This is not a fully general XML serialization framework; it is tuned to the needs of the WWT XML serialization formats.

Methods Summary

apply_to_xml(elem)

Serialize the data of this object to an existing XML tree

from_file(path)

Deserialize an instance of this class from an XML file on local disk.

from_text(text)

Deserialize an instance of this class from XML-formatted text.

from_url(url)

Deserialize an instance of this class from XML downloaded from the specified URL.

from_xml(elem)

Deserialize an instance of this class from XML.

to_xml()

Serialize this object to XML.

to_xml_string([indent])

Serialize this object to XML text.

write_xml(dest_stream[, dest_wants_bytes, …])

Serialize this object to XML, writing the data to a stream.

Methods Documentation

apply_to_xml(elem)[source]

Serialize the data of this object to an existing XML tree

Parameters
elemxml.etree.ElementTree.Element

An XML subtree that will be filled in with data values associated with this instance.

Returns
self

Notes

This method makes it possible to work with input data that may have additional contents not defined in the WWT specification – by modifying the existing tree, we can preserve those data.

classmethod from_file(path)[source]

Deserialize an instance of this class from an XML file on local disk.

Parameters
pathstring

The path of the XML file.

Returns
An instance of the class, initialized with data from the XML.
classmethod from_text(text)[source]

Deserialize an instance of this class from XML-formatted text.

Parameters
textstring

The XML text.

Returns
An instance of the class, initialized with data from the XML.
classmethod from_url(url)[source]

Deserialize an instance of this class from XML downloaded from the specified URL.

Parameters
urlstring

The URL from which to download the XML.

Returns
An instance of the class, initialized with data from the XML.
classmethod from_xml(elem)[source]

Deserialize an instance of this class from XML.

Parameters
elemxml.etree.ElementTree.Element

An XML element serializing the object.

Returns
An instance of the class, initialized with data from the XML.
to_xml()[source]

Serialize this object to XML.

Returns
elemxml.etree.ElementTree.Element

An XML element serializing the object.

to_xml_string(indent=True)[source]

Serialize this object to XML text.

Parameters
indentoptional bool, default True

Whether the returned XML text will have user-friendly indentation or not.

Returns
xml_textstring

A textual serialization of the object as XML.

write_xml(dest_stream, dest_wants_bytes=False, indent=True)[source]

Serialize this object to XML, writing the data to a stream.

Parameters
dest_streamwriteable file-like object or None

The destination to which the XML data will be written. If None, standard output is used.

dest_wants_bytesoptional bool, default False

Whether the destination stream expects to be fed bytes data rather than Unicode. If so, the XML text is encoded into UTF-8 before being written.

indentbool, default True

Whether the returned XML text will have user-friendly indentation or not.

Returns
None