summaryrefslogtreecommitdiffstats
path: root/Doc/tools
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>1999-08-26 17:51:56 (GMT)
committerFred Drake <fdrake@acm.org>1999-08-26 17:51:56 (GMT)
commita20581c1e56faeb9b90f6d9e887d5fb92fe395be (patch)
tree03a90b992bf868d686cc41fb3c4d36927a3506f4 /Doc/tools
parent53eae8e81bfc72754f9be607203c558e0cedee90 (diff)
downloadcpython-a20581c1e56faeb9b90f6d9e887d5fb92fe395be.zip
cpython-a20581c1e56faeb9b90f6d9e887d5fb92fe395be.tar.gz
cpython-a20581c1e56faeb9b90f6d9e887d5fb92fe395be.tar.bz2
write_esis(): Added support for ENTITY_REFERENCE nodes.
Diffstat (limited to 'Doc/tools')
-rwxr-xr-xDoc/tools/sgmlconv/docfixer.py84
1 files changed, 44 insertions, 40 deletions
diff --git a/Doc/tools/sgmlconv/docfixer.py b/Doc/tools/sgmlconv/docfixer.py
index a56ac6e..21d3522 100755
--- a/Doc/tools/sgmlconv/docfixer.py
+++ b/Doc/tools/sgmlconv/docfixer.py
@@ -15,6 +15,7 @@ import xml.dom.core
from xml.dom.core import \
ELEMENT, \
+ ENTITY_REFERENCE, \
TEXT
@@ -74,7 +75,7 @@ xml.dom.core.Document.get_childNodes = get_childNodes
def get_first_element(doc, gi):
for n in doc.childNodes:
- if n.nodeName == gi:
+ if n.get_nodeName() == gi:
return n
def extract_first_element(doc, gi):
@@ -86,11 +87,11 @@ def extract_first_element(doc, gi):
def find_all_elements(doc, gi):
nodes = []
- if doc.nodeName == gi:
+ if doc.get_nodeName() == gi:
nodes.append(doc)
for child in doc.childNodes:
if child.nodeType == ELEMENT:
- if child.tagName == gi:
+ if child.get_tagName() == gi:
nodes.append(child)
for node in child.getElementsByTagName(gi):
nodes.append(node)
@@ -99,7 +100,7 @@ def find_all_elements(doc, gi):
def find_all_child_elements(doc, gi):
nodes = []
for child in doc.childNodes:
- if child.nodeName == gi:
+ if child.get_nodeName() == gi:
nodes.append(child)
return nodes
@@ -107,10 +108,10 @@ def find_all_elements_from_set(doc, gi_set):
return __find_all_elements_from_set(doc, gi_set, [])
def __find_all_elements_from_set(doc, gi_set, nodes):
- if doc.nodeName in gi_set:
+ if doc.get_nodeName() in gi_set:
nodes.append(doc)
for child in doc.childNodes:
- if child.nodeType == ELEMENT:
+ if child.get_nodeType() == ELEMENT:
__find_all_elements_from_set(child, gi_set, nodes)
return nodes
@@ -143,7 +144,7 @@ def simplify(doc, fragment):
docelem.insertBefore(text, docelem.firstChild)
docelem.insertBefore(node, text)
docelem.insertBefore(doc.createTextNode("\n"), docelem.firstChild)
- while fragment.firstChild and fragment.firstChild.nodeType == TEXT:
+ while fragment.firstChild and fragment.firstChild.get_nodeType() == TEXT:
fragment.removeChild(fragment.firstChild)
@@ -153,9 +154,9 @@ def cleanup_root_text(doc):
for n in doc.childNodes:
prevskip = skip
skip = 0
- if n.nodeType == TEXT and not prevskip:
+ if n.get_nodeType() == TEXT and not prevskip:
discards.append(n)
- elif n.nodeName == "COMMENT":
+ elif n.get_nodeName() == "COMMENT":
skip = 1
for node in discards:
doc.removeChild(node)
@@ -177,8 +178,8 @@ def fixup_descriptors(doc, fragment):
def find_and_fix_descriptors(doc, container):
children = container.childNodes
for child in children:
- if child.nodeType == ELEMENT:
- tagName = child.tagName
+ if child.get_nodeType() == ELEMENT:
+ tagName = child.get_tagName()
if tagName in DESCRIPTOR_ELEMENTS:
rewrite_descriptor(doc, child)
elif tagName == "subsection":
@@ -200,7 +201,7 @@ def rewrite_descriptor(doc, descriptor):
# 6. Put it back together.
#
# 1.
- descname = descriptor.tagName
+ descname = descriptor.get_tagName()
index = 1
if descname[-2:] == "ni":
descname = descname[:-2]
@@ -235,7 +236,7 @@ def rewrite_descriptor(doc, descriptor):
pos = skip_leading_nodes(children)
if pos < len(children):
child = children[pos]
- if child.nodeName == "args":
+ if child.get_nodeName() == "args":
## bwrite("found <args> in descriptor, moving to <signature>\n")
## ewrite(descriptor.toxml() + "\n---\n")
# create an <args> in <signature>:
@@ -251,8 +252,8 @@ def rewrite_descriptor(doc, descriptor):
# 3, 4.
pos = skip_leading_nodes(children, pos)
while pos < len(children) \
- and children[pos].nodeName in (linename, "versionadded"):
- if children[pos].tagName == linename:
+ and children[pos].get_nodeName() in (linename, "versionadded"):
+ if children[pos].get_tagName() == linename:
# this is really a supplemental signature, create <signature>
sig = methodline_to_signature(doc, children[pos])
newchildren.append(sig)
@@ -307,7 +308,7 @@ def move_children(origin, dest, start=0):
def handle_appendix(doc, fragment):
# must be called after simplfy() if document is multi-rooted to begin with
docelem = get_documentElement(fragment)
- toplevel = docelem.tagName == "manual" and "chapter" or "section"
+ toplevel = docelem.get_tagName() == "manual" and "chapter" or "section"
appendices = 0
nodes = []
for node in docelem.childNodes:
@@ -339,13 +340,14 @@ def handle_labels(doc, fragment):
if not id:
continue
parent = label.parentNode
- if parent.tagName == "title":
+ parentTagName = parent.get_tagName()
+ if parentTagName == "title":
parent.parentNode.setAttribute("id", id)
else:
parent.setAttribute("id", id)
# now, remove <label id="..."/> from parent:
parent.removeChild(label)
- if parent.tagName == "title":
+ if parentTagName == "title":
parent.normalize()
children = parent.childNodes
if children[-1].nodeType == TEXT:
@@ -357,8 +359,8 @@ def fixup_trailing_whitespace(doc, wsmap):
while queue:
node = queue[0]
del queue[0]
- if wsmap.has_key(node.nodeName):
- ws = wsmap[node.tagName]
+ if wsmap.has_key(node.get_nodeName()):
+ ws = wsmap[node.get_tagName()]
children = node.childNodes
children.reverse()
if children[0].nodeType == TEXT:
@@ -366,8 +368,8 @@ def fixup_trailing_whitespace(doc, wsmap):
children[0].data = data
children.reverse()
# hack to get the title in place:
- if node.tagName == "title" \
- and node.parentNode.firstChild.nodeType == ELEMENT:
+ if node.get_tagName() == "title" \
+ and node.parentNode.firstChild.get_nodeType() == ELEMENT:
node.parentNode.insertBefore(doc.createText("\n "),
node.parentNode.firstChild)
for child in node.childNodes:
@@ -393,7 +395,7 @@ def cleanup_trailing_parens(doc, element_names):
while queue:
node = queue[0]
del queue[0]
- if rewrite_element(node.tagName):
+ if rewrite_element(node.get_tagName()):
children = node.childNodes
if len(children) == 1 \
and children[0].nodeType == TEXT:
@@ -416,7 +418,7 @@ def contents_match(left, right):
if nodeType != r.nodeType:
return 0
if nodeType == ELEMENT:
- if l.tagName != r.tagName:
+ if l.get_tagName() != r.get_tagName():
return 0
# should check attributes, but that's not a problem here
if not contents_match(l, r):
@@ -447,7 +449,7 @@ def create_module_info(doc, section):
modauthor.getAttribute("name")))
modauthor.removeAttribute("name")
platform = extract_first_element(section, "platform")
- if section.tagName == "section":
+ if section.get_tagName() == "section":
modinfo_pos = 2
modinfo = doc.createElement("moduleinfo")
moddecl = extract_first_element(section, "declaremodule")
@@ -472,7 +474,7 @@ def create_module_info(doc, section):
if title:
children = title.childNodes
if len(children) >= 2 \
- and children[0].nodeName == "module" \
+ and children[0].get_nodeName() == "module" \
and children[0].childNodes[0].data == name:
# this is it; morph the <title> into <short-synopsis>
first_data = children[1]
@@ -516,7 +518,7 @@ def create_module_info(doc, section):
children = section.childNodes
for i in range(len(children)):
node = children[i]
- if node.nodeName == "moduleinfo":
+ if node.get_nodeName() == "moduleinfo":
nextnode = children[i+1]
if nextnode.nodeType == TEXT:
data = nextnode.data
@@ -549,7 +551,7 @@ def fixup_table(doc, table):
children = table.childNodes
for child in children:
if child.nodeType == ELEMENT:
- tagName = child.tagName
+ tagName = child.get_tagName()
if tagName == "hline" and prev_row is not None:
prev_row.setAttribute("rowsep", "1")
elif tagName == "row":
@@ -567,9 +569,9 @@ def fixup_table(doc, table):
table.removeChild(child)
continue
if nodeType == ELEMENT:
- if child.tagName != "hline":
+ if child.get_tagName() != "hline":
raise ConversionError(
- "unexpected <%s> in table" % child.tagName)
+ "unexpected <%s> in table" % child.get_tagName())
table.removeChild(child)
continue
raise ConversionError(
@@ -598,7 +600,7 @@ def fixup_row(doc, row):
def move_elements_by_name(doc, source, dest, name, sep=None):
nodes = []
for child in source.childNodes:
- if child.nodeName == name:
+ if child.get_nodeName() == name:
nodes.append(child)
for node in nodes:
source.removeChild(node)
@@ -638,7 +640,7 @@ PARA_LEVEL_PRECEEDERS = (
def fixup_paras(doc, fragment):
for child in fragment.childNodes:
- if child.nodeName in RECURSE_INTO_PARA_CONTAINERS:
+ if child.get_nodeName() in RECURSE_INTO_PARA_CONTAINERS:
fixup_paras_helper(doc, child)
descriptions = find_all_elements(fragment, "description")
for description in descriptions:
@@ -650,7 +652,7 @@ def fixup_paras_helper(doc, container, depth=0):
children = container.childNodes
start = skip_leading_nodes(children)
while len(children) > start:
- if children[start].nodeName in RECURSE_INTO_PARA_CONTAINERS:
+ if children[start].get_nodeName() in RECURSE_INTO_PARA_CONTAINERS:
# Something to recurse into:
fixup_paras_helper(doc, children[start])
else:
@@ -673,7 +675,7 @@ def build_para(doc, parent, start, i):
child = children[j]
nodeType = child.nodeType
if nodeType == ELEMENT:
- if child.tagName in BREAK_ELEMENTS:
+ if child.get_tagName() in BREAK_ELEMENTS:
after = j
break
elif nodeType == TEXT:
@@ -747,7 +749,7 @@ def skip_leading_nodes(children, start=0):
return start
# all whitespace, just skip
elif nodeType == ELEMENT:
- tagName = child.tagName
+ tagName = child.get_tagName()
if tagName in RECURSE_INTO_PARA_CONTAINERS:
return start
if tagName not in PARA_LEVEL_ELEMENTS + PARA_LEVEL_PRECEEDERS:
@@ -777,7 +779,7 @@ def fixup_signatures(doc, fragment):
def fixup_args(doc, arglist):
for child in arglist.childNodes:
- if child.nodeName == "optional":
+ if child.get_nodeName() == "optional":
# found it; fix and return
arglist.insertBefore(doc.createTextNode("["), child)
optkids = child.childNodes
@@ -800,7 +802,7 @@ def fixup_sectionauthors(doc, fragment):
sectauth.removeAttribute("name")
after = section.childNodes[2]
title = section.childNodes[1]
- if title.nodeName != "title":
+ if title.get_nodeName() != "title":
after = section.childNodes[0]
section.insertBefore(doc.createTextNode("\n "), after)
section.insertBefore(sectauth, after)
@@ -843,7 +845,7 @@ def fixup_refmodindexes(fragment):
def fixup_refmodindexes_chunk(container):
# node is probably a <para>; let's see how often it isn't:
- if container.tagName != PARA_ELEMENT:
+ if container.get_tagName() != PARA_ELEMENT:
bwrite("--- fixup_refmodindexes_chunk(%s)\n" % container)
module_entries = find_all_elements(container, "module")
if not module_entries:
@@ -854,7 +856,7 @@ def fixup_refmodindexes_chunk(container):
children = entry.childNodes
if len(children) != 0:
bwrite("--- unexpected number of children for %s node:\n"
- % entry.tagName)
+ % entry.get_tagName())
ewrite(entry.toxml() + "\n")
continue
found = 0
@@ -911,7 +913,7 @@ def write_esis(doc, ofp, knownempty):
for node in doc.childNodes:
nodeType = node.nodeType
if nodeType == ELEMENT:
- gi = node.tagName
+ gi = node.get_tagName()
if knownempty(gi):
if node.hasChildNodes():
raise ValueError, \
@@ -929,6 +931,8 @@ def write_esis(doc, ofp, knownempty):
ofp.write(")%s\n" % gi)
elif nodeType == TEXT:
ofp.write("-%s\n" % esistools.encode(node.data))
+ elif nodeType == ENTITY_REFERENCE:
+ ofp.write("&%s\n" % node.get_nodeName())
else:
raise RuntimeError, "unsupported node type: %s" % nodeType