aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mako/codegen.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-06-23 15:14:00 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-06-23 15:14:00 +0000
commita136efc13700d33862da16a54e411ec27d3941af (patch)
tree10b9ab0dd17be7e6ff65debd3e777c592d5c89d5 /lib/mako/codegen.py
parentef8bc186d2836443be92cbdc23aca887e1479de4 (diff)
downloadexternal_python_mako-a136efc13700d33862da16a54e411ec27d3941af.tar.gz
external_python_mako-a136efc13700d33862da16a54e411ec27d3941af.tar.bz2
external_python_mako-a136efc13700d33862da16a54e411ec27d3941af.zip
- fixed a critical issue regarding caching, whereby
a cached block would raise an error when called within a cache-refresh operation that was initiated after the initiating template had completed rendering.
Diffstat (limited to 'lib/mako/codegen.py')
-rw-r--r--lib/mako/codegen.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/mako/codegen.py b/lib/mako/codegen.py
index a9255f1..04ee339 100644
--- a/lib/mako/codegen.py
+++ b/lib/mako/codegen.py
@@ -11,7 +11,7 @@ import re
from mako.pygen import PythonPrinter
from mako import util, ast, parsetree, filters
-MAGIC_NUMBER = 3
+MAGIC_NUMBER = 4
def compile(node, uri, filename=None, default_filters=None, buffer_filters=None, imports=None, source_encoding=None, generate_unicode=True):
@@ -366,13 +366,26 @@ class _GenerateRenderMethod(object):
"context.caller_stack._pop_frame()",
None
)
+
if buffered or filtered or cached:
- self.printer.writelines(
- "finally:",
- "__M_buf, __M_writer = context._pop_buffer_and_writer()"
- )
+ if buffered or cached:
+ # in a caching scenario, don't try to get a writer
+ # from the context after popping - if the callable
+ # is called within a cache refresh operation, there's
+ # no more buffers on the stack
+ self.printer.writelines(
+ "finally:",
+ "__M_buf = context._pop_buffer()"
+ )
+ else:
+ self.printer.writelines(
+ "finally:",
+ "__M_buf, __M_writer = context._pop_buffer_and_writer()"
+ )
+
if callstack:
self.printer.writeline("context.caller_stack._pop_frame()")
+
s = "__M_buf.getvalue()"
if filtered:
s = self.create_filter_callable(node.filter_args.args, s, False)