• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python domhelpers.gatherTextNodes函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_proxySearch

    def test_proxySearch(self):
        """
        When the user searches for a proxy, the results are displayed in a
        table, in a form that will allow them to submit it to add new read or
        write proxies.
        """
        self.expectSomeRecords()
        self.resource.getResourceById = partial(FakePrincipalResource, self)
        document = yield self.renderPage(dict(resourceId=["qux"],
                                              proxySearch=["bob"]))

        # Form is filled out with existing input.
        self.assertEquals(
            document.getElementById("txt_proxySearch").getAttribute("value"),
            "bob"
        )
        proxyAddForm = document.getElementById("frm_proxyAdd")
        [proxyResultsTable] = getElementsByTagName(proxyAddForm, "table")

        rows = getElementsByTagName(proxyResultsTable, 'tr')
        self.assertEquals(len(rows), 3)
        firstRowCells = getElementsByTagName(rows[1], 'td')
        self.assertEquals(
            [gatherTextNodes(cell) for cell in firstRowCells[1:]],
            ["User", "bob", "[email protected], [email protected]", ""]
        )
        self.assertNotIn(
            "No matches found for proxy resource bob",
            gatherTextNodes(document)
        )
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:30,代码来源:test_resource.py


示例2: test_selectResourceById

    def test_selectResourceById(self):
        """
        When a resource is selected by a 'resourceId' parameter,
        """
        self.resource.getResourceById = partial(FakePrincipalResource, self)
        document = yield self.renderPage(dict(resourceId=["qux"]))
        [detailsTitle] = getElementsByTagName(document, 'h3')
        detailString = gatherTextNodes(detailsTitle)
        self.assertEquals(detailString,
                          "Resource Details: Hello Fake Resource: 'qux'")
        hiddenResourceId = document.getElementById(
            "hdn_resourceId").getAttribute("value")
        self.assertEquals(hiddenResourceId, "qux")

        autoScheduleMenu = document.getElementById("sel_autoSchedule")

        # Now, some assertions about features that are covered in other tests
        # which should be turned _off_ here since we're not asking for them.

        # Not an auto-schedule resource; there should be no auto-schedule menu.
        self.assertIdentical(autoScheduleMenu, None)
        # No resource search present; we shouldn't be performing the search.
        self.assertNotIn("No matches found for resource",
                         gatherTextNodes(document))
        self.assertIdentical(document.getElementById("tab_searchResults"), None)
        # I'm not attempting to retrieve a property, there's nothing to fail to
        # parse.
        self.assertNotIn("Unable to parse property", gatherTextNodes(document))
        # I'm not searching for proxies, so there shouldn't be any results.
        self.assertNotIn("No matches found for proxy resource",
                         gatherTextNodes(document))
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:31,代码来源:test_resource.py


示例3: test_resourceSearch

    def test_resourceSearch(self):
        """
        Searching for resources should result in an HTML table resource search.
        """
        self.expectSomeRecords()
        document = yield self.renderPage(dict(resourceSearch=["bob"]))

        # Form is filled out with existing input.
        self.assertEquals(
            document.getElementById("txt_resourceSearch").getAttribute("value"),
            "bob"
        )
        tables = getElementsByTagName(document, "table")
        # search results are the first table
        rows = getElementsByTagName(tables[0], 'tr')
        self.assertEquals(len(rows), 3)
        firstRowCells = getElementsByTagName(rows[1], 'td')
        self.assertEquals(
            [gatherTextNodes(cell) for cell in firstRowCells[1:]],
            ["Bob Bobson", "User", "bob", "boblogin",
             "[email protected], [email protected]"]
        )
        [resourceLink] = getElementsByTagName(
            firstRowCells[0], 'a')
        self.assertEquals(
            resourceLink.getAttribute("href"),
            "/admin/?resourceId=users:bob"
        )
        self.assertEquals(gatherTextNodes(resourceLink), "select")
        self.assertNotIn(
            "No matches found for resource bob",
            gatherTextNodes(document)
        )
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:33,代码来源:test_resource.py


示例4: test_textEntitiesDecoded

 def test_textEntitiesDecoded(self):
     """
     Minidom does decode entities in text nodes.
     """
     doc5_xml = '<x>Souffl&amp;</x>'
     doc5 = self.dom.parseString(doc5_xml)
     actual = domhelpers.gatherTextNodes(doc5)
     expected = 'Souffl&'
     self.assertEqual(actual, expected)
     actual = domhelpers.gatherTextNodes(doc5.documentElement)
     self.assertEqual(actual, expected)
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:11,代码来源:test_domhelpers.py


示例5: 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


示例6: testComplexNotification

 def testComplexNotification(self):
     listNode = self.d.getElementById("theList")
     self.assert_(listNode, "Test %s failed" % outputNum)
     liNodes = domhelpers.getElementsByTagName(listNode, "li")
     self.assert_(liNodes, "DOM was not updated by notifying Widgets. Test %s" % outputNum)
     text = domhelpers.gatherTextNodes(liNodes[0])
     self.assert_(text.strip() == "test", "Wrong output: %s. Test %s" % (text, outputNum))
开发者ID:galaxysd,项目名称:BitTorrent,代码行数:7,代码来源:test_woven.py


示例7: test_proxiesListing

    def test_proxiesListing(self):
        """
        Resource principals will have their proxies listed in a table.
        """
        def fakeResourceById(request, resid):
            return FakePrincipalResource(self, request, resid,
                                         recordType="resources")

        self.resource.getResourceById = fakeResourceById
        document = yield self.renderPage(dict(resourceId=["qux"]))
        proxiesForm = document.getElementById("frm_proxies")
        [proxiesTable] = getElementsByTagName(proxiesForm, "table")
        rows = getElementsByTagName(proxiesTable, "tr")

        # header + 3 data rows (see FakePrincipalResource)
        self.assertEquals(len(rows), 4)
        firstRowCells = getElementsByTagName(rows[1], "td")
        # name, buttons, name, buttons
        self.assertEquals(len(firstRowCells), 4)
        lastRowCells = getElementsByTagName(rows[-1], "td")
        # name, buttons, blank space
        self.assertEquals(len(lastRowCells), 3)
        self.assertEquals(lastRowCells[-1].getAttribute("colspan"), "2")

        self.assertNotIn("This resource has no proxies.",
                         ''.join(gatherTextNodes(document)))
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:26,代码来源:test_resource.py


示例8: test_gatherTextNodes

    def test_gatherTextNodes(self):
        doc1=microdom.parseString('<a>foo</a>')
        actual=domhelpers.gatherTextNodes(doc1)
        expected='foo'
        self.assertEqual(actual, expected)
        actual=domhelpers.gatherTextNodes(doc1.documentElement)
        self.assertEqual(actual, expected)

        doc2_xml='<a>a<b>b</b><c>c</c>def<g>g<h>h</h></g></a>'
        doc2=microdom.parseString(doc2_xml)
        actual=domhelpers.gatherTextNodes(doc2)
        expected='abcdefgh'
        self.assertEqual(actual, expected)
        actual=domhelpers.gatherTextNodes(doc2.documentElement)
        self.assertEqual(actual, expected)

        doc3_xml=('<a>a<b>b<d>d<g>g</g><h>h</h></d><e>e<i>i</i></e></b>' +
                  '<c>c<f>f<j>j</j></f></c></a>')
        doc3=microdom.parseString(doc3_xml)
        actual=domhelpers.gatherTextNodes(doc3)
        expected='abdgheicfj'
        self.assertEqual(actual, expected)
        actual=domhelpers.gatherTextNodes(doc3.documentElement)
        self.assertEqual(actual, expected)

        doc4_xml='''<html>
  <head>
  </head>
  <body>
    stuff
  </body>
</html>
'''
        doc4=microdom.parseString(doc4_xml)
        actual=domhelpers.gatherTextNodes(doc4)
        expected='\n    stuff\n  '
        assert actual==expected, 'expected %s, got %s' % (expected, actual)
        actual=domhelpers.gatherTextNodes(doc4.documentElement)
        self.assertEqual(actual, expected)
        
        doc5_xml='<x>Souffl&eacute;</x>'
        doc5=microdom.parseString(doc5_xml)
        actual=domhelpers.gatherTextNodes(doc5)
        expected='Souffl&eacute;'
        self.assertEqual(actual, expected)
        actual=domhelpers.gatherTextNodes(doc5.documentElement)
        self.assertEqual(actual, expected)
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:47,代码来源:test_domhelpers.py


