#!/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 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)

@@ -642,16 +642,22 @@
 oot=True
+, **kw
 ):%0A    s

Allow adding kwargs to adapt in the future