Commit 583061a1 authored by Fred Drake's avatar Fred Drake

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.
parent 2b05ca34
...@@ -389,20 +389,16 @@ def cleanup_trailing_parens(doc, element_names): ...@@ -389,20 +389,16 @@ def cleanup_trailing_parens(doc, element_names):
for gi in element_names: for gi in element_names:
d[gi] = gi d[gi] = gi
rewrite_element = d.has_key rewrite_element = d.has_key
queue = [] queue = [node for node in doc.childNodes if node.nodeType == ELEMENT]
for node in doc.childNodes:
if node.nodeType == ELEMENT:
queue.append(node)
while queue: while queue:
node = queue[0] node = queue[0]
del queue[0] del queue[0]
if rewrite_element(node.tagName): if rewrite_element(node.tagName):
children = node.childNodes lastchild = node.lastChild
if len(children) == 1 \ if lastchild and lastchild.nodeType == TEXT:
and children[0].nodeType == TEXT: data = lastchild.data
data = children[0].data if data.endswith("()"):
if data[-2:] == "()": lastchild.data = data[:-2]
children[0].data = data[:-2]
else: else:
for child in node.childNodes: for child in node.childNodes:
if child.nodeType == ELEMENT: if child.nodeType == ELEMENT:
...@@ -773,13 +769,17 @@ def fixup_signatures(doc, fragment): ...@@ -773,13 +769,17 @@ def fixup_signatures(doc, fragment):
if child.nodeType == ELEMENT: if child.nodeType == ELEMENT:
args = child.getElementsByTagName("args") args = child.getElementsByTagName("args")
for arg in args: for arg in args:
fixup_args(doc, arg) rewrite_args(doc, arg)
arg.normalize()
args = child.getElementsByTagName("constructor-args") args = child.getElementsByTagName("constructor-args")
for arg in args: for arg in args:
fixup_args(doc, arg) rewrite_args(doc, arg)
arg.normalize()
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): def fixup_args(doc, arglist):
for child in arglist.childNodes: for child in arglist.childNodes:
...@@ -788,9 +788,7 @@ def fixup_args(doc, arglist): ...@@ -788,9 +788,7 @@ def fixup_args(doc, arglist):
arglist.insertBefore(doc.createTextNode("["), child) arglist.insertBefore(doc.createTextNode("["), child)
optkids = child.childNodes optkids = child.childNodes
while optkids: while optkids:
k = optkids[0] arglist.insertBefore(child.firstChild, child)
child.removeChild(k)
arglist.insertBefore(k, child)
arglist.insertBefore(doc.createTextNode("]"), child) arglist.insertBefore(doc.createTextNode("]"), child)
arglist.removeChild(child) arglist.removeChild(child)
return fixup_args(doc, arglist) return fixup_args(doc, arglist)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment