changeset 33:1fdb7054fb42 trunk

Add doctests for path module.
author cmlenz
date Wed, 28 Jun 2006 21:09:54 +0000
parents 2224a52256ca
children 3421dd98f015
files markup/path.py
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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('<root><elem><child>Text</child></elem></root>')
+        >>> print Path('child').select(xml)
+        <child>Text</child>
+        
+        >>> 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('<root><elem><child id="1"/></elem><child id="2"/></root>')
+        >>> 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
 
Copyright (C) 2012-2017 Edgewall Software