Merge "Use WebOb 1.8.1"
This commit is contained in:
commit
3e97060669
|
@ -53,12 +53,6 @@ from glance import i18n
|
||||||
from glance.i18n import _, _LE, _LI, _LW
|
from glance.i18n import _, _LE, _LI, _LW
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
from webob.acceptparse import AcceptLanguageValidHeader # noqa
|
|
||||||
USING_WEBOB_1_8 = True
|
|
||||||
except ImportError:
|
|
||||||
USING_WEBOB_1_8 = False
|
|
||||||
|
|
||||||
bind_opts = [
|
bind_opts = [
|
||||||
cfg.HostAddressOpt('bind_host',
|
cfg.HostAddressOpt('bind_host',
|
||||||
default='0.0.0.0',
|
default='0.0.0.0',
|
||||||
|
@ -1048,18 +1042,7 @@ class Request(webob.Request):
|
||||||
else:
|
else:
|
||||||
return content_type
|
return content_type
|
||||||
|
|
||||||
def _best_match_language_1_7(self):
|
def best_match_language(self):
|
||||||
"""Determines best available locale from the Accept-Language header.
|
|
||||||
|
|
||||||
:returns: the best language match or None if the 'Accept-Language'
|
|
||||||
header was not available in the request.
|
|
||||||
"""
|
|
||||||
if not self.accept_language:
|
|
||||||
return None
|
|
||||||
langs = i18n.get_available_languages('glance')
|
|
||||||
return self.accept_language.best_match(langs)
|
|
||||||
|
|
||||||
def _best_match_language_1_8(self):
|
|
||||||
"""Determines best available locale from the Accept-Language header.
|
"""Determines best available locale from the Accept-Language header.
|
||||||
|
|
||||||
:returns: the best language match or None if the 'Accept-Language'
|
:returns: the best language match or None if the 'Accept-Language'
|
||||||
|
@ -1076,12 +1059,6 @@ class Request(webob.Request):
|
||||||
best_match = None
|
best_match = None
|
||||||
return best_match
|
return best_match
|
||||||
|
|
||||||
def best_match_language(self):
|
|
||||||
if USING_WEBOB_1_8:
|
|
||||||
return self._best_match_language_1_8()
|
|
||||||
else:
|
|
||||||
return self._best_match_language_1_7()
|
|
||||||
|
|
||||||
def get_range_from_request(self, image_size):
|
def get_range_from_request(self, image_size):
|
||||||
"""Return the `Range` in a request."""
|
"""Return the `Range` in a request."""
|
||||||
|
|
||||||
|
|
|
@ -184,31 +184,20 @@ class RequestTest(test_utils.BaseTestCase):
|
||||||
req = wsgi.Request.blank('/', headers={'Accept-Language': 'unknown'})
|
req = wsgi.Request.blank('/', headers={'Accept-Language': 'unknown'})
|
||||||
self.assertIsNone(req.best_match_language())
|
self.assertIsNone(req.best_match_language())
|
||||||
|
|
||||||
def test_best_match_language_unknown(self):
|
@mock.patch.object(webob.acceptparse.AcceptLanguageValidHeader, 'lookup')
|
||||||
# Test that we are actually invoking language negotiation by webop
|
def test_best_match_language_unknown(self, mock_lookup):
|
||||||
|
# Test that we are actually invoking language negotiation by WebOb
|
||||||
request = wsgi.Request.blank('/')
|
request = wsgi.Request.blank('/')
|
||||||
accepted = 'unknown-lang'
|
accepted = 'unknown-lang'
|
||||||
request.headers = {'Accept-Language': accepted}
|
request.headers = {'Accept-Language': accepted}
|
||||||
|
|
||||||
# TODO(rosmaita): simplify when lower_constraints has webob >= 1.8.1
|
|
||||||
try:
|
|
||||||
from webob.acceptparse import AcceptLanguageValidHeader # noqa
|
|
||||||
cls = webob.acceptparse.AcceptLanguageValidHeader
|
|
||||||
funcname = 'lookup'
|
|
||||||
# Bug #1765748: see comment in code in the function under test
|
# Bug #1765748: see comment in code in the function under test
|
||||||
# to understand why this is the correct return value for the
|
# to understand why this is the correct return value for the
|
||||||
# webob 1.8.x mock
|
# webob 1.8.x mock
|
||||||
retval = 'fake_LANG'
|
mock_lookup.return_value = 'fake_LANG'
|
||||||
except ImportError:
|
|
||||||
cls = webob.acceptparse.AcceptLanguage
|
|
||||||
funcname = 'best_match'
|
|
||||||
retval = None
|
|
||||||
|
|
||||||
with mock.patch.object(cls, funcname) as mocked_function:
|
|
||||||
mocked_function.return_value = retval
|
|
||||||
|
|
||||||
self.assertIsNone(request.best_match_language())
|
self.assertIsNone(request.best_match_language())
|
||||||
mocked_function.assert_called_once()
|
mock_lookup.assert_called_once()
|
||||||
|
|
||||||
# If Accept-Language is missing or empty, match should be None
|
# If Accept-Language is missing or empty, match should be None
|
||||||
request.headers = {'Accept-Language': ''}
|
request.headers = {'Accept-Language': ''}
|
||||||
|
@ -389,20 +378,11 @@ class ResourceTest(test_utils.BaseTestCase):
|
||||||
resource, request)
|
resource, request)
|
||||||
self.assertEqual(message_es, str(e))
|
self.assertEqual(message_es, str(e))
|
||||||
|
|
||||||
|
@mock.patch.object(webob.acceptparse.AcceptLanguageValidHeader, 'lookup')
|
||||||
@mock.patch.object(i18n, 'translate')
|
@mock.patch.object(i18n, 'translate')
|
||||||
def test_translate_exception(self, mock_translate):
|
def test_translate_exception(self, mock_translate, mock_lookup):
|
||||||
# TODO(rosmaita): simplify when lower_constraints has webob >= 1.8.1
|
|
||||||
try:
|
|
||||||
from webob.acceptparse import AcceptLanguageValidHeader # noqa
|
|
||||||
cls = webob.acceptparse.AcceptLanguageValidHeader
|
|
||||||
funcname = 'lookup'
|
|
||||||
except ImportError:
|
|
||||||
cls = webob.acceptparse.AcceptLanguage
|
|
||||||
funcname = 'best_match'
|
|
||||||
|
|
||||||
with mock.patch.object(cls, funcname) as mocked_function:
|
|
||||||
mock_translate.return_value = 'No Encontrado'
|
mock_translate.return_value = 'No Encontrado'
|
||||||
mocked_function.return_value = 'de'
|
mock_lookup.return_value = 'de'
|
||||||
|
|
||||||
req = wsgi.Request.blank('/tests/123')
|
req = wsgi.Request.blank('/tests/123')
|
||||||
req.headers["Accept-Language"] = "de"
|
req.headers["Accept-Language"] = "de"
|
||||||
|
|
|
@ -138,7 +138,7 @@ unittest2==1.1.0
|
||||||
urllib3==1.22
|
urllib3==1.22
|
||||||
vine==1.1.4
|
vine==1.1.4
|
||||||
voluptuous==0.11.1
|
voluptuous==0.11.1
|
||||||
WebOb==1.7.1
|
WebOb==1.8.1
|
||||||
whereto===0.3.0
|
whereto===0.3.0
|
||||||
wrapt==1.10.11
|
wrapt==1.10.11
|
||||||
WSME==0.8.0
|
WSME==0.8.0
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
other:
|
||||||
|
- |
|
||||||
|
Negotiation of the 'Accept-Language' header now follows the "Lookup"
|
||||||
|
matching scheme described in `RFC 4647, section 3.4
|
||||||
|
<https://tools.ietf.org/html/rfc4647.html#section-3.4>`_. The
|
||||||
|
"Lookup" scheme is one of the algorithms suggested in `RFC 7231,
|
||||||
|
section 5.3.5
|
||||||
|
<https://tools.ietf.org/html/rfc7231.html#section-5.3.5>`_. (This is
|
||||||
|
due to a change in an underlying library, which previously used a
|
||||||
|
matching scheme that did not conform to `RFC 7231
|
||||||
|
<https://tools.ietf.org/html/rfc7231.html>`_.)
|
|
@ -10,7 +10,7 @@ SQLAlchemy!=1.1.5,!=1.1.6,!=1.1.7,!=1.1.8,>=1.0.10 # MIT
|
||||||
eventlet!=0.18.3,!=0.20.1,>=0.18.2 # MIT
|
eventlet!=0.18.3,!=0.20.1,>=0.18.2 # MIT
|
||||||
PasteDeploy>=1.5.0 # MIT
|
PasteDeploy>=1.5.0 # MIT
|
||||||
Routes>=2.3.1 # MIT
|
Routes>=2.3.1 # MIT
|
||||||
WebOb>=1.7.1 # MIT
|
WebOb>=1.8.1 # MIT
|
||||||
sqlalchemy-migrate>=0.11.0 # Apache-2.0
|
sqlalchemy-migrate>=0.11.0 # Apache-2.0
|
||||||
sqlparse>=0.2.2 # BSD
|
sqlparse>=0.2.2 # BSD
|
||||||
alembic>=0.8.10 # MIT
|
alembic>=0.8.10 # MIT
|
||||||
|
|
Loading…
Reference in New Issue