Bert JW Regeer
2017-02-10 def87036ffadb53ce9009861128c4f743d3bb36e
Merge pull request #2956 from Pylons/bugfix/httpexception__str__-1.7

(BP: 1.7) Bugfix: httpexception __str__

Backport of https://github.com/Pylons/pyramid/pull/2956
3 files modified
15 ■■■■■ changed files
CHANGES.txt 7 ●●●●● patch | view | raw | blame | history
pyramid/httpexceptions.py 2 ●●● patch | view | raw | blame | history
pyramid/tests/test_httpexceptions.py 6 ●●●●● patch | view | raw | blame | history
CHANGES.txt
@@ -1,5 +1,12 @@
.. _changes_1.7.4:
Unreleased
==========
- HTTPException's accepts a detail kwarg that may be used to pass additional
  details to the exception. You may now pass objects so long as they have a
  valid __str__ method. See https://github.com/Pylons/pyramid/pull/2951
1.7.4 (2017-01-24)
==================
pyramid/httpexceptions.py
@@ -235,7 +235,7 @@
            del self.content_length
    def __str__(self):
        return self.detail or self.explanation
        return str(self.detail) if self.detail else self.explanation
    def _json_formatter(self, status, body, title, environ):
        return {'message': body,
pyramid/tests/test_httpexceptions.py
@@ -2,6 +2,7 @@
from pyramid.compat import (
    bytes_,
    string_types,
    text_,
    )
@@ -364,6 +365,11 @@
        body = list(exc(environ, start_response))[0]
        self.assertEqual(body, b'200 OK\n\n/La Pe\xc3\xb1a')
    def test_allow_detail_non_str(self):
        exc = self._makeOne(detail={'error': 'This is a test'})
        self.assertIsInstance(exc.__str__(), string_types)
class TestRenderAllExceptionsWithoutArguments(unittest.TestCase):
    def _doit(self, content_type):
        from pyramid.httpexceptions import status_map