Commit e1b5bdea authored by Malthe Borch's avatar Malthe Borch

Backport changeset committed to trunk in r121131.

parent dda24a1c
...@@ -11,6 +11,10 @@ http://docs.zope.org/zope2/releases/. ...@@ -11,6 +11,10 @@ http://docs.zope.org/zope2/releases/.
Bugs Fixed Bugs Fixed
++++++++++ ++++++++++
- Fix `WSGIResponse` and `publish_module` functions such that they
support the `IStreamIterator` interface in addition to `file` (as
supported by `ZServer.HTTPResponse`).
- Corrected copyright information shown in the ZMI. - Corrected copyright information shown in the ZMI.
- OFS: Fixed editing offset-naive 'date' properties in the ZMI. - OFS: Fixed editing offset-naive 'date' properties in the ZMI.
......
...@@ -30,6 +30,7 @@ from ZPublisher.Publish import call_object ...@@ -30,6 +30,7 @@ from ZPublisher.Publish import call_object
from ZPublisher.Publish import dont_publish_class from ZPublisher.Publish import dont_publish_class
from ZPublisher.Publish import get_module_info from ZPublisher.Publish import get_module_info
from ZPublisher.Publish import missing_name from ZPublisher.Publish import missing_name
from ZPublisher.Iterators import IStreamIterator
_NOW = None # overwrite for testing _NOW = None # overwrite for testing
def _now(): def _now():
...@@ -125,7 +126,7 @@ class WSGIResponse(HTTPResponse): ...@@ -125,7 +126,7 @@ class WSGIResponse(HTTPResponse):
self.stdout.write(data) self.stdout.write(data)
def setBody(self, body, title='', is_error=0): def setBody(self, body, title='', is_error=0):
if isinstance(body, file): if isinstance(body, file) or IStreamIterator.providedBy(body):
body.seek(0, 2) body.seek(0, 2)
length = body.tell() length = body.tell()
body.seek(0) body.seek(0)
...@@ -226,8 +227,10 @@ def publish_module(environ, start_response, ...@@ -226,8 +227,10 @@ def publish_module(environ, start_response,
status, headers = response.finalize() status, headers = response.finalize()
start_response(status, headers) start_response(status, headers)
if isinstance(response.body, file): body = response.body
result = response.body
if isinstance(body, file) or IStreamIterator.providedBy(body):
result = body
else: else:
# If somebody used response.write, that data will be in the # If somebody used response.write, that data will be in the
# stdout StringIO, so we put that before the body. # stdout StringIO, so we put that before the body.
......
...@@ -370,6 +370,32 @@ class Test_publish_module(unittest.TestCase): ...@@ -370,6 +370,32 @@ class Test_publish_module(unittest.TestCase):
app_iter = self._callFUT(environ, start_response, _publish) app_iter = self._callFUT(environ, start_response, _publish)
self.assertTrue(app_iter is body) self.assertTrue(app_iter is body)
def test_response_is_stream(self):
from ZPublisher.Iterators import IStreamIterator
from zope.interface import implements
class test_streamiterator:
implements(IStreamIterator)
data = "hello"
done = 0
def next(self):
if not self.done:
self.done = 1
return self.data
raise StopIteration
_response = DummyResponse()
_response._status = '200 OK'
_response._headers = [('Content-Length', '4')]
body = _response.body = test_streamiterator()
environ = self._makeEnviron()
start_response = DummyCallable()
_publish = DummyCallable()
_publish._result = _response
app_iter = self._callFUT(environ, start_response, _publish)
self.assertTrue(app_iter is body)
def test_request_closed_when_tm_middleware_not_active(self): def test_request_closed_when_tm_middleware_not_active(self):
environ = self._makeEnviron() environ = self._makeEnviron()
start_response = DummyCallable() start_response = DummyCallable()
......
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