summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-09-08 12:24:45 +0200
committerTimotej Lazar <timotej.lazar@araneo.org>2015-09-08 12:24:45 +0200
commit8d29abdb953b5fc949ed520dccd956e908eb9265 (patch)
tree2a85641ba692fccbe045fde543c7ba34afe93323 /server
parenta293cf9d5fd64ff29bc05daa80d2f9a3a8c0abe0 (diff)
Check for syntax errors in python_session.hint
Diffstat (limited to 'server')
-rw-r--r--server/python_session.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/server/python_session.py b/server/python_session.py
index 4c4a781..011adc3 100644
--- a/server/python_session.py
+++ b/server/python_session.py
@@ -1,7 +1,9 @@
# coding=utf-8
+import ast
import multiprocessing.managers
import threading
+
import server.user_session
from db.models import Problem
from . import problems
@@ -67,6 +69,13 @@ class PythonSession(object):
language, problem_group, problem = Problem.get_identifier(problem_id)
problem_module = problems.load_problem(language, problem_group, problem, 'common')
+ # Check syntax.
+ try:
+ tree = ast.parse(program, filename='user')
+ except SyntaxError as ex:
+ error_msg = '{}{}^\n{}'.format(ex.text, ' '*(ex.offset-1), ex.msg)
+ return [{'id': 'syntax_error', 'args': {'lineno': ex.lineno, 'message': error_msg}}]
+
# Try problem-specific hints.
if hasattr(problem_module, 'hint'):
hints = problem_module.hint(session, program)