Mercurial > libervia-backend
changeset 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 | c86e60ac70c3 |
children | 27d9d25ec3cd |
files | sat/tools/xml_tools.py |
diffstat | 1 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/sat/tools/xml_tools.py Thu Feb 28 18:56:48 2019 +0100 +++ b/sat/tools/xml_tools.py Thu Feb 28 18:57:00 2019 +0100 @@ -1664,6 +1664,25 @@ # Misc other funtions +def elementCopy(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 + """ + 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[:] + return new_elt + + def isXHTMLField(field): """Check if a data_form.Field is an XHTML one""" return (field.fieldType is None and field.ext_type == u"xml" and