Remove i18n stub

This removes the translation functions from the codebase and drops the
i18n integration stub.

Change-Id: I4cd21d25f768e6915f813a784b89eb66f6fe006f
This commit is contained in:
Louis Taylor 2015-05-29 13:36:43 +01:00 committed by Morgan Fainberg
parent ebb48db1c8
commit 7201269804
11 changed files with 78 additions and 117 deletions

View File

@ -17,7 +17,6 @@
import functools
from keystoneauth import _utils as utils
from keystoneauth.i18n import _
from keystoneauth import service_catalog
@ -38,7 +37,7 @@ def create(resp=None, body=None, auth_token=None):
elif 'access' in body:
return AccessInfoV2(body, auth_token)
raise ValueError(_('Unrecognized auth response'))
raise ValueError('Unrecognized auth response')
def missingproperty(f):

View File

@ -20,7 +20,6 @@ from keystoneauth import _utils as utils
from keystoneauth.auth import base
from keystoneauth import discover
from keystoneauth import exceptions
from keystoneauth.i18n import _LW
LOG = logging.getLogger(__name__)
@ -205,9 +204,9 @@ class BaseIdentityPlugin(base.BaseAuthPlugin):
return self.auth_url
if not service_type:
LOG.warn(_LW('Plugin cannot return an endpoint without knowing '
'the service type that is required. Add service_type '
'to endpoint filtering data.'))
LOG.warn('Plugin cannot return an endpoint without knowing '
'the service type that is required. Add service_type '
'to endpoint filtering data.')
return None
if not interface:
@ -240,8 +239,8 @@ class BaseIdentityPlugin(base.BaseAuthPlugin):
# NOTE(jamielennox): Again if we can't contact the server we fall
# back to just returning the URL from the catalog. This may not be
# the best default but we need it for now.
LOG.warn(_LW('Failed to contact the endpoint at %s for discovery. '
'Fallback to using that endpoint as the base url.'),
LOG.warn('Failed to contact the endpoint at %s for discovery. '
'Fallback to using that endpoint as the base url.',
url)
else:
url = disc.url_for(version)

View File

@ -20,7 +20,6 @@ import six.moves.urllib.parse as urlparse
from keystoneauth.auth.identity import base
from keystoneauth import discover
from keystoneauth import exceptions
from keystoneauth.i18n import _, _LW
LOG = logging.getLogger(__name__)
@ -130,9 +129,9 @@ class BaseGenericPlugin(base.BaseIdentityPlugin):
except (exceptions.DiscoveryFailure,
exceptions.HttpError,
exceptions.ConnectionError):
LOG.warn(_LW('Discovering versions from the identity service '
'failed when creating the password plugin. '
'Attempting to determine version from URL.'))
LOG.warn('Discovering versions from the identity service '
'failed when creating the password plugin. '
'Attempting to determine version from URL.')
url_parts = urlparse.urlparse(self.auth_url)
path = url_parts.path.lower()
@ -166,7 +165,7 @@ class BaseGenericPlugin(base.BaseIdentityPlugin):
return plugin
# so there were no URLs that i could use for auth of any version.
msg = _('Could not determine a suitable URL for the plugin')
msg = 'Could not determine a suitable URL for the plugin'
raise exceptions.DiscoveryFailure(msg)
def get_auth_ref(self, session, **kwargs):

View File

@ -20,7 +20,6 @@ from keystoneauth import _utils as utils
from keystoneauth import access
from keystoneauth.auth.identity import base
from keystoneauth import exceptions
from keystoneauth.i18n import _
_logger = logging.getLogger(__name__)
@ -138,7 +137,7 @@ class Auth(BaseAuth):
if not ident:
raise exceptions.AuthorizationFailure(
_('Authentication method required (e.g. password)'))
'Authentication method required (e.g. password)')
mutual_exclusion = [bool(self.domain_id or self.domain_name),
bool(self.project_id or self.project_name),
@ -147,8 +146,8 @@ class Auth(BaseAuth):
if sum(mutual_exclusion) > 1:
raise exceptions.AuthorizationFailure(
_('Authentication cannot be scoped to multiple targets. Pick '
'one of: project, domain, trust or unscoped'))
'Authentication cannot be scoped to multiple targets. Pick '
'one of: project, domain, trust or unscoped')
if self.domain_id:
body['auth']['scope'] = {'domain': {'id': self.domain_id}}
@ -211,7 +210,7 @@ class AuthMethod(object):
setattr(self, param, kwargs.pop(param, None))
if kwargs:
msg = _("Unexpected Attributes: %s") % ", ".join(kwargs.keys())
msg = "Unexpected Attributes: %s" % ", ".join(kwargs.keys())
raise AttributeError(msg)
@classmethod

