WebOb: Do not use the deprecated best_match method

Doing so requires WebOb >= 1.8.0 so that's updated

Change-Id: I5ddbc9244446afdd8e0fbe547967805de3e4071d
Closes-Bug: #1819752
This commit is contained in:
Cyril Roelandt 2019-03-12 19:48:06 +01:00 committed by Stephen Finucane
parent cf4d3b10ae
commit 0ed01983a7
5 changed files with 13 additions and 5 deletions

@ -1,5 +1,5 @@
six>=1.9.0 six>=1.9.0
WebOb>=1.2.3 WebOb>=1.8.0
simplegeneric simplegeneric
pytz pytz
netaddr>=0.7.12 netaddr>=0.7.12

@ -1,5 +1,5 @@
six>=1.9.0 six>=1.9.0
WebOb>=1.2.3 WebOb>=1.8.0
simplegeneric simplegeneric
pytz pytz
netaddr>=0.7.12 netaddr>=0.7.12

@ -126,7 +126,7 @@ def media_type_accept(request, content_types):
""" """
if request.method in ['GET', 'HEAD']: if request.method in ['GET', 'HEAD']:
if request.accept: if request.accept:
if request.accept.best_match(content_types): if request.accept.acceptable_offers(content_types):
return True return True
error_message = ('Unacceptable Accept type: %s not in %s' error_message = ('Unacceptable Accept type: %s not in %s'
% (request.accept, content_types)) % (request.accept, content_types))

@ -41,7 +41,11 @@ class RestProtocol(Protocol):
context.outformat = None context.outformat = None
ext = os.path.splitext(request.path.split('/')[-1])[1] ext = os.path.splitext(request.path.split('/')[-1])[1]
inmime = request.content_type inmime = request.content_type
outmime = request.accept.best_match(self.content_types) try:
offers = request.accept.acceptable_offers(self.content_types)
outmime = offers[0][0]
except IndexError:
outmime = None
outformat = None outformat = None
informat = None informat = None

@ -317,7 +317,11 @@ class WSRoot(object):
# Attempt to correctly guess what content-type we should return. # Attempt to correctly guess what content-type we should return.
ctypes = [ct for ct in protocol.content_types if ct] ctypes = [ct for ct in protocol.content_types if ct]
if ctypes: if ctypes:
res_content_type = request.accept.best_match(ctypes) try:
offers = request.accept.acceptable_offers(ctypes)
res_content_type = offers[0][0]
except IndexError:
res_content_type = None
# If not we will attempt to convert the body to an accepted # If not we will attempt to convert the body to an accepted
# output format. # output format.