def __init__(self, environ, *d, **kw): """ """ # method handlers = self.supported_methods(environ) try: handler_name = handlers[environ['REQUEST_METHOD']] except: raise exc.HTTPMethodNotAllowed(allow = handlers) # handler handler = getattr(self, handler_name, None) if not handler: raise exc.HTTPNotFound() environ['sancus.handler_name'] = handler_name environ['sancus.handler'] = handler # arguments pos_args, named_args = environ.get('wsgiorg.routing_args', ((), {})) named_args = dict((k, v) for k, v in named_args.iteritems() if v is not None) environ['sancus.pos_args'] = pos_args environ['sancus.named_args'] = named_args # webob req = Request(environ) Response.__init__(self, *d, request=req, **kw) self.allow = handlers
def __init__(self, msgs=[('location', 'name', 'description')]): super(HTTPErrorJSON, self).__init__() msgs_ = [] for loc, name, desc in msgs: msgs_.append({"location": loc, "name": name, "description": desc}) body = {'status': "errors", 'errors': msgs_} Response.__init__(self, body=json.dumps(body), status=self.code)
def __init__(self, environ, *d, **kw): method = environ['REQUEST_METHOD'] if method not in self.supported_methods(): raise exc.HTTPMethodNotAllowed(allow = self.supported_methods()) pos_args, named_args = environ['wsgiorg.routing_args'] # remove keys with value None named_args = dict((k, v) for k, v in named_args.iteritems() if v is not None) param = named_args.get(self.__param_arg__, None) if param is None: handler_name = method else: del named_args[self.__param_arg__] handler_name = "%s_%s" % (method, param) if method == 'HEAD': if not hasattr(self, handler_name): handler_name = "GET_%s" % param h = getattr(self, handler_name, None) if not h: raise exc.HTTPNotFound() else: # add data to environ environ['sancus.args'] = named_args environ['sancus.handler_name'] = handler_name environ['sancus.handler'] = h req = Request(environ) Response.__init__(self, *d, request=req, **kw) self.allow = self.supported_methods()
def __init__(self, status=400, location='body', name='', description=''): body = {'status': status, 'errors': [{'location': location, 'name': name, 'description': description}] } Response.__init__(self, json.dumps(body)) self.status = status self.content_type = 'application/json'
def __init__(self, code, label, title, explanation, **kw): self.code = code self.label = label self.title = title self.explanation = explanation Response.__init__(self, status='%s %s' % (self.code, self.title), **kw) webob.exc.HTTPException.__init__(self, self.explanation, self)
def __init__(self, status_code, message): body = { 'status': status_code, 'errors': [ {'description': message or self.message} ] } Response.__init__(self, json.dumps(body)) self.status = status_code self.content_type = 'application/vnd.collection+json'
def __init__(self, status_code, message): body = { 'status': status_code, 'errors': [{ 'description': message or self.message }] } Response.__init__(self, json.dumps(body)) self.status = status_code self.content_type = 'application/vnd.collection+json'
def __init__(self, detail=None, headers=None, comment=None, body_template=None, **kw): Response.__init__(self, status="%s %s" % (self.code, self.title), **kw) Exception.__init__(self, detail) if headers: self.headers.extend(headers) self.detail = detail self.comment = comment if body_template is not None: self.body_template = body_template self.body_template_obj = Template(body_template) if self.empty_body: del self.content_type del self.content_length
def __init__(self, detail=None, headers=None, comment=None, body_template=None, **kw): Response.__init__(self, status='%s %s' % (self.code, self.title), **kw) Exception.__init__(self, detail) if headers: self.headers.extend(headers) self.detail = detail self.comment = comment if body_template is not None: self.body_template = body_template self.body_template_obj = Template(body_template) if self.empty_body: del self.content_type del self.content_length
def __init__(self, msgs, status=400): # XXX: status code is pulled from the first error message # (probably not the most intuitive way) msg = next((msg for msg in msgs if 'status' in msg), None) log.debug("JSONError.__init__: errors -> %r", msgs) if msg: status = msg.pop('status') # leave only debugging info if not DEBUG: body = [{"description": "", "name": m['name'], "location": ""} for \ m in msgs] else: body = msgs Response.__init__(self, json.dumps(body)) self.status = status self.content_type = 'application/json'
def __init__(self, msg='Not Found'): body = {'status': 404, 'message': msg} Response.__init__(self, write_json(body)) self.status = 404 self.content_type = 'application/json'
def __init__(self, msg='Internal Server Error'): body = {'status': 500, 'message': msg} Response.__init__(self, json.dumps(body)) self.status = 500 self.content_type = 'application/json'
def __init__(self, msg="Unauthorized"): body = {"status": 401, "message": msg} Response.__init__(self, json.dumps(body)) self.status = 401 self.content_type = "application/json"
def __init__(self, msg='Not Implemented'): body = {'status': 501, 'message': msg} Response.__init__(self, json.dumps(body)) self.status = 501 self.content_type = 'application/json'
def __init__(self, callback=None, **kwargs): body = self.serialize(kwargs.pop('body')) if callback is not None: self.default_content_type = 'application/javascript' body = '%s(%s);' % (callback, body) Response.__init__(self, body=body, charset='utf8', **kwargs)
def __init__(self, *args, **kargs): Response.__init__(self, *args, **kargs) self.content_type = 'text/plain'
def __init__(self, msg='Resource Not found'): body = {'status': 401, 'message': msg} Response.__init__(self, json.dumps(body)) self.status = 404 self.content_type = 'application/json'
def __init__(self, msg='Bad Gateway'): body = {'status': 502, 'message': msg} Response.__init__(self, json.dumps(body)) self.status = 502 self.content_type = 'application/json'
def __init__(self, msg='Forbidden'): body = {'status': 403, 'message': msg} Response.__init__(self, json.dumps(body)) self.status = 403 self.content_type = 'application/json'
def __init__(self, r): Response.__init__(self, content_type="application/json", body=simplejson.dumps(r))
def __init__(self, msg='Unauthorized'): """Customize init to create a json response object and body.""" body = {'status': 401, 'message': msg} Response.__init__(self, json.dumps(body)) self.status = 401 self.content_type = 'application/json'
def __init__(self, **kwargs): Response.__init__(self, body=self.serialize(kwargs.pop('body', None)), **kwargs)
def __init__(self, msg='Bad Request'): body = {'status': 400, 'message': msg} Response.__init__(self, json.dumps(body)) self.status = 400 self.content_type = 'application/json'
def __init__(self, errors, status=400): body = {'status': 'error', 'errors': errors} Response.__init__(self, json.dumps(body, use_decimal=True)) self.status = status self.content_type = 'application/json'
def __init__(self, msg='No Content'): body = {'status': 204, 'message': msg} Response.__init__(self, json.dumps(body)) self.status = 204 self.content_type = 'application/json'
def __init__(self, msg='Unauthorized'): body = {'status': 401, 'message': msg} Response.__init__(self, json.dumps(body)) self.status = 401 self.content_type = 'application/json'
def __init__(self): self.json = {} self.sid = None self.messages, self.errors, self.logs, self.info = [], [], [], [] Response.__init__(self)