Exemplo n.º 1
0
 def debugPage(table):
     logger.info("Request: %s /debug/%s" % (request.method, table))
     tableName = table.lower()
     if tableName not in tables:
         logger.warning("Table %s not found." % tableName)
         return "Table %s not found." % tableName
     fields = tables[tableName].__requiredFields__
     return render_template("debugPage.html", fields=fields, tableName=tableName)
Exemplo n.º 2
0
def dealRequests():
    logger.info("Request: %s /api" % (request.method,))
    if request.method == "GET":
        form = request.args.to_dict()
    elif request.method == "POST":
        form = request.form.to_dict()
    else:
        logger.warning("supported method: get, post.")
        return "supported method: get, post."
    logger.info("Request form: %s" % jsonDumps(form))
    result = api.postCallAPI(form)
    return jsonDumps(result)
Exemplo n.º 3
0
    def queryAPI(table):
        logger.info("Request: %s /debugapi/%s" % (request.method, table))
        tableName = table.lower()
        if request.method == "GET":
            getArgs = request.args.to_dict()
            logger.info("Request form: %s" % jsonDumps(getArgs))
            result = api.commonGetAPI(tableName, **getArgs)
            return jsonDumps(result)

        elif request.method == "POST":
            postForm = request.form.to_dict()
            logger.info("Request form: %s" % jsonDumps(postForm))
            result = api.commonAddAPI(tableName, **postForm)
            return jsonDumps(result)
Exemplo n.º 4
0
 def debugPageWithoutTable():
     logger.info("Request: %s /debug" % (request.method,))
     return "Table not found. Url format: /debug/tablename"
Exemplo n.º 5
0
 def queryAPIWithoutTable():
     logger.info("Request: %s /debugapi" % (request.method,))
     return "Table not found. Url format: /debugapi/tablename"
Exemplo n.º 6
0
def send_file(filename):
    logger.info("Request: %s /%s" % (request.method, filename))
    directory = os.getcwd()
    return send_from_directory(directory, filename, as_attachment=True)
Exemplo n.º 7
0
def getIndex():
    logger.info("Request: %s /" % (request.method,))
    return '<script>s="It works! ";for(i=0;i<11;i++) s+=s;document.write(s);</script>'
Exemplo n.º 8
0
 def testcos():
     logger.info("Request: %s /testcos" % (request.method,))
     return render_template("test.html")
Exemplo n.º 9
0
    @app.route("/echo", methods=["GET"])
    def echo():
        return request.args.get("echo")

    @app.route("/debug/", methods=["GET", "POST"])
    def debugPageWithoutTable():
        logger.info("Request: %s /debug" % (request.method,))
        return "Table not found. Url format: /debug/tablename"

    @app.route("/debug/<table>")
    def debugPage(table):
        logger.info("Request: %s /debug/%s" % (request.method, table))
        tableName = table.lower()
        if tableName not in tables:
            logger.warning("Table %s not found." % tableName)
            return "Table %s not found." % tableName
        fields = tables[tableName].__requiredFields__
        return render_template("debugPage.html", fields=fields, tableName=tableName)

    @app.route('/testcos')
    def testcos():
        logger.info("Request: %s /testcos" % (request.method,))
        return render_template("test.html")

if __name__ == "__main__":

    logger.info("Debug API %sabled." % "en" if DEBUG else "dis")
    logger.info("Flask server: %s:%d" % ("0.0.0.0", PORT))

    app.run(host="0.0.0.0", port=PORT)