diff options
author | prashantsinalkar | 2019-06-29 15:26:46 +0530 |
---|---|---|
committer | prashantsinalkar | 2019-06-29 15:26:46 +0530 |
commit | 3e9b2c2a0eae3a614a3ea3e3ac8670f380cba04e (patch) | |
tree | 0cddbd959b2a08ecd3562f84b5305e14729deb2e /instances.py | |
parent | aec7175e6e60cf222b678e0f96c67f03c329e16c (diff) | |
download | R_on_Cloud_Web_Interface-3e9b2c2a0eae3a614a3ea3e3ac8670f380cba04e.tar.gz R_on_Cloud_Web_Interface-3e9b2c2a0eae3a614a3ea3e3ac8670f380cba04e.tar.bz2 R_on_Cloud_Web_Interface-3e9b2c2a0eae3a614a3ea3e3ac8670f380cba04e.zip |
added user id and clean the code
Diffstat (limited to 'instances.py')
-rw-r--r-- | instances.py | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/instances.py b/instances.py index c6f4f1a..c11aca9 100644 --- a/instances.py +++ b/instances.py @@ -9,6 +9,7 @@ import requests import json import urllib.request import base64 +import uuid from datetime import datetime from django.template.loader import render_to_string, get_template @@ -19,12 +20,13 @@ from R_on_Cloud.config import (BIN) URL = "http://127.0.0.1:8001/rscript" + def execute_code(code, token): # Check for system commands system_commands = re.compile( - 'unix\(.*\)|unix_g\(.*\)|unix_w\(.*\)|' - 'unix_x\(.*\)|unix_s\(.*\)|host|newfun' - '|execstr|ascii|mputl|dir\(\)' + r'unix\(.*\)|unix_g\(.*\)|unix_w\(.*\)|' + r'unix_x\(.*\)|unix_s\(.*\)|host|newfun' + r'|execstr|ascii|mputl|dir\(\)' ) if system_commands.search(code): return { @@ -33,28 +35,26 @@ def execute_code(code, token): code = re.sub(r"View\(", "print(", code) - - - - body = {'code': code} + session_id = uuid.uuid4() + user_id = uuid.uuid4() + body = {'code': code, + 'user_id': user_id + } req = urllib.request.Request(URL) req.add_header('Content-Type', 'application/json; charset=utf-8') jsondata = json.dumps(body) - jsondataasbytes = jsondata.encode('utf-8') # needs to be bytes always as it R code + jsondataasbytes = jsondata.encode('utf-8') req.add_header('Content-Length', len(jsondataasbytes)) - print (jsondataasbytes) + print(jsondataasbytes) result = urllib.request.urlopen(req, jsondataasbytes) result = result.read().decode("utf8") - print("----------", result) - #print("----", json.loads(result)['value']) output = json.loads(result)["output"] - print ("-------------------------------", output) - #output = "okk" data = { 'output': output } return data -#https://github.com/trestletech/plumber/issues/105 + + def trim(output): output = [line for line in output.split('\n') if line.strip() != ''] output = '\n'.join(output) |