Skip to content

Commit

Permalink
Merge pull request #498 from Cornices/remove-bestmatch
Browse files Browse the repository at this point in the history
Remove usage of deprecated ``.best_match()``
  • Loading branch information
leplatrem committed Nov 30, 2018
2 parents b897e07 + 59e7a52 commit ad581dc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ CHANGELOG
3.5.0 (unreleased)
==================

- Nothing changed yet.
**Internal changes**

- Remove usage of deprecated ``.best_match()`` (thanks @abk-code)


3.4.2 (2018-10-24)
Expand Down
6 changes: 3 additions & 3 deletions cornice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def set_localizer_for_languages(event, available_languages,
"""
request = event.request
if request.accept_language:
accepted = request.accept_language
locale = accepted.best_match(available_languages, default_locale_name)
request._LOCALE_ = locale
accepted = request.accept_language.lookup(available_languages,
default=default_locale_name)
request._LOCALE_ = accepted


def setup_localization(config):
Expand Down
2 changes: 1 addition & 1 deletion cornice/pyramidhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _fallback_view(request):
acceptable = list(set(acceptable))

# Now check if that was actually the source of the problem.
if not request.accept.best_match(acceptable):
if not request.accept.acceptable_offers(offers=acceptable):
request.errors.add(
'header', 'Accept',
'Accept header should be one of {0}'.format(
Expand Down
7 changes: 4 additions & 3 deletions cornice/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ def __call__(self, data, context):
json_str = renderer(data, context)

# XXX So we (re)set it ourselves here, i.e.: *after* the previous call.
content_type = (request.accept.best_match(self.acceptable) or
self.acceptable[0])
response.content_type = content_type
ctypes = request.accept.acceptable_offers(offers=self.acceptable)
if not ctypes:
ctypes = [(self.acceptable[0], 1.0)]
response.content_type = ctypes[0][0]
return json_str


Expand Down
1 change: 0 additions & 1 deletion tests/test_pyramidhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ def setUp(self):

def test_no_sniff_is_added_to_responses(self):
response = self.app.get('/wrapperservice')
print(response.headers)
self.assertEqual(response.headers['X-Content-Type-Options'], 'nosniff')


Expand Down

0 comments on commit ad581dc

Please sign in to comment.