test(self,
ignore_context=False)
|
|
Returns a function that can be used to track whether the path matches
a specific stream event.
The function returned expects the positional arguments event,
namespaces and variables. The first is a stream event, while the
latter two are a mapping of namespace prefixes to URIs, and a mapping
of variable names to values, respectively. In addition, the function
accepts an updateonly keyword argument that default to False. If
it is set to True, the function only updates its internal state,
but does not perform any tests or return a result.
If the path matches the event, the function returns the match (for
example, a START or TEXT event.) Otherwise, it returns None.
>>> from genshi.input import XML
>>> xml = XML('<root><elem><child id="1"/></elem><child id="2"/></root>')
>>> test = Path('child').test()
>>> namespaces, variables = {}, {}
>>> for event in xml:
... if test(event, namespaces, variables):
... print('%s %r' % (event[0], event[1]))
START (QName('child'), Attrs([(QName('id'), u'2')]))
- Parameters:
ignore_context - if True , the path is interpreted like a pattern
in XSLT, meaning for example that it will match
at any depth
- Returns: function
- a function that can be used to test individual events in a
stream against the path
|