本文整理汇总了Python中twisted.web.domhelpers.gatherTextNodes函数的典型用法代码示例。如果您正苦于以下问题:Python gatherTextNodes函数的具体用法?Python gatherTextNodes怎么用?Python gatherTextNodes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gatherTextNodes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
)
示例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))
示例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)
)
示例4: test_textEntitiesDecoded
def test_textEntitiesDecoded(self):
"""
Minidom does decode entities in text nodes.
"""
doc5_xml = '<x>Souffl&</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)
示例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')
示例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))
示例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)))
示例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é</x>'
doc5=microdom.parseString(doc5_xml)
actual=domhelpers.gatherTextNodes(doc5)
expected='Soufflé'
self.assertEqual(actual, expected)
actual=domhelpers.gatherTextNodes(doc5.documentElement)
self.assertEqual(actual, expected)
示例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)
示例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
示例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")
示例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)
示例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))
示例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
示例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)))