removeNamespacedElements: Avoid calling it twice as it is indempotent
Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
parent
29a7474f74
commit
045f1f0ad5
1 changed files with 3 additions and 5 deletions
|
|
@ -975,7 +975,6 @@ def removeNamespacedAttributes(node, namespaces):
|
||||||
|
|
||||||
|
|
||||||
def removeNamespacedElements(node, namespaces):
|
def removeNamespacedElements(node, namespaces):
|
||||||
global _num_elements_removed
|
|
||||||
num = 0
|
num = 0
|
||||||
if node.nodeType == Node.ELEMENT_NODE:
|
if node.nodeType == Node.ELEMENT_NODE:
|
||||||
# remove all namespace'd child nodes from this element
|
# remove all namespace'd child nodes from this element
|
||||||
|
|
@ -985,9 +984,8 @@ def removeNamespacedElements(node, namespaces):
|
||||||
if child is not None and child.namespaceURI in namespaces:
|
if child is not None and child.namespaceURI in namespaces:
|
||||||
childrenToRemove.append(child)
|
childrenToRemove.append(child)
|
||||||
for child in childrenToRemove:
|
for child in childrenToRemove:
|
||||||
num += 1
|
|
||||||
_num_elements_removed += 1
|
|
||||||
node.removeChild(child)
|
node.removeChild(child)
|
||||||
|
num += len(childrenToRemove)
|
||||||
|
|
||||||
# now recurse for children
|
# now recurse for children
|
||||||
for child in node.childNodes:
|
for child in node.childNodes:
|
||||||
|
|
@ -3652,8 +3650,8 @@ def scourString(in_string, options=None):
|
||||||
# on the first pass, so we do it multiple times
|
# on the first pass, so we do it multiple times
|
||||||
# does it have to do with removal of children affecting the childlist?
|
# does it have to do with removal of children affecting the childlist?
|
||||||
if options.keep_editor_data is False:
|
if options.keep_editor_data is False:
|
||||||
while removeNamespacedElements(doc.documentElement, unwanted_ns) > 0:
|
_num_elements_removed += removeNamespacedElements(doc.documentElement,
|
||||||
pass
|
unwanted_ns)
|
||||||
_num_attributes_removed += removeNamespacedAttributes(doc.documentElement,
|
_num_attributes_removed += removeNamespacedAttributes(doc.documentElement,
|
||||||
unwanted_ns)
|
unwanted_ns)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue