Bert JW Regeer
2015-08-03 af03335162ede632d53eac29638dda5ef6e92dbc
Fix Pyramid against WebOb >=1.5.0

Due to changes in WebOb we may no longer create a Response() object with
an invalid status (i.e. 'None None'). For the top-level HTTPException if
it is not correctly overriden in child classes then we now use '520
Unknown Error'.

While not an official RFC error, this has been used by Microsoft's Azure
as well as CloudFlare to signify an error that doesn't have a more
appropriate error message.
2 files modified
15 ■■■■ changed files
pyramid/httpexceptions.py 11 ●●●● patch | view | raw | blame | history
pyramid/tests/test_httpexceptions.py 4 ●●●● patch | view | raw | blame | history
pyramid/httpexceptions.py
@@ -158,6 +158,13 @@
    # title = 'OK'
    # explanation = 'why this happens'
    # body_template_obj = Template('response template')
    #
    # This class itself uses the error code "520" with the error message/title
    # of "Unknown Error". This is not an RFC standard, however it is
    # implemented in practice. Sub-classes should be overriding the default
    # values and 520 should not be seen in the wild from Pyramid applications.
    # Due to changes in WebOb, a code of "None" is not valid, and WebOb due to
    # more strict error checking rejects it now.
    # differences from webob.exc.WSGIHTTPException:
    #
@@ -176,8 +183,8 @@
    #
    # - documentation improvements (Pyramid-specific docstrings where necessary)
    #
    code = None
    title = None
    code = 520
    title = 'Unknown Error'
    explanation = ''
    body_template_obj = Template('''\
${explanation}${br}${br}
pyramid/tests/test_httpexceptions.py
@@ -120,7 +120,7 @@
    def test_ctor_calls_Response_ctor(self):
        exc = self._makeOne('message')
        self.assertEqual(exc.status, 'None None')
        self.assertEqual(exc.status, '520 Unknown Error')
    def test_ctor_extends_headers(self):
        exc = self._makeOne(headers=[('X-Foo', 'foo')])
@@ -329,7 +329,7 @@
        start_response = DummyStartResponse()
        app_iter = exc(environ, start_response)
        self.assertEqual(app_iter[0],
                         (b'None None\n\nThe resource has been moved to foo; '
                         (b'520 Unknown Error\n\nThe resource has been moved to foo; '
                          b'you should be redirected automatically.\n\n'))
class TestHTTPForbidden(unittest.TestCase):