Mercurial > libervia-backend
comparison sat/tools/xml_tools.py @ 3466:80f8635dc66e
tools (xml_tools): fix pFmtElt:
default URI was not handled correctly, and attributes were missing, this patch fixes
those bugs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 19 Feb 2021 15:53:25 +0100 |
parents | 987198910e56 |
children | e12e9e1535d3 |
comparison
equal
deleted
inserted
replaced
3465:1c7f4ce6a4a2 | 3466:80f8635dc66e |
---|---|
1816 yield child | 1816 yield child |
1817 for found in findAll(child, namespaces, names): | 1817 for found in findAll(child, namespaces, names): |
1818 yield found | 1818 yield found |
1819 | 1819 |
1820 | 1820 |
1821 def pFmtElt(elt, indent=0): | 1821 def pFmtElt(elt, indent=0, defaultUri=""): |
1822 """Pretty format a domish.Element""" | 1822 """Pretty format a domish.Element""" |
1823 strings = [] | 1823 strings = [] |
1824 for child in elt.children: | 1824 for child in elt.children: |
1825 if domish.IElement.providedBy(child): | 1825 if domish.IElement.providedBy(child): |
1826 strings.append(pFmtElt(child, indent+2)) | 1826 strings.append(pFmtElt(child, indent+2, defaultUri=elt.defaultUri)) |
1827 else: | 1827 else: |
1828 strings.append(f"{(indent+2)*' '}{child!s}") | 1828 strings.append(f"{(indent+2)*' '}{child!s}") |
1829 if elt.children: | 1829 if elt.children: |
1830 nochild_elt = domish.Element( | 1830 nochild_elt = domish.Element( |
1831 (elt.uri, elt.name), elt.defaultUri, elt.attribs, elt.localPrefixes | 1831 (elt.uri, elt.name), elt.defaultUri, elt.attributes, elt.localPrefixes |
1832 ) | 1832 ) |
1833 strings.insert(0, f"{indent*' '}{nochild_elt.toXml()[:-2]}>") | 1833 strings.insert(0, f"{indent*' '}{nochild_elt.toXml(defaultUri=defaultUri)[:-2]}>") |
1834 strings.append(f"{indent*' '}</{nochild_elt.name}>") | 1834 strings.append(f"{indent*' '}</{nochild_elt.name}>") |
1835 else: | 1835 else: |
1836 strings.append(f"{indent*' '}{elt.toXml()}") | 1836 strings.append(f"{indent*' '}{elt.toXml(defaultUri=defaultUri)}") |
1837 return '\n'.join(strings) | 1837 return '\n'.join(strings) |
1838 | 1838 |
1839 | 1839 |
1840 def ppElt(elt): | 1840 def ppElt(elt): |
1841 """Pretty print a domish.Element""" | 1841 """Pretty print a domish.Element""" |