diff options
author | Fred Drake <fdrake@acm.org> | 2001-09-29 05:05:25 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-09-29 05:05:25 (GMT) |
commit | 583061a10fad5445d8597fc5da56705e5bb21d11 (patch) | |
tree | 4b6021f56b4b7db4e4b90f3544eb4a669764d4ef /Doc/tools | |
parent | 2b05ca3454f5f9e34d9443b5b06df580285c2f61 (diff) | |
download | cpython-583061a10fad5445d8597fc5da56705e5bb21d11.zip cpython-583061a10fad5445d8597fc5da56705e5bb21d11.tar.gz cpython-583061a10fad5445d8597fc5da56705e5bb21d11.tar.bz2 |
Fix up whitespace in <args> elements; reduce sequences of consecutive
whitespace characters to a single space.
Small changes elsewhere, mostly to clean up the code a little.
Diffstat (limited to 'Doc/tools')
-rwxr-xr-x | Doc/tools/sgmlconv/docfixer.py | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/Doc/tools/sgmlconv/docfixer.py b/Doc/tools/sgmlconv/docfixer.py index 1760cf3..f2ad181 100755 --- a/Doc/tools/sgmlconv/docfixer.py +++ b/Doc/tools/sgmlconv/docfixer.py @@ -389,20 +389,16 @@ def cleanup_trailing_parens(doc, element_names): for gi in element_names: d[gi] = gi rewrite_element = d.has_key - queue = [] - for node in doc.childNodes: - if node.nodeType == ELEMENT: - queue.append(node) + queue = [node for node in doc.childNodes if node.nodeType == ELEMENT] while queue: node = queue[0] del queue[0] if rewrite_element(node.tagName): - children = node.childNodes - if len(children) == 1 \ - and children[0].nodeType == TEXT: - data = children[0].data - if data[-2:] == "()": - children[0].data = data[:-2] + lastchild = node.lastChild + if lastchild and lastchild.nodeType == TEXT: + data = lastchild.data + if data.endswith("()"): + lastchild.data = data[:-2] else: for child in node.childNodes: if child.nodeType == ELEMENT: @@ -773,13 +769,17 @@ def fixup_signatures(doc, fragment): if child.nodeType == ELEMENT: args = child.getElementsByTagName("args") for arg in args: - fixup_args(doc, arg) - arg.normalize() + rewrite_args(doc, arg) args = child.getElementsByTagName("constructor-args") for arg in args: - fixup_args(doc, arg) - arg.normalize() + rewrite_args(doc, arg) +def rewrite_args(doc, arglist): + fixup_args(doc, arglist) + arglist.normalize() + if arglist.childNodes.length == 1 and arglist.firstChild.nodeType == TEXT: + node = arglist.firstChild + node.data = ' '.join(node.data.split()) def fixup_args(doc, arglist): for child in arglist.childNodes: @@ -788,9 +788,7 @@ def fixup_args(doc, arglist): arglist.insertBefore(doc.createTextNode("["), child) optkids = child.childNodes while optkids: - k = optkids[0] - child.removeChild(k) - arglist.insertBefore(k, child) + arglist.insertBefore(child.firstChild, child) arglist.insertBefore(doc.createTextNode("]"), child) arglist.removeChild(child) return fixup_args(doc, arglist) |