comparison genshi/template/markup.py @ 784:ea46fb523485 experimental-match-fastpaths

update to 0.5.x branch, up through r907 don't know how this fits in with SoC work, but I wanted to do due diligence and keep this branch working in case it someday gets considered for trunk
author aflett
date Mon, 21 Jul 2008 23:17:52 +0000
parents 919809e55d16
children
comparison
equal deleted inserted replaced
724:919809e55d16 784:ea46fb523485
301 for test in [mt[0] for mt in match_candidates]: 301 for test in [mt[0] for mt in match_candidates]:
302 test(tail[0], namespaces, ctxt, updateonly=True) 302 test(tail[0], namespaces, ctxt, updateonly=True)
303 303
304 # Make the select() function available in the body of the 304 # Make the select() function available in the body of the
305 # match template 305 # match template
306 selected = [False]
306 def select(path): 307 def select(path):
308 selected[0] = True
307 return Stream(content).select(path, namespaces, ctxt) 309 return Stream(content).select(path, namespaces, ctxt)
308 vars = dict(select=select) 310 vars = dict(select=select)
309 311
310 # Recursively process the output 312 # Recursively process the output
311 template = _apply_directives(template, directives, ctxt, 313 template = _apply_directives(template, directives, ctxt,
318 ctxt, **vars), 320 ctxt, **vars),
319 ctxt, post_match_templates, 321 ctxt, post_match_templates,
320 **vars): 322 **vars):
321 yield event 323 yield event
322 324
325 # If the match template did not actually call select to
326 # consume the matched stream, the original events need to
327 # be consumed here or they'll get appended to the output
328 if not selected[0]:
329 for event in content:
330 pass
331
323 break 332 break
324 333
325 else: # no matches 334 else: # no matches
326 yield event 335 yield event
Copyright (C) 2012-2017 Edgewall Software