comparison genshi/template/directives.py @ 562:b3dc05d88751 trunk

In the py:choose stack, store the information of whether a test expression has been supplied separate from the result of its evaluation.
author cmlenz
date Thu, 05 Jul 2007 17:49:20 +0000
parents 489a47873950
children 59fbd7586454
comparison
equal deleted inserted replaced
561:21b473243e63 562:b3dc05d88751
585 return super(ChooseDirective, cls).attach(template, stream, value, 585 return super(ChooseDirective, cls).attach(template, stream, value,
586 namespaces, pos) 586 namespaces, pos)
587 attach = classmethod(attach) 587 attach = classmethod(attach)
588 588
589 def __call__(self, stream, ctxt, directives): 589 def __call__(self, stream, ctxt, directives):
590 info = [False, None] 590 info = [False, bool(self.expr), None]
591 if self.expr: 591 if self.expr:
592 info[1] = self.expr.evaluate(ctxt) 592 info[2] = self.expr.evaluate(ctxt)
593 ctxt._choice_stack.append(info) 593 ctxt._choice_stack.append(info)
594 for event in _apply_directives(stream, ctxt, directives): 594 for event in _apply_directives(stream, ctxt, directives):
595 yield event 595 yield event
596 ctxt._choice_stack.pop() 596 ctxt._choice_stack.pop()
597 597
626 if not self.expr and not info[1]: 626 if not self.expr and not info[1]:
627 raise TemplateRuntimeError('either "choose" or "when" directive ' 627 raise TemplateRuntimeError('either "choose" or "when" directive '
628 'must have a test expression', 628 'must have a test expression',
629 self.filename, *stream.next()[2][1:]) 629 self.filename, *stream.next()[2][1:])
630 if info[1]: 630 if info[1]:
631 value = info[1] 631 value = info[2]
632 if self.expr: 632 if self.expr:
633 matched = value == self.expr.evaluate(ctxt) 633 matched = value == self.expr.evaluate(ctxt)
634 else: 634 else:
635 matched = bool(value) 635 matched = bool(value)
636 else: 636 else:
Copyright (C) 2012-2017 Edgewall Software