示例9: testUnEntities

 def testUnEntities(self):
     s = """
             <HTML>
                 This HTML goes between Stupid <=CrAzY!=> Dumb.
             </HTML>
         """
     d = microdom.parseString(s, beExtremelyLenient=1)
     n = domhelpers.gatherTextNodes(d)
     self.assertNotEquals(n.find('>'), -1)
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:9,代码来源:test_xml.py


示例10: textFromHtml

def textFromHtml(htmlText):
    """
    Convert html text into its text nodes, with extreme leniency.  If the input
    is unicode, keep it unicode.
    """
    d = microdom.parseString(htmlText, beExtremelyLenient=1)
    s = domhelpers.gatherTextNodes(d, joinWith=u" ")
    ## print '\n'.join('| ' + l for l in s.splitlines())
    return s
开发者ID:corydodt,项目名称:Playtools,代码行数:9,代码来源:search.py


示例11: test_scrubTrustsH1

 def test_scrubTrustsH1(self):
     """
     Test that L{xquotient.scrubber.Scrubber} considers h1 to be a safe tag.
     Added because of #1895.
     """
     node = parseString("<h1>Foo</h1>").documentElement
     scrubbed = scrub(node)
     h1s = getElementsByTagName(scrubbed, 'h1')
     self.assertEquals(len(h1s), 1)
     self.assertEquals(gatherTextNodes(h1s[0]).strip(), "Foo")
开发者ID:pombredanne,项目名称:quotient,代码行数:10,代码来源:test_scrubber.py


示例12: test_gatherTextNodesDropsWhitespace

    def test_gatherTextNodesDropsWhitespace(self):
        """
        Microdom discards whitespace-only text nodes, so L{gatherTextNodes}
        returns only the text from nodes which had non-whitespace characters.
        """
        doc4_xml = '''<html>
  <head>
  </head>
  <body>
    stuff
  </body>
</html>
'''
        doc4 = self.dom.parseString(doc4_xml)
        actual = domhelpers.gatherTextNodes(doc4)
        expected = '\n    stuff\n  '
        self.assertEqual(actual, expected)
        actual = domhelpers.gatherTextNodes(doc4.documentElement)
        self.assertEqual(actual, expected)
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:19,代码来源:test_domhelpers.py


示例13: test_davProperty

 def test_davProperty(self):
     """
     When a resource is selected by a resourceId parameter, and a DAV
     property is selected by the 'davPropertyName' parameter, that property
     will displayed.
     """
     self.resource.getResourceById = partial(FakePrincipalResource, self)
     document = yield self.renderPage(
         dict(resourceId=["qux"],
              davPropertyName=["DAV:#displayname"])
     )
     propertyName = document.getElementById('txt_davPropertyName')
     self.assertEquals(propertyName.getAttribute("value"),
                       "DAV:#displayname")
     propertyValue = DisplayName("The Name To Display").toxml()
     self.assertIn(cgi.escape(propertyValue),
                   gatherTextNodes(document))
     self.assertNotIn("Unable to parse property to read:",
                      gatherTextNodes(document))
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:19,代码来源:test_resource.py


示例14: scrub

    def scrub(self, node, filterCIDLinks=True):
        """
        Remove all potentially harmful elements from the node and
        return a wrapper node.

        For reasons (perhaps dubious) of performance, this mutates its
        input.
        """
        if node.nodeName == 'html':
            filler = body = lmx().div(_class="message-html")
            for c in node.childNodes:
                if c.nodeName == 'head':
                    for hc in c.childNodes:
                        if hc.nodeName == 'title':
                            body.div(_class="message-title").text(domhelpers.gatherTextNodes(hc))
                            break
                elif c.nodeName == 'body':
                    filler = body.div(_class='message-body')
                    break
        else:
            filler = body = lmx().div(_class="message-nohtml")
        for e in self.iternode(node):
            if getattr(e, 'clean', False):
                # If I have manually exploded this node, just forget about it.
                continue
            ennl = e.nodeName.lower()

            if filterCIDLinks and self._filterCIDLink(e):
                # we could replace these with a marker element, like we do
                # with dangerous tags, but i'm not sure there is a reason to
                e.parentNode.removeChild(e)

            if ennl in self._goodHtml:
                handler = getattr(self, '_handle_' + ennl, None)
                if handler is not None:
                    e = handler(e)
                newAttributes = {}
                oldAttributes = e.attributes
                e.attributes = newAttributes
                goodAttributes = self._goodHtml[ennl] + self._alwaysSafeAttributes
                for attr in goodAttributes:
                    if attr in oldAttributes:
                        newAttributes[attr] = oldAttributes[attr]
            else:
                e.attributes.clear()
                e.setTagName("div")
                e.setAttribute("class", "message-html-unknown")
                e.setAttribute("style", "display: none")
                div = Element('div')
                div.setAttribute('class', 'message-html-unknown-tag')
                div.appendChild(Text("Untrusted %s tag" % (ennl, )))
                e.childNodes.insert(0, div)
        filler.node.appendChild(node)
        return body.node
