Coverage for documents/templating/environment.py: 58%

10 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 09:07 +0000

1from jinja2.sandbox import SandboxedEnvironment 

2 

3 

4class JinjaEnvironment(SandboxedEnvironment): 

5 def __init__(self, *args, **kwargs): 

6 super().__init__(*args, **kwargs) 

7 self.undefined_tracker = None 

8 

9 def is_safe_callable(self, obj): 

10 # Block access to .save() and .delete() methods 

11 if callable(obj) and getattr(obj, "__name__", None) in ( 

12 "save", 

13 "delete", 

14 "update", 

15 ): 

16 return False 

17 # Call the parent method for other cases 

18 return super().is_safe_callable(obj) 

19 

20 

21_template_environment = JinjaEnvironment( 

22 trim_blocks=True, 

23 lstrip_blocks=True, 

24 keep_trailing_newline=False, 

25 autoescape=False, 

26 extensions=["jinja2.ext.loopcontrols"], 

27)