diff --git a/keystone/common/wsgi.py b/keystone/common/wsgi.py index 79113f1dbc..3db55eb0a8 100644 --- a/keystone/common/wsgi.py +++ b/keystone/common/wsgi.py @@ -20,7 +20,7 @@ import copy -from oslo import i18n +import oslo_i18n from oslo_serialization import jsonutils from oslo_utils import importutils from oslo_utils import strutils @@ -114,7 +114,7 @@ def best_match_language(req): if not req.accept_language: return None return req.accept_language.best_match( - i18n.get_available_languages('keystone')) + oslo_i18n.get_available_languages('keystone')) 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.""" 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: # translate() didn't do anything because it wasn't a Message, # convert to a string. diff --git a/keystone/hacking/checks.py b/keystone/hacking/checks.py index 2df86d9a84..74df764239 100644 --- a/keystone/hacking/checks.py +++ b/keystone/hacking/checks.py @@ -400,9 +400,9 @@ class CheckForLoggingIssues(BaseASTChecker): def check_oslo_namespace_imports(logical_line, blank_before, filename): oslo_namespace_imports = re.compile( r"(((from)|(import))\s+oslo\.(" - "(config)|(db)|(messaging)|(serialization)|(utils)))|" + "(config)|(db)|(messaging)|(serialization)|(utils)|(i18n)))|" "(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): msg = ("K333: '%s' must be used instead of '%s'.") % ( diff --git a/keystone/i18n.py b/keystone/i18n.py index 4d5c3b6570..2eb42d3a07 100644 --- a/keystone/i18n.py +++ b/keystone/i18n.py @@ -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 "_" _ = _translators.primary diff --git a/keystone/server/eventlet.py b/keystone/server/eventlet.py index f29d6e34c6..a03c700056 100644 --- a/keystone/server/eventlet.py +++ b/keystone/server/eventlet.py @@ -17,8 +17,8 @@ import logging import os import socket -from oslo import i18n from oslo_concurrency import processutils +import oslo_i18n import pbr.version @@ -26,7 +26,7 @@ import pbr.version # keystone.i18n._() is called to ensure it has the desired lazy lookup # behavior. This includes cases, like keystone.exceptions, where # keystone.i18n._() is called at import time. -i18n.enable_lazy() +oslo_i18n.enable_lazy() from keystone.common import environment diff --git a/keystone/server/wsgi.py b/keystone/server/wsgi.py index 2d15c08e1a..0e22cf0d78 100644 --- a/keystone/server/wsgi.py +++ b/keystone/server/wsgi.py @@ -14,14 +14,14 @@ import logging -from oslo import i18n +import oslo_i18n # NOTE(dstanek): i18n.enable_lazy() must be called before # keystone.i18n._() is called to ensure it has the desired lazy lookup # behavior. This includes cases, like keystone.exceptions, where # keystone.i18n._() is called at import time. -i18n.enable_lazy() +oslo_i18n.enable_lazy() from keystone.common import environment diff --git a/keystone/tests/__init__.py b/keystone/tests/__init__.py index 5dea2a23fe..9355f92262 100644 --- a/keystone/tests/__init__.py +++ b/keystone/tests/__init__.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo import i18n +import oslo_i18n import six @@ -32,10 +32,10 @@ if six.PY3: sys.modules['pycadf'] = 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 # behavior. This includes cases, like keystone.exceptions, where # keystone.i18n._() is called at import time. -i18n.enable_lazy() +oslo_i18n.enable_lazy() from keystone.tests.core import * # noqa diff --git a/keystone/tests/ksfixtures/hacking.py b/keystone/tests/ksfixtures/hacking.py index c4956b714a..a005330954 100644 --- a/keystone/tests/ksfixtures/hacking.py +++ b/keystone/tests/ksfixtures/hacking.py @@ -220,6 +220,14 @@ class HackingCode(fixtures.Fixture): from oslo import config 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': [ (1, 0, 'K333'), @@ -242,6 +250,10 @@ class HackingCode(fixtures.Fixture): (35, 0, 'K333'), (37, 0, 'K333'), (38, 0, 'K333'), + (41, 0, 'K333'), + (43, 0, 'K333'), + (45, 0, 'K333'), + (46, 0, 'K333'), ], } diff --git a/keystone/tests/test_wsgi.py b/keystone/tests/test_wsgi.py index 35faacc43d..4c8d4f57ba 100644 --- a/keystone/tests/test_wsgi.py +++ b/keystone/tests/test_wsgi.py @@ -17,7 +17,7 @@ import socket import uuid import mock -from oslo import i18n +import oslo_i18n from oslo_serialization import jsonutils import six from testtools import matchers @@ -278,7 +278,7 @@ class LocalizedResponseTest(tests.TestCase): req = webob.Request.blank('/') 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): # If Accept-Language is a supported language, best_match_language() # returns it. @@ -289,7 +289,7 @@ class LocalizedResponseTest(tests.TestCase): req = webob.Request.blank('/', headers={'Accept-Language': 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): # If Accept-Language is a language we do not support, # best_match_language() returns None. @@ -308,7 +308,7 @@ class LocalizedResponseTest(tests.TestCase): self.assertNotEqual(type(exception.Unauthorized.message_format), 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): # If the request has the Accept-Language set to a supported language # and an exception is raised by the application that is translatable