From da2083ee3616a040a2477dcf56d5285294c86cac Mon Sep 17 00:00:00 2001 From: mdipierro Date: Fri, 24 Aug 2012 23:47:47 -0500 Subject: [PATCH] better fix of recycle Response in template, thanks Anthony --- VERSION | 2 +- gluon/template.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index ab9bd0d7..e2ae8483 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.00.0 (2012-08-24 23:37:07) dev +Version 2.00.0 (2012-08-24 23:47:44) dev diff --git a/gluon/template.py b/gluon/template.py index 72a75555..06d01023 100644 --- a/gluon/template.py +++ b/gluon/template.py @@ -903,12 +903,6 @@ def render(content = "hello world", >>> render(content='{{for i in range(3):\\n=i\\npass}}') '012' """ - # save current response class - if context and 'response' in context: - old_response = context['response'] - else: - old_response = None - # here to avoid circular Imports try: from globals import Response @@ -920,6 +914,14 @@ def render(content = "hello world", if not 'NOESCAPE' in context: context['NOESCAPE'] = XML + # save current response class + if context and 'response' in context: + old_response_body = context['response'].body + context['response'].body = cStringIO.StringIO() + else: + old_response_body = None + context['response'] = Response() + # If we don't have anything to render, why bother? if not content and not stream and not filename: raise SyntaxError, "Must specify a stream or filename or content" @@ -934,9 +936,6 @@ def render(content = "hello world", elif content: stream = cStringIO.StringIO(content) - # Get a response class. - context['response'] = Response() - # Execute the template. code = str(TemplateParser(stream.read(), context=context, path=path, lexers=lexers, delimiters=delimiters)) try: @@ -950,7 +949,8 @@ def render(content = "hello world", # Returned the rendered content. text = context['response'].body.getvalue() - if old_response is not None: context['response'] = old_response + if old_response_body is not None: + context['response'].body = old_response_body return text