diff --git a/sat/tools/xml_tools.py b/sat/tools/xml_tools.py index 69f9c6a5..57e6a94b 100644 --- a/sat/tools/xml_tools.py +++ b/sat/tools/xml_tools.py @@ -1812,3 +1812,27 @@ def findAll(elt, namespaces=None, names=None): yield child for found in findAll(child, namespaces, names): yield found + + +def pFmtElt(elt, indent=0): + """Pretty format a domish.Element""" + strings = [] + for child in elt.children: + if domish.IElement.providedBy(child): + strings.append(pFmtElt(child, indent+2)) + else: + strings.append(f"{(indent+2)*' '}{child!s}") + if elt.children: + nochild_elt = domish.Element( + (elt.uri, elt.name), elt.defaultUri, elt.attribs, elt.localPrefixes + ) + strings.insert(0, f"{indent*' '}{nochild_elt.toXml()[:-2]}>") + strings.append(f"{indent*' '}") + else: + strings.append(f"{indent*' '}{elt.toXml()}") + return '\n'.join(strings) + + +def ppElt(elt): + """Pretty print a domish.Element""" + print(pFmtElt(elt))