/usr/lib/python2.7/dist-packages/html5_parser/stdlib_etree.py is in python-html5-parser 0.4.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: Apache 2.0 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
from __future__ import absolute_import, division, print_function, unicode_literals
import sys
from lxml.etree import _Comment
if sys.version_info.major < 3:
from xml.etree.cElementTree import Element, SubElement, ElementTree, Comment, register_namespace
else:
from xml.etree.ElementTree import Element, SubElement, ElementTree, Comment, register_namespace
register_namespace('svg', "http://www.w3.org/2000/svg")
register_namespace('xlink', "http://www.w3.org/1999/xlink")
def convert_elem(src, parent=None):
if parent is None:
ans = Element(src.tag, dict(src.items()))
else:
ans = SubElement(parent, src.tag, dict(src.items()))
return ans
def adapt(src_tree, return_root=True, **kw):
src_root = src_tree.getroot()
dest_root = convert_elem(src_root)
stack = [(src_root, dest_root)]
while stack:
src, dest = stack.pop()
for src_child in src.iterchildren():
if isinstance(src_child, _Comment):
dest_child = Comment(src_child.text)
dest_child.tail = src_child.tail
dest.append(dest_child)
else:
dest_child = convert_elem(src_child, dest)
dest_child.text, dest_child.tail = src_child.text, src_child.tail
stack.append((src_child, dest_child))
return dest_root if return_root else ElementTree(dest_root)
|