summaryrefslogtreecommitdiff
path: root/yaksh/python_stdio_evaluator.py
diff options
context:
space:
mode:
authorankitjavalkar2016-09-21 15:07:43 +0530
committerankitjavalkar2016-09-30 10:33:42 +0530
commitac8d6720bc75676e05462cc38ad144d5aedc14e7 (patch)
treee2e527e159a0704ecdaa2f15ae13900f4555ea63 /yaksh/python_stdio_evaluator.py
parent6b08e56fe3cf70ffbcbd1ed432dde25babe48148 (diff)
downloadonline_test-ac8d6720bc75676e05462cc38ad144d5aedc14e7.tar.gz
online_test-ac8d6720bc75676e05462cc38ad144d5aedc14e7.tar.bz2
online_test-ac8d6720bc75676e05462cc38ad144d5aedc14e7.zip
Migrate python code server and evaluators to python 2/3 compatible
Diffstat (limited to 'yaksh/python_stdio_evaluator.py')
-rw-r--r--yaksh/python_stdio_evaluator.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/yaksh/python_stdio_evaluator.py b/yaksh/python_stdio_evaluator.py
index 2cfd9c8..3011179 100644
--- a/yaksh/python_stdio_evaluator.py
+++ b/yaksh/python_stdio_evaluator.py
@@ -1,16 +1,23 @@
#!/usr/bin/env python
+from __future__ import absolute_import
import sys
import traceback
import os
from os.path import join
import importlib
from contextlib import contextmanager
-from ast import literal_eval
-# local imports
-from code_evaluator import CodeEvaluator
-from StringIO import StringIO
-from file_utils import copy_files, delete_files
from textwrap import dedent
+
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
+
+# Local imports
+from .code_evaluator import CodeEvaluator
+from .file_utils import copy_files, delete_files
+
+
@contextmanager
def redirect_stdout():
new_target = StringIO()
@@ -43,7 +50,7 @@ class PythonStdioEvaluator(CodeEvaluator):
sys.stdin = input_buffer
with redirect_stdout() as output_buffer:
exec_scope = {}
- exec submitted in exec_scope
+ exec(submitted, exec_scope)
self.output_value = output_buffer.getvalue().rstrip("\n")
return self.output_value