[placement] replace deprecated accept.best_match

Webob has deprecated the best_match[1] method on accept headers and now
spews warnings when it sees it.

This change fixes it by using the equivalent (but more correct with
regard to the relevant RFCs[2]) acceptable_offers[3] method.

Existing unit tests in placement/test_util.py cover this change.

[1] https://docs.pylonsproject.org/projects/webob/en/stable/api/webob.html#webob.acceptparse.AcceptValidHeader.best_match
[2] https://tools.ietf.org/html/rfc7231#section-5.3.2
[3] https://docs.pylonsproject.org/projects/webob/en/stable/api/webob.html#webob.acceptparse.AcceptValidHeader.acceptable_offers

Change-Id: Ie4d81fa178b3ed6b2a7b450b4978009486f07810
Closes-Bug: #1773225
This commit is contained in:
Chris Dent 2018-06-13 15:16:35 +01:00
parent ca7d23a3e7
commit 450444a782
1 changed files with 2 additions and 2 deletions

View File

@ -70,8 +70,8 @@ def check_accept(*types):
@functools.wraps(f)
def decorated_function(req):
if req.accept:
best_match = req.accept.best_match(types)
if not best_match:
best_matches = req.accept.acceptable_offers(types)
if not best_matches:
type_string = ', '.join(types)
raise webob.exc.HTTPNotAcceptable(
_('Only %(type)s is provided') % {'type': type_string},