|
16 | 16 | from mako import filters |
17 | 17 | from mako import parsetree |
18 | 18 | from mako import util |
19 | | -from mako.filters import DEFAULT_ESCAPE_PREFIX |
20 | 19 | from mako.pygen import PythonPrinter |
21 | 20 |
|
22 | 21 |
|
|
27 | 26 | # context itself |
28 | 27 | TOPLEVEL_DECLARED = {"UNDEFINED", "STOP_RENDERING"} |
29 | 28 | RESERVED_NAMES = {"context", "loop"}.union(TOPLEVEL_DECLARED) |
30 | | -DEFAULT_ESCAPED_N = "%sn" % DEFAULT_ESCAPE_PREFIX |
31 | 29 |
|
32 | 30 |
|
33 | 31 | def compile( # noqa |
@@ -524,7 +522,6 @@ def write_variable_declares(self, identifiers, toplevel=False, limit=None): |
524 | 522 | self.printer.writeline("loop = __M_loop = runtime.LoopStack()") |
525 | 523 |
|
526 | 524 | for ident in to_write: |
527 | | - ident = ident.replace(DEFAULT_ESCAPE_PREFIX, "") |
528 | 525 | if ident in comp_idents: |
529 | 526 | comp = comp_idents[ident] |
530 | 527 | if comp.is_block: |
@@ -788,48 +785,25 @@ def locate_encode(name): |
788 | 785 | else: |
789 | 786 | return filters.DEFAULT_ESCAPES.get(name, name) |
790 | 787 |
|
791 | | - filter_args = set() |
792 | | - if DEFAULT_ESCAPED_N not in args: |
| 788 | + if "n" not in args: |
793 | 789 | if is_expression: |
794 | 790 | if self.compiler.pagetag: |
795 | 791 | args = self.compiler.pagetag.filter_args.args + args |
796 | | - filter_args = set(self.compiler.pagetag.filter_args.args) |
797 | | - if ( |
798 | | - self.compiler.default_filters |
799 | | - and DEFAULT_ESCAPED_N not in args |
800 | | - ): |
| 792 | + if self.compiler.default_filters and "n" not in args: |
801 | 793 | args = self.compiler.default_filters + args |
802 | 794 | for e in args: |
803 | | - if e == DEFAULT_ESCAPED_N: |
804 | | - continue |
805 | | - |
806 | | - if e.startswith(DEFAULT_ESCAPE_PREFIX): |
807 | | - render_e = e.replace(DEFAULT_ESCAPE_PREFIX, "") |
808 | | - is_default_filter = True |
809 | | - else: |
810 | | - render_e = e |
811 | | - is_default_filter = False |
812 | | - |
813 | 795 | # if filter given as a function, get just the identifier portion |
| 796 | + if e == "n": |
| 797 | + continue |
814 | 798 | m = re.match(r"(.+?)(\(.*\))", e) |
815 | 799 | if m: |
816 | | - if not is_default_filter: |
817 | | - ident, fargs = m.group(1, 2) |
818 | | - f = locate_encode(ident) |
819 | | - render_e = f + fargs |
820 | | - target = "%s(%s)" % (render_e, target) |
821 | | - elif is_default_filter and e not in filter_args: |
822 | | - target = "%s(%s) if %s is not UNDEFINED else %s(%s)" % ( |
823 | | - render_e, |
824 | | - target, |
825 | | - render_e, |
826 | | - locate_encode(render_e), |
827 | | - target, |
828 | | - ) |
| 800 | + ident, fargs = m.group(1, 2) |
| 801 | + f = locate_encode(ident) |
| 802 | + e = f + fargs |
829 | 803 | else: |
830 | | - e = locate_encode(render_e) |
| 804 | + e = locate_encode(e) |
831 | 805 | assert e is not None |
832 | | - target = "%s(%s)" % (e, target) |
| 806 | + target = "%s(%s)" % (e, target) |
833 | 807 | return target |
834 | 808 |
|
835 | 809 | def visitExpression(self, node): |
|
0 commit comments