]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Stop use of .module in generated code
authorArmin Ronacher <armin.ronacher@active-4.com>
Wed, 28 Dec 2016 13:57:34 +0000 (14:57 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Wed, 28 Dec 2016 13:57:34 +0000 (14:57 +0100)
jinja2/compiler.py
jinja2/environment.py

index 09ad42b912aea89e45c6e5215e955db654df5112..f60769eacb41d9154656aec36fe7bff2b827d371 100644 (file)
@@ -976,7 +976,7 @@ class CodeGenerator(NodeVisitor):
                            'template.new_context(context.parent, True, '
                            'locals())):')
         else:
-            self.writeline('for event in template.module._body_stream:')
+            self.writeline('for event in template._get_default_module()._body_stream:')
 
         self.indent()
         self.simple_write('event', frame)
index 3b3dc4cc72bed8d6470b8bcd5275fb91bd7db029..6c9fc193eaf6650973f1d95ee3ac33386b343606 100644 (file)
@@ -1035,6 +1035,12 @@ class Template(object):
         """
         return TemplateModule(self, self.new_context(vars, shared, locals))
 
+    def _get_default_module(self):
+        if self._module is not None:
+            return self._module
+        self._module = rv = self.make_module()
+        return rv
+
     @property
     def module(self):
         """The template as module.  This is used for imports in the
@@ -1047,10 +1053,7 @@ class Template(object):
         >>> t.module.foo() == u'42'
         True
         """
-        if self._module is not None:
-            return self._module
-        self._module = rv = self.make_module()
-        return rv
+        return self._get_default_module()
 
     def get_corresponding_lineno(self, lineno):
         """Return the source line number of a line number in the