Пример #1
0
def get_response_from_exception(excep, exception_mapping):
    status = exception_mapping.get(excep.__class__, None)
    if status is None:
        status = 500
    ret = HTTPResponse(status=status, body=str(excep))
    ret.add_header("Content-Type", "text/plain")
    return ret
Пример #2
0
def get_response_from_exception(excep, exception_mapping):
    status = exception_mapping.get(excep.__class__, None)
    if status is None:
        status = 500
    ret = HTTPResponse(status=status, body=str(excep))
    ret.add_header("Content-Type", "text/plain")
    return ret
Пример #3
0
def send_response(code, message=None):
    r = HTTPResponse(status=code)
    r.add_header('Access-Control-Allow-Origin', '*')
    r.set_header('Content-Type', 'application/json')
    if message is None:
        r.set_header('Content-Type', 'text/plain')
    elif type(message) is str:
        e = {'error': message}
        r.body = json.dumps(e)
    elif type(message) is dict:
        r.body = json.dumps(message)
    else:
        r.body = message
    return r
Пример #4
0
def options_group(gid):
    r = HTTPResponse(status=200)
    r.add_header('Access-Control-Allow-Origin', '*')
    r.add_header('Access-Control-Allow-Methods', 'GET, DELETE, PUT')
    return r
Пример #5
0
 def post(self):
     m = self.insert(request.json)
     response = HTTPResponse(status=201, body=json.dumps(m.to_dict()))
     response.content_type = "application/json"
     response.add_header("Location", "{}/{}".format(self.base, m.id))
     return response
Пример #6
0
 def post(self):
     m = self.insert(request.json)
     response = HTTPResponse(status=201, body=json.dumps(m.to_dict()))
     response.content_type = "application/json"
     response.add_header("Location", "{}/{}".format(self.base, m.id))
     return response