Mercurial > libervia-backend
comparison sat/tools/xml_tools.py @ 2814:777a582d9641
core (xml_tools): new elementCopy method to shallow copy a domish.Element
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 28 Feb 2019 18:57:00 +0100 |
parents | b17e6fa1e607 |
children | 48985ef7682f |
comparison
equal
deleted
inserted
replaced
2813:c86e60ac70c3 | 2814:777a582d9641 |
---|---|
1662 return d | 1662 return d |
1663 | 1663 |
1664 | 1664 |
1665 # Misc other funtions | 1665 # Misc other funtions |
1666 | 1666 |
1667 def elementCopy(element): | |
1668 """Make a copy of a domish.Element | |
1669 | |
1670 The copy will have its own children list, so other elements | |
1671 can be added as direct children without modifying orignal one. | |
1672 Children are not deeply copied, so if an element is added to a child or grandchild, | |
1673 it will also affect original element. | |
1674 @param element(domish.Element): Element to clone | |
1675 """ | |
1676 new_elt = domish.Element( | |
1677 (element.uri, element.name), | |
1678 defaultUri = element.defaultUri, | |
1679 attribs = element.attributes, | |
1680 localPrefixes = element.localPrefixes) | |
1681 new_elt.parent = element.parent | |
1682 new_elt.children = element.children[:] | |
1683 return new_elt | |
1684 | |
1685 | |
1667 def isXHTMLField(field): | 1686 def isXHTMLField(field): |
1668 """Check if a data_form.Field is an XHTML one""" | 1687 """Check if a data_form.Field is an XHTML one""" |
1669 return (field.fieldType is None and field.ext_type == u"xml" and | 1688 return (field.fieldType is None and field.ext_type == u"xml" and |
1670 field.value.uri == C.NS_XHTML) | 1689 field.value.uri == C.NS_XHTML) |
1671 | 1690 |