# HG changeset patch # User cmlenz # Date 1151528994 0 # Node ID 0e1fc02114164fe0d8819c75b535319445003442 # Parent 3b8c41bbf83d68f22ebe31b4f238cb65d2c45179 Add doctests for path module. diff --git a/markup/path.py b/markup/path.py --- a/markup/path.py +++ b/markup/path.py @@ -97,6 +97,15 @@ If there are no matches, this method returns an empty stream. + >>> from markup.input import XML + >>> xml = XML('Text') + >>> print Path('child').select(xml) + Text + + >>> xpath = Path('child') + >>> print Path('child/text()').select(xml) + Text + @param stream: the stream to select from @return: the substream matching the path, or an empty stream """ @@ -128,6 +137,15 @@ and `pos`, i.e. basically an unpacked stream event. If the path matches the event, the function returns the match (for example, a `START` or `TEXT` event.) Otherwise, it returns `None` or `False`. + + >>> from markup.input import XML + >>> xml = XML('') + >>> test = Path('child').test() + >>> for kind, data, pos in xml: + ... if test(kind, data, pos): + ... print kind, data + START (u'child', [(u'id', u'1')]) + START (u'child', [(u'id', u'2')]) """ stack = [0] # stack of cursors into the location path