def ec2_error_response(request_id, code, message, status=500): """Helper to construct an EC2 compatible error response.""" LOG.debug('EC2 error response: %(code)s: %(message)s', {'code': code, 'message': message}) resp = webob.Response() resp.status = status resp.headers['Content-Type'] = 'text/xml' resp.body = ( '<?xml version="1.0"?>\n' '<Response><Errors><Error><Code>%s</Code>' '<Message>%s</Message></Error></Errors>' '<RequestID>%s</RequestID></Response>' % (utils.xhtml_escape(code), utils.xhtml_escape(message), utils.xhtml_escape(request_id))).encode() return resp
def _render_parts(self, value, parts=None): if not parts: parts = [] if isinstance(value, six.string_types): parts.append(utils.xhtml_escape(value)) elif isinstance(value, six.integer_types): parts.append(str(value)) elif isinstance(value, datetime.datetime): parts.append(value.strftime("%Y-%m-%dT%H:%M:%S.000Z")) elif isinstance(value, dict): for name, subvalue in value.items(): if not isinstance(subvalue, list): subvalue = [subvalue] for subsubvalue in subvalue: parts.append('<' + name + '>') self._render_parts(subsubvalue, parts) parts.append('</' + name + '>') else: raise Exception("Unknown S3 value type %r", value)
def _render_parts(self, value, parts=None): if not parts: parts = [] if isinstance(value, six.string_types): parts.append(utils.xhtml_escape(value)) elif isinstance(value, six.integer_types): parts.append(str(value)) elif isinstance(value, datetime.datetime): parts.append(value.strftime("%Y-%m-%dT%H:%M:%S.000Z")) elif isinstance(value, dict): for name, subvalue in six.iteritems(value): if not isinstance(subvalue, list): subvalue = [subvalue] for subsubvalue in subvalue: parts.append('<' + name + '>') self._render_parts(subsubvalue, parts) parts.append('</' + name + '>') else: raise Exception("Unknown S3 value type %r", value)