当前位置: 首页>>代码示例>>Python>>正文


Python domhelpers.findNodesNamed函数代码示例

本文整理汇总了Python中twisted.web.domhelpers.findNodesNamed函数的典型用法代码示例。如果您正苦于以下问题:Python findNodesNamed函数的具体用法?Python findNodesNamed怎么用?Python findNodesNamed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了findNodesNamed函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: munge

def munge(document, template, linkrel, d, fullpath, ext, url, config):
    fixRelativeLinks(template, linkrel)
    addMtime(template, fullpath)
    removeH1(document)
    fixAPI(document, url)
    fontifyPython(document)
    addPyListings(document, d)
    addHTMLListings(document, d)
    fixLinks(document, ext)
    putInToC(template, generateToC(document))
    footnotes(document)
    notes(document)

    # Insert the document into the template
    title = domhelpers.findNodesNamed(document, 'title')[0].childNodes
    setTitle(template, title)

    authors = domhelpers.findNodesNamed(document, 'link')
    authors = [(n.getAttribute('title',''), n.getAttribute('href', ''))
               for n in authors if n.getAttribute('rel', '') == 'author']
    setAuthors(template, authors)

    body = domhelpers.findNodesNamed(document, "body")[0]
    tmplbody = domhelpers.findElementsWithAttribute(template, "class",
                                                              "body")[0]
    tmplbody.childNodes = body.childNodes
    tmplbody.setAttribute("class", "content")
开发者ID:fxia22,项目名称:ASM_xf,代码行数:27,代码来源:tree.py

示例2: check_lists

 def check_lists(self, dom, filename):
     for node in domhelpers.findNodesNamed(dom, "ul") + domhelpers.findNodesNamed(dom, "ol"):
         if not node.childNodes:
             self._reportError(filename, node, "empty list")
         for child in node.childNodes:
             if child.nodeName != "li":
                 self._reportError(filename, node, "only list items allowed in lists")
开发者ID:pelluch,项目名称:VTK,代码行数:7,代码来源:lint.py

示例3: makeBook

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)
开发者ID:fxia22,项目名称:ASM_xf,代码行数:25,代码来源:book.py

示例4: check_80_columns

    def check_80_columns(self, dom, filename):
        for node in domhelpers.findNodesNamed(dom, 'pre'):
            # the ps/pdf output is in a font that cuts off at 80 characters,
            # so this is enforced to make sure the interesting parts (which
            # are likely to be on the right-hand edge) stay on the printed
            # page.
            for line in domhelpers.gatherTextNodes(node, 1).split('\n'):
                if len(line.rstrip()) > 80:
                    self._reportError(filename, node, 
                                      'text wider than 80 columns in pre')
        for node in domhelpers.findNodesNamed(dom, 'a'):
            if node.getAttribute('class', '').endswith('listing'):
                try:
                    fn = os.path.dirname(filename) 
                    fn = os.path.join(fn, node.getAttribute('href'))
                    lines = open(fn,'r').readlines()
                except:
                    self._reportError(filename, node,
                                      'bad listing href: %r' %
                                      node.getAttribute('href'))
                    continue

                for line in lines:
                    if len(line.rstrip()) > 80:
                        self._reportError(filename, node, 
                                          'listing wider than 80 columns')
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:26,代码来源:lint.py

示例5: getTitleLink

def getTitleLink(url):
    d = client.getPage("http://moshez.org/discuss/rss")
    d.addCallback(microdom.parseString)
    d.addCallback(lambda d: domhelpers.findNodesNamed(d, 'item')[0])
    d.addCallback(lambda d: (
               domhelpers.getNodeText(domhelpers.findNodesNamed(d, 'link')[0]),
               domhelpers.getNodeText(domhelpers.findNodesNamed(d, 'title')[0]),
              ))
    return d
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:9,代码来源:wovenrss.rpy.py

示例6: check_lists

 def check_lists(self, dom, filename):
     for node in (domhelpers.findNodesNamed(dom, 'ul')+
                  domhelpers.findNodesNamed(dom, 'ol')):
         if not node.childNodes:
             self._reportError(filename, node, 'empty list')
         for child in node.childNodes:
             if child.nodeName != 'li':
                 self._reportError(filename, node,
                                   'only list items allowed in lists')
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:9,代码来源:lint.py

示例7: check_title

 def check_title(self, dom, filename):
     doc = dom.documentElement
     title = domhelpers.findNodesNamed(dom, 'title')
     if len(title)!=1:
         return self._reportError(filename, doc, 'not exactly one title')
     h1 = domhelpers.findNodesNamed(dom, 'h1')
     if len(h1)!=1:
         return self._reportError(filename, doc, 'not exactly one h1')
     if domhelpers.getNodeText(h1[0]) != domhelpers.getNodeText(title[0]):
         self._reportError(filename, h1[0], 'title and h1 text differ')
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:10,代码来源:lint.py

示例8: extractRSSFeeds

def extractRSSFeeds(dom):
    for bookmark in domhelpers.findNodesNamed(dom, "bookmark"):
        titleNodes = domhelpers.findNodesNamed(bookmark, "title")
        if titleNodes:
            title = domhelpers.getNodeText(titleNodes[0])
        else:
            title = None

        url = bookmark.getAttribute("href")
        url = urllib.unquote(url)
        yield title, url
开发者ID:tv42,项目名称:toursst,代码行数:11,代码来源:xbel.py

示例9: findRSSFolder

def findRSSFolder(dom, folderName=None):
    if folderName is None:
        folderName = "RSS"
    if folderName == "":
        return dom
    for folder in domhelpers.findNodesNamed(dom, "folder"):
        for title in domhelpers.findNodesNamed(folder, "title"):
            text = domhelpers.getNodeText(title)
            if text == folderName:
                return folder
    return None
开发者ID:tv42,项目名称:toursst,代码行数:11,代码来源:xbel.py

示例10: numberDocument

def numberDocument(document, chapterNumber):
    """
    Number the sections of the given document.

    A dot-separated chapter, section number is added to the beginning of each
    section, as defined by C{h2} nodes.

    This is probably intended to interact in a rather specific way with
    L{getSectionNumber}.

    @type document: A DOM Node or Document
    @param document: The input document which contains all of the content to be
    presented.

    @type chapterNumber: C{int}
    @param chapterNumber: The chapter number of this content in an overall
    document.

    @return: C{None}
    """
    i = 1
    for node in domhelpers.findNodesNamed(document, "h2"):
        label = dom.Text()
        label.data = "%s.%d " % (chapterNumber, i)
        node.insertBefore(label, node.firstChild)
        i += 1
开发者ID:AlexanderHerlan,项目名称:syncpy,代码行数:26,代码来源:tree.py

示例11: getDescription

 def getDescription(self):
     # http://purl.org/dc/elements/1.1/ description
     l = domhelpers.findNodesNamed(self.dom, 'description')
     if l:
         return domhelpers.getNodeText(l[0])
     else:
         return None
开发者ID:raamdev,项目名称:toursst,代码行数:7,代码来源:fetch.py

示例12: testAwfulTagSoup

    def testAwfulTagSoup(self):
        s = """
        <html>
        <head><title> I send you this message to have your advice!!!!</titl e
        </headd>

        <body bgcolor alink hlink vlink>

        <h1><BLINK>SALE</blINK> TWENTY MILLION EMAILS & FUR COAT NOW
        FREE WITH `ENLARGER'</h1>

        YES THIS WONDERFUL AWFER IS NOW HERER!!!

        <script LANGUAGE="javascript">
function give_answers() {
if (score < 70) {
alert("I hate you");
}}
        </script><a href=/foo.com/lalal name=foo>lalal</a>
        </body>
        </HTML>
        """
        d = microdom.parseString(s, beExtremelyLenient=1)
        l = domhelpers.findNodesNamed(d.documentElement, 'blink')
        self.assertEquals(len(l), 1)
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:25,代码来源:test_xml.py

示例13: setAuthors

def setAuthors(template, authors):
    # First, similarly to setTitle, insert text into an <div class="authors">
    text = ''
    for name, href in authors:
        # FIXME: Do proper quoting/escaping (is it ok to use
        # xml.sax.saxutils.{escape,quoteattr}?)
        anchor = '<a href="%s">%s</a>' % (href, name)
        if (name, href) == authors[-1]:
            if len(authors) == 1:
                text = anchor
            else:
                text += 'and ' + anchor
        else:
            text += anchor + ','

    childNodes = microdom.parseString('<span>' + text +'</span>').childNodes

    for node in domhelpers.findElementsWithAttribute(template, 
                                                     "class", 'authors'):
        node.childNodes.extend(childNodes) 

    # Second, add appropriate <link rel="author" ...> tags to the <head>.
    head = domhelpers.findNodesNamed(template, 'head')[0]
    authors = [microdom.parseString('<link rel="author" href="%s" title="%s"/>'
                                    % (href, name)).childNodes[0]
               for name, href in authors]
    head.childNodes.extend(authors)
开发者ID:galaxysd,项目名称:BitTorrent,代码行数:27,代码来源:tree.py

示例14: getFirstAncestorWithSectionHeader

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 []
开发者ID:galaxysd,项目名称:BitTorrent,代码行数:7,代码来源:tree.py

示例15: setTitle

def setTitle(template, title, chapterNumber):
    """
    Add title and chapter number information to the template document.

    The title is added to the end of the first C{title} tag and the end of the
    first tag with a C{class} attribute set to C{title}.  If specified, the
    chapter is inserted before the title.

    @type template: A DOM Node or Document
    @param template: The output template which defines the presentation of the
    version information.

    @type title: C{list} of DOM Nodes
    @param title: Nodes from the input document defining its title.

    @type chapterNumber: C{int}
    @param chapterNumber: The chapter number of this content in an overall
    document.  If not applicable, any C{False} value will result in this
    information being omitted.

    @return: C{None}
    """
    for nodeList in (
        domhelpers.findNodesNamed(template, "title"),
        domhelpers.findElementsWithAttribute(template, "class", "title"),
    ):
        if nodeList:
            if numberer.getNumberSections() and chapterNumber:
                nodeList[0].childNodes.append(microdom.Text("%s. " % chapterNumber))
            nodeList[0].childNodes.extend(title)
开发者ID:radical-software,项目名称:radicalspam,代码行数:30,代码来源:tree.py


注:本文中的twisted.web.domhelpers.findNodesNamed函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。