Mercurial > libervia-backend
comparison sat/tools/xml_tools.py @ 3395:d6a482a78bda
tools (xml_tools): added `with_parent` and `with_children` argument to `elementCopy`
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 12 Nov 2020 14:53:15 +0100 |
parents | 2b6f69f6df8c |
children | a4774f5b6b17 |
comparison
equal
deleted
inserted
replaced
3394:23af257ae780 | 3395:d6a482a78bda |
---|---|
1674 return d | 1674 return d |
1675 | 1675 |
1676 | 1676 |
1677 # Misc other funtions | 1677 # Misc other funtions |
1678 | 1678 |
1679 def elementCopy(element): | 1679 def elementCopy( |
1680 element: domish.Element, | |
1681 with_parent: bool = True, | |
1682 with_children: bool = True | |
1683 ) -> domish.Element: | |
1680 """Make a copy of a domish.Element | 1684 """Make a copy of a domish.Element |
1681 | 1685 |
1682 The copy will have its own children list, so other elements | 1686 The copy will have its own children list, so other elements |
1683 can be added as direct children without modifying orignal one. | 1687 can be added as direct children without modifying orignal one. |
1684 Children are not deeply copied, so if an element is added to a child or grandchild, | 1688 Children are not deeply copied, so if an element is added to a child or grandchild, |
1685 it will also affect original element. | 1689 it will also affect original element. |
1686 @param element(domish.Element): Element to clone | 1690 @param element: Element to clone |
1687 """ | 1691 """ |
1688 new_elt = domish.Element( | 1692 new_elt = domish.Element( |
1689 (element.uri, element.name), | 1693 (element.uri, element.name), |
1690 defaultUri = element.defaultUri, | 1694 defaultUri = element.defaultUri, |
1691 attribs = element.attributes, | 1695 attribs = element.attributes, |
1692 localPrefixes = element.localPrefixes) | 1696 localPrefixes = element.localPrefixes) |
1693 new_elt.parent = element.parent | 1697 if with_parent: |
1694 new_elt.children = element.children[:] | 1698 new_elt.parent = element.parent |
1699 if with_children: | |
1700 new_elt.children = element.children[:] | |
1695 return new_elt | 1701 return new_elt |
1696 | 1702 |
1697 | 1703 |
1698 def isXHTMLField(field): | 1704 def isXHTMLField(field): |
1699 """Check if a data_form.Field is an XHTML one""" | 1705 """Check if a data_form.Field is an XHTML one""" |