Benchanything's picture
Add 300 CheckerBench tasks, dataset card, and restoration tools (part 3)
8247f19 verified
Raw History Blame Contribute Delete
1.29 kB
diff --git a/templated_dictionary/__init__.py b/templated_dictionary/__init__.py
index 994166a..ec004c0 100644
--- a/templated_dictionary/__init__.py
+++ b/templated_dictionary/__init__.py
@@ -2,7 +2,7 @@
# vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:textwidth=0:
from collections.abc import MutableMapping
-import jinja2
+from jinja2 import sandbox
# pylint: disable=no-member,unsupported-assignment-operation
@@ -19,6 +19,8 @@ class TemplatedDictionary(MutableMapping):
'''
self.__dict__.update(*args, **kwargs)
+ self.sandbox = sandbox.SandboxedEnvironment(keep_trailing_newline=True)
+
self._aliases = {}
if alias_spec:
for aliased_to, aliases in alias_spec.items():
@@ -80,8 +82,7 @@ class TemplatedDictionary(MutableMapping):
orig = last = value
max_recursion = self.__dict__.get('jinja_max_recursion', 5)
for _ in range(max_recursion):
- template = jinja2.Template(value, keep_trailing_newline=True)
- value = _to_native(template.render(self.__dict__))
+ value = _to_native(self.sandbox.from_string(value).render(self.__dict__, func=lambda:None))
if value == last:
return value
last = value