How to use the xiblint.xmlutils._TreeBuilder function in xiblint

To help you get started, we’ve selected a few xiblint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lyft / xiblint / xiblint / xmlutils.py View on Github external
def parse_xml(file_path):
    builder = _TreeBuilder()
    parser = DefusedXMLParser(target=builder, forbid_dtd=False, forbid_entities=True, forbid_external=True)
    builder.parser = weakref.proxy(parser)
    tree = ElementTree.parse(file_path, parser=parser)

    # ElementTree does not implement parent attributes: add parent property to every element
    parent_map = {child: parent
                  for parent in tree.getiterator()
                  for child in parent}
    for p in tree.getiterator():
        p.parent = parent_map.get(p)

    return tree
github lyft / xiblint / xiblint / xmlutils.py View on Github external
def start(self, tag, attrs):
        elem = super(_TreeBuilder, self).start(tag, attrs)
        elem.line = self.parser.parser.CurrentLineNumber
        elem.column = self.parser.parser.CurrentLineNumber
        return elem