summaryrefslogtreecommitdiff
path: root/foreign/client_handling/interpreter.py
diff options
context:
space:
mode:
Diffstat (limited to 'foreign/client_handling/interpreter.py')
-rw-r--r--foreign/client_handling/interpreter.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/foreign/client_handling/interpreter.py b/foreign/client_handling/interpreter.py
new file mode 100644
index 0000000..f589cc9
--- /dev/null
+++ b/foreign/client_handling/interpreter.py
@@ -0,0 +1,11 @@
+import contextlib
+import io
+
+
+def interpreter(execute):
+ try:
+ with io.StringIO() as stdout, contextlib.redirect_stdout(stdout):
+ exec_data = exec(execute)
+ return {'message': f'Python successfully interpreted', 'result': stdout.getvalue().strip(), 'text_mode': 'success'}
+ except Exception as err:
+ return {'message': f'Python could not be interpreted\nError message: \'{err}\'', 'text_mode': 'danger'} \ No newline at end of file