本文整理汇总了Python中genshi.path.Path.select方法的典型用法代码示例。如果您正苦于以下问题:Python Path.select方法的具体用法?Python Path.select怎么用?Python Path.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类genshi.path.Path
的用法示例。
在下文中一共展示了Path.select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_predicate_attr_equality
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import select [as 别名]
def test_predicate_attr_equality(self):
xml = XML('<root><item/><item important="notso"/></root>')
path = Path('item[@important="very"]')
self.assertEqual('', path.select(xml).render())
path = Path('item[@important!="very"]')
self.assertEqual('<item/><item important="notso"/>',
path.select(xml).render())
示例2: test_predicate_number_function
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import select [as 别名]
def test_predicate_number_function(self):
xml = XML('<root><foo>bar</foo></root>')
path = Path('*[number("3.0")=3]')
self.assertEqual('<foo>bar</foo>', path.select(xml).render())
path = Path('*[number("3.0")=3.0]')
self.assertEqual('<foo>bar</foo>', path.select(xml).render())
path = Path('*[number("0.1")=.1]')
self.assertEqual('<foo>bar</foo>', path.select(xml).render())
示例3: test_1step_self
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import select [as 别名]
def test_1step_self(self):
xml = XML('<root><elem/></root>')
path = Path('.')
self.assertEqual('<Path "self::node()">', repr(path))
self.assertEqual('<root><elem/></root>', path.select(xml).render())
path = Path('self::node()')
self.assertEqual('<Path "self::node()">', repr(path))
self.assertEqual('<root><elem/></root>', path.select(xml).render())
示例4: test_predicate_termination
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import select [as 别名]
def test_predicate_termination(self):
"""
Verify that a patch matching the self axis with a predicate doesn't
cause an infinite loop. See <http://genshi.edgewall.org/ticket/82>.
"""
xml = XML('<ul flag="1"><li>a</li><li>b</li></ul>')
path = Path('.[@flag="1"]/*')
self.assertEqual('<li>a</li><li>b</li>', path.select(xml).render())
xml = XML('<ul flag="1"><li>a</li><li>b</li></ul>')
path = Path('.[@flag="0"]/*')
self.assertEqual('', path.select(xml).render())
示例5: test_3step_complex
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import select [as 别名]
def test_3step_complex(self):
xml = XML('<root><foo><bar/></foo></root>')
path = Path('*/bar')
self.assertEqual('<Path "child::*/child::bar">', repr(path))
self.assertEqual('<bar/>', path.select(xml).render())
xml = XML('<root><foo><bar id="1"/></foo><bar id="2"/></root>')
path = Path('//bar')
self.assertEqual('<Path "descendant-or-self::node()/child::bar">',
repr(path))
self.assertEqual('<bar id="1"/><bar id="2"/>',
path.select(xml).render())
示例6: test_1step_attribute
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import select [as 别名]
def test_1step_attribute(self):
path = Path('@foo')
self.assertEqual('<Path "attribute::foo">', repr(path))
xml = XML('<root/>')
self.assertEqual('', path.select(xml).render())
xml = XML('<root foo="bar"/>')
self.assertEqual('bar', path.select(xml).render())
path = Path('./@foo')
self.assertEqual('<Path "self::node()/attribute::foo">', repr(path))
self.assertEqual('bar', path.select(xml).render())
示例7: test_node_type_processing_instruction
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import select [as 别名]
def test_node_type_processing_instruction(self):
xml = XML('<?python x = 2 * 3 ?><root><?php echo("x") ?></root>')
path = Path('processing-instruction()')
self.assertEqual('<Path "child::processing-instruction()">',
repr(path))
self.assertEqual('<?python x = 2 * 3 ?><?php echo("x") ?>',
path.select(xml).render())
path = Path('processing-instruction("php")')
self.assertEqual('<Path "child::processing-instruction(\"php\")">',
repr(path))
self.assertEqual('<?php echo("x") ?>', path.select(xml).render())
示例8: test_wildcard_with_namespace
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import select [as 别名]
def test_wildcard_with_namespace(self):
xml = XML('<root xmlns:f="FOO"><f:foo>bar</f:foo></root>')
path = Path('f:*')
self.assertEqual('<Path "child::f:*">', repr(path))
namespaces = {'f': 'FOO'}
self.assertEqual('<foo xmlns="FOO">bar</foo>',
path.select(xml, namespaces=namespaces).render())
示例9: test_attr_selection
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import select [as 别名]
def test_attr_selection(self):
xml = XML('<root><foo bar="abc"></foo></root>')
path = Path('foo/@bar')
result = path.select(xml)
self.assertEqual(list(result), [
Attrs([(QName('bar'), u'abc')])
])
示例10: test_1step_wildcard
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import select [as 别名]
def test_1step_wildcard(self):
xml = XML('<root><elem/></root>')
path = Path('*')
self.assertEqual('<Path "child::*">', repr(path))
self.assertEqual('<elem/>', path.select(xml).render())
path = Path('child::*')
self.assertEqual('<Path "child::*">', repr(path))
self.assertEqual('<elem/>', path.select(xml).render())
path = Path('child::node()')
self.assertEqual('<Path "child::node()">', repr(path))
self.assertEqual('<elem/>', Path('child::node()').select(xml).render())
path = Path('//*')
self.assertEqual('<Path "descendant-or-self::node()/child::*">',
repr(path))
self.assertEqual('<root><elem/></root>', path.select(xml).render())
示例11: test_1step
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import select [as 别名]
def test_1step(self):
xml = XML('<root><elem/></root>')
path = Path('elem')
self.assertEqual('<Path "child::elem">', repr(path))
self.assertEqual('<elem/>', path.select(xml).render())
path = Path('child::elem')
self.assertEqual('<Path "child::elem">', repr(path))
self.assertEqual('<elem/>', path.select(xml).render())
path = Path('//elem')
self.assertEqual('<Path "descendant-or-self::node()/child::elem">',
repr(path))
self.assertEqual('<elem/>', path.select(xml).render())
path = Path('descendant::elem')
self.assertEqual('<Path "descendant::elem">', repr(path))
self.assertEqual('<elem/>', path.select(xml).render())
示例12: test_2step_complex
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import select [as 别名]
def test_2step_complex(self):
xml = XML('<root><foo><bar/></foo></root>')
path = Path('foo/bar')
self.assertEqual('<Path "child::foo/child::bar">', repr(path))
self.assertEqual('<bar/>', path.select(xml).render())
path = Path('./bar')
self.assertEqual('<Path "self::node()/child::bar">', repr(path))
self.assertEqual('', path.select(xml).render())
path = Path('foo/*')
self.assertEqual('<Path "child::foo/child::*">', repr(path))
self.assertEqual('<bar/>', path.select(xml).render())
xml = XML('<root><foo><bar id="1"/></foo><bar id="2"/></root>')
path = Path('./bar')
self.assertEqual('<Path "self::node()/child::bar">', repr(path))
self.assertEqual('<bar id="2"/>', path.select(xml).render())
示例13: test_attr_selection_with_namespace
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import select [as 别名]
def test_attr_selection_with_namespace(self):
xml = XML(
'<root xmlns:ns1="http://example.com">'
'<foo ns1:bar="abc"></foo>'
'</root>')
path = Path('foo/@ns1:bar')
result = path.select(xml, namespaces={'ns1': 'http://example.com'})
self.assertEqual(list(result), [
Attrs([(QName('http://example.com}bar'), u'abc')])
])
示例14: test_1step_text
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import select [as 别名]
def test_1step_text(self):
xml = XML('<root>Hey</root>')
path = Path('text()')
self.assertEqual('<Path "child::text()">', repr(path))
self.assertEqual('Hey', path.select(xml).render())
path = Path('./text()')
self.assertEqual('<Path "self::node()/child::text()">', repr(path))
self.assertEqual('Hey', path.select(xml).render())
path = Path('//text()')
self.assertEqual('<Path "descendant-or-self::node()/child::text()">',
repr(path))
self.assertEqual('Hey', path.select(xml).render())
path = Path('.//text()')
self.assertEqual('<Path "self::node()/descendant-or-self::node()/child::text()">',
repr(path))
self.assertEqual('Hey', path.select(xml).render())
示例15: test_2step_text
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import select [as 别名]
def test_2step_text(self):
xml = XML('<root><item>Foo</item></root>')
path = Path('item/text()')
self.assertEqual('<Path "child::item/child::text()">', repr(path))
self.assertEqual('Foo', path.select(xml).render())
path = Path('*/text()')
self.assertEqual('<Path "child::*/child::text()">', repr(path))
self.assertEqual('Foo', path.select(xml).render())
path = Path('//text()')
self.assertEqual('<Path "descendant-or-self::node()/child::text()">',
repr(path))
self.assertEqual('Foo', path.select(xml).render())
path = Path('./text()')
self.assertEqual('<Path "self::node()/child::text()">', repr(path))
self.assertEqual('', path.select(xml).render())
xml = XML('<root><item>Foo</item><item>Bar</item></root>')
path = Path('item/text()')
self.assertEqual('<Path "child::item/child::text()">', repr(path))
self.assertEqual('FooBar', path.select(xml).render())
xml = XML('<root><item>Foo</item><item>Bar</item></root>')
self.assertEqual('FooBar', path.select(xml).render())