Exemple #1
0
def abort(code):
    """
    A standardized way to abort
    """

    return code, {'errors': [{
        'message': str(code) + ' ' + status_codes.get(code, 'Unknown')
    }]}
Exemple #2
0
def abort(code, ref=''):
  """
  A standardized way to abort
  """

  return code, {'errors': [{
    'message': str(code) + ' ' + status_codes.get(code, 'Unknown'),
    'ref': ref,
  }]}
Exemple #3
0
def serve(environ, start_response):
    """
    Handle a WSGI request and response.
    """

    make_db_connection()
    code, data = call_handler(environ)
    close_db_connection()
    response_headers = [('Content-Type', 'application/json; charset=utf-8')]
    if isinstance(data, dict):
        response_headers += set_cookie_headers(data.pop('cookies', {}))
    status = str(code) + ' ' + status_codes.get(code, 'Unknown')
    start_response(status, response_headers)
    if isinstance(data, str):
        body = data.encode()
    elif isinstance(data, dict):
        body = json.dumps(data, default=json_serial, ensure_ascii=False)
        body = body.encode()
    return [body]
Exemple #4
0
def serve(environ, start_response):
    """
  Handle a WSGI request and response.
  """

    db_conn = make_db_connection()
    request = construct_request(db_conn, environ)
    code, data = call_handler(request)
    is_json = isinstance(data, dict)
    close_db_connection(db_conn)
    content_type = (('Content-Type',
                     'application/json; charset=utf-8') if is_json else
                    ('Content-Type', 'text/plain; charset=utf-8'))
    cookie_headers = (set_cookie_headers(data.pop('cookies', {}))
                      if is_json else [])
    response_headers = [content_type] + cookie_headers
    status = str(code) + ' ' + status_codes.get(code, 'Unknown')
    start_response(status, response_headers)
    if is_json:
        data = json.dumps(data, default=json_serial, ensure_ascii=False)
    return [data.encode()]