本文整理汇总了Python中genshi.path.Path.test方法的典型用法代码示例。如果您正苦于以下问题:Python Path.test方法的具体用法?Python Path.test怎么用?Python Path.test使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类genshi.path.Path
的用法示例。
在下文中一共展示了Path.test方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MatchDirective
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import test [as 别名]
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)
示例2: MatchDirective
# 需要导入模块: from genshi.path import Path [as 别名]
# 或者: from genshi.path.Path import test [as 别名]
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)