当前位置: 首页>>代码示例>>Python>>正文


Python path.Path类代码示例

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


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

示例1: test_wildcard_with_namespace

 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())
开发者ID:alon,项目名称:polinax,代码行数:7,代码来源:path.py

示例2: test_predicate_attr_equality

 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())
开发者ID:alon,项目名称:polinax,代码行数:7,代码来源:path.py

示例3: test_attr_selection

 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')])
     ])
开发者ID:NixePix,项目名称:genshi,代码行数:7,代码来源:path.py

示例4: test_1step_self

    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())
开发者ID:alon,项目名称:polinax,代码行数:10,代码来源:path.py

示例5: test_attr_selection_with_namespace

 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')])
     ])
开发者ID:NixePix,项目名称:genshi,代码行数:10,代码来源:path.py

示例6: test_predicate_termination

    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())
开发者ID:alon,项目名称:polinax,代码行数:12,代码来源:path.py

示例7: test_3step_complex

    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())
开发者ID:alon,项目名称:polinax,代码行数:12,代码来源:path.py

示例8: test_1step_attribute

    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())
开发者ID:alon,项目名称:polinax,代码行数:13,代码来源:path.py

示例9: test_node_type_processing_instruction

    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())
开发者ID:alon,项目名称:polinax,代码行数:13,代码来源:path.py

示例10: MatchDirective

class MatchDirective(Directive):
    """Implementation of the ``py:match`` template directive.

    >>> from genshi.template import MarkupTemplate
    >>> tmpl = MarkupTemplate('''<div xmlns:py="http://genshi.edgewall.org/">
    ...   <span py:match="greeting">
    ...     Hello ${select('@name')}
    ...   </span>
    ...   <greeting name="Dude" />
    ... </div>''')
    >>> print tmpl.generate()
    <div>
      <span>
        Hello Dude
      </span>
    </div>
    """
    __slots__ = ['path', 'namespaces']

    ATTRIBUTE = 'path'

    def __init__(self, value, template, namespaces=None, lineno=-1, offset=-1):
        Directive.__init__(self, None, template, namespaces, lineno, offset)
        self.path = Path(value, template.filepath, lineno)
        self.namespaces = namespaces or {}

    def __call__(self, stream, ctxt, directives):
        ctxt._match_templates.append((self.path.test(ignore_context=True),
                                      self.path, list(stream), self.namespaces,
                                      directives))
        return []

    def __repr__(self):
        return '<%s "%s">' % (self.__class__.__name__, self.path.source)
开发者ID:jacoco,项目名称:www.eclemma.org,代码行数:34,代码来源:directives.py

示例11: _test_eval

    def _test_eval(self, path, equiv=None, input=None, output='',
                         namespaces=None, variables=None):
        path = Path(path)
        if equiv is not None:
            self.assertEqual(equiv, repr(path))

        if input is None:
            return

        rendered = path.select(input, namespaces=namespaces,
                               variables=variables).render(encoding=None)
        msg = 'Bad output using whole path'
        msg += '\nExpected:\t%r' % output
        msg += '\nRendered:\t%r' % rendered
        self.assertEqual(output, rendered, msg)

        if len(path.paths) == 1:
            self._test_strategies(input, path.paths[0], output,
                                  namespaces=namespaces, variables=variables)
开发者ID:nervatura,项目名称:nerva2py,代码行数:19,代码来源:path.py

示例12: test_predicate_number_function

 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())
开发者ID:alon,项目名称:polinax,代码行数:8,代码来源:path.py

示例13: MatchDirective

class MatchDirective(Directive):
    """Implementation of the ``py:match`` template directive.

    >>> from genshi.template import MarkupTemplate
    >>> tmpl = MarkupTemplate('''<div xmlns:py="http://genshi.edgewall.org/">
    ...   <span py:match="greeting">
    ...     Hello ${select('@name')}
    ...   </span>
    ...   <greeting name="Dude" />
    ... </div>''')
    >>> print(tmpl.generate())
    <div>
      <span>
        Hello Dude
      </span>
    </div>
    """
    __slots__ = ['path', 'namespaces', 'hints']

    def __init__(self, value, template, hints=None, namespaces=None,
                 lineno=-1, offset=-1):
        Directive.__init__(self, None, template, namespaces, lineno, offset)
        self.path = Path(value, template.filepath, lineno)
        self.namespaces = namespaces or {}
        self.hints = hints or ()

    @classmethod
    def attach(cls, template, stream, value, namespaces, pos):
        hints = []
        if type(value) is dict:
            if value.get('buffer', '').lower() == 'false':
                hints.append('not_buffered')
            if value.get('once', '').lower() == 'true':
                hints.append('match_once')
            if value.get('recursive', '').lower() == 'false':
                hints.append('not_recursive')
            value = value.get('path')
        return cls(value, template, frozenset(hints), namespaces, *pos[1:]), \
               stream

    def __call__(self, stream, directives, ctxt, **vars):
        ctxt._match_templates.append((self.path.test(ignore_context=True),
                                      self.path, list(stream), self.hints,
                                      self.namespaces, directives))
        return []

    def __repr__(self):
        return '<%s "%s">' % (type(self).__name__, self.path.source)
开发者ID:kamroot,项目名称:mc27,代码行数:48,代码来源:directives.py

示例14: test_1step

    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())
开发者ID:alon,项目名称:polinax,代码行数:19,代码来源:path.py

示例15: test_2step_complex

    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())
开发者ID:alon,项目名称:polinax,代码行数:19,代码来源:path.py


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