View File

@ -26,7 +26,6 @@ import re
from keystoneauth import _utils as utils
from keystoneauth import exceptions
from keystoneauth.i18n import _, _LI, _LW
_LOGGER = logging.getLogger(__name__)
@ -66,7 +65,7 @@ def get_version_data(session, url, authenticated=None):
pass
err_text = resp.text[:50] + '...' if len(resp.text) > 50 else resp.text
msg = _('Invalid Response - Bad version data returned: %s') % err_text
msg = 'Invalid Response - Bad version data returned: %s' % err_text
raise exceptions.DiscoveryFailure(msg)
@ -100,7 +99,7 @@ def normalize_version_number(version):
except Exception:
pass
raise TypeError(_('Invalid version specified: %s') % version)
raise TypeError('Invalid version specified: %s' % version)
def version_match(required, candidate):
@ -162,8 +161,8 @@ class Discover(object):
try:
status = v['status']
except KeyError:
_LOGGER.warning(_LW('Skipping over invalid version data. '
'No stability status in version.'))
_LOGGER.warning('Skipping over invalid version data. '
'No stability status in version.')
continue
status = status.lower()
@ -202,14 +201,13 @@ class Discover(object):
try:
version_str = v['id']
except KeyError:
_LOGGER.info(_LI('Skipping invalid version data. Missing ID.'))
_LOGGER.info('Skipping invalid version data. Missing ID.')
continue
try:
links = v['links']
except KeyError:
_LOGGER.info(
_LI('Skipping invalid version data. Missing links'))
_LOGGER.info('Skipping invalid version data. Missing links')
continue
version_number = normalize_version_number(version_str)
@ -219,15 +217,15 @@ class Discover(object):
rel = link['rel']
url = link['href']
except (KeyError, TypeError):
_LOGGER.info(_LI('Skipping invalid version link. '
'Missing link URL or relationship.'))
_LOGGER.info('Skipping invalid version link. '
'Missing link URL or relationship.')
continue
if rel.lower() == 'self':
break
else:
_LOGGER.info(_LI('Skipping invalid version data. '
'Missing link to endpoint.'))
_LOGGER.info('Skipping invalid version data. '
'Missing link to endpoint.')
continue
versions.append({'version': version_number,

View File

@ -11,7 +11,6 @@
# under the License.
from keystoneauth.exceptions import base
from keystoneauth.i18n import _
class AuthPluginException(base.ClientException):
@ -35,5 +34,5 @@ class NoMatchingPlugin(AuthPluginException):
def __init__(self, name):
self.name = name
msg = _('The plugin %s could not be found') % name
msg = 'The plugin %s could not be found' % name
super(NoMatchingPlugin, self).__init__(msg)

View File

@ -26,7 +26,6 @@ import sys
import six
from keystoneauth.exceptions import base
from keystoneauth.i18n import _
__all__ = ['HttpError',
@ -67,7 +66,7 @@ class HttpError(base.ClientException):
"""The base exception class for all HTTP exceptions.
"""
http_status = 0
message = _("HTTP Error")
message = "HTTP Error"
def __init__(self, message=None, details=None,
response=None, request_id=None,
@ -90,7 +89,7 @@ class HTTPClientError(HttpError):
Exception for cases in which the client seems to have erred.
"""
message = _("HTTP Client Error")
message = "HTTP Client Error"
class HttpServerError(HttpError):
@ -99,7 +98,7 @@ class HttpServerError(HttpError):
Exception for cases in which the server is aware that it has
erred or is incapable of performing the request.
"""
message = _("HTTP Server Error")
message = "HTTP Server Error"
class BadRequest(HTTPClientError):
@ -108,7 +107,7 @@ class BadRequest(HTTPClientError):
The request cannot be fulfilled due to bad syntax.
"""
http_status = 400
message = _("Bad Request")
message = "Bad Request"
class Unauthorized(HTTPClientError):
@ -118,7 +117,7 @@ class Unauthorized(HTTPClientError):
is required and has failed or has not yet been provided.
"""
http_status = 401
message = _("Unauthorized")
message = "Unauthorized"
class PaymentRequired(HTTPClientError):
@ -127,7 +126,7 @@ class PaymentRequired(HTTPClientError):
Reserved for future use.
"""
http_status = 402
message = _("Payment Required")
message = "Payment Required"
class Forbidden(HTTPClientError):
@ -137,7 +136,7 @@ class Forbidden(HTTPClientError):
to it.
"""
http_status = 403
message = _("Forbidden")
message = "Forbidden"
class NotFound(HTTPClientError):
@ -147,7 +146,7 @@ class NotFound(HTTPClientError):
in the future.
"""
http_status = 404
message = _("Not Found")
message = "Not Found"
class MethodNotAllowed(HTTPClientError):
@ -157,7 +156,7 @@ class MethodNotAllowed(HTTPClientError):
by that resource.
"""
http_status = 405
message = _("Method Not Allowed")
message = "Method Not Allowed"
class NotAcceptable(HTTPClientError):
@ -167,7 +166,7 @@ class NotAcceptable(HTTPClientError):
acceptable according to the Accept headers sent in the request.
"""
http_status = 406
message = _("Not Acceptable")
message = "Not Acceptable"
class ProxyAuthenticationRequired(HTTPClientError):
@ -176,7 +175,7 @@ class ProxyAuthenticationRequired(HTTPClientError):
The client must first authenticate itself with the proxy.
"""
http_status = 407
message = _("Proxy Authentication Required")
message = "Proxy Authentication Required"
class RequestTimeout(HTTPClientError):
@ -185,7 +184,7 @@ class RequestTimeout(HTTPClientError):
The server timed out waiting for the request.
"""
http_status = 408
message = _("Request Timeout")
message = "Request Timeout"
class Conflict(HTTPClientError):
@ -195,7 +194,7 @@ class Conflict(HTTPClientError):
in the request, such as an edit conflict.
"""
http_status = 409
message = _("Conflict")
message = "Conflict"
class Gone(HTTPClientError):
@ -205,7 +204,7 @@ class Gone(HTTPClientError):
not be available again.
"""
http_status = 410
message = _("Gone")
message = "Gone"
class LengthRequired(HTTPClientError):
@ -215,7 +214,7 @@ class LengthRequired(HTTPClientError):
required by the requested resource.
"""
http_status = 411
message = _("Length Required")
message = "Length Required"
class PreconditionFailed(HTTPClientError):
@ -225,7 +224,7 @@ class PreconditionFailed(HTTPClientError):
put on the request.
"""
http_status = 412
message = _("Precondition Failed")
message = "Precondition Failed"
class RequestEntityTooLarge(HTTPClientError):
@ -234,7 +233,7 @@ class RequestEntityTooLarge(HTTPClientError):
The request is larger than the server is willing or able to process.
"""
http_status = 413
message = _("Request Entity Too Large")
message = "Request Entity Too Large"
def __init__(self, *args, **kwargs):
try:
@ -251,7 +250,7 @@ class RequestUriTooLong(HTTPClientError):
The URI provided was too long for the server to process.
"""
http_status = 414
message = _("Request-URI Too Long")
message = "Request-URI Too Long"
class UnsupportedMediaType(HTTPClientError):
@ -261,7 +260,7 @@ class UnsupportedMediaType(HTTPClientError):
not support.
"""
http_status = 415
message = _("Unsupported Media Type")
message = "Unsupported Media Type"
class RequestedRangeNotSatisfiable(HTTPClientError):
@ -271,7 +270,7 @@ class RequestedRangeNotSatisfiable(HTTPClientError):
supply that portion.
"""
http_status = 416
message = _("Requested Range Not Satisfiable")
message = "Requested Range Not Satisfiable"
class ExpectationFailed(HTTPClientError):
@ -280,7 +279,7 @@ class ExpectationFailed(HTTPClientError):
The server cannot meet the requirements of the Expect request-header field.
"""
http_status = 417
message = _("Expectation Failed")
message = "Expectation Failed"
class UnprocessableEntity(HTTPClientError):
@ -290,7 +289,7 @@ class UnprocessableEntity(HTTPClientError):
errors.
"""
http_status = 422
message = _("Unprocessable Entity")
message = "Unprocessable Entity"
class InternalServerError(HttpServerError):
@ -299,7 +298,7 @@ class InternalServerError(HttpServerError):
A generic error message, given when no more specific message is suitable.
"""
http_status = 500
message = _("Internal Server Error")
message = "Internal Server Error"
# NotImplemented is a python keyword.
@ -310,7 +309,7 @@ class HttpNotImplemented(HttpServerError):
the ability to fulfill the request.
"""
http_status = 501
message = _("Not Implemented")
message = "Not Implemented"
class BadGateway(HttpServerError):
@ -320,7 +319,7 @@ class BadGateway(HttpServerError):
response from the upstream server.
"""
http_status = 502
message = _("Bad Gateway")
message = "Bad Gateway"
class ServiceUnavailable(HttpServerError):
@ -329,7 +328,7 @@ class ServiceUnavailable(HttpServerError):
The server is currently unavailable.
"""
http_status = 503
message = _("Service Unavailable")
message = "Service Unavailable"
class GatewayTimeout(HttpServerError):
@ -339,7 +338,7 @@ class GatewayTimeout(HttpServerError):
response from the upstream server.
"""
http_status = 504
message = _("Gateway Timeout")
message = "Gateway Timeout"
class HttpVersionNotSupported(HttpServerError):
@ -348,7 +347,7 @@ class HttpVersionNotSupported(HttpServerError):
The server does not support the HTTP protocol version used in the request.
"""
http_status = 505
message = _("HTTP Version Not Supported")
message = "HTTP Version Not Supported"
# _code_map contains all the classes that have http_status attribute.

View File

@ -1,28 +0,0 @@
# Copyright 2014 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""oslo.i18n integration stub.
This module is a stub to allow dropping the use of oslo.i18n without
requiring a change to all of the various strings throughout keystoneauth.
"""
# TODO(morganfainberg): Eliminate the use of translation functions around
# each string in the keystoneauth library and then remove this file.
_ = lambda x: x
_LI = _
_LW = _
_LE = _
_LC = _

View File

@ -22,7 +22,6 @@ import six
from keystoneauth import _utils as utils
from keystoneauth import exceptions
from keystoneauth.i18n import _
@six.add_metaclass(abc.ABCMeta)
@ -166,7 +165,7 @@ class ServiceCatalog(object):
"""
if not self._catalog:
raise exceptions.EmptyCatalog(_('The service catalog is empty.'))
raise exceptions.EmptyCatalog('The service catalog is empty.')
urls = self.get_urls(service_type=service_type,
endpoint_type=endpoint_type,
@ -179,26 +178,26 @@ class ServiceCatalog(object):
pass
if service_name and region_name:
msg = (_('%(endpoint_type)s endpoint for %(service_type)s service '
'named %(service_name)s in %(region_name)s region not '
'found') %
msg = ('%(endpoint_type)s endpoint for %(service_type)s service '
'named %(service_name)s in %(region_name)s region not '
'found' %
{'endpoint_type': endpoint_type,
'service_type': service_type, 'service_name': service_name,
'region_name': region_name})
elif service_name:
msg = (_('%(endpoint_type)s endpoint for %(service_type)s service '
'named %(service_name)s not found') %
msg = ('%(endpoint_type)s endpoint for %(service_type)s service '
'named %(service_name)s not found' %
{'endpoint_type': endpoint_type,
'service_type': service_type,
'service_name': service_name})
elif region_name:
msg = (_('%(endpoint_type)s endpoint for %(service_type)s service '
'in %(region_name)s region not found') %
msg = ('%(endpoint_type)s endpoint for %(service_type)s service '
'in %(region_name)s region not found' %
{'endpoint_type': endpoint_type,
'service_type': service_type, 'region_name': region_name})
else:
msg = (_('%(endpoint_type)s endpoint for %(service_type)s service '
'not found') %
msg = ('%(endpoint_type)s endpoint for %(service_type)s service '
'not found' %
{'endpoint_type': endpoint_type,
'service_type': service_type})
@ -213,7 +212,7 @@ class ServiceCatalogV2(ServiceCatalog):
@classmethod
def from_token(cls, token):
if 'access' not in token:
raise ValueError(_('Invalid token format for fetching catalog'))
raise ValueError('Invalid token format for fetching catalog')
return cls(token['access'].get('serviceCatalog', {}))
@ -249,7 +248,7 @@ class ServiceCatalogV3(ServiceCatalog):
@classmethod
def from_token(cls, token):
if 'token' not in token:
raise ValueError(_('Invalid token format for fetching catalog'))
raise ValueError('Invalid token format for fetching catalog')
return cls(token['token'].get('catalog', {}))

View File

@ -28,7 +28,6 @@ from six.moves import urllib
from keystoneauth import _utils as utils
from keystoneauth import exceptions
from keystoneauth.i18n import _, _LI, _LW
try:
import netaddr
@ -51,10 +50,10 @@ def _positive_non_zero_float(argument_value):
try:
value = float(argument_value)
except ValueError:
msg = _("%s must be a float") % argument_value
msg = "%s must be a float" % argument_value
raise argparse.ArgumentTypeError(msg)
if value <= 0:
msg = _("%s must be greater than 0") % argument_value
msg = "%s must be greater than 0" % argument_value
raise argparse.ArgumentTypeError(msg)
return value
@ -326,7 +325,7 @@ class Session(object):
auth_headers = self.get_auth_headers(auth)
if auth_headers is None:
msg = _('No valid authentication is available')
msg = 'No valid authentication is available'
raise exceptions.AuthorizationFailure(msg)
headers.update(auth_headers)
@ -428,17 +427,17 @@ class Session(object):
try:
resp = self.session.request(method, url, **kwargs)
except requests.exceptions.SSLError as e:
msg = _('SSL exception connecting to %(url)s: '
'%(error)s') % {'url': url, 'error': e}
msg = 'SSL exception connecting to %(url)s: %(error)s' % {
'url': url, 'error': e}
raise exceptions.SSLError(msg)
except requests.exceptions.Timeout:
msg = _('Request to %s timed out') % url
msg = 'Request to %s timed out' % url
raise exceptions.ConnectTimeout(msg)
except requests.exceptions.ConnectionError:
msg = _('Unable to establish connection to %s') % url
msg = 'Unable to establish connection to %s' % url
raise exceptions.ConnectFailure(msg)
except requests.exceptions.RequestException as e:
msg = _('Unexpected exception for %(url)s: %(error)s') % {
msg = 'Unexpected exception for %(url)s: %(error)s' % {
'url': url, 'error': e}
raise exceptions.UnknownConnectionError(msg, e)
@ -446,7 +445,7 @@ class Session(object):
if connect_retries <= 0:
raise
logger.info(_LI('Failure: %(e)s. Retrying in %(delay).1fs.'),
logger.info('Failure: %(e)s. Retrying in %(delay).1fs.',
{'e': e, 'delay': connect_retry_delay})
time.sleep(connect_retry_delay)
@ -473,8 +472,8 @@ class Session(object):
try:
location = resp.headers['location']
except KeyError:
logger.warn(_LW("Failed to redirect request to %s as new "
"location was not provided."), resp.url)
logger.warn("Failed to redirect request to %s as new "
"location was not provided.", resp.url)
else:
# NOTE(jamielennox): We don't pass through connect_retry_delay.
# This request actually worked so we can reset the delay count.
@ -565,7 +564,7 @@ class Session(object):
auth = self.auth
if not auth:
msg_fmt = _('An auth plugin is required to %s')
msg_fmt = 'An auth plugin is required to %s'
raise exceptions.MissingAuthPlugin(msg_fmt % msg)
return auth

View File

@ -26,7 +26,6 @@ from testtools import matchers
from keystoneauth import adapter
from keystoneauth.auth import base
from keystoneauth import exceptions
from keystoneauth.i18n import _
from keystoneauth import session as client_session
from keystoneauth.tests.unit import utils
@ -223,7 +222,7 @@ class SessionTests(utils.TestCase):
session = client_session.Session()
# The exception should contain the URL and details about the SSL error
msg = _('SSL exception connecting to %(url)s: %(error)s') % {
msg = 'SSL exception connecting to %(url)s: %(error)s' % {
'url': self.TEST_URL, 'error': error}
self.assertRaisesRegex(exceptions.SSLError,
msg,