Spaces:
Running
Running
Update app.py
Browse files98 unmodified lines9910010110210310410598 unmodified linespath="xe.js",mimetype="application/javascript")@app.route("/drive.com/files", strict_slashes=False)def drive():98 unmodified lines9910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613798 unmodified linespath="xe.js",mimetype="application/javascript")@app.route("/execute", methods=["POST"])def execute():data = request.get_json(silent=True)if not data or "code" not in data:return jsonify({"error": "JSON body with 'code' field is required"}), 400code = data["code"]# stdout / stderr をキャプチャstdout_buf = io.StringIO()stderr_buf = io.StringIO()# 実行環境(グローバル名前空間)exec_globals = {"__name__": "__main__"}try:with contextlib.redirect_stdout(stdout_buf), contextlib.redirect_stderr(stderr_buf):exec(code, exec_globals)return jsonify({"success": True,"stdout": stdout_buf.getvalue(),"stderr": stderr_buf.getvalue(),"result": None,})except Exception as e:return jsonify({"success": False,"stdout": stdout_buf.getvalue(),"stderr": stderr_buf.getvalue(),"error": f"{type(e).__name__}: {e}","traceback": traceback.format_exc(),}), 200@app.route("/drive.com/files", strict_slashes=False)def drive():
app.py+32