diff options
| author | Chris McDonough <chrism@plope.com> | 2012-11-02 22:00:35 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2012-11-02 22:00:35 -0400 |
| commit | a007a4f5a7a6c81ef9bb15f4ccea35212bc020c0 (patch) | |
| tree | 696b1a8a0003b176080c359d94aced0386966504 | |
| parent | f156e1fdffb95cef721848a5a20cd7ec02157f0f (diff) | |
| download | pyramid-a007a4f5a7a6c81ef9bb15f4ccea35212bc020c0.tar.gz pyramid-a007a4f5a7a6c81ef9bb15f4ccea35212bc020c0.tar.bz2 pyramid-a007a4f5a7a6c81ef9bb15f4ccea35212bc020c0.zip | |
- In the past if a renderer returned ``None``, the body of the resulting
response would be set explicitly to the empty string. Instead, now, the body
is left unchanged, which allows the renderer to set a body itself by using
e.g. ``request.response.body = b'foo'``. The body set by the renderer will
be unmolested on the way out. See
https://github.com/Pylons/pyramid/issues/709
Closes #709
| -rw-r--r-- | CHANGES.txt | 10 | ||||
| -rw-r--r-- | pyramid/renderers.py | 12 | ||||
| -rw-r--r-- | pyramid/tests/test_renderers.py | 12 |
3 files changed, 26 insertions, 8 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 563851e74..0ef1a0593 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -21,6 +21,16 @@ Features it doesn't make sense to assert that a nonexistent view is execution-permitted. See https://github.com/Pylons/pyramid/issues/299. +Bug Fixes +--------- + +- In the past if a renderer returned ``None``, the body of the resulting + response would be set explicitly to the empty string. Instead, now, the body + is left unchanged, which allows the renderer to set a body itself by using + e.g. ``request.response.body = b'foo'``. The body set by the renderer will + be unmolested on the way out. See + https://github.com/Pylons/pyramid/issues/709 + 1.4a3 (2012-10-26) ================== diff --git a/pyramid/renderers.py b/pyramid/renderers.py index 57a61ebba..6839d72f5 100644 --- a/pyramid/renderers.py +++ b/pyramid/renderers.py @@ -573,13 +573,11 @@ class RendererHelper(object): response = response_factory() - if result is None: - result = '' - - if isinstance(result, text_type): - response.text = result - else: - response.body = result + if result is not None: + if isinstance(result, text_type): + response.text = result + else: + response.body = result if request is not None: # deprecated mechanism to set up request.response_* attrs, see diff --git a/pyramid/tests/test_renderers.py b/pyramid/tests/test_renderers.py index cb6c364a7..befb714bd 100644 --- a/pyramid/tests/test_renderers.py +++ b/pyramid/tests/test_renderers.py @@ -663,13 +663,23 @@ class TestRendererHelper(unittest.TestCase): response = helper._make_response(la.encode('utf-8'), request) self.assertEqual(response.body, la.encode('utf-8')) - def test__make_response_result_is_None(self): + def test__make_response_result_is_None_no_body(self): from pyramid.response import Response request = testing.DummyRequest() request.response = Response() helper = self._makeOne('loo.foo') response = helper._make_response(None, request) self.assertEqual(response.body, b'') + + def test__make_response_result_is_None_existing_body_not_molested(self): + from pyramid.response import Response + request = testing.DummyRequest() + response = Response() + response.body = b'abc' + request.response = response + helper = self._makeOne('loo.foo') + response = helper._make_response(None, request) + self.assertEqual(response.body, b'abc') def test__make_response_with_content_type(self): from pyramid.response import Response |
