Wrap common exceptions in _()

Change-Id: Idb7aabc1dbabc0bbcb9b8b3892372059024c55c3
Partial-bug: #1199695
This commit is contained in:
Angus Salkeld 2013-10-18 10:43:43 +11:00
parent 6895615582
commit 5e9ed5ed5f
6 changed files with 22 additions and 22 deletions

View File

@ -181,7 +181,7 @@ def load_paste_app(app_name=None):
conf_file = _get_deployment_config_file()
if conf_file is None:
raise RuntimeError("Unable to locate config file")
raise RuntimeError(_("Unable to locate config file"))
try:
app = wsgi.paste_deploy_app(conf_file, app_name, cfg.CONF)
@ -193,8 +193,8 @@ def load_paste_app(app_name=None):
return app
except (LookupError, ImportError) as e:
raise RuntimeError("Unable to load %(app_name)s from "
"configuration file %(conf_file)s."
"\nGot: %(e)r" % {'app_name': app_name,
'conf_file': conf_file,
'e': e})
raise RuntimeError(_("Unable to load %(app_name)s from "
"configuration file %(conf_file)s."
"\nGot: %(e)r") % {'app_name': app_name,
'conf_file': conf_file,
'e': e})

View File

@ -36,7 +36,7 @@ def parse(env_str):
for param in env:
if param not in SECTIONS:
raise ValueError('environment has wrong section "%s"' % param)
raise ValueError(_('environment has wrong section "%s"') % param)
return env

View File

@ -37,7 +37,7 @@ class HeatIdentifier(collections.Mapping):
path = '/' + path
if '/' in stack_name:
raise ValueError('Stack name may not contain "/"')
raise ValueError(_('Stack name may not contain "/"'))
self.identity = {
self.TENANT: tenant,
@ -53,13 +53,13 @@ class HeatIdentifier(collections.Mapping):
'''
fields = arn.split(':')
if len(fields) < 6 or fields[0].lower() != 'arn':
raise ValueError('"%s" is not a valid ARN' % arn)
raise ValueError(_('"%s" is not a valid ARN') % arn)
id_fragment = ':'.join(fields[5:])
path = cls.path_re.match(id_fragment)
if fields[1] != 'openstack' or fields[2] != 'heat' or not path:
raise ValueError('"%s" is not a valid Heat ARN' % arn)
raise ValueError(_('"%s" is not a valid Heat ARN') % arn)
return cls(urllib.unquote(fields[4]),
urllib.unquote(path.group(1)),
@ -76,13 +76,13 @@ class HeatIdentifier(collections.Mapping):
urlp = urlparse.urlparse(url)
if (urlp.scheme not in ('http', 'https') or
not urlp.netloc or not urlp.path):
raise ValueError('"%s" is not a valid URL' % url)
raise ValueError(_('"%s" is not a valid URL') % url)
# Remove any query-string and extract the ARN
arn_url_prefix = '/arn%3Aopenstack%3Aheat%3A%3A'
match = re.search(arn_url_prefix, urlp.path, re.IGNORECASE)
if match is None:
raise ValueError('"%s" is not a valid ARN URL' % url)
raise ValueError(_('"%s" is not a valid ARN URL') % url)
# the +1 is to skip the leading /
url_arn = urlp.path[match.start() + 1:]
arn = urllib.unquote(url_arn)
@ -129,14 +129,14 @@ class HeatIdentifier(collections.Mapping):
attribute.
'''
if attr not in self.FIELDS:
raise AttributeError('Unknown attribute "%s"' % attr)
raise AttributeError(_('Unknown attribute "%s"') % attr)
return self.identity[attr]
def __getitem__(self, key):
'''Return one of the components of the identity.'''
if key not in self.FIELDS:
raise KeyError('Unknown attribute "%s"' % key)
raise KeyError(_('Unknown attribute "%s"') % key)
return self.identity[key]
@ -167,7 +167,7 @@ class ResourceIdentifier(HeatIdentifier):
'''
if resource_name is not None:
if '/' in resource_name:
raise ValueError('Resource name may not contain "/"')
raise ValueError(_('Resource name may not contain "/"'))
path = '/'.join([path.rstrip('/'), 'resources', resource_name])
super(ResourceIdentifier, self).__init__(tenant,
stack_name,

View File

@ -40,7 +40,7 @@ def get_id(source_uuid):
if isinstance(source_uuid, basestring):
source_uuid = uuid.UUID(source_uuid)
if source_uuid.version != 4:
raise ValueError('Invalid UUID version (%d)' % source_uuid.version)
raise ValueError(_('Invalid UUID version (%d)') % source_uuid.version)
# The "time" field of a v4 UUID contains 60 random bits
# (see RFC4122, Section 4.4)

View File

@ -31,8 +31,8 @@ def parse_isoduration(duration):
"""
result = iso_duration_re.match(duration)
if not result:
raise ValueError('Only ISO 8601 duration format of the form '
'PT#H#M#S is supported.')
raise ValueError(_('Only ISO 8601 duration format of the form '
'PT#H#M#S is supported.'))
t = 0
t += (3600 * int(result.group(1))) if result.group(1) else 0

View File

@ -46,13 +46,13 @@ def get(url, allowed_schemes=('http', 'https')):
components = urlparse.urlparse(url)
if components.scheme not in allowed_schemes:
raise IOError('Invalid URL scheme %s' % components.scheme)
raise IOError(_('Invalid URL scheme %s') % components.scheme)
if components.scheme == 'file':
try:
return urllib2.urlopen(url).read()
except urllib2.URLError as uex:
raise IOError('Failed to retrieve template: %s' % str(uex))
raise IOError(_('Failed to retrieve template: %s') % str(uex))
try:
max_size = cfg.CONF.max_template_size
@ -61,8 +61,8 @@ def get(url, allowed_schemes=('http', 'https')):
resp.raise_for_status()
result = resp.raw.read(max_fetched_size)
if len(result) == max_fetched_size:
raise IOError("Template exceeds maximum allowed size (%s bytes)"
raise IOError(_("Template exceeds maximum allowed size (%s bytes)")
% max_size)
return result
except exceptions.RequestException as ex:
raise IOError('Failed to retrieve template: %s' % str(ex))
raise IOError(_('Failed to retrieve template: %s') % str(ex))