From 88fcdc4e6a48f2646488565fbafd050f8e298ffa Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 3 Aug 2015 15:35:00 -0600 Subject: 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. --- pyramid/httpexceptions.py | 11 +++++++++-- pyramid/tests/test_httpexceptions.py | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) 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): -- cgit v1.2.3 From 10dd6084ff6ee3fd96e56a7a14f301855dc6f89f Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 3 Aug 2015 16:00:19 -0600 Subject: base64 encode cookie values This way they are valid according to the RFC, and newer versions of WebOb won't complain. --- pyramid/tests/test_session.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyramid/tests/test_session.py b/pyramid/tests/test_session.py index b013ffa66..2fd764e5e 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,10 @@ 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')) + return json.loads(base64.b64decode(value).decode('utf-8')) class DummySessionFactory(dict): _dirty = False -- cgit v1.2.3 From bb494a32d77b4f36473bece91cfaf8cf17c4bc07 Mon Sep 17 00:00:00 2001 From: Alexandre Conrad Date: Mon, 24 Aug 2015 20:42:26 -0700 Subject: document +dot+ for dotfiles in scaffolds --- docs/narr/scaffolding.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/narr/scaffolding.rst b/docs/narr/scaffolding.rst index f924d0d62..4fcdeb537 100644 --- a/docs/narr/scaffolding.rst +++ b/docs/narr/scaffolding.rst @@ -57,6 +57,11 @@ As you create files and directories within the template directory, note that: have that string replaced with the value of the ``var`` variable provided to the scaffold. +- Files that start with a dot (e.g., ``.env``) are ignored and will not be + copied over to the destination directory. If you want to include a file with + a leading dot then you must replace the dot with ``+dot+`` (e.g., + ``+dot+env``). + Otherwise, files and directories which live in the template directory will be copied directly without modification to the ``pcreate`` output location. -- cgit v1.2.3 From a512769644eb6e9773d9805a5fe4dfc85e31ded9 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 31 Aug 2015 01:54:35 -0700 Subject: move extra credit question about @forbidden_view_config from authentication to authorization --- docs/quick_tutorial/authentication.rst | 3 --- docs/quick_tutorial/authorization.rst | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/quick_tutorial/authentication.rst b/docs/quick_tutorial/authentication.rst index a4ab83c45..7fd8173d4 100644 --- a/docs/quick_tutorial/authentication.rst +++ b/docs/quick_tutorial/authentication.rst @@ -123,9 +123,6 @@ Extra Credit #. Can I use a database behind my ``groupfinder`` to look up principals? -#. Do I have to put a ``renderer`` in my ``@forbidden_view_config`` - decorator? - #. Once I am logged in, does any user-centric information get jammed onto each request? Use ``import pdb; pdb.set_trace()`` to answer this. diff --git a/docs/quick_tutorial/authorization.rst b/docs/quick_tutorial/authorization.rst index 08df15a28..855043f7f 100644 --- a/docs/quick_tutorial/authorization.rst +++ b/docs/quick_tutorial/authorization.rst @@ -101,6 +101,9 @@ by decorating the view with ``@forbidden_view_config``. Extra Credit ============ +#. Do I have to put a ``renderer`` in my ``@forbidden_view_config`` + decorator? + #. Perhaps you would like the experience of not having enough permissions (forbidden) to be richer. How could you change this? -- cgit v1.2.3 From e0a230a8006c11097469510c47a84fd9b107b748 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Mon, 31 Aug 2015 10:09:27 -0500 Subject: update changelog --- CHANGES.txt | 5 +++++ 1 file changed, 5 insertions(+) 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 ------------ -- cgit v1.2.3 From 5b5d5ed4c011ef71258a2c34463c6fe3821dab40 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Mon, 31 Aug 2015 11:30:01 -0500 Subject: fix difference between py2 and py3 with base64.b64decode --- pyramid/tests/test_session.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyramid/tests/test_session.py b/pyramid/tests/test_session.py index 2fd764e5e..eac6593d9 100644 --- a/pyramid/tests/test_session.py +++ b/pyramid/tests/test_session.py @@ -654,7 +654,13 @@ class DummySerializer(object): return base64.b64encode(json.dumps(value).encode('utf-8')) def loads(self, value): - return json.loads(base64.b64decode(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 -- cgit v1.2.3 From 82862ba554ff97932b5f6745c8e6b022dcdfe18c Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Tue, 1 Sep 2015 02:42:05 -0700 Subject: - add pylonswebframework to intersphinx config, sort entries so they can be found (meh! 79 char columns) - replace final pylonshq reference with RTD reference --- docs/conf.py | 41 ++++++++++++++--------------------------- docs/narr/i18n.rst | 7 +++---- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 11e42c5f3..8a9bac6ed 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -58,37 +58,24 @@ extensions = [ # Looks for objects in external projects intersphinx_mapping = { - 'tutorials': ('http://docs.pylonsproject.org/projects/pyramid-tutorials/en/latest/', None), + 'colander': ( 'http://docs.pylonsproject.org/projects/colander/en/latest', None), 'cookbook': ('http://docs.pylonsproject.org/projects/pyramid-cookbook/en/latest/', None), + 'deform': ('http://docs.pylonsproject.org/projects/deform/en/latest', None), 'jinja2': ('http://docs.pylonsproject.org/projects/pyramid-jinja2/en/latest/', None), - 'tm': ( - 'http://docs.pylonsproject.org/projects/pyramid_tm/en/latest/', - None, - ), - 'zcomponent': ('http://docs.zope.org/zope.component', None), - 'webtest': ('http://webtest.pythonpaste.org/en/latest', None), - 'webob': ('http://docs.webob.org/en/latest', None), - 'colander': ( - 'http://docs.pylonsproject.org/projects/colander/en/latest', - None), - 'deform': ( - 'http://docs.pylonsproject.org/projects/deform/en/latest', - None), - 'sqla': ('http://docs.sqlalchemy.org/en/latest', None), - 'who': ('http://repozewho.readthedocs.org/en/latest', None), + 'pylonswebframework': ('http://docs.pylonsproject.org/projects/pylons-webframework/en/latest/', None), 'python': ('http://docs.python.org', None), 'python3': ('http://docs.python.org/3', None), - 'tstring': - ('http://docs.pylonsproject.org/projects/translationstring/en/latest', - None), - 'venusian': - ('http://docs.pylonsproject.org/projects/venusian/en/latest', None), - 'toolbar': - ('http://docs.pylonsproject.org/projects/pyramid-debugtoolbar/en/latest', - None), - 'zcml': - ('http://docs.pylonsproject.org/projects/pyramid-zcml/en/latest', - None), + 'sqla': ('http://docs.sqlalchemy.org/en/latest', None), + 'tm': ('http://docs.pylonsproject.org/projects/pyramid_tm/en/latest/', None), + 'toolbar': ('http://docs.pylonsproject.org/projects/pyramid-debugtoolbar/en/latest', None), + 'tstring': ('http://docs.pylonsproject.org/projects/translationstring/en/latest', None), + 'tutorials': ('http://docs.pylonsproject.org/projects/pyramid-tutorials/en/latest/', None), + 'venusian': ('http://docs.pylonsproject.org/projects/venusian/en/latest', None), + 'webob': ('http://docs.webob.org/en/latest', None), + 'webtest': ('http://webtest.pythonpaste.org/en/latest', None), + 'who': ('http://repozewho.readthedocs.org/en/latest', None), + 'zcml': ('http://docs.pylonsproject.org/projects/pyramid-zcml/en/latest', None), + 'zcomponent': ('http://docs.zope.org/zope.component', None), } diff --git a/docs/narr/i18n.rst b/docs/narr/i18n.rst index 3c804a158..8d81418d9 100644 --- a/docs/narr/i18n.rst +++ b/docs/narr/i18n.rst @@ -219,10 +219,9 @@ by creating various kinds of gettext files. The steps a developer must take to work with :term:`gettext` :term:`message catalog` files within a :app:`Pyramid` application are very similar to the steps a :term:`Pylons` - developer must take to do the same. See the `Pylons - internationalization documentation - `_ - for more information. + developer must take to do the same. See the :ref:`Pylons + Internationalization and Localization documentation + ` for more information. GNU gettext uses three types of files in the translation framework, ``.pot`` files, ``.po`` files and ``.mo`` files. -- cgit v1.2.3