From 29a7474f746b2807058385ca6a6d9cf33812f4b2 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Tue, 19 May 2020 21:56:15 +0000 Subject: [PATCH] removeNamespacedAttributes: Avoid calling it twice as it is indempotent Signed-off-by: Niels Thykier --- scour/scour.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scour/scour.py b/scour/scour.py index 78ae200..6bb1b8f 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -955,7 +955,6 @@ def removeUnreferencedIDs(referencedIDs, identifiedElements): def removeNamespacedAttributes(node, namespaces): - global _num_attributes_removed num = 0 if node.nodeType == Node.ELEMENT_NODE: # remove all namespace'd attributes from this element @@ -966,9 +965,8 @@ def removeNamespacedAttributes(node, namespaces): if attr is not None and attr.namespaceURI in namespaces: attrsToRemove.append(attr.nodeName) for attrName in attrsToRemove: - num += 1 - _num_attributes_removed += 1 node.removeAttribute(attrName) + num += len(attrsToRemove) # now recurse for children for child in node.childNodes: @@ -3656,8 +3654,8 @@ def scourString(in_string, options=None): if options.keep_editor_data is False: while removeNamespacedElements(doc.documentElement, unwanted_ns) > 0: pass - while removeNamespacedAttributes(doc.documentElement, unwanted_ns) > 0: - pass + _num_attributes_removed += removeNamespacedAttributes(doc.documentElement, + unwanted_ns) # remove the xmlns: declarations now xmlnsDeclsToRemove = []