Chris McDonough
2015-04-16 bedd5f21f6f2c7660824cf901c24a31cad8f737d
Merge branch 'master' of github.com:Pylons/pyramid
3 files modified
75 ■■■■ changed files
RELEASING.txt 10 ●●●●● patch | view | raw | blame | history
pyramid/renderers.py 23 ●●●●● patch | view | raw | blame | history
pyramid/tests/test_renderers.py 42 ●●●●● patch | view | raw | blame | history
RELEASING.txt
@@ -24,7 +24,9 @@
  communicate with contributors).
- Copy relevant changes (delta bug fixes) from CHANGES.txt to
  docs/whatsnew-X.X (if it's a major release).
  docs/whatsnew-X.X (if it's a major release).  Minor releases should
  include a link under "Bug Fix Releases" to the minor feature
  changes in CHANGES.txt .
- update README.rst to use correct versions of badges and URLs according to
  each branch and context, i.e., RTD "latest" == GitHub/Travis "1.x-branch".
@@ -49,6 +51,12 @@
  $ python setup.py sdist bdist_wheel
  $ twine upload dist/pyramid-X.X-*
- Edit Pylons/pylonshq/templates/home/home.mako for minor and major updates.
- Edit Pylons/pylonshq/templates/home/inside.rst for major updates only.
- Edit Pylons/pylonsrtd/pylonsrtd/docs/pyramid.rst for all updates.
- Edit `http://wiki.python.org/moin/WebFrameworks
  <http://wiki.python.org/moin/WebFrameworks>`_.
pyramid/renderers.py
@@ -142,25 +142,22 @@
    return result
_marker = object()
@contextlib.contextmanager
def temporary_response(request):
    """
    Temporarily delete request.response and restore it afterward.
    """
    saved_response = None
    # save the current response, preventing the renderer from affecting it
    attrs = request.__dict__ if request is not None else {}
    if 'response' in attrs:
        saved_response = attrs['response']
        del attrs['response']
    yield
    # restore the original response, overwriting any changes
    if saved_response is not None:
        attrs['response'] = saved_response
    elif 'response' in attrs:
        del attrs['response']
    saved_response = attrs.pop('response', _marker)
    try:
        yield
    finally:
        if saved_response is not _marker:
            attrs['response'] = saved_response
        elif 'response' in attrs:
            del attrs['response']
def get_renderer(renderer_name, package=None):
    """ Return the renderer object for the renderer ``renderer_name``.
pyramid/tests/test_renderers.py
@@ -592,6 +592,48 @@
        self.assertEqual(result.body, b'{"a": 1}')
        self.assertFalse('response' in request.__dict__)
class Test_temporary_response(unittest.TestCase):
    def _callFUT(self, request):
        from pyramid.renderers import temporary_response
        return temporary_response(request)
    def test_restores_response(self):
        request = testing.DummyRequest()
        orig_response = request.response
        with self._callFUT(request):
            request.response = object()
        self.assertEqual(request.response, orig_response)
    def test_restores_response_on_exception(self):
        request = testing.DummyRequest()
        orig_response = request.response
        try:
            with self._callFUT(request):
                request.response = object()
                raise RuntimeError()
        except RuntimeError:
            self.assertEqual(request.response, orig_response)
        else:                   # pragma: no cover
            self.fail("RuntimeError not raised")
    def test_restores_response_to_none(self):
        request = testing.DummyRequest(response=None)
        with self._callFUT(request):
            request.response = object()
        self.assertEqual(request.response, None)
    def test_deletes_response(self):
        request = testing.DummyRequest()
        with self._callFUT(request):
            request.response = object()
        self.assertTrue('response' not in request.__dict__)
    def test_does_not_delete_response_if_no_response_to_delete(self):
        request = testing.DummyRequest()
        with self._callFUT(request):
            pass
        self.assertTrue('response' not in request.__dict__)
class Test_get_renderer(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()