<commit_before>#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: Apache 2.0 Copyright: 2017, <NAME> <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 adapt(src_tree, return_root=True):
    src_root = src_tree.getroot()
    dest_root = Element(src_root.tag, dict(src_root.items()))
    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 = SubElement(dest, src_child.tag, dict(src_child.items()))
                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)<commit_msg>Allow adding kwargs to adapt in the future<commit_after>#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: Apache 2.0 Copyright: 2017, <NAME> <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 adapt(src_tree, return_root=True, **kw):
    src_root = src_tree.getroot()
    dest_root = Element(src_root.tag, dict(src_root.items()))
    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 = SubElement(dest, src_child.tag, dict(src_child.items()))
                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)
{'fraction_non_alphanumeric': 0.10528181495923432, 'fraction_numerical': 0.012761432116270826, 'mean_word_length': 3.3751937984496125, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4018906', 'n_tokens_mistral': 909, 'n_tokens_neox': 862, 'n_words': 195}