开发者ID:pombredanne,项目名称:quotient,代码行数:54,代码来源:scrubber.py


示例15: test_noProxiesListing

 def test_noProxiesListing(self):
     """
     When the selected resource principal has no proxies, the page should
     display a message saying so.
     """
     self.resource.getResourceById = partial(FakePrincipalResource, self,
                                             recordType='resources',
                                             hasProxies=False)
     document = yield self.renderPage(dict(resourceId=['qux']))
     self.assertIn("This resource has no proxies.",
                   ''.join(gatherTextNodes(document)))
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:11,代码来源:test_resource.py


示例16: test_withoutDocType

 def test_withoutDocType(self):
     """
     A Lore XML input document may omit a I{DOCTYPE} declaration.  If it
     does so, the XHTML1 Strict DTD is used.
     """
     # Parsing should succeed.
     document = self._parseTest("<foo>uses an xhtml entity: &copy;</foo>")
     # But even more than that, the &copy; entity should be turned into the
     # appropriate unicode codepoint.
     self.assertEqual(
         domhelpers.gatherTextNodes(document.documentElement),
         u"uses an xhtml entity: \N{COPYRIGHT SIGN}")
开发者ID:0004c,项目名称:VTK,代码行数:12,代码来源:test_lore.py


示例17: test_noResourceFound

 def test_noResourceFound(self):
     """
     Searching for resources which don't exist should result in an
     informative message.
     """
     self.expectRecordSearch("bob", [])
     document = yield self.renderPage(dict(resourceSearch=["bob"]))
     self.assertIn(
         "No matches found for resource bob",
         gatherTextNodes(document)
     )
     # Search results table should not be displayed.
     self.assertIdentical(document.getElementById("tab_searchResults"), None)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:13,代码来源:test_resource.py


示例18: testTameDocument

 def testTameDocument(self):
     s = """
     <test>
      <it>
       <is>
        <a>
         test
        </a>
       </is>
      </it>
     </test>
     """
     d = microdom.parseString(s)
     self.assertEqual(domhelpers.gatherTextNodes(d.documentElement).strip(), "test")
开发者ID:RCBiczok,项目名称:VTK,代码行数:14,代码来源:test_xml.py


示例19: test_noDavProperty

 def test_noDavProperty(self):
     """
     When a DAV property is not found, an error will be displayed.
     """
     self.resource.getResourceById = partial(FakePrincipalResource, self)
     document = yield self.renderPage(
         dict(resourceId=["qux"],
              davPropertyName=["DAV:#blub"])
     )
     propertyName = document.getElementById('txt_davPropertyName')
     self.assertEquals(propertyName.getAttribute("value"),
                       "DAV:#blub")
     propertyValue = "No such property: DAV:#blub"
     self.assertIn(cgi.escape(propertyValue),
                   gatherTextNodes(document))
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:15,代码来源:test_resource.py


示例20: test_withStrictDocType

    def test_withStrictDocType(self):
        """
        A Lore XML input document may include a I{DOCTYPE} declaration
        referring to the XHTML1 Strict DTD.
        """
        # Parsing should succeed.
        document = self._parseTest("""\
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<foo>uses an xhtml entity: &copy;</foo>
""")
        # But even more than that, the &copy; entity should be turned into the
        # appropriate unicode codepoint.
        self.assertEqual(
            domhelpers.gatherTextNodes(document.documentElement),
            u"uses an xhtml entity: \N{COPYRIGHT SIGN}")
开发者ID:0004c,项目名称:VTK,代码行数:16,代码来源:test_lore.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python domhelpers.getNodeText函数代码示例发布时间:2022-05-27
下一篇:
Python domhelpers.findNodesNamed函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap