Commit af09790a authored by Hanno Schlichting's avatar Hanno Schlichting

Simplify new _publish_wsgi function.

parent 6b0f04d5
...@@ -262,8 +262,7 @@ def publish(request, module_info): ...@@ -262,8 +262,7 @@ def publish(request, module_info):
return response return response
def _publish_wsgi(request, response, module_info, start_response, stdout, def _publish_response(request, response, module_info, _publish=publish):
_publish=publish):
try: try:
with transaction_pubevents(request): with transaction_pubevents(request):
response = _publish(request, module_info) response = _publish(request, module_info)
...@@ -274,18 +273,7 @@ def _publish_wsgi(request, response, module_info, start_response, stdout, ...@@ -274,18 +273,7 @@ def _publish_wsgi(request, response, module_info, start_response, stdout,
# middleware, maybe it should be handled here. # middleware, maybe it should be handled here.
response.redirect(exc) response.redirect(exc)
# Start the WSGI server response return response
status, headers = response.finalize()
start_response(status, headers)
if (isinstance(response.body, IOBase) or
IUnboundStreamIterator.providedBy(response.body)):
result = response.body
else:
# If somebody used response.write, that data will be in the
# stdout StringIO, so we put that before the body.
result = (stdout.getvalue(), response.body)
return (response, result)
def publish_module(environ, start_response, def publish_module(environ, start_response,
...@@ -309,10 +297,8 @@ def publish_module(environ, start_response, ...@@ -309,10 +297,8 @@ def publish_module(environ, start_response,
for i in range(getattr(request, 'retry_max_count', 3) + 1): for i in range(getattr(request, 'retry_max_count', 3) + 1):
try: try:
response, result = _publish_wsgi( response = _publish_response(
request, response, request, response, module_info, _publish=_publish)
module_info, start_response,
stdout, _publish=_publish)
break break
except (ConflictError, TransientError) as exc: except (ConflictError, TransientError) as exc:
if request.supports_retry(): if request.supports_retry():
...@@ -325,6 +311,18 @@ def publish_module(environ, start_response, ...@@ -325,6 +311,18 @@ def publish_module(environ, start_response,
finally: finally:
request.close() request.close()
# Start the WSGI server response
status, headers = response.finalize()
start_response(status, headers)
if (isinstance(response.body, IOBase) or
IUnboundStreamIterator.providedBy(response.body)):
result = response.body
else:
# If somebody used response.write, that data will be in the
# stdout StringIO, so we put that before the body.
result = (stdout.getvalue(), response.body)
for func in response.after_list: for func in response.after_list:
func() func()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment