Change oslo.i18n to oslo_i18n
The oslo libraries are moving away from namespace packages. bp drop-namespace-packages Change-Id: I5b6bb46ac55b8309845fcc8b01d93d97be4e86ca
This commit is contained in:
parent
fe50dbe9e9
commit
2666d30283
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from oslo import i18n
|
import oslo_i18n
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
@ -114,7 +114,7 @@ def best_match_language(req):
|
|||||||
if not req.accept_language:
|
if not req.accept_language:
|
||||||
return None
|
return None
|
||||||
return req.accept_language.best_match(
|
return req.accept_language.best_match(
|
||||||
i18n.get_available_languages('keystone'))
|
oslo_i18n.get_available_languages('keystone'))
|
||||||
|
|
||||||
|
|
||||||
class BaseApplication(object):
|
class BaseApplication(object):
|
||||||
@ -778,7 +778,7 @@ def render_exception(error, context=None, request=None, user_locale=None):
|
|||||||
"""Forms a WSGI response based on the current error."""
|
"""Forms a WSGI response based on the current error."""
|
||||||
|
|
||||||
error_message = error.args[0]
|
error_message = error.args[0]
|
||||||
message = i18n.translate(error_message, desired_locale=user_locale)
|
message = oslo_i18n.translate(error_message, desired_locale=user_locale)
|
||||||
if message is error_message:
|
if message is error_message:
|
||||||
# translate() didn't do anything because it wasn't a Message,
|
# translate() didn't do anything because it wasn't a Message,
|
||||||
# convert to a string.
|
# convert to a string.
|
||||||
|
@ -400,9 +400,9 @@ class CheckForLoggingIssues(BaseASTChecker):
|
|||||||
def check_oslo_namespace_imports(logical_line, blank_before, filename):
|
def check_oslo_namespace_imports(logical_line, blank_before, filename):
|
||||||
oslo_namespace_imports = re.compile(
|
oslo_namespace_imports = re.compile(
|
||||||
r"(((from)|(import))\s+oslo\.("
|
r"(((from)|(import))\s+oslo\.("
|
||||||
"(config)|(db)|(messaging)|(serialization)|(utils)))|"
|
"(config)|(db)|(messaging)|(serialization)|(utils)|(i18n)))|"
|
||||||
"(from\s+oslo\s+import\s+("
|
"(from\s+oslo\s+import\s+("
|
||||||
"(config)|(db)|(messaging)|(serialization)|(utils)))")
|
"(config)|(db)|(messaging)|(serialization)|(utils)|(i18n)))")
|
||||||
|
|
||||||
if re.match(oslo_namespace_imports, logical_line):
|
if re.match(oslo_namespace_imports, logical_line):
|
||||||
msg = ("K333: '%s' must be used instead of '%s'.") % (
|
msg = ("K333: '%s' must be used instead of '%s'.") % (
|
||||||
|
@ -18,10 +18,10 @@ See http://docs.openstack.org/developer/oslo.i18n/usage.html .
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from oslo import i18n
|
import oslo_i18n
|
||||||
|
|
||||||
|
|
||||||
_translators = i18n.TranslatorFactory(domain='keystone')
|
_translators = oslo_i18n.TranslatorFactory(domain='keystone')
|
||||||
|
|
||||||
# The primary translation function using the well-known name "_"
|
# The primary translation function using the well-known name "_"
|
||||||
_ = _translators.primary
|
_ = _translators.primary
|
||||||
|
@ -17,8 +17,8 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from oslo import i18n
|
|
||||||
from oslo_concurrency import processutils
|
from oslo_concurrency import processutils
|
||||||
|
import oslo_i18n
|
||||||
import pbr.version
|
import pbr.version
|
||||||
|
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ import pbr.version
|
|||||||
# keystone.i18n._() is called to ensure it has the desired lazy lookup
|
# keystone.i18n._() is called to ensure it has the desired lazy lookup
|
||||||
# behavior. This includes cases, like keystone.exceptions, where
|
# behavior. This includes cases, like keystone.exceptions, where
|
||||||
# keystone.i18n._() is called at import time.
|
# keystone.i18n._() is called at import time.
|
||||||
i18n.enable_lazy()
|
oslo_i18n.enable_lazy()
|
||||||
|
|
||||||
|
|
||||||
from keystone.common import environment
|
from keystone.common import environment
|
||||||
|
@ -14,14 +14,14 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from oslo import i18n
|
import oslo_i18n
|
||||||
|
|
||||||
|
|
||||||
# NOTE(dstanek): i18n.enable_lazy() must be called before
|
# NOTE(dstanek): i18n.enable_lazy() must be called before
|
||||||
# keystone.i18n._() is called to ensure it has the desired lazy lookup
|
# keystone.i18n._() is called to ensure it has the desired lazy lookup
|
||||||
# behavior. This includes cases, like keystone.exceptions, where
|
# behavior. This includes cases, like keystone.exceptions, where
|
||||||
# keystone.i18n._() is called at import time.
|
# keystone.i18n._() is called at import time.
|
||||||
i18n.enable_lazy()
|
oslo_i18n.enable_lazy()
|
||||||
|
|
||||||
|
|
||||||
from keystone.common import environment
|
from keystone.common import environment
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from oslo import i18n
|
import oslo_i18n
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ if six.PY3:
|
|||||||
sys.modules['pycadf'] = mock.Mock()
|
sys.modules['pycadf'] = mock.Mock()
|
||||||
sys.modules['paste'] = mock.Mock()
|
sys.modules['paste'] = mock.Mock()
|
||||||
|
|
||||||
# NOTE(dstanek): i18n.enable_lazy() must be called before
|
# NOTE(dstanek): oslo_i18n.enable_lazy() must be called before
|
||||||
# keystone.i18n._() is called to ensure it has the desired lazy lookup
|
# keystone.i18n._() is called to ensure it has the desired lazy lookup
|
||||||
# behavior. This includes cases, like keystone.exceptions, where
|
# behavior. This includes cases, like keystone.exceptions, where
|
||||||
# keystone.i18n._() is called at import time.
|
# keystone.i18n._() is called at import time.
|
||||||
i18n.enable_lazy()
|
oslo_i18n.enable_lazy()
|
||||||
|
|
||||||
from keystone.tests.core import * # noqa
|
from keystone.tests.core import * # noqa
|
||||||
|
@ -220,6 +220,14 @@ class HackingCode(fixtures.Fixture):
|
|||||||
from oslo import config
|
from oslo import config
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
|
import oslo.i18n
|
||||||
|
import oslo_i18n
|
||||||
|
import oslo.i18n.log
|
||||||
|
import oslo_i18n.log
|
||||||
|
from oslo import i18n
|
||||||
|
from oslo.i18n import log
|
||||||
|
from oslo_i18n import log
|
||||||
""",
|
""",
|
||||||
'expected_errors': [
|
'expected_errors': [
|
||||||
(1, 0, 'K333'),
|
(1, 0, 'K333'),
|
||||||
@ -242,6 +250,10 @@ class HackingCode(fixtures.Fixture):
|
|||||||
(35, 0, 'K333'),
|
(35, 0, 'K333'),
|
||||||
(37, 0, 'K333'),
|
(37, 0, 'K333'),
|
||||||
(38, 0, 'K333'),
|
(38, 0, 'K333'),
|
||||||
|
(41, 0, 'K333'),
|
||||||
|
(43, 0, 'K333'),
|
||||||
|
(45, 0, 'K333'),
|
||||||
|
(46, 0, 'K333'),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import socket
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
from oslo import i18n
|
import oslo_i18n
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import six
|
import six
|
||||||
from testtools import matchers
|
from testtools import matchers
|
||||||
@ -278,7 +278,7 @@ class LocalizedResponseTest(tests.TestCase):
|
|||||||
req = webob.Request.blank('/')
|
req = webob.Request.blank('/')
|
||||||
self.assertIsNone(wsgi.best_match_language(req))
|
self.assertIsNone(wsgi.best_match_language(req))
|
||||||
|
|
||||||
@mock.patch.object(i18n, 'get_available_languages')
|
@mock.patch.object(oslo_i18n, 'get_available_languages')
|
||||||
def test_request_match_language_expected(self, mock_gal):
|
def test_request_match_language_expected(self, mock_gal):
|
||||||
# If Accept-Language is a supported language, best_match_language()
|
# If Accept-Language is a supported language, best_match_language()
|
||||||
# returns it.
|
# returns it.
|
||||||
@ -289,7 +289,7 @@ class LocalizedResponseTest(tests.TestCase):
|
|||||||
req = webob.Request.blank('/', headers={'Accept-Language': language})
|
req = webob.Request.blank('/', headers={'Accept-Language': language})
|
||||||
self.assertEqual(wsgi.best_match_language(req), language)
|
self.assertEqual(wsgi.best_match_language(req), language)
|
||||||
|
|
||||||
@mock.patch.object(i18n, 'get_available_languages')
|
@mock.patch.object(oslo_i18n, 'get_available_languages')
|
||||||
def test_request_match_language_unexpected(self, mock_gal):
|
def test_request_match_language_unexpected(self, mock_gal):
|
||||||
# If Accept-Language is a language we do not support,
|
# If Accept-Language is a language we do not support,
|
||||||
# best_match_language() returns None.
|
# best_match_language() returns None.
|
||||||
@ -308,7 +308,7 @@ class LocalizedResponseTest(tests.TestCase):
|
|||||||
self.assertNotEqual(type(exception.Unauthorized.message_format),
|
self.assertNotEqual(type(exception.Unauthorized.message_format),
|
||||||
six.text_type)
|
six.text_type)
|
||||||
|
|
||||||
@mock.patch.object(i18n, 'get_available_languages')
|
@mock.patch.object(oslo_i18n, 'get_available_languages')
|
||||||
def test_get_localized_response(self, mock_gal):
|
def test_get_localized_response(self, mock_gal):
|
||||||
# If the request has the Accept-Language set to a supported language
|
# If the request has the Accept-Language set to a supported language
|
||||||
# and an exception is raised by the application that is translatable
|
# and an exception is raised by the application that is translatable
|
||||||
|
Loading…
Reference in New Issue
Block a user