From c7e3c6605428656c893c394684135637c4636733 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Thu, 5 Apr 2018 17:39:06 -0600 Subject: [PATCH 1/5] Add .cache folder to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fe132412a2..2fe3b3386d 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ jyenv/ pypyenv/ env*/ venv/ +.cache/ From 21882e4e11a61b9ec639407adb0f67784d2b50b3 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Thu, 5 Apr 2018 17:39:27 -0600 Subject: [PATCH 2/5] Depend on newer version of WebOb Also sort all of the dependencies --- setup.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/setup.py b/setup.py index cdad8c6353..1873612c58 100644 --- a/setup.py +++ b/setup.py @@ -11,47 +11,49 @@ # FITNESS FOR A PARTICULAR PURPOSE # ############################################################################## -from setuptools import setup, find_packages +from setuptools import find_packages, setup + def readfile(name): with open(name) as f: return f.read() + README = readfile('README.rst') CHANGES = readfile('CHANGES.rst') install_requires = [ - 'setuptools', - 'WebOb >= 1.7.0', # Response.has_body - 'zope.interface >= 3.8.0', # has zope.interface.registry - 'zope.deprecation >= 3.5.0', # py3 compat - 'venusian >= 1.0', # ``ignore`` - 'translationstring >= 0.4', # py3 compat + 'hupper', 'plaster', 'plaster_pastedeploy', - 'hupper', - ] + 'setuptools', + 'translationstring >= 0.4', # py3 compat + 'venusian >= 1.0', # ``ignore`` + 'webob >= 1.8.0', # acceptparse.create_accept_header + 'zope.deprecation >= 3.5.0', # py3 compat + 'zope.interface >= 3.8.0', # has zope.interface.registry +] tests_require = [ - 'WebTest >= 1.3.1', # py3 compat - 'zope.component >= 4.0', # py3 compat - ] + 'webtest >= 1.3.1', # py3 compat + 'zope.component >= 4.0', # py3 compat +] docs_extras = [ 'Sphinx >= 1.7.4', 'docutils', - 'repoze.sphinx.autointerface', - 'pylons_sphinx_latesturl', 'pylons-sphinx-themes', + 'pylons_sphinx_latesturl', + 'repoze.sphinx.autointerface', 'sphinxcontrib-autoprogram', - ] +] testing_extras = tests_require + [ - 'nose', 'coverage', + 'nose', 'virtualenv', # for scaffolding tests - ] +] setup(name='pyramid', version='1.10.dev0', @@ -87,7 +89,7 @@ def readfile(name): ':python_version<"3.2"': ['repoze.lru >= 0.4'], 'testing': testing_extras, 'docs': docs_extras, - }, + }, tests_require=tests_require, test_suite="pyramid.tests", entry_points="""\ From 62dbd4554223e4980730c1fb459f5aaf8f946608 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Thu, 5 Apr 2018 17:44:08 -0600 Subject: [PATCH 3/5] Add failing test for MIMEAccept in httpexceptions --- pyramid/tests/test_httpexceptions.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pyramid/tests/test_httpexceptions.py b/pyramid/tests/test_httpexceptions.py index e2d4630085..ed6c41e0e2 100644 --- a/pyramid/tests/test_httpexceptions.py +++ b/pyramid/tests/test_httpexceptions.py @@ -283,6 +283,17 @@ def test__content_type_application_json(self): if header[0] == 'Content-Type': self.assertEqual(header[1], 'application/json') + def test__content_type_invalid(self): + cls = self._getTargetSubclass() + exc = cls() + environ = _makeEnviron() + environ['HTTP_ACCEPT'] = 'invalid' + start_response = DummyStartResponse() + exc(environ, start_response) + for header in start_response.headerlist: + if header[0] == 'Content-Type': + self.assertEqual(header[1], 'text/html; charset=UTF-8') + def test__default_app_iter_with_comment_ampersand(self): cls = self._getTargetSubclass() exc = cls(comment='comment & comment') From 12a58d211a7868337aaf5f040e7cd0c10e095c5b Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Thu, 5 Apr 2018 17:44:33 -0600 Subject: [PATCH 4/5] Replace MIMEAccept with acceptparse.create_accept_header This is the new API that WebOb makes available and follows the standards. --- pyramid/httpexceptions.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pyramid/httpexceptions.py b/pyramid/httpexceptions.py index 7340804342..718d51b50c 100644 --- a/pyramid/httpexceptions.py +++ b/pyramid/httpexceptions.py @@ -133,7 +133,7 @@ from zope.interface import implementer from webob import html_escape as _html_escape -from webob.acceptparse import MIMEAccept +from webob.acceptparse import create_accept_header from pyramid.compat import ( class_types, @@ -250,10 +250,12 @@ def prepare(self, environ): html_comment = '' comment = self.comment or '' accept_value = environ.get('HTTP_ACCEPT', '') - accept = MIMEAccept(accept_value) + accept = create_accept_header(accept_value) # Attempt to match text/html or application/json, if those don't # match, we will fall through to defaulting to text/plain - match = accept.best_match(['text/html', 'application/json']) + acceptable = accept.acceptable_offers(['text/html', 'application/json']) + acceptable = [offer[0] for offer in acceptable] + ['text/plain'] + match = acceptable[0] if match == 'text/html': self.content_type = 'text/html' From f7a313d68452840d1f67fe8e808575243af0fb41 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Thu, 5 Apr 2018 17:49:34 -0600 Subject: [PATCH 5/5] Update CHANGES.rst for #3251 --- CHANGES.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index d24fb24e8b..334a9b62fc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -38,6 +38,11 @@ Bug Fixes error code. See https://github.com/Pylons/pyramid/pull/3280 +- Replace ``webob.acceptparse.MIMEAccept`` from WebOb with + ``webob.acceptparse.create_accept_header`` in the HTTP exception handling + code. The old ``MIMEAccept`` has been deprecated. The new methods follow the + RFC's more closely. See https://github.com/Pylons/pyramid/pull/3251 + Deprecations ------------