From e65c1516d616e7dcfaf9a1b984961e01a2aef16d Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Fri, 22 Nov 2013 02:03:07 +0400 Subject: [PATCH] Minor refactoring --- xml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/xml b/xml index e78e47e..71dc2b9 100755 --- 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: -- 2.39.5