-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
74 lines (63 loc) · 1.9 KB
/
app.py
File metadata and controls
74 lines (63 loc) · 1.9 KB
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
from flask import Flask, render_template, request
from pow_core import evaluatePowREPL
import logging
import re
import traceback
logger = logging.getLogger(__name__)
FORMAT = "🐛 [%(filename)s:%(lineno)s - %(funcName)20s()] %(message)s"
logging.basicConfig(format=FORMAT)
logger.setLevel(logging.DEBUG)
app = Flask(__name__, static_folder='public', static_url_path='')
@app.route('/')
def home():
return render_template('index.html')
def log(msg):
logger.log(logging.DEBUG, msg)
def verify_input(unpure):
_buffer = ''
for x in unpure.split(' '):
log(f'SPLIT: {unpure.split(' ')}')
#_buffer += x
log(f'BUFFER: {_buffer}')
if re.search(r'\+', x):
_buffer += '+'
continue
elif re.search('-', x):
_buffer += '-'
continue
elif re.search(r'\*', x):
_buffer += '*'
continue
elif re.search('/', x):
_buffer += '/'
continue
elif re.search(r'\(', x):
_buffer += '('
continue
elif re.search(r'\)', x):
_buffer += ')'
continue
if re.search(r'%>', x):
_buffer += '%>'
continue
if re.search(r'\d+', x):
_buffer += x
continue
else:
raise SyntaxError('Invalid syntax')
return _buffer
@app.route('/eval', methods=['POST'])
def eval():
data = request.get_json()
log(f'Data coming in: {data}')
log(f'Evaluating...: {data.get('expr')}')
_verified_evaluated = None
try:
_verified_evaluated = evaluatePowREPL(verify_input(data.get('expr').strip()))
log(f'Evaluated correctly!')
except:
log(f'There was a goddamn error evaluating')
print(traceback.format_exc())
return {"res": _verified_evaluated or 'ERR'}, 200
if __name__ == '__main__':
app.run(debug=True)