xdl.readwrite.xml_generator module

xdl.readwrite.xml_generator._add_step_property(step_tree: xml.etree.ElementTree.Element, step: xdl.steps.core.step.Step, prop: str, full_properties: bool = False, full_tree: bool = False) None[source]

Add given property to step tree of given step.

Parameters
  • step_tree (ET.Element) – Step tree to add property to.

  • step (Step) – Step corresponding to step_tree.

  • prop (str) – Property to add to step_tree.

  • full_properties (bool) – If True, all properties will be written. If False only mandatory, non default values and always write properties will be written.

  • full_tree (bool) – If True, full step tree will be written as is the case in xdlexe files. This applies to 'children' property.

xdl.readwrite.xml_generator._append_hardware_tree(xdltree: xml.etree.ElementTree.ElementTree, hardware: xdl.hardware.Hardware) None[source]

Create and add Hardware section to XDL tree.

Parameters
  • xdltree (ET.ElementTree) – Full XDL XML tree to add hardware to.

  • hardware (Hardware) – Hardware to add to XML tree.

xdl.readwrite.xml_generator._append_metadata(xdltree: xml.etree.ElementTree.ElementTree, metadata: xdl.metadata.Metadata) None[source]

Create and add Metadata section to XDL tree. Only add if Metadata has been used.

Parameters
  • xdltree (ET.ElementTree) – Full XDL XML tree to add hardware to.

  • metadata (Metadata) – Metadawta to add to XML tree.

xdl.readwrite.xml_generator._append_procedure_tree(xdltree: ET.ElementTree, xdl_obj: XDL, full_properties: bool = False, full_tree: bool = False) None[source]

Create and add Procedure section to XDL tree.

Parameters
  • xdltree (ET.ElementTree) – Full XDL XML tree to add steps to.

  • steps (List[Step]) – Steps to add to XML tree.

  • full_properties (bool) – If True, all properties will be written. If False only mandatory, non default values and always write properties will be written.

  • full_tree (bool) – If True, full step tree will be written as is the case in xdlexe files.

xdl.readwrite.xml_generator._append_reagents_tree(xdltree: ET.ElementTree, reagents: list[Reagent]) None[source]

Create and add Reagents section to XDL tree.

Parameters
  • xdltree (ET.ElementTree) – Full XDL XML tree to add reagents to.

  • reagents (List[Reagent]) – Reagents to add to XML tree.

xdl.readwrite.xml_generator._get_element_xdl_string(element: xml.etree.ElementTree.ElementTree, indent_level=0, indent='  ') str[source]

Return given Step, Reagent or Component XML tree as pretty printed XML string.

Parameters
  • element (ET.ElementTree) – Step, Reagent or Component XML tree to convert to string.

  • indent_level (int) – Defaults to 0. Used by this function to handle indendation during recursive calls.

  • indent (str) – Defaults to '  '. Indent to use for pretty printing XML string.

Returns

Pretty printed XML string of given XML tree.

Return type

str

xdl.readwrite.xml_generator._get_step_tree(step: xdl.steps.core.step.Step, full_properties: bool = False, full_tree: bool = False) xml.etree.ElementTree.Element[source]

Get XML tree associated with given step.

Parameters
  • step (Step) – Step to generate XML tree for.

  • full_properties (bool) – If True, all properties will be written. If False only mandatory, non default values and always write properties will be written.

  • full_tree (bool) – If True, full step tree will be written as is the case in xdlexe files.

xdl.readwrite.xml_generator._get_xdl_string(xdltree: xml.etree.ElementTree.ElementTree) str[source]

Convert XDL element tree to pretty XML string.

Parameters

xdltree (ET.ElementTree) – element tree of XDL

Returns

XML string

Return type

str

xdl.readwrite.xml_generator.get_xdl_tree(xdl_obj: XDL, full_properties: bool = False, full_tree: bool = False, graph_hash: str = None) ET.Element[source]

Get XDL element tree ready for saving as XML.

Parameters
  • xdl_obj (XDL) – XDL object to convert to XML tree.

  • full_properties (bool) – If True include all properties regardless of whether they are internal props or the same as the default props. Defaults to False.

  • full_tree (bool) – If True include all substeps, i.e. for a xdlexe file. Defaults to False.

  • graph_hash (str) – Hash of graph used to produce xdlexe for including in <Synthesis> tag.

Returns

XML tree of xdl_obj ready to save to XML file.

Return type

ET.ElementTree

xdl.readwrite.xml_generator.step_to_xml_string(step: xdl.steps.core.step.Step, full_properties: bool = False, full_tree: bool = False) str[source]

Get pretty printed XML string of given step.

Parameters
  • step (Step) – Step to get XDLEXE string for.

  • full_properties (bool) – If True, all properties will be written. If False only mandatory, non default values and always write properties will be written.

  • full_tree (bool) – If True, full step tree will be written as is the case in xdlexe files.

xdl.readwrite.xml_generator.xdl_to_xml_string(xdl_obj: XDL, full_properties: bool = False, full_tree: bool = False, graph_hash: str = None) str[source]

Convert given XDL object to XML string.

Parameters

xdl_obj (XDL) – XDL object to convert to XML string.

full_properties (bool): If ``True`, all properties will be written.

If False only mandatory, non default values and always write properties will be written.

full_tree (bool): If True, full step tree will be written as is the

case in xdlexe files.

graph_hash (str): Hash of graph to include in xdlexe files.

Returns

Pretty printed XML string of procedure.

Return type

str