]> git.phdru.name Git - extfs.d.git/commitdiff
Minor refactoring
authorOleg Broytman <phd@phdru.name>
Thu, 21 Nov 2013 22:03:07 +0000 (02:03 +0400)
committerOleg Broytman <phd@phdru.name>
Thu, 21 Nov 2013 22:03:07 +0000 (02:03 +0400)
xml

diff --git a/xml b/xml
index e78e47e4bc20d13403eb85f7cf8b43591ec18fdf..71dc2b98ed95dc6b5976e934bb2d4702d4582ac7 100755 (executable)
--- a/xml
+++ b/xml
@@ -158,6 +158,15 @@ class XmlVfs(object):
                     len(text), subpath_encoded)
             self._list(element, subpath)
 
+    def get_tag_node(self, node, i):
+        n = 0
+        for element in self.getchildren(node):
+            if self.istag(element):
+                n += 1
+                if n == i:
+                    return element
+        xml_error('There are less than %d nodes' % i)
+
     def attrs2text(self, node):
         attr_accumulator = []
         for name, value in self.getattrs(node):
@@ -169,15 +178,6 @@ class XmlVfs(object):
     def has_ns(self, node):
         return False
 
-    def get_child_node(self, node, i):
-        n = 0
-        for element in self.getchildren(node):
-            if self.istag(element):
-                n += 1
-                if n == i:
-                    return element
-        xml_error('There are less than %d nodes' % i)
-
 
 class MiniDOMXmlVfs(XmlVfs):
     def parse(self):
@@ -293,6 +293,12 @@ if use_lxml:
         def parse(self):
             self.document = etree.parse(sys.argv[2])
 
+        def getroot(self):
+            return [self.document.getroot()]
+
+        def getlocalname(self, name):
+            return etree.QName(name).localname
+
         def has_ns(self, node):
             return bool(node.nsmap)
 
@@ -304,12 +310,6 @@ if use_lxml:
                 ns_accumulator.append("%s=%s" % (name, value))
             return '\n'.join(ns_accumulator)
 
-        def getroot(self):
-            return [self.document.getroot()]
-
-        def getlocalname(self, name):
-            return etree.QName(name).localname
-
 
 def build_xmlvfs():
     if force_implementation is None:
@@ -347,7 +347,7 @@ def mcxml_copyout():
     for path_comp in xml_filename.split('/'):
         if ' ' in path_comp:
             i = int(path_comp.split(' ', 1)[0])
-            node = xmlvfs.get_child_node(node, i)
+            node = xmlvfs.get_tag_node(node, i)
         elif path_comp in ('attributes', 'namespaces', 'text'):
             break
         else: