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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxx>
Reviewed-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx>
---
 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

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list



[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux