Mercurial > genshi > mirror
comparison genshi/path.py @ 261:da3137c427a2 stable-0.3.x
Ported [321:323] to 0.3.x stable branch.
author | cmlenz |
---|---|
date | Fri, 22 Sep 2006 12:07:23 +0000 |
parents | 6a809835cf62 |
children | 24b3cbbc1b1b |
comparison
equal
deleted
inserted
replaced
257:5c8125e03b72 | 261:da3137c427a2 |
---|---|
155 START (u'child', [(u'id', u'2')]) | 155 START (u'child', [(u'id', u'2')]) |
156 """ | 156 """ |
157 paths = [(p, len(p), [0], [], [0] * len(p)) for p in self.paths] | 157 paths = [(p, len(p), [0], [], [0] * len(p)) for p in self.paths] |
158 | 158 |
159 def _test(kind, data, pos, namespaces, variables): | 159 def _test(kind, data, pos, namespaces, variables): |
160 retval = None | |
160 for steps, size, cursors, cutoff, counter in paths: | 161 for steps, size, cursors, cutoff, counter in paths: |
161 | 162 |
162 # Manage the stack that tells us "where we are" in the stream | 163 # Manage the stack that tells us "where we are" in the stream |
163 if kind is END: | 164 if kind is END: |
164 if cursors: | 165 if cursors: |
165 cursors.pop() | 166 cursors.pop() |
166 continue | 167 continue |
167 elif kind is START: | 168 elif kind is START: |
168 cursors.append(cursors and cursors[-1] or 0) | 169 cursors.append(cursors and cursors[-1] or 0) |
169 elif not cursors: | 170 |
171 if retval or not cursors: | |
170 continue | 172 continue |
171 cursor = cursors[-1] | 173 cursor = cursors[-1] |
172 depth = len(cursors) | 174 depth = len(cursors) |
173 | 175 |
174 if cutoff and depth + int(kind is not START) > cutoff[0]: | 176 if cutoff and depth + int(kind is not START) > cutoff[0]: |
175 continue | 177 continue |
176 | 178 |
177 ctxtnode = not ignore_context and kind is START \ | 179 ctxtnode = not ignore_context and kind is START \ |
178 and depth == 2 | 180 and depth == 2 |
179 matched = retval = None | 181 matched = None |
180 while 1: | 182 while 1: |
181 # Fetch the next location step | 183 # Fetch the next location step |
182 axis, nodetest, predicates = steps[cursor] | 184 axis, nodetest, predicates = steps[cursor] |
183 | 185 |
184 # If this is the start event for the context node, and the | 186 # If this is the start event for the context node, and the |
260 cursor -= 1 | 262 cursor -= 1 |
261 cutoff[:] = [] | 263 cutoff[:] = [] |
262 break | 264 break |
263 cursors[-1] = cursor | 265 cursors[-1] = cursor |
264 | 266 |
265 if retval: | 267 return retval |
266 return retval | |
267 | 268 |
268 return _test | 269 return _test |
269 | 270 |
270 | 271 |
271 class PathSyntaxError(Exception): | 272 class PathSyntaxError(Exception): |