diff options
| author | Bert JW Regeer <xistence@0x58.com> | 2017-02-09 18:13:09 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-02-09 18:13:09 -0700 |
| commit | 40d71e805bfcf8522c6af71995c05c496f1c4b4f (patch) | |
| tree | e46bf79d1a8811ad273a40ce194d05836fcc7409 | |
| parent | a6de1c854b0ca7c71a6b4a283c2a89519808d434 (diff) | |
| parent | 564b63771ae370fafe059c5cf8e4a6bd7a1a5853 (diff) | |
| download | pyramid-40d71e805bfcf8522c6af71995c05c496f1c4b4f.tar.gz pyramid-40d71e805bfcf8522c6af71995c05c496f1c4b4f.tar.bz2 pyramid-40d71e805bfcf8522c6af71995c05c496f1c4b4f.zip | |
Merge pull request #2951 from Pylons/bugfix/httpexception__str__
Bugfix: pyramid.httpexception.HTTPException.__str __
| -rw-r--r-- | CHANGES.txt | 4 | ||||
| -rw-r--r-- | pyramid/httpexceptions.py | 2 | ||||
| -rw-r--r-- | pyramid/tests/test_httpexceptions.py | 6 |
3 files changed, 11 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 218fea289..59a733bcd 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -7,6 +7,10 @@ Features Bug Fixes --------- +- 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 + Deprecations ------------ diff --git a/pyramid/httpexceptions.py b/pyramid/httpexceptions.py index a22b088c6..1f3934fdc 100644 --- a/pyramid/httpexceptions.py +++ b/pyramid/httpexceptions.py @@ -238,7 +238,7 @@ ${body}''') 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, diff --git a/pyramid/tests/test_httpexceptions.py b/pyramid/tests/test_httpexceptions.py index 224fa4cf0..e2d463008 100644 --- a/pyramid/tests/test_httpexceptions.py +++ b/pyramid/tests/test_httpexceptions.py @@ -2,6 +2,7 @@ import unittest from pyramid.compat import ( bytes_, + string_types, text_, ) @@ -364,6 +365,11 @@ class TestHTTPException(unittest.TestCase): 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 |
