diff options
| author | Michael Merickel <michael@merickel.org> | 2018-05-19 14:46:15 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-19 14:46:15 -0500 |
| commit | 77caaff93f3c7dc8d43d6375b06b05e2be6cf7d3 (patch) | |
| tree | d2659f1aedbd94f7f47cc535e9336786b8b47477 | |
| parent | 2cbea29fae5adf311d46b6a1f1dcf8d71a64e5bd (diff) | |
| parent | f7a313d68452840d1f67fe8e808575243af0fb41 (diff) | |
| download | pyramid-77caaff93f3c7dc8d43d6375b06b05e2be6cf7d3.tar.gz pyramid-77caaff93f3c7dc8d43d6375b06b05e2be6cf7d3.tar.bz2 pyramid-77caaff93f3c7dc8d43d6375b06b05e2be6cf7d3.zip | |
Merge pull request #3251 from Pylons/replace-mimeaccept
Replace MIMEAccept with acceptparse.create_accept_header
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | CHANGES.rst | 5 | ||||
| -rw-r--r-- | pyramid/httpexceptions.py | 8 | ||||
| -rw-r--r-- | pyramid/tests/test_httpexceptions.py | 11 | ||||
| -rw-r--r-- | setup.py | 38 |
5 files changed, 42 insertions, 21 deletions
diff --git a/.gitignore b/.gitignore index fe132412a..2fe3b3386 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ jyenv/ pypyenv/ env*/ venv/ +.cache/ diff --git a/CHANGES.rst b/CHANGES.rst index d24fb24e8..334a9b62f 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 ------------ diff --git a/pyramid/httpexceptions.py b/pyramid/httpexceptions.py index 734080434..718d51b50 100644 --- a/pyramid/httpexceptions.py +++ b/pyramid/httpexceptions.py @@ -133,7 +133,7 @@ from string import Template 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 @@ ${body}''') 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' diff --git a/pyramid/tests/test_httpexceptions.py b/pyramid/tests/test_httpexceptions.py index e2d463008..ed6c41e0e 100644 --- a/pyramid/tests/test_httpexceptions.py +++ b/pyramid/tests/test_httpexceptions.py @@ -283,6 +283,17 @@ class TestHTTPException(unittest.TestCase): 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') @@ -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 @@ setup(name='pyramid', ':python_version<"3.2"': ['repoze.lru >= 0.4'], 'testing': testing_extras, 'docs': docs_extras, - }, + }, tests_require=tests_require, test_suite="pyramid.tests", entry_points="""\ |
