diff genshi/path.py @ 305:60111a041e7c trunk

Various performance-oriented tweaks.
author cmlenz
date Mon, 16 Oct 2006 15:15:53 +0000
parents 24b3cbbc1b1b
children 095a754f95a8
line wrap: on
line diff
--- a/genshi/path.py
+++ b/genshi/path.py
@@ -117,19 +117,19 @@
         stream = iter(stream)
         def _generate():
             test = self.test()
-            for kind, data, pos in stream:
-                result = test(kind, data, pos, namespaces, variables)
+            for event in stream:
+                result = test(event, namespaces, variables)
                 if result is True:
-                    yield kind, data, pos
+                    yield event
                     depth = 1
                     while depth > 0:
-                        subkind, subdata, subpos = stream.next()
-                        if subkind is START:
+                        subevent = stream.next()
+                        if subevent[0] is START:
                             depth += 1
-                        elif subkind is END:
+                        elif subevent[0] is END:
                             depth -= 1
-                        yield subkind, subdata, subpos
-                        test(subkind, subdata, subpos, namespaces, variables)
+                        yield subevent
+                        test(subevent, namespaces, variables)
                 elif result:
                     yield result
         return Stream(_generate())
@@ -138,10 +138,10 @@
         """Returns a function that can be used to track whether the path matches
         a specific stream event.
         
-        The function returned expects the positional arguments `kind`, `data`,
-        `pos` (basically an unpacked stream event), as well as `namespaces`
-        and `variables`. The latter two are a mapping of namespace prefixes to
-        URIs, and a mapping of variable names to values, respectively.
+        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.
         
         If the path matches the event, the function returns the match (for
         example, a `START` or `TEXT` event.) Otherwise, it returns `None`.
@@ -149,14 +149,15 @@
         >>> from genshi.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'2')])
+        >>> for event in xml:
+        ...     if test(event, {}, {}):
+        ...         print event
+        ('START', (u'child', [(u'id', u'2')]), (None, 1, 34))
         """
         paths = [(p, len(p), [0], [], [0] * len(p)) for p in self.paths]
 
-        def _test(kind, data, pos, namespaces, variables):
+        def _test(event, namespaces, variables):
+            kind, data, pos = event
             retval = None
             for steps, size, cursors, cutoff, counter in paths:
 
Copyright (C) 2012-2017 Edgewall Software