diff options
author | Cole Robinson <crobinso@redhat.com> | 2016-08-24 15:55:08 -0400 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2016-08-24 15:56:13 -0400 |
commit | eb2a56f70069b5a6e5fd21720b9a632f94d8f426 (patch) | |
tree | b24acc0450e036a76879c08075eb9b5c874bf06d /virtinst/xmlbuilder.py | |
parent | 5dea1c2d8097d38ebb1161f11caa026fd638b851 (diff) | |
download | virt-manager-eb2a56f70069b5a6e5fd21720b9a632f94d8f426.tar.gz |
util: Move xml_indent to XMLBuilder
Diffstat (limited to 'virtinst/xmlbuilder.py')
-rw-r--r-- | virtinst/xmlbuilder.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/virtinst/xmlbuilder.py b/virtinst/xmlbuilder.py index 039662e6..5183b323 100644 --- a/virtinst/xmlbuilder.py +++ b/virtinst/xmlbuilder.py @@ -775,6 +775,20 @@ class XMLBuilder(object): # https://bugzilla.redhat.com/show_bug.cgi?id=1184131 _XML_SANITIZE = False + + @staticmethod + def xml_indent(xmlstr, level): + """ + Indent the passed str the specified number of spaces + """ + xml = "" + if not xmlstr: + return xml + if not level: + return xmlstr + return "\n".join((" " * level + l) for l in xmlstr.splitlines()) + + def __init__(self, conn, parsexml=None, parsexmlnode=None, parent_xpath=None, relative_object_xpath=None): """ @@ -1020,7 +1034,7 @@ class XMLBuilder(object): if not obj._xmlstate.is_build: use_xpath = obj.get_root_xpath().rsplit("/", 1)[0] indent = 2 * obj.get_root_xpath().count("/") - newnode = libxml2.parseDoc(util.xml_indent(xml, indent)).children + newnode = libxml2.parseDoc(self.xml_indent(xml, indent)).children parentnode = _build_xpath_node(self._xmlstate.xml_ctx, use_xpath) # Tack newnode on the end _add_pretty_child(parentnode, newnode) |