better fix of recycle Response in template, thanks Anthony
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.00.0 (2012-08-24 23:37:07) dev
|
Version 2.00.0 (2012-08-24 23:47:44) dev
|
||||||
|
|||||||
+10
-10
@@ -903,12 +903,6 @@ def render(content = "hello world",
|
|||||||
>>> render(content='{{for i in range(3):\\n=i\\npass}}')
|
>>> render(content='{{for i in range(3):\\n=i\\npass}}')
|
||||||
'012'
|
'012'
|
||||||
"""
|
"""
|
||||||
# save current response class
|
|
||||||
if context and 'response' in context:
|
|
||||||
old_response = context['response']
|
|
||||||
else:
|
|
||||||
old_response = None
|
|
||||||
|
|
||||||
# here to avoid circular Imports
|
# here to avoid circular Imports
|
||||||
try:
|
try:
|
||||||
from globals import Response
|
from globals import Response
|
||||||
@@ -920,6 +914,14 @@ def render(content = "hello world",
|
|||||||
if not 'NOESCAPE' in context:
|
if not 'NOESCAPE' in context:
|
||||||
context['NOESCAPE'] = XML
|
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 we don't have anything to render, why bother?
|
||||||
if not content and not stream and not filename:
|
if not content and not stream and not filename:
|
||||||
raise SyntaxError, "Must specify a stream or filename or content"
|
raise SyntaxError, "Must specify a stream or filename or content"
|
||||||
@@ -934,9 +936,6 @@ def render(content = "hello world",
|
|||||||
elif content:
|
elif content:
|
||||||
stream = cStringIO.StringIO(content)
|
stream = cStringIO.StringIO(content)
|
||||||
|
|
||||||
# Get a response class.
|
|
||||||
context['response'] = Response()
|
|
||||||
|
|
||||||
# Execute the template.
|
# Execute the template.
|
||||||
code = str(TemplateParser(stream.read(), context=context, path=path, lexers=lexers, delimiters=delimiters))
|
code = str(TemplateParser(stream.read(), context=context, path=path, lexers=lexers, delimiters=delimiters))
|
||||||
try:
|
try:
|
||||||
@@ -950,7 +949,8 @@ def render(content = "hello world",
|
|||||||
|
|
||||||
# Returned the rendered content.
|
# Returned the rendered content.
|
||||||
text = context['response'].body.getvalue()
|
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
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user