[virt-tools-list] [PATCH virt-manager 01/14] xmlapi: refactor node_is_text function

Marc Hartmayer mhartmay at linux.ibm.com
Tue Dec 18 13:44:50 UTC 2018


...since it's used at least at three places.

Signed-off-by: Marc Hartmayer <mhartmay at linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy at linux.ibm.com>
---
 virtinst/xmlapi.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/virtinst/xmlapi.py b/virtinst/xmlapi.py
index 1b0452c3f097..00b551468d03 100644
--- a/virtinst/xmlapi.py
+++ b/virtinst/xmlapi.py
@@ -248,6 +248,10 @@ class _XMLBase(object):
             self._node_remove_child(parent, child)
 
 
+def node_is_text(n):
+    return bool(n and n.type == "text")
+
+
 class _Libxml2API(_XMLBase):
     def __init__(self, xml):
         _XMLBase.__init__(self)
@@ -343,20 +347,17 @@ class _Libxml2API(_XMLBase):
 
         # Look for preceding whitespace and remove it
         white = node.get_prev()
-        if white and white.type == "text":
+        if node_is_text(white):
             white.unlinkNode()
             white.freeNode()
 
         node.unlinkNode()
         node.freeNode()
-        if all([n.type == "text" for n in parentnode.children]):
+        if all([node_is_text(n) for n in parentnode.children]):
             parentnode.setContent(None)
 
     def _node_add_child(self, parentxpath, parentnode, newnode):
         ignore = parentxpath
-        def node_is_text(n):
-            return bool(n and n.type == "text")
-
         if not node_is_text(parentnode.get_last()):
             prevsib = parentnode.get_prev()
             if node_is_text(prevsib):
-- 
2.17.0




More information about the virt-tools-list mailing list