예제 #1
0
파일: tree.py 프로젝트: galaxysd/BitTorrent
def getFirstAncestorWithSectionHeader(entry):
    """Go up ancestors until one with at least one <h2> is found, then return the <h2> nodes"""
    for a in domhelpers.getParents(entry)[1:]:
        headers = domhelpers.findNodesNamed(a, "h2")
        if len(headers) > 0:
            return headers
    return []
예제 #2
0
 def test_getParents(self):
     doc1=microdom.parseString('<a><b><c><d/></c><e/></b><f/></a>')
     node_list=domhelpers.getParents(doc1.childNodes[0].childNodes[0].childNodes[0])
     actual=''.join([node.tagName for node in node_list
                     if hasattr(node, 'tagName')])
     expected='cba'
     assert actual==expected, 'expected %s, got %s' % (expected, actual)
예제 #3
0
 def test_getParents(self):
     doc1 = self.dom.parseString('<a><b><c><d/></c><e/></b><f/></a>')
     node_list = domhelpers.getParents(
         doc1.childNodes[0].childNodes[0].childNodes[0])
     actual = ''.join(
         [node.tagName for node in node_list if hasattr(node, 'tagName')])
     self.assertEqual(actual, 'cba')
예제 #4
0
 def test_getParents(self):
     doc1 = self.dom.parseString('<a><b><c><d/></c><e/></b><f/></a>')
     node_list = domhelpers.getParents(
         doc1.childNodes[0].childNodes[0].childNodes[0])
     actual = ''.join([node.tagName for node in node_list
                       if hasattr(node, 'tagName')])
     self.assertEqual(actual, 'cba')
예제 #5
0
파일: book.py 프로젝트: fxia22/ASM_xf
def makeBook(dom, d):
    body = microdom.Element('body')
    body.appendChild(domhelpers.findNodesNamed(dom, 'h1')[0])
    toc = domhelpers.findElementsWithAttribute(dom, 'class', 'toc')[0]
    toc = domhelpers.findNodesNamed(toc, 'li')
    for node in toc:
        if (node.hasAttribute('class') and
            node.getAttribute('class')=='tocignore'):
             continue
        parents = domhelpers.getParents(node)
        nodeLevel = len([1 for parent in parents if hasattr(parent, 'tagName')
                                           and parent.tagName in ('ol', 'ul')])
        data = node.childNodes[0].data != ''
        if not data:
            node = node.childNodes[1]
            newNode = lowerDocument(node.getAttribute('href'), d, nodeLevel)
            for child in newNode.childNodes:
                body.appendChild(child)
        else:
            text = microdom.Text(node.childNodes[0].data)
            newNode = microdom.Element('h'+str(nodeLevel))
            newNode.appendChild(text)
            body.appendChild(newNode)
    origBody = domhelpers.findNodesNamed(dom, 'body')[0]
    origBody.parentNode.replaceChild(body, origBody)
예제 #6
0
 def test_getParents(self):
     doc1 = microdom.parseString('<a><b><c><d/></c><e/></b><f/></a>')
     node_list = domhelpers.getParents(
         doc1.childNodes[0].childNodes[0].childNodes[0])
     actual = ''.join(
         [node.tagName for node in node_list if hasattr(node, 'tagName')])
     expected = 'cba'
     assert actual == expected, 'expected %s, got %s' % (expected, actual)
예제 #7
0
파일: texi.py 프로젝트: Almad/twisted
 def visitNode_title(self, node):
     self.writer('@node ')
     self.visitNodeDefault(node)
     self.writer('\n')
     self.writer('@section ')
     self.visitNodeDefault(node)
     self.writer('\n')
     headers = tree.getHeaders(domhelpers.getParents(node)[-1])
     if not headers:
         return
     self.writer('@menu\n')
     for header in headers:
         self.writer('* %s::\n' % domhelpers.getNodeText(header))
     self.writer('@end menu\n')
예제 #8
0
 def visitNode_title(self, node):
     self.writer('@node ')
     self.visitNodeDefault(node)
     self.writer('\n')
     self.writer('@section ')
     self.visitNodeDefault(node)
     self.writer('\n')
     headers = tree.getHeaders(domhelpers.getParents(node)[-1])
     if not headers:
         return
     self.writer('@menu\n')
     for header in headers:
         self.writer('* %s::\n' % domhelpers.getNodeText(header))
     self.writer('@end menu\n')
예제 #9
0
def getFirstAncestorWithSectionHeader(entry):
    """
    Visit the ancestors of C{entry} until one with at least one C{h2} child
    node is found, then return all of that node's C{h2} child nodes.

    @type entry: A DOM Node
    @param entry: The node from which to begin traversal.  This node itself is
    excluded from consideration.

    @rtype: C{list} of DOM Nodes
    @return: All C{h2} nodes of the ultimately selected parent node.
    """
    for a in domhelpers.getParents(entry)[1:]:
        headers = domhelpers.findNodesNamed(a, "h2")
        if len(headers) > 0:
            return headers
    return []
예제 #10
0
def getFirstAncestorWithSectionHeader(entry):
    """
    Visit the ancestors of C{entry} until one with at least one C{h2} child
    node is found, then return all of that node's C{h2} child nodes.

    @type entry: A DOM Node
    @param entry: The node from which to begin traversal.  This node itself is
    excluded from consideration.

    @rtype: C{list} of DOM Nodes
    @return: All C{h2} nodes of the ultimately selected parent node.
    """
    for a in domhelpers.getParents(entry)[1:]:
        headers = domhelpers.findNodesNamed(a, "h2")
        if len(headers) > 0:
            return headers
    return []
예제 #11
0
 def matcher(node):
     return ('"' in getattr(node, 'data', '')
             and not isinstance(node, dom.Comment) and not [
                 1 for n in domhelpers.getParents(node)[1:-1]
                 if n.tagName in ('pre', 'code')
             ])
예제 #12
0
 def matcher(node):
     return ('"' in getattr(node, 'data', '') and
             not isinstance(node, microdom.Comment) and
             not  [1 for n in domhelpers.getParents(node)[1:-1]
                    if n.tagName in ('pre', 'code')])
예제 #13
0
파일: lint.py 프로젝트: pelluch/VTK
 def matcher(node):
     return (
         '"' in getattr(node, "data", "")
         and not isinstance(node, dom.Comment)
         and not [1 for n in domhelpers.getParents(node)[1:-1] if n.tagName in ("pre", "code")]
     )