示例#1
0
def get_all(type):
	endp = EndpointGet(request, type=type, search_by=None)
	response = endp.get_response()
	return Response(response.json_content(), mimetype=response.mime_type), response.http_code
示例#2
0
 def wrapper(*args, **kwargs):
     location_url = f(*args, **kwargs)
     headers = [('Location', location_url)]
     return Response(status=204, headers=headers)
示例#3
0
def get_product(p_id):
    resp = {
        'data': list( mongo.db.products.find({"_id": ObjectId(p_id)}) )
    }
    return Response(dumps(resp), mimetype='application/json')
示例#4
0
def create_empty_json_response(status):
    """Create a JSON response with the given status code and an empty
    object as its content.
    """
    return Response('{}', status=status, mimetype='application/json')
示例#5
0
 def wrapper(*args, **kwargs):
     url = f(*args, **kwargs)
     return Response(status=201, headers=[('Location', url)])
示例#6
0
def explain(concept):

    mt = "text/plain"

    if concept == "route":
        result = """
                    A route definition has the form /x/y/z.
                    If an element in the definition is of the for <x>,
                    Flask passes the element's value to a parameter x in the function definition.
                    """
    elif concept == 'request':
        result = """
                http://flask.pocoo.org/docs/1.0/api/#incoming-request-data
                explains the request object.
            """
    elif concept == 'method':
        method = request.method

        result = """
                    The @app.route() example shows how to define eligible methods.
                    explains the request object. The Flask framework request.method
                    is how you determine the method sent.
                    
                    This request sent the method:
                    """ \
                    + request.method
    elif concept == 'query':
        result = """
                    A query string is of the form '?param1=value1&param2=value2.'
                    Try invoking ' http://127.0.0.1:5000/explain/query?param1=value1&param2=value2.
                    
                """

        if len(request.args) > 0:
            result += """
                Query parameters are:
                """
            qparams = str(request.args)
            result += qparams
    elif concept == "body":
        if request.method != 'PUT' and request.method != 'POST':
            result = """
                Only PUT and POST have bodies/data.
            """
        else:
            result = """
                The content type was
            """ + request.content_type

            if "text/plain" in request.content_type:
                result += """
                You sent plain text.
                
                request.data will contain the body.
                
                Your plain text was:
                
                """ + str(request.data) + \
                """
                
                Do not worry about the b'' thing. That is Python showing the string encoding.
                """
            elif "application/json" in request.content_type:
                js = request.get_json()
                mt = "application/json"
                result = {
                    "YouSent": "Some JSON. Cool!",
                    "Note": "The cool kids use JSON.",
                    "YourJSONWas": js
                }
                result = json.dumps(result, indent=2)
            else:
                """
                I have no idea what you sent.
                """
    else:
        result = """
            I should not have to explain all of these concepts. You should be able to read the documents.
        """

    response = Response(result, status=200, mimetype=mt)

    return response
示例#7
0
def return_database_list():
    databases = read_config()
    data = {'databases': databases.keys()}
    return Response(json.dumps(data), mimetype='application/json')
示例#8
0
def shutdown():
    if Shutdown():
        return Response('Shutting down...', 200)
    else:
        return Response('Error shutting down server', 400)
示例#9
0
def api_update_server():
    if UpdateServer():
        return Response("Updating...", 200)
    else:
        return Response('Error shutting down server', 400)
示例#10
0
def return_item():
    return Response(response="{0}".format(list_values), status=200)
示例#11
0
def set_motion(state):
    enabled = (state == "true" or state == "on")
    config.SetValue(enabled, "motionEnabled")

    return Response(enabled, 200)
示例#12
0
def put_item():
    args = get_parser()
    list_values.update({'num_entries': len(args), 'entries': args})
    return Response(status=201)
示例#13
0
def report_for_policy(policyid):
	endp = EndpointPolicyCheck(request, "policy", {"policyid": policyid})
	response = endp.get_response()	
	return Response(response.json_content(), mimetype=response.mime_type), response.http_code
示例#14
0
def get_by_id(type, id):
	endp = EndpointGet(request, type=type, search_by="id", search_for=id)
	response = endp.get_response()
	return Response(response.json_content(), mimetype=response.mime_type), response.http_code
