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:
Brant Knudson 2015-01-31 09:00:59 -06:00
parent fe50dbe9e9
commit 2666d30283
8 changed files with 30 additions and 18 deletions

View File

@ -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.

View File

@ -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'.") % (

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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'),
],
}

View File

@ -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