Commit 0f58fc15 authored by Guido van Rossum's avatar Guido van Rossum

Remove code for working with DOM trees.

Move quote() function here from TALInterpreter.
parent 4db70e76
...@@ -156,54 +156,11 @@ def splitParts(arg): ...@@ -156,54 +156,11 @@ def splitParts(arg):
del parts[-1] # It ended in a semicolon del parts[-1] # It ended in a semicolon
return parts return parts
import cgi
def macroIndexer(document): _cgi = cgi
""" del cgi
Return a dictionary containing all define-macro nodes in a document. def quote(s):
if '"' in s and "'" not in s:
The dictionary will have the form {macroName: node, ...}. return "'%s'" % _cgi.escape(s)
""" else:
macroIndex = {} return '"%s"' % _cgi.escape(s, 1)
_macroVisitor(document.documentElement, macroIndex)
return macroIndex
from xml.dom import Node
def _macroVisitor(node, macroIndex, __elementNodeType=Node.ELEMENT_NODE):
# Internal routine to efficiently recurse down the tree of elements
macroName = node.getAttributeNS(ZOPE_METAL_NS, "define-macro")
if macroName:
if macroIndex.has_key(macroName):
print ("Duplicate macro definition: %s in <%s>" %
(macroName, node.nodeName))
else:
macroIndex[macroName] = node
for child in node.childNodes:
if child.nodeType == __elementNodeType:
_macroVisitor(child, macroIndex)
def slotIndexer(rootNode):
"""
Return a dictionary containing all fill-slot nodes in a subtree.
The dictionary will have the form {slotName: node, ...}.
"""
slotIndex = {}
_slotVisitor(rootNode, slotIndex)
return slotIndex
def _slotVisitor(node, slotIndex, __elementNodeType=Node.ELEMENT_NODE):
# Internal routine to efficiently recurse down the tree of elements
slotName = node.getAttributeNS(ZOPE_METAL_NS, "fill-slot")
if slotName:
if slotIndex.has_key(slotName):
print ("Duplicate slot definition: %s in <%s>" %
(slotName, node.nodeName))
else:
slotIndex[slotName] = node
for child in node.childNodes:
if child.nodeType == __elementNodeType:
_slotVisitor(child, slotIndex)
del Node
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