Fix best_match() deprecation warning

wsgi call to best_match() generates the following warning:

DeprecationWarning: The behavior of AcceptValidHeader.best_match
is currently being maintained for backward compatibility, but it
will be deprecated in the future, as it does not conform to the RFC.

Change to use acceptable_offers() as was done in nova code.

Simlar changes in the wsgi best language code as well, except
new call is to lookup().

Required bump to get WebOb 1.8.2.

Trivialfix

Change-Id: I45a222c098658eef6a49adcc168b0f5625ea49db
This commit is contained in:
Brian Haley 2018-09-28 16:37:01 -04:00 committed by Brian Haley
parent 6a767c2954
commit bc4f93c232
4 changed files with 16 additions and 7 deletions

View File

@ -147,6 +147,6 @@ unittest2==1.1.0
vine==1.1.4
waitress==1.1.0
weakrefmethod==1.0.2
WebOb==1.7.1
WebOb==1.8.2
WebTest==2.0.27
wrapt==1.7.0

View File

@ -28,8 +28,11 @@ class ExceptionTranslationHook(hooks.PecanHook):
def on_error(self, state, e):
language = None
if state.request.accept_language:
language = state.request.accept_language.best_match(
oslo_i18n.get_available_languages('neutron'))
all_languages = oslo_i18n.get_available_languages('neutron')
language = state.request.accept_language.lookup(all_languages,
default='fake_LANG')
if language == 'fake_LANG':
language = None
exc = api_common.convert_exception_to_http_exc(e, faults.FAULT_MAP,
language)
if hasattr(exc, 'code') and 400 <= exc.code < 500:

View File

@ -249,8 +249,10 @@ class Request(wsgi.Request):
ctypes = ['application/json']
# Finally search in Accept-* headers
bm = self.accept.best_match(ctypes)
return bm or 'application/json'
acceptable = self.accept.acceptable_offers(ctypes)
if acceptable:
return acceptable[0][0]
return 'application/json'
def get_content_type(self):
allowed_types = ("application/json",)
@ -271,7 +273,11 @@ class Request(wsgi.Request):
if not self.accept_language:
return None
all_languages = oslo_i18n.get_available_languages('neutron')
return self.accept_language.best_match(all_languages)
best_match = self.accept_language.lookup(all_languages,
default='fake_LANG')
if best_match == 'fake_LANG':
best_match = None
return best_match
@property
def context(self):

View File

@ -20,7 +20,7 @@ python-neutronclient>=6.7.0 # Apache-2.0
tenacity>=3.2.1 # Apache-2.0
ryu>=4.24 # Apache-2.0
SQLAlchemy!=1.1.5,!=1.1.6,!=1.1.7,!=1.1.8,>=1.2.0 # MIT
WebOb>=1.7.1 # MIT
WebOb>=1.8.2 # MIT
keystoneauth1>=3.4.0 # Apache-2.0
alembic>=0.8.10 # MIT
six>=1.10.0 # MIT