示例#15
0
def handle_tables(dbname, resource_name, resource_name2, primary_key):

    resp = Response("Internal server error", status=500, mimetype="text/plain")

    try:

        # Form the compound resource names dbschema.table_name
        # resource = dbname + "." + resource_name
        # resource2 = dbname + "." + resource_name2

        if request.method == "GET":
            # Get the field list if it exists.
            field_list = request.args.get('fields', None)
            if field_list is not None:
                field_list = field_list.split(",")

            limit = request.args.get("limit", "10")
            offset = request.args.get("offset", "0")
            order_by = request.args.get("order_by", None)


            # The query string is of the form ?f1=v1&f2=v2& ...
            # This maps to a query template of the form { "f1" : "v1", ... }
            # We need to ignore the fields parameters.
            tmp = None
            for k,v in request.args.items():
                if (not k == "fields") and (not k == "limit") and (not k == "offset") and \
                        (not k == "order_by"):
                    if tmp is None:
                        tmp = {}
                    tmp[k] = v

            # Find by template.
            join_paths = ds.get_join_column_mapping(dbname, resource_name, dbname, resource_name2)

            if join_paths:
                columns = join_paths[list(join_paths.keys())[0]]["MAP"][0]
                referenced_table_name = columns["REFERENCED_TABLE_NAME"]
                referenced_column_name = columns["REFERENCED_COLUMN_NAME"]
                table_name = columns["TABLE_NAME"]
                column_name = columns["COLUMN_NAME"]
                tmp[column_name] = primary_key
                result = ds.get_by_template(dbname +"."+ table_name, tmp, \
                            field_list=field_list, limit=limit, offset=offset, order_by=order_by, commit=True)
                #
                result = {"data": result}
                result = compute_links(result, limit, offset)
                result_data = json.dumps(result, default=str)
                resp = Response(result_data, status=200, mimetype='application/json')
            else:
                resp = Response("Not found", status=404, mimetype="text/plain")

        elif request.method == "POST":
            join_paths = ds.get_join_column_mapping(dbname, resource_name, dbname, resource_name2)

            if join_paths:
                columns = join_paths[list(join_paths.keys())[0]]["MAP"][0]
                referenced_table_name = columns["REFERENCED_TABLE_NAME"]
                referenced_column_name = columns["REFERENCED_COLUMN_NAME"]
                table_name = columns["TABLE_NAME"]
                column_name = columns["COLUMN_NAME"]
                new_r = request.get_json()
                new_r[column_name] = primary_key

                result = ds.create(dbname + "." + table_name, new_r)
                if result and result == 1:
                    resp = Response("CREATED", status=201, mimetype="text/plain")

            else:
                resp = Response("Not found", status=404, mimetype="text/plain")

    except Exception as e:
        utils.debug_message("Something awlful happened, e = ", e)

    return resp
示例#16
0
def cameras_status():
    cam_info = video.GetCamInfo()
    return Response(json.dumps(cam_info))
示例#17
0
def explain_what():

    result = "Explain what?"
    response = Response(result, status=200, mimetype="text/plain")

    return response
示例#18
0
def api_versions():
    versions = {
        "latest": updater.GetLatestVersion(),
        "current": config.GetValue("version")
    }
    return Response(json.dumps(versions))
示例#19
0
def authenticate():
    return Response(
        'Could not verify your access level for that URL.\n'
        'You have to login with proper credentials', 401,
        {'WWW-Authenticate': 'Basic realm="Login Required"'})
示例#20
0
def api_ping():
    return Response("pong!", 200)
示例#21
0
 def inner(*args, **kwargs):
     # Change our datetime columns into strings so we can serialize
     jsonstring = json.dumps(f(*args, **kwargs), default=json_fixup)
     return Response(jsonstring, mimetype='application/json')
示例#22
0
def api_config():
    configData = config.AsString()
    return Response(configData, 200)
示例#23
0
 def wrapper(*args, **kwargs):
     data = f(*args, **kwargs)
     return Response(stream_with_context(data), mimetype='text/plain')
示例#24
0
def get_messages():
    state = config.GetValue("email", "enabled")
    response = json.dumps({
        "enabled": state
    })
    return Response(response, 200)
示例#25
0
 def wrapper(*args, **kwargs):
     headers = f(*args, **kwargs)
     return Response(status=204, headers=headers)
示例#26
0
def get_motion():
    state = config.GetValue("motionEnabled")
    response = json.dumps({
        "enabled": state
    })
    return Response(response, 200)
示例#27
0
def products():
    resp = {
        'data': list(mongo.db.products.find())
    }
    return Response(dumps(resp), mimetype='application/json')
示例#28
0
def lbheartbeat_response():
    """Per the Dockerflow spec:
    Respond to /__lbheartbeat__ with an HTTP 200. This is for load balancer
    checks and should not check any dependent services."""
    return Response("OK!", headers={"Cache-Control": "no-cache"})
示例#29
0
def products_cateory(category):
    return Response(dumps(mongo.db.products.find({"category": category})), mimetype='application/json')
示例#30
0
def delete_by_id(type, id):
	endp = EndpointDelete(request, type=type, id=id)
	response = endp.get_response()
	return Response(response.json_content(), mimetype=response.mime_type), response.http_code