diff options
| author | 2019-03-25 12:36:33 -0700 | |
|---|---|---|
| committer | 2019-03-28 13:48:45 -0700 | |
| commit | 0e09d10281798dd365364a12af4487fc150844c1 (patch) | |
| tree | 028996ba83a000272f05b00f1d974b0942078749 /snekbox.py | |
| parent | Replace RMQ with a POST endpoint (#7) (diff) | |
Restructure project layout
* Move all code into a "snekbox" package
* Use logging code as __init__.py
* Rename Snekbox class to NsJail
* Create "site" sub-package
* Move templates into this sub-package
* Move Flask code into a new snekapp module
Diffstat (limited to '')
| -rw-r--r-- | snekbox/nsjail.py (renamed from snekbox.py) | 42 |
1 files changed, 2 insertions, 40 deletions
diff --git a/snekbox.py b/snekbox/nsjail.py index 65fc4b3..458a94e 100644 --- a/snekbox.py +++ b/snekbox/nsjail.py @@ -2,11 +2,9 @@ import os import subprocess import sys -from flask import Flask, jsonify, render_template, request - -class Snekbox: - """Core snekbox functionality, providing safe execution of Python code.""" +class NsJail: + """Core Snekbox functionality, providing safe execution of Python code.""" def __init__(self, nsjail_binary='nsjail', @@ -95,39 +93,3 @@ class Snekbox: return 'unknown error, no error code' return output - - -snekbox = Snekbox() - -# Load app -app = Flask(__name__) -app.use_reloader = False - -# Logging -log = app.logger - - [email protected]('/') -def index(): - """Return a page with a form for inputting code to be executed.""" - - return render_template('index.html') - - [email protected]('/result', methods=["POST", "GET"]) -def result(): - """Execute code and return a page displaying the results.""" - - if request.method == "POST": - code = request.form["Code"] - output = snekbox.python3(code) - return render_template('result.html', code=code, result=output) - - [email protected]('/input', methods=["POST"]) -def code_input(): - """Execute code and return the results.""" - - body = request.get_json() - output = snekbox.python3(body["code"]) - return jsonify(input=body["code"], output=output) |