tools (xml_tools): added with_parent and with_children argument to elementCopy
This commit is contained in:
parent
4e803712f7
commit
54494409d2
1 changed files with 10 additions and 4 deletions
|
|
@ -1676,22 +1676,28 @@ def deferConfirm(*args, **kwargs):
|
|||
|
||||
# Misc other funtions
|
||||
|
||||
def elementCopy(element):
|
||||
def elementCopy(
|
||||
element: domish.Element,
|
||||
with_parent: bool = True,
|
||||
with_children: bool = True
|
||||
) -> domish.Element:
|
||||
"""Make a copy of a domish.Element
|
||||
|
||||
The copy will have its own children list, so other elements
|
||||
can be added as direct children without modifying orignal one.
|
||||
Children are not deeply copied, so if an element is added to a child or grandchild,
|
||||
it will also affect original element.
|
||||
@param element(domish.Element): Element to clone
|
||||
@param element: Element to clone
|
||||
"""
|
||||
new_elt = domish.Element(
|
||||
(element.uri, element.name),
|
||||
defaultUri = element.defaultUri,
|
||||
attribs = element.attributes,
|
||||
localPrefixes = element.localPrefixes)
|
||||
new_elt.parent = element.parent
|
||||
new_elt.children = element.children[:]
|
||||
if with_parent:
|
||||
new_elt.parent = element.parent
|
||||
if with_children:
|
||||
new_elt.children = element.children[:]
|
||||
return new_elt
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue