]> granicus.if.org Git - python/commitdiff
Make <rfc> no longer an empty element but a container. The text
authorFred Drake <fdrake@acm.org>
Thu, 14 Jan 1999 21:18:03 +0000 (21:18 +0000)
committerFred Drake <fdrake@acm.org>
Thu, 14 Jan 1999 21:18:03 +0000 (21:18 +0000)
currently generated by the LaTeX and LaTeX2HTML processes is generated
here as well, making it more flexible in the SGML version.

Reduce the <args> element so that <optional> goes away; just use
square brackets to indicate what's optional.  This makes it easier to
read than the LaTeX, and the processor can do any checking it needs to
in order to make sure it's legit.  Possible shortcoming: DSSSL
processors may need more explicit markup.  Can probably hack around it
for this case, but we'll see.

Doc/tools/sgmlconv/docfixer.py

index 28cef8380f422c0caa7ccb4e1b736ad993e2ba04..d8434909a2a26eb15c96919edff08e0a3570774b 100755 (executable)
@@ -578,6 +578,46 @@ def skip_leading_nodes(children, start, i):
     return start, i
 
 
+def fixup_rfc_references(doc):
+    rfc_nodes = []
+    for child in doc.childNodes:
+        if child.nodeType == xml.dom.core.ELEMENT:
+            kids = child.getElementsByTagName("rfc")
+            for k in kids:
+                rfc_nodes.append(k)
+    for rfc_node in rfc_nodes:
+        rfc_node.appendChild(doc.createTextNode(
+            "RFC " + rfc_node.getAttribute("num")))
+
+
+def fixup_signatures(doc):
+    for child in doc.childNodes:
+        if child.nodeType == xml.dom.core.ELEMENT:
+            args = child.getElementsByTagName("args")
+            for arg in args:
+                fixup_args(doc, arg)
+            args = child.getElementsByTagName("constructor-args")
+            for arg in args:
+                fixup_args(doc, arg)
+                arg.normalize()
+
+
+def fixup_args(doc, arglist):
+    for child in arglist.childNodes:
+        if child.nodeType == xml.dom.core.ELEMENT \
+           and child.tagName == "optional":
+            # found it; fix and return
+            arglist.insertBefore(doc.createTextNode("["), child)
+            optkids = child.childNodes
+            while optkids:
+                k = optkids[0]
+                child.removeChild(k)
+                arglist.insertBefore(k, child)
+            arglist.insertBefore(doc.createTextNode("]"), child)
+            arglist.removeChild(child)
+            return fixup_args(doc, arglist)
+
+
 _token_rx = re.compile(r"[a-zA-Z][a-zA-Z0-9.-]*$")
 
 def write_esis(doc, ofp, knownempty):
@@ -638,10 +678,14 @@ def convert(ifp, ofp):
         "lineiv": ("row", {}),
         })
     fixup_table_structures(doc)
+    fixup_rfc_references(doc)
+    fixup_signatures(doc)
     #
     d = {}
     for gi in p.get_empties():
         d[gi] = gi
+    if d.has_key("rfc"):
+        del d["rfc"]
     knownempty = d.has_key
     #
     try: