本文整理汇总了Python中qonos.openstack.common._i18n._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_request
def process_request(self, req):
"""Try to find a version first in the accept header, then the URL."""
msg = _("Determining version of request: %(method)s %(path)s" " Accept: %(accept)s")
args = {"method": req.method, "path": req.path, "accept": req.accept}
LOG.debug(msg % args)
accept = str(req.accept)
if accept.startswith("application/vnd.openstack.qonos-"):
LOG.debug(_("Using media-type versioning"))
token_loc = len("application/vnd.openstack.qonos-")
req_version = accept[token_loc:]
else:
LOG.debug(_("Using url versioning"))
# Remove version in url so it doesn't conflict later
req_version = req.path_info_pop()
try:
version = self._match_version_string(req_version)
except ValueError:
LOG.debug(_("Unknown version. Returning version choices."))
return self.versions_app
req.environ["api.version"] = version
req.path_info = "".join(("/v", str(version), req.path_info or "/"))
LOG.debug(_("Matched version: v%d"), version)
LOG.debug("new uri %s" % req.path_info)
return None
示例2: update
def update(self, request, schedule_id, body):
if not body:
msg = _('The request body must not be empty')
raise webob.exc.HTTPBadRequest(explanation=msg)
elif 'schedule' not in body:
msg = _('The request body must contain a "schedule" entity')
raise webob.exc.HTTPBadRequest(explanation=msg)
# NOTE(jculp): only raise if a blank tenant is passed
# passing no tenant at all is perfectly fine.
elif('tenant' in body['schedule'] and not
body['schedule']['tenant'].strip()):
msg = _('The request body has not specified a "tenant" entity')
raise webob.exc.HTTPBadRequest(explanation=msg)
api_utils.deserialize_schedule_metadata(body['schedule'])
values = {}
values.update(body['schedule'])
try:
values = api_utils.check_read_only_properties(values)
except exception.Forbidden as e:
raise webob.exc.HTTPForbidden(explanation=unicode(e))
request_next_run = body['schedule'].get('next_run')
times = {
'minute': None,
'hour': None,
'month': None,
'day_of_week': None,
'day_of_month': None,
}
update_schedule_times = False
for key in times:
if key in values:
times[key] = values[key]
update_schedule_times = True
if update_schedule_times:
# NOTE(ameade): We must recalculate the schedules next_run time
# since the schedule has changed
values.update(times)
values['next_run'] = api_utils.schedule_to_next_run(times)
elif request_next_run:
try:
timeutils.parse_isotime(request_next_run)
except ValueError as e:
msg = _('Invalid "next_run" value. Must be ISO 8601 format')
raise webob.exc.HTTPBadRequest(explanation=msg)
try:
schedule = self.db_api.schedule_update(schedule_id, values)
except exception.NotFound:
msg = _('Schedule %s could not be found.') % schedule_id
raise webob.exc.HTTPNotFound(explanation=msg)
utils.serialize_datetimes(schedule)
api_utils.serialize_schedule_metadata(schedule)
return {'schedule': schedule}
示例3: _validate_limit
def _validate_limit(limit):
try:
limit = int(limit)
except ValueError:
msg = _("limit param must be an integer")
raise exc.Invalid(message=msg)
if limit <= 0:
msg = _("limit param must be positive")
raise exc.Invalid(message=msg)
return limit
示例4: _error
def _error(self, inner, req):
LOG.exception(_("Caught error: %s"), unicode(inner))
status = getattr(inner, 'code', 500)
if status is None:
status = 500
msg_dict = dict(url=req.url, status=status)
LOG.info(_("%(url)s returned with HTTP %(status)d") % msg_dict)
return webob.exc.HTTPInternalServerError()
示例5: create
def create(self, request, body=None):
invalid_params = []
if not body:
invalid_params.append('request body is empty')
elif 'schedule' not in body:
invalid_params.append('request body needs "schedule" entity')
else:
if not body['schedule'].get('tenant'):
invalid_params.append('request body needs "tenant" entity')
if not body['schedule'].get('action'):
invalid_params.append('request body needs "action" entity')
if invalid_params:
msg = _('The following errors occured with your request: %s') \
% ', '.join(invalid_params)
raise webob.exc.HTTPBadRequest(explanation=msg)
api_utils.deserialize_schedule_metadata(body['schedule'])
values = {}
values.update(body['schedule'])
values['next_run'] = api_utils.schedule_to_next_run(body['schedule'])
schedule = self.db_api.schedule_create(values)
utils.serialize_datetimes(schedule)
api_utils.serialize_schedule_metadata(schedule)
return {'schedule': schedule}