summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt5
-rw-r--r--pyramid/httpexceptions.py11
-rw-r--r--pyramid/tests/test_httpexceptions.py4
-rw-r--r--pyramid/tests/test_session.py13
4 files changed, 26 insertions, 7 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 9ed486b26..98fa7f85a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -201,6 +201,11 @@ Bug Fixes
default to an iterable instead of ``None``. It may be checked for a length
of 0. This was the behavior in 1.5.
+- ``pyramid.httpexceptions.HTTPException`` now defaults to
+ ``520 Unknown Error`` instead of ``None None`` to conform with changes in
+ WebOb 1.5.
+ See https://github.com/Pylons/pyramid/pull/1865
+
Deprecations
------------
diff --git a/pyramid/httpexceptions.py b/pyramid/httpexceptions.py
index 93d06e0d6..8bf9a0a72 100644
--- a/pyramid/httpexceptions.py
+++ b/pyramid/httpexceptions.py
@@ -160,6 +160,13 @@ class HTTPException(Response, Exception):
# 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:
#
@@ -178,8 +185,8 @@ class HTTPException(Response, Exception):
#
# - documentation improvements (Pyramid-specific docstrings where necessary)
#
- code = None
- title = None
+ code = 520
+ title = 'Unknown Error'
explanation = ''
body_template_obj = Template('''\
${explanation}${br}${br}
diff --git a/pyramid/tests/test_httpexceptions.py b/pyramid/tests/test_httpexceptions.py
index c700dc80e..b94ef30e4 100644
--- a/pyramid/tests/test_httpexceptions.py
+++ b/pyramid/tests/test_httpexceptions.py
@@ -120,7 +120,7 @@ class TestHTTPException(unittest.TestCase):
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 @@ class Test_HTTPMove(unittest.TestCase):
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):
diff --git a/pyramid/tests/test_session.py b/pyramid/tests/test_session.py
index b013ffa66..eac6593d9 100644
--- a/pyramid/tests/test_session.py
+++ b/pyramid/tests/test_session.py
@@ -1,3 +1,4 @@
+import base64
import json
import unittest
from pyramid import testing
@@ -277,7 +278,7 @@ class TestBaseCookieSession(SharedCookieSessionTests, unittest.TestCase):
return BaseCookieSessionFactory(serializer, **kw)(request)
def _serialize(self, value):
- return json.dumps(value)
+ return base64.b64encode(json.dumps(value).encode('utf-8'))
def test_reissue_not_triggered(self):
import time
@@ -650,10 +651,16 @@ class Test_check_csrf_token(unittest.TestCase):
class DummySerializer(object):
def dumps(self, value):
- return json.dumps(value).encode('utf-8')
+ return base64.b64encode(json.dumps(value).encode('utf-8'))
def loads(self, value):
- return json.loads(value.decode('utf-8'))
+ try:
+ return json.loads(base64.b64decode(value).decode('utf-8'))
+
+ # base64.b64decode raises a TypeError on py2 instead of a ValueError
+ # and a ValueError is required for the session to handle it properly
+ except TypeError:
+ raise ValueError
class DummySessionFactory(dict):
_dirty = False