本文整理汇总了Python中twisted.words.xish.xpath.XPathQuery.queryForStringList方法的典型用法代码示例。如果您正苦于以下问题:Python XPathQuery.queryForStringList方法的具体用法?Python XPathQuery.queryForStringList怎么用?Python XPathQuery.queryForStringList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.words.xish.xpath.XPathQuery
的用法示例。
在下文中一共展示了XPathQuery.queryForStringList方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testFunctionality
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import queryForStringList [as 别名]
def testFunctionality(self):
xp = XPathQuery("/foo/bar")
self.assertEquals(xp.matches(self.e), 1)
xp = XPathQuery("/foo/bar/foo")
self.assertEquals(xp.matches(self.e), 1)
self.assertEquals(xp.queryForNodes(self.e), [self.subfoo])
xp = XPathQuery("/foo/bar3")
self.assertEquals(xp.matches(self.e), 0)
xp = XPathQuery("/foo/*")
self.assertEquals(xp.matches(self.e), True)
self.assertEquals(xp.queryForNodes(self.e), [self.bar1, self.bar2, self.bar4])
xp = XPathQuery("/foo[@attrib1]")
self.assertEquals(xp.matches(self.e), True)
xp = XPathQuery("/foo/*[@attrib2='value2']")
self.assertEquals(xp.matches(self.e), True)
self.assertEquals(xp.queryForNodes(self.e), [self.bar2])
# XXX: Revist this, given new grammar
# xp = XPathQuery("/foo/bar[2]")
# self.assertEquals(xp.matches(self.e), 1)
# self.assertEquals(xp.queryForNodes(self.e), [self.bar1])
xp = XPathQuery("/foo[@xmlns='testns']/bar")
self.assertEquals(xp.matches(self.e), 1)
xp = XPathQuery("/foo[@xmlns='badns']/bar2")
self.assertEquals(xp.matches(self.e), 0)
xp = XPathQuery("/foo[@attrib1='value1']")
self.assertEquals(xp.matches(self.e), 1)
xp = XPathQuery("/foo")
self.assertEquals(xp.queryForString(self.e), "somecontent")
self.assertEquals(xp.queryForStringList(self.e), ["somecontent", "somemorecontent"])
xp = XPathQuery("/foo/bar")
self.assertEquals(xp.queryForNodes(self.e), [self.bar1, self.bar2, self.bar4])
xp = XPathQuery("/foo[text() = 'somecontent']")
self.assertEquals(xp.matches(self.e), True)
xp = XPathQuery("/foo[not(@nosuchattrib)]")
self.assertEquals(xp.matches(self.e), True)
xp = XPathQuery("//gar")
self.assertEquals(xp.matches(self.e), True)
self.assertEquals(xp.queryForNodes(self.e), [self.gar1, self.gar2])
self.assertEquals(xp.queryForStringList(self.e), ["DEF", "ABC"])
xp = XPathQuery("//bar")
self.assertEquals(xp.matches(self.e), True)
self.assertEquals(xp.queryForNodes(self.e), [self.bar1, self.bar2, self.bar3, self.bar4])
示例2: test_queryForString
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import queryForStringList [as 别名]
def test_queryForString(self):
"""
Test for queryForString and queryForStringList.
"""
xp = XPathQuery("/foo")
self.assertEquals(xp.queryForString(self.e), "somecontent")
self.assertEquals(xp.queryForStringList(self.e), ["somecontent", "somemorecontent"])
示例3: test_queryForStringListAnyLocation
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import queryForStringList [as 别名]
def test_queryForStringListAnyLocation(self):
"""
queryforStringList on relative paths returns all their CDATA.
"""
xp = XPathQuery("//foo")
self.assertEqual(xp.queryForStringList(self.e),
["somecontent", "somemorecontent"])
示例4: test_anyLocationAndText
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import queryForStringList [as 别名]
def test_anyLocationAndText(self):
"""
Test finding any nodes named gar and getting their text contents.
"""
xp = XPathQuery("//gar")
self.assertEquals(xp.matches(self.e), True)
self.assertEquals(xp.queryForNodes(self.e), [self.gar1, self.gar2, self.gar3, self.gar4])
self.assertEquals(xp.queryForStringList(self.e), ["DEF", "ABC", "JKL", "MNO"])