-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwsgi_file_template.py
More file actions
27 lines (21 loc) · 897 Bytes
/
wsgi_file_template.py
File metadata and controls
27 lines (21 loc) · 897 Bytes
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
import _ast
from pyflakes.checker import Checker
from flask import Flask, Response, request
application = Flask(__name__)
def pyflakes_check(code):
try:
tree = compile(code, "ignored.py", "exec", _ast.PyCF_ONLY_AST)
except SyntaxError as syntax_error:
return [dict(text='Syntax Error', row=syntax_error.lineno - 1, type='error')]
except ValueError as value_error:
message = 'Error: {} somewhere in file'.format(value_error.message)
return [dict(text=message, row=0, type='error')]
w = Checker(tree, '')
return [
dict(text=m.message % m.message_args, row=m.lineno - 1, type='warning')
for m in w.messages
]
@application.route('/', methods=['POST'])
def check_code():
code = request.form.get('code')
return {"errors": pyflakes_check(code)}, 200, {'Access-Control-Allow-Origin':"REPLACE_WITH_REAL_ALLOWED_ORIGIN"}