-
Notifications
You must be signed in to change notification settings - Fork 18
/
webdev.py
97 lines (84 loc) · 2.55 KB
/
webdev.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from flask import Flask, render_template, request
from runcode import runcode
app = Flask(__name__)
default_c_code = """#include <stdio.h>
int main(int argc, char **argv)
{
printf("Hello C World!!\\n");
return 0;
}
"""
default_cpp_code = """#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
cout << "Hello C++ World" << endl;
return 0;
}
"""
default_py_code = """import sys
import os
if __name__ == "__main__":
print "Hello Python World!!"
"""
default_rows = "15"
default_cols = "60"
@app.route("/")
@app.route("/runc", methods=['POST', 'GET'])
def runc():
if request.method == 'POST':
code = request.form['code']
run = runcode.RunCCode(code)
rescompil, resrun = run.run_c_code()
if not resrun:
resrun = 'No result!'
else:
code = default_c_code
resrun = 'No result!'
rescompil = ''
return render_template("main.html",
code=code,
target="runc",
resrun=resrun,
rescomp=rescompil,
rows=default_rows, cols=default_cols)
@app.route("/cpp")
@app.route("/runcpp", methods=['POST', 'GET'])
def runcpp():
if request.method == 'POST':
code = request.form['code']
run = runcode.RunCppCode(code)
rescompil, resrun = run.run_cpp_code()
if not resrun:
resrun = 'No result!'
else:
code = default_cpp_code
resrun = 'No result!'
rescompil = ''
return render_template("main.html",
code=code,
target="runcpp",
resrun=resrun,
rescomp=rescompil,
rows=default_rows, cols=default_cols)
@app.route("/py")
@app.route("/runpy", methods=['POST', 'GET'])
def runpy():
if request.method == 'POST':
code = request.form['code']
run = runcode.RunPyCode(code)
rescompil, resrun = run.run_py_code()
if not resrun:
resrun = 'No result!'
else:
code = default_py_code
resrun = 'No result!'
rescompil = "No compilation for Python"
return render_template("main.html",
code=code,
target="runpy",
resrun=resrun,
rescomp=rescompil,#"No compilation for Python",
rows=default_rows, cols=default_cols)
if __name__ == "__main__":
app.run()