Convert "outgoing" literals to unicode
The patch convers most literals throughout marconi to unicode. Lietrals not leaving "marconi-land" were left untouched. This is the first patch of a serie that will enforce unicode usage within marconi. Decode early, encode late. String format parameters were left untouched on purpose. Those parameters should be decoded before getting there. Implements blueprint enforce-decoding Change-Id: I85e534ced188191c9c7a17e9908cb720e7d63ca9
This commit is contained in:
parent
9272cf4742
commit
d8c68d8609
@ -43,7 +43,7 @@ class Bootstrap(object):
|
||||
|
||||
@decorators.lazy_property(write=False)
|
||||
def storage(self):
|
||||
LOG.debug(_('Loading Storage Driver'))
|
||||
LOG.debug(_(u'Loading Storage Driver'))
|
||||
try:
|
||||
mgr = driver.DriverManager('marconi.storage',
|
||||
CFG.storage,
|
||||
@ -55,7 +55,7 @@ class Bootstrap(object):
|
||||
|
||||
@decorators.lazy_property(write=False)
|
||||
def transport(self):
|
||||
LOG.debug(_('Loading Transport Driver'))
|
||||
LOG.debug(_(u'Loading Transport Driver'))
|
||||
try:
|
||||
mgr = driver.DriverManager('marconi.transport',
|
||||
CFG.transport,
|
||||
|
@ -39,8 +39,8 @@ def run():
|
||||
"""
|
||||
|
||||
try:
|
||||
info = _('Starting marconi-gc')
|
||||
print(info + _('. Use CTRL+C to exit...\n'))
|
||||
info = _(u'Starting marconi-gc')
|
||||
print(info + _(u'. Use CTRL+C to exit...\n'))
|
||||
LOG.info(info)
|
||||
|
||||
boot = bootstrap.Bootstrap(cli_args=sys.argv[1:])
|
||||
@ -57,7 +57,5 @@ def run():
|
||||
time.sleep(gc_interval)
|
||||
|
||||
except NotImplementedError as ex:
|
||||
print('The configured storage driver does not support GC.\n')
|
||||
|
||||
print(_(u'The configured storage driver does not support GC.\n'))
|
||||
LOG.exception(ex)
|
||||
print('')
|
||||
|
@ -72,7 +72,7 @@ def runnable(func):
|
||||
PROJECT_CFG.load(args=sys.argv[1:])
|
||||
func()
|
||||
except KeyboardInterrupt:
|
||||
LOG.info('Terminating')
|
||||
LOG.info(_(u'Terminating'))
|
||||
except Exception as ex:
|
||||
_fail(1, ex)
|
||||
|
||||
|
@ -197,4 +197,4 @@ def _make_opt(name, default):
|
||||
try:
|
||||
return deduction[type(default)](name, help=help, default=default)
|
||||
except KeyError:
|
||||
raise cfg.Error('unrecognized option type')
|
||||
raise cfg.Error(u'unrecognized option type')
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
|
||||
class InvalidDriver(Exception):
|
||||
pass
|
||||
"""A driver was not found or loaded."""
|
||||
|
||||
|
||||
class PatternNotFound(Exception):
|
||||
|
@ -21,11 +21,11 @@ class ConnectionError(Exception):
|
||||
|
||||
|
||||
class DoesNotExist(Exception):
|
||||
pass
|
||||
"""Resource does not exist."""
|
||||
|
||||
|
||||
class NotPermitted(Exception):
|
||||
pass
|
||||
"""Operation not permitted."""
|
||||
|
||||
|
||||
class Conflict(Exception):
|
||||
@ -53,9 +53,9 @@ class MessageConflict(Conflict):
|
||||
posted. Note that these must be in the same order as the
|
||||
list of messages originally submitted to be enqueued.
|
||||
"""
|
||||
msg = ('Message could not be enqueued due to a conflict '
|
||||
'with another message that is already in '
|
||||
'queue %(queue)s for project %(project)s' %
|
||||
msg = (u'Message could not be enqueued due to a conflict '
|
||||
u'with another message that is already in '
|
||||
u'queue %(queue)s for project %(project)s' %
|
||||
dict(queue=queue, project=project))
|
||||
|
||||
super(MessageConflict, self).__init__(msg)
|
||||
@ -70,7 +70,7 @@ class MessageConflict(Conflict):
|
||||
class QueueDoesNotExist(DoesNotExist):
|
||||
|
||||
def __init__(self, name, project):
|
||||
msg = ('Queue %(name)s does not exist for project %(project)s' %
|
||||
msg = (u'Queue %(name)s does not exist for project %(project)s' %
|
||||
dict(name=name, project=project))
|
||||
super(QueueDoesNotExist, self).__init__(msg)
|
||||
|
||||
@ -78,7 +78,7 @@ class QueueDoesNotExist(DoesNotExist):
|
||||
class QueueIsEmpty(Exception):
|
||||
|
||||
def __init__(self, name, project):
|
||||
msg = ('Queue %(name)s in project %(project)s is empty' %
|
||||
msg = (u'Queue %(name)s in project %(project)s is empty' %
|
||||
dict(name=name, project=project))
|
||||
super(QueueIsEmpty, self).__init__(msg)
|
||||
|
||||
@ -86,8 +86,8 @@ class QueueIsEmpty(Exception):
|
||||
class MessageDoesNotExist(DoesNotExist):
|
||||
|
||||
def __init__(self, mid, queue, project):
|
||||
msg = ('Message %(mid)s does not exist in '
|
||||
'queue %(queue)s for project %(project)s' %
|
||||
msg = (u'Message %(mid)s does not exist in '
|
||||
u'queue %(queue)s for project %(project)s' %
|
||||
dict(mid=mid, queue=queue, project=project))
|
||||
super(MessageDoesNotExist, self).__init__(msg)
|
||||
|
||||
@ -95,8 +95,8 @@ class MessageDoesNotExist(DoesNotExist):
|
||||
class ClaimDoesNotExist(DoesNotExist):
|
||||
|
||||
def __init__(self, cid, queue, project):
|
||||
msg = ('Claim %(cid)s does not exist in '
|
||||
'queue %(queue)s for project %(project)s' %
|
||||
msg = (u'Claim %(cid)s does not exist in '
|
||||
u'queue %(queue)s for project %(project)s' %
|
||||
dict(cid=cid, queue=queue, project=project))
|
||||
super(ClaimDoesNotExist, self).__init__(msg)
|
||||
|
||||
@ -104,6 +104,6 @@ class ClaimDoesNotExist(DoesNotExist):
|
||||
class ClaimNotPermitted(NotPermitted):
|
||||
|
||||
def __init__(self, mid, cid):
|
||||
msg = ('Message %(mid)s is not claimed by %(cid)s' %
|
||||
msg = (u'Message %(mid)s is not claimed by %(cid)s' %
|
||||
dict(cid=cid, mid=mid))
|
||||
super(ClaimNotPermitted, self).__init__(msg)
|
||||
|
@ -198,7 +198,7 @@ class ClaimController(storage.ClaimBase):
|
||||
expires = now + ttl_delta
|
||||
|
||||
if now > expires:
|
||||
raise ValueError('New ttl will make the claim expires')
|
||||
raise ValueError(u'New ttl will make the claim expires')
|
||||
|
||||
msg_ctrl = self.driver.message_controller
|
||||
claimed = msg_ctrl.claimed(queue, cid, expires=now,
|
||||
|
@ -46,7 +46,7 @@ class Driver(storage.DriverBase):
|
||||
return self._database
|
||||
|
||||
def gc(self):
|
||||
LOG.info('Performing garbage collection.')
|
||||
LOG.info(_(u'Performing garbage collection.'))
|
||||
|
||||
try:
|
||||
self.message_controller.remove_expired()
|
||||
|
@ -208,7 +208,7 @@ class MessageController(storage.MessageBase):
|
||||
|
||||
if head is None:
|
||||
# Assume queue was just deleted via a parallel request
|
||||
LOG.warning(_('Queue %s is empty or missing.') % queue_name)
|
||||
LOG.warning(_(u'Queue %s is empty or missing.') % queue_name)
|
||||
return
|
||||
|
||||
# NOTE(flaper87): Can we use k instead of
|
||||
@ -257,8 +257,8 @@ class MessageController(storage.MessageBase):
|
||||
"""
|
||||
|
||||
if sort not in (1, -1):
|
||||
raise ValueError('sort must be either 1 (ascending) '
|
||||
'or -1 (descending)')
|
||||
raise ValueError(u'sort must be either 1 (ascending) '
|
||||
u'or -1 (descending)')
|
||||
|
||||
now = timeutils.utcnow()
|
||||
|
||||
@ -273,7 +273,7 @@ class MessageController(storage.MessageBase):
|
||||
}
|
||||
|
||||
if fields and not isinstance(fields, (dict, list)):
|
||||
raise TypeError('Fields must be an instance of list / dict')
|
||||
raise TypeError(u'Fields must be an instance of list / dict')
|
||||
|
||||
if not echo and client_uuid is not None:
|
||||
query['u'] = {'$ne': client_uuid}
|
||||
@ -519,9 +519,9 @@ class MessageController(storage.MessageBase):
|
||||
|
||||
# Log a message if we retried, for debugging perf issues
|
||||
if attempt != 0:
|
||||
message = _('%(attempts)d attempt(s) required to post '
|
||||
'%(num_messages)d messages to queue '
|
||||
'%(queue_name)s and project %(project)s')
|
||||
message = _(u'%(attempts)d attempt(s) required to post '
|
||||
u'%(num_messages)d messages to queue '
|
||||
u'%(queue_name)s and project %(project)s')
|
||||
message %= dict(queue_name=queue_name, attempts=attempt+1,
|
||||
num_messages=len(ids), project=project)
|
||||
|
||||
@ -539,8 +539,9 @@ class MessageController(storage.MessageBase):
|
||||
#
|
||||
# TODO(kgriffs): Add transaction ID to help match up loglines
|
||||
if attempt == 0:
|
||||
message = _('First attempt failed while adding messages '
|
||||
'to queue %s for current request') % queue_name
|
||||
message = _(u'First attempt failed while '
|
||||
u'adding messages to queue %s '
|
||||
u'for current request') % queue_name
|
||||
|
||||
LOG.debug(message)
|
||||
|
||||
@ -584,8 +585,8 @@ class MessageController(storage.MessageBase):
|
||||
LOG.exception(ex)
|
||||
raise
|
||||
|
||||
message = _('Hit maximum number of attempts (%(max)s) for queue '
|
||||
'%(id)s in project %(project)s')
|
||||
message = _(u'Hit maximum number of attempts (%(max)s) for queue '
|
||||
u'%(id)s in project %(project)s')
|
||||
message %= dict(max=options.CFG.max_attempts, id=queue_name,
|
||||
project=project)
|
||||
|
||||
|
@ -44,7 +44,7 @@ def dup_marker_from_error(error_message):
|
||||
"""
|
||||
match = DUP_MARKER_REGEX.findall(error_message)
|
||||
if not match:
|
||||
description = ('Error message could not be parsed: %s' %
|
||||
description = (u'Error message could not be parsed: %s' %
|
||||
error_message)
|
||||
raise exceptions.PatternNotFound(description)
|
||||
|
||||
@ -96,16 +96,16 @@ def calculate_backoff(attempt, max_attempts, max_sleep, max_jitter=0):
|
||||
the ratio attempt / max_attempts, with optional jitter.
|
||||
"""
|
||||
if max_attempts < 0:
|
||||
raise ValueError('max_attempts must be >= 0')
|
||||
raise ValueError(u'max_attempts must be >= 0')
|
||||
|
||||
if max_sleep < 0:
|
||||
raise ValueError('max_sleep must be >= 0')
|
||||
raise ValueError(u'max_sleep must be >= 0')
|
||||
|
||||
if max_jitter < 0:
|
||||
raise ValueError('max_jitter must be >= 0')
|
||||
raise ValueError(u'max_jitter must be >= 0')
|
||||
|
||||
if not (0 <= attempt < max_attempts):
|
||||
raise ValueError('attempt value is out of range')
|
||||
raise ValueError(u'attempt value is out of range')
|
||||
|
||||
ratio = float(attempt) / float(max_attempts)
|
||||
backoff_sec = ratio * max_sleep
|
||||
@ -128,7 +128,7 @@ def to_oid(obj):
|
||||
try:
|
||||
return objectid.ObjectId(obj)
|
||||
except (TypeError, berrors.InvalidId):
|
||||
msg = 'Invalid oid: %s' % obj
|
||||
msg = u'Invalid oid: %s' % obj
|
||||
raise storage_exceptions.MalformedID(msg)
|
||||
|
||||
|
||||
@ -137,7 +137,7 @@ def oid_utc(oid):
|
||||
try:
|
||||
return timeutils.normalize_time(oid.generation_time)
|
||||
except AttributeError:
|
||||
raise TypeError('Expected ObjectId and got %s' % type(oid))
|
||||
raise TypeError(u'Expected ObjectId and got %s' % type(oid))
|
||||
|
||||
|
||||
def stat_message(message, now):
|
||||
@ -166,7 +166,7 @@ def raises_conn_error(func):
|
||||
return func(*args, **kwargs)
|
||||
except errors.ConnectionFailure:
|
||||
# NOTE(flaper87): Raise the error
|
||||
msg = "ConnectionFailure caught"
|
||||
msg = u'ConnectionFailure caught'
|
||||
LOG.error(msg)
|
||||
raise storage_exceptions.ConnectionError(msg)
|
||||
|
||||
|
@ -99,8 +99,8 @@ class MessageController(base.MessageBase):
|
||||
limit 1'''
|
||||
|
||||
if sort not in (1, -1):
|
||||
raise ValueError('sort must be either 1 (ascending) '
|
||||
'or -1 (descending)')
|
||||
raise ValueError(u'sort must be either 1 (ascending) '
|
||||
u'or -1 (descending)')
|
||||
|
||||
sql = sql % ('DESC' if sort == -1 else 'ASC')
|
||||
|
||||
|
@ -39,7 +39,7 @@ class KeystoneAuth(object):
|
||||
@classmethod
|
||||
def install(cls, app, conf):
|
||||
"""Install Auth check on application."""
|
||||
LOG.debug(_("Installing Keystone's auth protocol"))
|
||||
LOG.debug(_(u"Installing Keystone's auth protocol"))
|
||||
cls._register_opts(conf)
|
||||
conf = dict(conf.get(cls.OPT_GROUP_NAME))
|
||||
return auth_token.AuthProtocol(app, conf=conf)
|
||||
|
@ -42,9 +42,9 @@ class CollectionResource(object):
|
||||
self.claim_controller = claim_controller
|
||||
|
||||
def on_post(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_("Claims collection POST - queue: %(queue)s, "
|
||||
"project: %(project)s") %
|
||||
{"queue": queue_name, "project": project_id})
|
||||
LOG.debug(_(u'Claims collection POST - queue: %(queue)s, '
|
||||
u'project: %(project)s') %
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
|
||||
# Check for an explicit limit on the # of messages to claim
|
||||
limit = req.get_param_as_int('limit')
|
||||
@ -52,7 +52,7 @@ class CollectionResource(object):
|
||||
|
||||
# Place JSON size restriction before parsing
|
||||
if req.content_length > CFG.metadata_max_length:
|
||||
description = _('Claim metadata size is too large.')
|
||||
description = _(u'Claim metadata size is too large.')
|
||||
raise wsgi_exceptions.HTTPBadRequestBody(description)
|
||||
|
||||
# Read claim metadata (e.g., TTL) and raise appropriate
|
||||
@ -81,7 +81,7 @@ class CollectionResource(object):
|
||||
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Claim could not be created.')
|
||||
description = _(u'Claim could not be created.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
# Serialize claimed messages, if any. This logic assumes
|
||||
@ -108,11 +108,11 @@ class ItemResource(object):
|
||||
self.claim_controller = claim_controller
|
||||
|
||||
def on_get(self, req, resp, project_id, queue_name, claim_id):
|
||||
LOG.debug(_("Claim item GET - claim: %(claim_id)s, "
|
||||
"queue: %(queue_name)s, project: %(project_id)s") %
|
||||
{"queue_name": queue_name,
|
||||
"project_id": project_id,
|
||||
"claim_id": claim_id})
|
||||
LOG.debug(_(u'Claim item GET - claim: %(claim_id)s, '
|
||||
u'queue: %(queue_name)s, project: %(project_id)s') %
|
||||
{'queue_name': queue_name,
|
||||
'project_id': project_id,
|
||||
'claim_id': claim_id})
|
||||
try:
|
||||
meta, msgs = self.claim_controller.get(
|
||||
queue_name,
|
||||
@ -127,7 +127,7 @@ class ItemResource(object):
|
||||
raise falcon.HTTPNotFound()
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Claim could not be queried.')
|
||||
description = _(u'Claim could not be queried.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
# Serialize claimed messages
|
||||
@ -145,15 +145,15 @@ class ItemResource(object):
|
||||
resp.status = falcon.HTTP_200
|
||||
|
||||
def on_patch(self, req, resp, project_id, queue_name, claim_id):
|
||||
LOG.debug(_("Claim Item PATCH - claim: %(claim_id)s, "
|
||||
"queue: %(queue_name)s, project:%(project_id)s") %
|
||||
{"queue_name": queue_name,
|
||||
"project_id": project_id,
|
||||
"claim_id": claim_id})
|
||||
LOG.debug(_(u'Claim Item PATCH - claim: %(claim_id)s, '
|
||||
u'queue: %(queue_name)s, project:%(project_id)s') %
|
||||
{'queue_name': queue_name,
|
||||
'project_id': project_id,
|
||||
'claim_id': claim_id})
|
||||
|
||||
# Place JSON size restriction before parsing
|
||||
if req.content_length > CFG.metadata_max_length:
|
||||
description = _('Claim metadata size is too large.')
|
||||
description = _(u'Claim metadata size is too large.')
|
||||
raise wsgi_exceptions.HTTPBadRequestBody(description)
|
||||
|
||||
# Read claim metadata (e.g., TTL) and raise appropriate
|
||||
@ -178,15 +178,15 @@ class ItemResource(object):
|
||||
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Claim could not be updated.')
|
||||
description = _(u'Claim could not be updated.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
def on_delete(self, req, resp, project_id, queue_name, claim_id):
|
||||
LOG.debug(_("Claim item DELETE - claim: %(claim_id)s, "
|
||||
"queue: %(queue_name)s, project: %(project_id)s") %
|
||||
{"queue_name": queue_name,
|
||||
"project_id": project_id,
|
||||
"claim_id": claim_id})
|
||||
LOG.debug(_(u'Claim item DELETE - claim: %(claim_id)s, '
|
||||
u'queue: %(queue_name)s, project: %(project_id)s') %
|
||||
{'queue_name': queue_name,
|
||||
'project_id': project_id,
|
||||
'claim_id': claim_id})
|
||||
try:
|
||||
self.claim_controller.delete(queue_name,
|
||||
claim_id=claim_id,
|
||||
@ -196,7 +196,7 @@ class ItemResource(object):
|
||||
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Claim could not be deleted.')
|
||||
description = _(u'Claim could not be deleted.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
|
||||
|
@ -43,11 +43,11 @@ LOG = logging.getLogger(__name__)
|
||||
def _check_media_type(req, resp, params):
|
||||
if not req.client_accepts('application/json'):
|
||||
raise falcon.HTTPNotAcceptable(
|
||||
'''
|
||||
u'''
|
||||
Endpoint only serves `application/json`; specify client-side
|
||||
media type support with the "Accept" header.''',
|
||||
href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html",
|
||||
href_text='"14.1 Accept", Hypertext Transfer Protocol -- HTTP/1.1')
|
||||
href=u'http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html',
|
||||
href_text=u'14.1 Accept, Hypertext Transfer Protocol -- HTTP/1.1')
|
||||
|
||||
|
||||
def _extract_project_id(req, resp, params):
|
||||
@ -121,7 +121,7 @@ class Driver(transport.DriverBase):
|
||||
def listen(self):
|
||||
"""Self-host using 'bind' and 'port' from the WSGI config group."""
|
||||
|
||||
msg = _('Serving on host %(bind)s:%(port)s')
|
||||
msg = _(u'Serving on host %(bind)s:%(port)s')
|
||||
msg %= {'bind': WSGI_CFG.bind, 'port': WSGI_CFG.port}
|
||||
LOG.info(msg)
|
||||
|
||||
|
@ -19,8 +19,8 @@ import falcon
|
||||
class HTTPServiceUnavailable(falcon.HTTPServiceUnavailable):
|
||||
"""Wraps falcon.HTTPServiceUnavailable with Marconi messaging."""
|
||||
|
||||
TITLE = _('Service temporarily unavailable')
|
||||
DESCRIPTION = ('Please try again in a few seconds.')
|
||||
TITLE = _(u'Service temporarily unavailable')
|
||||
DESCRIPTION = (u'Please try again in a few seconds.')
|
||||
|
||||
def __init__(self, description, retry_after=30):
|
||||
description = description + ' ' + self.DESCRIPTION
|
||||
@ -31,7 +31,7 @@ class HTTPServiceUnavailable(falcon.HTTPServiceUnavailable):
|
||||
class HTTPBadRequestBody(falcon.HTTPBadRequest):
|
||||
"""Wraps falcon.HTTPBadRequest with a contextual title."""
|
||||
|
||||
TITLE = _('Invalid request body')
|
||||
TITLE = _(u'Invalid request body')
|
||||
|
||||
def __init__(self, description):
|
||||
super(HTTPBadRequestBody, self).__init__(self.TITLE, description)
|
||||
@ -40,7 +40,7 @@ class HTTPBadRequestBody(falcon.HTTPBadRequest):
|
||||
class HTTPDocumentTypeNotSupported(HTTPBadRequestBody):
|
||||
"""Wraps HTTPBadRequestBody with a standard description."""
|
||||
|
||||
DESCRIPTION = ('Document type not supported.')
|
||||
DESCRIPTION = _(u'Document type not supported.')
|
||||
|
||||
def __init__(self):
|
||||
super(HTTPDocumentTypeNotSupported, self).__init__(self.DESCRIPTION)
|
||||
|
@ -58,7 +58,7 @@ class CollectionResource(object):
|
||||
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Message could not be retrieved.')
|
||||
description = _(u'Message could not be retrieved.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
# Prepare response
|
||||
@ -103,19 +103,19 @@ class CollectionResource(object):
|
||||
raise falcon.HTTPNotFound()
|
||||
|
||||
except storage_exceptions.MalformedMarker:
|
||||
title = _('Invalid query string parameter')
|
||||
description = _('The value for the query string '
|
||||
'parameter "marker" could not be '
|
||||
'parsed. We recommend using the '
|
||||
'"next" URI from a previous '
|
||||
'request directly, rather than '
|
||||
'constructing the URI manually. ')
|
||||
title = _(u'Invalid query string parameter')
|
||||
description = _(u'The value for the query string '
|
||||
u'parameter "marker" could not be '
|
||||
u'parsed. We recommend using the '
|
||||
u'"next" URI from a previous '
|
||||
u'request directly, rather than '
|
||||
u'constructing the URI manually. ')
|
||||
|
||||
raise falcon.HTTPBadRequest(title, description)
|
||||
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Messages could not be listed.')
|
||||
description = _(u'Messages could not be listed.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
if not messages:
|
||||
@ -142,15 +142,15 @@ class CollectionResource(object):
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
def on_post(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_("Messages collection POST - queue: %(queue)s, "
|
||||
"project: %(project)s") %
|
||||
{"queue": queue_name, "project": project_id})
|
||||
LOG.debug(_(u'Messages collection POST - queue: %(queue)s, '
|
||||
u'project: %(project)s') %
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
|
||||
uuid = req.get_header('Client-ID', required=True)
|
||||
|
||||
# Place JSON size restriction before parsing
|
||||
if req.content_length > CFG.content_max_length:
|
||||
description = _('Message collection size is too large.')
|
||||
description = _(u'Message collection size is too large.')
|
||||
raise wsgi_exceptions.HTTPBadRequestBody(description)
|
||||
|
||||
# Pull out just the fields we care about
|
||||
@ -164,7 +164,7 @@ class CollectionResource(object):
|
||||
# NOTE(kgriffs): This check assumes messages is a
|
||||
# collection (not a generator).
|
||||
if not messages:
|
||||
description = _('No messages were provided.')
|
||||
description = _(u'No messages were provided.')
|
||||
raise wsgi_exceptions.HTTPBadRequestBody(description)
|
||||
|
||||
# Enqueue the messages
|
||||
@ -197,12 +197,12 @@ class CollectionResource(object):
|
||||
if not message_ids:
|
||||
# TODO(kgriffs): Include error code that is different
|
||||
# from the code used in the generic case, below.
|
||||
description = _('No messages could be enqueued.')
|
||||
description = _(u'No messages could be enqueued.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Messages could not be enqueued.')
|
||||
description = _(u'Messages could not be enqueued.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
# Prepare the response
|
||||
@ -216,9 +216,9 @@ class CollectionResource(object):
|
||||
resp.body = utils.to_json(body)
|
||||
|
||||
def on_get(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_("Messages collection GET - queue: %(queue)s, "
|
||||
"project: %(project)s") %
|
||||
{"queue": queue_name, "project": project_id})
|
||||
LOG.debug(_(u'Messages collection GET - queue: %(queue)s, '
|
||||
u'project: %(project)s') %
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
|
||||
resp.content_location = req.relative_uri
|
||||
|
||||
@ -252,7 +252,7 @@ class CollectionResource(object):
|
||||
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = 'Messages could not be deleted.'
|
||||
description = _(u'Messages could not be deleted.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
else:
|
||||
@ -267,11 +267,11 @@ class ItemResource(object):
|
||||
self.message_controller = message_controller
|
||||
|
||||
def on_get(self, req, resp, project_id, queue_name, message_id):
|
||||
LOG.debug(_("Messages item GET - message: %(message)s, "
|
||||
"queue: %(queue)s, project: %(project)s") %
|
||||
{"message": message_id,
|
||||
"queue": queue_name,
|
||||
"project": project_id})
|
||||
LOG.debug(_(u'Messages item GET - message: %(message)s, '
|
||||
u'queue: %(queue)s, project: %(project)s') %
|
||||
{'message': message_id,
|
||||
'queue': queue_name,
|
||||
'project': project_id})
|
||||
try:
|
||||
message = self.message_controller.get(
|
||||
queue_name,
|
||||
@ -283,7 +283,7 @@ class ItemResource(object):
|
||||
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Message could not be retrieved.')
|
||||
description = _(u'Message could not be retrieved.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
# Prepare response
|
||||
@ -295,11 +295,11 @@ class ItemResource(object):
|
||||
resp.status = falcon.HTTP_200
|
||||
|
||||
def on_delete(self, req, resp, project_id, queue_name, message_id):
|
||||
LOG.debug(_("Messages item DELETE - message: %(message)s, "
|
||||
"queue: %(queue)s, project: %(project)s") %
|
||||
{"message": message_id,
|
||||
"queue": queue_name,
|
||||
"project": project_id})
|
||||
LOG.debug(_(u'Messages item DELETE - message: %(message)s, '
|
||||
u'queue: %(queue)s, project: %(project)s') %
|
||||
{'message': message_id,
|
||||
'queue': queue_name,
|
||||
'project': project_id})
|
||||
try:
|
||||
self.message_controller.delete(
|
||||
queue_name,
|
||||
@ -309,13 +309,13 @@ class ItemResource(object):
|
||||
|
||||
except storage_exceptions.NotPermitted as ex:
|
||||
LOG.exception(ex)
|
||||
title = _('Invalid claim')
|
||||
description = _('The specified claim either does not '
|
||||
'exist or has expired.')
|
||||
title = _(u'Invalid claim')
|
||||
description = _(u'The specified claim either does not '
|
||||
u'exist or has expired.')
|
||||
raise falcon.HTTPForbidden(title, description)
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Message could not be deleted.')
|
||||
description = _(u'Message could not be deleted.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
# Alles guete
|
||||
|
@ -36,9 +36,9 @@ class Resource(object):
|
||||
self.queue_ctrl = queue_controller
|
||||
|
||||
def on_get(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_("Queue metadata GET - queue: %(queue)s, "
|
||||
"project: %(project)s") %
|
||||
{"queue": queue_name, "project": project_id})
|
||||
LOG.debug(_(u'Queue metadata GET - queue: %(queue)s, '
|
||||
u'project: %(project)s') %
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
|
||||
try:
|
||||
resp_dict = self.queue_ctrl.get_metadata(queue_name,
|
||||
@ -49,7 +49,7 @@ class Resource(object):
|
||||
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Queue metadata could not be retrieved.')
|
||||
description = _(u'Queue metadata could not be retrieved.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
resp.content_location = req.path
|
||||
@ -57,13 +57,13 @@ class Resource(object):
|
||||
resp.status = falcon.HTTP_200
|
||||
|
||||
def on_put(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_("Queue metadata PUT - queue: %(queue)s, "
|
||||
"project: %(project)s") %
|
||||
{"queue": queue_name, "project": project_id})
|
||||
LOG.debug(_(u'Queue metadata PUT - queue: %(queue)s, '
|
||||
u'project: %(project)s') %
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
|
||||
# Place JSON size restriction before parsing
|
||||
if req.content_length > CFG.metadata_max_length:
|
||||
description = _('Queue metadata size is too large.')
|
||||
description = _(u'Queue metadata size is too large.')
|
||||
raise wsgi_exceptions.HTTPBadRequestBody(description)
|
||||
|
||||
# Deserialize queue metadata
|
||||
@ -81,7 +81,7 @@ class Resource(object):
|
||||
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Metadata could not be updated.')
|
||||
description = _(u'Metadata could not be updated.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
resp.status = falcon.HTTP_204
|
||||
|
@ -34,9 +34,9 @@ class ItemResource(object):
|
||||
self.message_controller = message_controller
|
||||
|
||||
def on_put(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_("Queue item PUT - queue: %(queue)s, "
|
||||
"project: %(project)s") %
|
||||
{"queue": queue_name, "project": project_id})
|
||||
LOG.debug(_(u'Queue item PUT - queue: %(queue)s, '
|
||||
u'project: %(project)s') %
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
|
||||
try:
|
||||
validation.queue_creation(name=queue_name)
|
||||
@ -49,16 +49,16 @@ class ItemResource(object):
|
||||
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Queue could not be created.')
|
||||
description = _(u'Queue could not be created.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
resp.status = falcon.HTTP_201 if created else falcon.HTTP_204
|
||||
resp.location = req.path
|
||||
|
||||
def on_head(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_("Queue item exists - queue: %(queue)s, "
|
||||
"project: %(project)s") %
|
||||
{"queue": queue_name, "project": project_id})
|
||||
LOG.debug(_(u'Queue item exists - queue: %(queue)s, '
|
||||
'project: %(project)s') %
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
|
||||
if self.queue_controller.exists(queue_name,
|
||||
project=project_id):
|
||||
@ -71,15 +71,15 @@ class ItemResource(object):
|
||||
on_get = on_head
|
||||
|
||||
def on_delete(self, req, resp, project_id, queue_name):
|
||||
LOG.debug(_("Queue item DELETE - queue: %(queue)s, "
|
||||
"project: %(project)s") %
|
||||
{"queue": queue_name, "project": project_id})
|
||||
LOG.debug(_(u'Queue item DELETE - queue: %(queue)s, '
|
||||
u'project: %(project)s') %
|
||||
{'queue': queue_name, 'project': project_id})
|
||||
try:
|
||||
self.queue_controller.delete(queue_name, project=project_id)
|
||||
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Queue could not be deleted.')
|
||||
description = _(u'Queue could not be deleted.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
resp.status = falcon.HTTP_204
|
||||
@ -109,7 +109,7 @@ class CollectionResource(object):
|
||||
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Queues could not be listed.')
|
||||
description = _(u'Queues could not be listed.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
# Buffer list of queues
|
||||
|
@ -58,5 +58,5 @@ class Resource(object):
|
||||
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Queue stats could not be read.')
|
||||
description = _(u'Queue stats could not be read.')
|
||||
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
||||
|
@ -56,7 +56,7 @@ def filter_stream(stream, len, spec=None, doctype=JSONObject):
|
||||
"""
|
||||
|
||||
if len is None:
|
||||
description = _('Request body can not be empty')
|
||||
description = _(u'Request body can not be empty')
|
||||
raise exceptions.HTTPBadRequestBody(description)
|
||||
|
||||
try:
|
||||
@ -67,18 +67,18 @@ def filter_stream(stream, len, spec=None, doctype=JSONObject):
|
||||
|
||||
except utils.MalformedJSON as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('Request body could not be parsed.')
|
||||
description = _(u'Request body could not be parsed.')
|
||||
raise exceptions.HTTPBadRequestBody(description)
|
||||
|
||||
except utils.OverflowedJSONInteger as ex:
|
||||
LOG.exception(ex)
|
||||
description = _('JSON contains integer that is too large.')
|
||||
description = _(u'JSON contains integer that is too large.')
|
||||
raise exceptions.HTTPBadRequestBody(description)
|
||||
|
||||
except Exception as ex:
|
||||
# Error while reading from the network/server
|
||||
LOG.exception(ex)
|
||||
description = _('Request body could not be read.')
|
||||
description = _(u'Request body could not be read.')
|
||||
raise exceptions.HTTPServiceUnavailable(description)
|
||||
|
||||
if doctype is JSONObject:
|
||||
@ -144,12 +144,12 @@ def get_checked_field(document, name, value_type):
|
||||
try:
|
||||
value = document[name]
|
||||
except KeyError:
|
||||
description = _('Missing "{name}" field.').format(name=name)
|
||||
description = _(u'Missing "{name}" field.').format(name=name)
|
||||
raise exceptions.HTTPBadRequestBody(description)
|
||||
|
||||
if value_type == '*' or isinstance(value, value_type):
|
||||
return value
|
||||
|
||||
description = _('The value of the "{name}" field must be a {vtype}.')
|
||||
description = _(u'The value of the "{name}" field must be a {vtype}.')
|
||||
description = description.format(name=name, vtype=value_type.__name__)
|
||||
raise exceptions.HTTPBadRequestBody(description)
|
||||
|
Loading…
Reference in New Issue
Block a user