Mercurial > genshi > genshi-test
comparison genshi/template/directives.py @ 935:705727288d7e
Merge r1143 from py3k:
add support for python 3 to remaining genshi.template components:
* minor changes to track encoding=None API change in core genshi modules.
* genshi/template/directives:
* slightly odd syntax changes to make the 2to3 .next() fixer pick up *stream.next()
* minor test fix for change in behaviour of division (/) in Python 3.
* genshi/template/loader:
* add 'b' to file modes to ensure it's loaded as bytes in Python 3.
* use not isinstance(s, unicode) instead of isinstance(s, str) since the former is correctly converted by 2to3.
author | hodgestar |
---|---|
date | Fri, 18 Mar 2011 09:17:52 +0000 |
parents | 2772fa7c10a3 |
children |
comparison
equal
deleted
inserted
replaced
934:7c9ec79caedc | 935:705727288d7e |
---|---|
620 def __call__(self, stream, directives, ctxt, **vars): | 620 def __call__(self, stream, directives, ctxt, **vars): |
621 info = ctxt._choice_stack and ctxt._choice_stack[-1] | 621 info = ctxt._choice_stack and ctxt._choice_stack[-1] |
622 if not info: | 622 if not info: |
623 raise TemplateRuntimeError('"when" directives can only be used ' | 623 raise TemplateRuntimeError('"when" directives can only be used ' |
624 'inside a "choose" directive', | 624 'inside a "choose" directive', |
625 self.filename, *stream.next()[2][1:]) | 625 self.filename, *(stream.next())[2][1:]) |
626 if info[0]: | 626 if info[0]: |
627 return [] | 627 return [] |
628 if not self.expr and not info[1]: | 628 if not self.expr and not info[1]: |
629 raise TemplateRuntimeError('either "choose" or "when" directive ' | 629 raise TemplateRuntimeError('either "choose" or "when" directive ' |
630 'must have a test expression', | 630 'must have a test expression', |
631 self.filename, *stream.next()[2][1:]) | 631 self.filename, *(stream.next())[2][1:]) |
632 if info[1]: | 632 if info[1]: |
633 value = info[2] | 633 value = info[2] |
634 if self.expr: | 634 if self.expr: |
635 matched = value == _eval_expr(self.expr, ctxt, vars) | 635 matched = value == _eval_expr(self.expr, ctxt, vars) |
636 else: | 636 else: |
659 def __call__(self, stream, directives, ctxt, **vars): | 659 def __call__(self, stream, directives, ctxt, **vars): |
660 info = ctxt._choice_stack and ctxt._choice_stack[-1] | 660 info = ctxt._choice_stack and ctxt._choice_stack[-1] |
661 if not info: | 661 if not info: |
662 raise TemplateRuntimeError('an "otherwise" directive can only be ' | 662 raise TemplateRuntimeError('an "otherwise" directive can only be ' |
663 'used inside a "choose" directive', | 663 'used inside a "choose" directive', |
664 self.filename, *stream.next()[2][1:]) | 664 self.filename, *(stream.next())[2][1:]) |
665 if info[0]: | 665 if info[0]: |
666 return [] | 666 return [] |
667 info[0] = True | 667 info[0] = True |
668 | 668 |
669 return _apply_directives(stream, directives, ctxt, vars) | 669 return _apply_directives(stream, directives, ctxt, vars) |