From fef2786c5ebe4b6d40980dbb66dd7142a75f2664 Mon Sep 17 00:00:00 2001 From: Michael Witten Date: Thu, 24 Aug 2017 18:41:04 +0000 Subject: [PATCH] scour.py: minor rearrangement for the sake of clarity There has been a minor rearrangement of the code that handles the children of the element being serialized: The relevant `if' statement has had its condition effectively negated and thus has also had its consequent and alternative swapped; now, there is a very short consequent, followed by a very long alternative, rather than a very long consequent followed by a very short alternative. --- scour/scour.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scour/scour.py b/scour/scour.py index fe468f0..4a13125 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -3282,9 +3282,12 @@ def serializeXML(element, options, ind=0, preserveWhitespace=False): elif attrValue == 'default': preserveWhitespace = False - # if no children, self-close children = element.childNodes - if children.length > 0: + if children.length == 0: + outParts.append('/>') + if indent > 0: + outParts.append(newline) + else: outParts.append('>') onNewLine = False @@ -3319,10 +3322,6 @@ def serializeXML(element, options, ind=0, preserveWhitespace=False): outParts.extend(['']) if indent > 0: outParts.append(newline) - else: - outParts.append('/>') - if indent > 0: - outParts.append(newline) return "".join(outParts)