本文整理汇总了Python中twisted.words.xish.xpath.XPathQuery.matches方法的典型用法代码示例。如果您正苦于以下问题:Python XPathQuery.matches方法的具体用法?Python XPathQuery.matches怎么用?Python XPathQuery.matches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.words.xish.xpath.XPathQuery
的用法示例。
在下文中一共展示了XPathQuery.matches方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_locationAllChilds
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import matches [as 别名]
def test_locationAllChilds(self):
"""
Test finding childs of foo.
"""
xp = XPathQuery("/foo/*")
self.assertEquals(xp.matches(self.e), True)
self.assertEquals(xp.queryForNodes(self.e), [self.bar1, self.bar2, self.bar4, self.bar5, self.bar6, self.bar7])
示例2: test_textConditionUnicode
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import matches [as 别名]
def test_textConditionUnicode(self):
"""
A node can be matched by text with non-ascii code points.
"""
xp = XPathQuery(u"//*[text()='\N{SNOWMAN}']")
self.assertEqual(xp.matches(self.e), True)
self.assertEqual(xp.queryForNodes(self.e), [self.quux])
示例3: test_attributeWithValueAny
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import matches [as 别名]
def test_attributeWithValueAny(self):
"""
Test find nodes with attribute having value.
"""
xp = XPathQuery("/foo/*[@attrib2='value2']")
self.assertEqual(xp.matches(self.e), True)
self.assertEqual(xp.queryForNodes(self.e), [self.bar2])
示例4: test_orOperator
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import matches [as 别名]
def test_orOperator(self):
"""
Test boolean or operator in condition.
"""
xp = XPathQuery("//bar[@attrib5='value4' or @attrib5='value5']")
self.assertEqual(xp.matches(self.e), True)
self.assertEqual(xp.queryForNodes(self.e), [self.bar5, self.bar6])
示例5: test_position
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import matches [as 别名]
def test_position(self):
"""
Test finding element at position.
"""
xp = XPathQuery("/foo/bar[2]")
self.assertEqual(xp.matches(self.e), 1)
self.assertEqual(xp.queryForNodes(self.e), [self.bar1])
示例6: test_locationFooBarFoo
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import matches [as 别名]
def test_locationFooBarFoo(self):
"""
Test finding foos at the second level.
"""
xp = XPathQuery("/foo/bar/foo")
self.assertEquals(xp.matches(self.e), 1)
self.assertEquals(xp.queryForNodes(self.e), [self.subfoo, self.subfoo3, self.subfoo4])
示例7: test_andOperator
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import matches [as 别名]
def test_andOperator(self):
"""
Test boolean and operator in condition.
"""
xp = XPathQuery("//bar[@attrib4='value4' and @attrib5='value5']")
self.assertEqual(xp.matches(self.e), True)
self.assertEqual(xp.queryForNodes(self.e), [self.bar5])
示例8: test_locationWithValueUnicode
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import matches [as 别名]
def test_locationWithValueUnicode(self):
"""
Nodes' attributes can be matched with non-ASCII values.
"""
xp = XPathQuery(u"/foo/*[@attrib6='á']")
self.assertEqual(xp.matches(self.e), True)
self.assertEqual(xp.queryForNodes(self.e), [self.bar7])
示例9: test_booleanOperatorsParens
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import matches [as 别名]
def test_booleanOperatorsParens(self):
"""
Test multiple boolean operators in condition with parens.
"""
xp = XPathQuery("""//bar[@attrib4='value4' and
(@attrib5='value4' or @attrib5='value6')]""")
self.assertEqual(xp.matches(self.e), True)
self.assertEqual(xp.queryForNodes(self.e), [self.bar6, self.bar7])
示例10: test_anyLocationAndText
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import matches [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"])
示例11: test_anyLocation
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import matches [as 别名]
def test_anyLocation(self):
"""
Test finding any nodes named bar.
"""
xp = XPathQuery("//bar")
self.assertEquals(xp.matches(self.e), True)
self.assertEquals(
xp.queryForNodes(self.e), [self.bar1, self.bar2, self.bar3, self.bar4, self.bar5, self.bar6, self.bar7]
)
示例12: test_textNotOperator
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import matches [as 别名]
def test_textNotOperator(self):
"""
Test for not operator.
"""
xp = XPathQuery("/foo[not(@nosuchattrib)]")
self.assertEqual(xp.matches(self.e), True)
示例13: test_textCondition
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import matches [as 别名]
def test_textCondition(self):
"""
Test matching a node with given text.
"""
xp = XPathQuery("/foo[text() = 'somecontent']")
self.assertEqual(xp.matches(self.e), True)
示例14: test_attributeWithValue
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import matches [as 别名]
def test_attributeWithValue(self):
"""
Test matching node with attribute having value.
"""
xp = XPathQuery("/foo[@attrib1='value1']")
self.assertEqual(xp.matches(self.e), 1)
示例15: test_namespaceNotFound
# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import matches [as 别名]
def test_namespaceNotFound(self):
"""
Test not matching node with wrong namespace.
"""
xp = XPathQuery("/foo[@xmlns='badns']/bar2")
self.assertEqual(xp.matches(self.e), 0)