Lines Matching refs:env
38 def test_unsafe(self, env): argument
39 env = SandboxedEnvironment()
41 SecurityError, env.from_string("{{ foo.foo() }}").render, foo=PrivateStuff()
43 assert env.from_string("{{ foo.bar() }}").render(foo=PrivateStuff()) == "23"
46 SecurityError, env.from_string("{{ foo._foo() }}").render, foo=PublicStuff()
48 assert env.from_string("{{ foo.bar() }}").render(foo=PublicStuff()) == "23"
49 assert env.from_string("{{ foo.__class__ }}").render(foo=42) == ""
50 assert env.from_string("{{ foo.func_code }}").render(foo=lambda: None) == ""
54 env.from_string("{{ foo.__class__.__subclasses__() }}").render,
58 def test_immutable_environment(self, env): argument
59 env = ImmutableSandboxedEnvironment()
60 pytest.raises(SecurityError, env.from_string("{{ [].append(23) }}").render)
61 pytest.raises(SecurityError, env.from_string("{{ {1:2}.clear() }}").render)
63 def test_restricted(self, env): argument
64 env = SandboxedEnvironment()
67 env.from_string,
72 env.from_string,
76 def test_template_data(self, env): argument
77 env = Environment(autoescape=True)
78 t = env.from_string(
89 escape(t.module.say_hello(EvalContext(env), "<blink>foo</blink>"))
94 def test_attr_filter(self, env): argument
95 env = SandboxedEnvironment()
96 tmpl = env.from_string('{{ cls|attr("__subclasses__")() }}')
99 def test_binary_operator_intercepting(self, env): argument
104 env = SandboxedEnvironment()
105 env.binop_table["+"] = disable_op
106 t = env.from_string(f"{{{{ {expr} }}}}")
108 env.intercepted_binops = frozenset(["+"])
109 t = env.from_string(f"{{{{ {expr} }}}}")
113 def test_unary_operator_intercepting(self, env): argument
118 env = SandboxedEnvironment()
119 env.unop_table["-"] = disable_op
120 t = env.from_string(f"{{{{ {expr} }}}}")
122 env.intercepted_unops = frozenset(["-"])
123 t = env.from_string(f"{{{{ {expr} }}}}")
130 env = SandboxedEnvironment()
131 t = env.from_string('{{ "a{0.__class__}b".format(42) }}')
135 env = SandboxedEnvironment()
136 t = env.from_string('{{ "a{0.foo}b".format({"foo": 42}) }}')
140 env = SandboxedEnvironment()
141 t = env.from_string('{{ ("a{0.__class__}b{1}"|safe).format(42, "<foo>") }}')
145 env = SandboxedEnvironment()
146 t = env.from_string('{{ ("a{0.foo}b{1}"|safe).format({"foo": 42}, "<foo>") }}')
150 env = SandboxedEnvironment()
151 t1 = env.from_string('{{ ("a{}b{}").format("foo", "42")}}')
152 t2 = env.from_string('{{ ("a{}b{}"|safe).format(42, "<foo>") }}')
159 env = SandboxedEnvironment()
160 t = env.from_string('{{ "a{x.__class__}b".format_map({"x":42}) }}')
164 env = SandboxedEnvironment()
165 t = env.from_string('{{ "a{x.foo}b".format_map({"x":{"foo": 42}}) }}')
169 env = SandboxedEnvironment()
170 t = env.from_string(