File size: 1,288 Bytes
8247f19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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