def __init__(self, message): self.message = message if settings.DEBUG: print('message: ' + self.message.body['text']) m = re.search(pattern, message.body['text']) if m: self.lang = m.group('lang').strip() self.options = m.group('args').strip().lower() or '' self.source = m.group('src') self.input = m.group('in') or '' if (m is None or not self.lang or not self.source): raise ValueError() if settings.DEBUG: print('lang: ' + self.lang) print('args: ' + self.options) print('source: ' + self.source) print('input: ' + self.input) self.client = CompilersClientV3(settings.SE_API_TOKEN, settings.SE_API_ENDPOINT)
""" Example presents usage of the successful initialization of Sphere Engine Compilers API client """ from sphere_engine import CompilersClientV3 # define access parameters accessToken = '<access_token>' endpoint = '<endpoint>' # initialization client = CompilersClientV3(accessToken, endpoint)
def test_autorization_fail(self, mock_get): mock_get.return_value = get_mock_data('exceptions/unauthorizedAccess') client = CompilersClientV3('wrong-access-token', 'test.mock') with self.assertRaises(SphereEngineException): client.test()
def setUp(self): self.client = CompilersClientV3('781e6696de8ccfc6a3e04de943ea90fda', 'problems.sphere-engine.com')
def setUp(self): self.client = CompilersClientV3('access-token', 'endpoint')
def send_pusher_compiler(source_code, input_data=None): all_start_time = time.time() # language_id = 116 # id:11 C /id:4 python / id: 116 python3 language_id=11 hash_code = random.getrandbits(128) pusher_client = pusher.Pusher( app_id='569164', key='aa225154c5e541e7a10e', secret='76d2b29358645c575fb2', cluster='ap1', ssl=True ) access_token = 'cba27dc862322761011d7a7a6a4aefde' endpoint = '0c44c635.api.compilers.sphere-engine.com' client = CompilersClientV3(access_token, endpoint) # 1.submission을 생성하고, 0.5 stay start_time = time.time() r = client.submissions.create(source_code, language_id, input_data) submission_id = int(r['id']) print('submission_id:', submission_id) print("---create time %s seconds ---" % (time.time() - start_time)) # 2.submission의 결과를 돌려받는다. # compiler api문서에는 5초를 기다리라고 했지만 그전에 완료될 수 있음. # 1초마다 한번씩 받아와서 compiler는 status가 0이면 성공, problems(judge)는 status가 15면 성공 status_num = 100 output = "" data = {} while status_num != 0: start_get_time = time.time() data = client.submissions.get(submission_id, withCmpinfo=True, withSource=True, withInput=True, withOutput=True, withStderr=True) print("---get time %s seconds ---" % (time.time() - start_get_time)) time.sleep(1) status = int(data['status']) print('status:', status) if status == 0: output = data['output'] print("output", output) break # print("data", data) if output: acc_percent = 0 new_keyword = output.replace(" ", "") percent = 100 / len(list(new_keyword)) for i in list(new_keyword): acc_percent += percent is_loading = False if "%.2f" % acc_percent == "100.00" else True if i != " ": time.sleep(0.5) pusher_client.trigger('my-channel', 'my-event', { 'output': i, 'acc_percent': "%.2f" % acc_percent, 'hash_code': hash_code, 'is_loading': is_loading }) else: output = data['cmpinfo'] print('error_message:', output) pusher_client.trigger('my-channel', 'my-event', { 'output': output, 'acc_percent': 0, 'hash_code': hash_code, }) print("---In task %s seconds ---" % (time.time() - all_start_time))
def execute(request): c={} c.update(csrf(request)) if request.session.has_key('username') and request.session['username']!='dishank1': # define access parameters accessToken='635261e9572cfed16a140f349c08df82' endpoint='e6a34d7a.compilers.sphere-engine.com' # initialization client = CompilersClientV3(accessToken, endpoint) # API usage source = request.POST.get('sourcecode') compiler = request.POST.get('language') y=0 input1 = Question.objects.filter(question_Id=request.session['pcode']) # Apply on all the test cases for var in input1: input=var.cinput try: response = client.submissions.create(source, compiler, input) # Response from API x=var.Eoutput id=response['id'] time.sleep(5) response=client.submissions.get(id) if(response['result']==11): c['q']="Compilation error" return render(request,'code.html',c) elif(response['result']==15): if(response['time']<=1): url = "https://e6a34d7a.compilers.sphere-engine.com/api/v3/submissions/"+str(id)+"/output?access_token=635261e9572cfed16a140f349c08df82" response = requests.get(url) if(str(x)!=str(response.content.decode("utf-8"))): c['q']="Wrong Answer!!" c['q1']="You Got 0 marks." c['q2']=str(input) c['q3']=str(x) c['q4']=str(response.content.decode("utf-8")) return render(request,'code.html',c) else: y=1 c['q2']=str(input) c['q3']=str(x) else: c['q']="Time limit exceeded" c['q1']="You Got 0 marks." c['q2']=str(input) c['q3']=str(x) return render(request,'code.html',c) elif(response['result']==12): c['q']="Runtime error" return render(request,'code.html',c) elif(response['result']==13): c['q']="Time limit exceeded" c['q1']="You Got 0 marks." return render(request,'code.html',c) except SphereEngineException as e: print(e) if e.code == 401: print('Invalid access token') if(y==1): marks=(str)(request.session['max']) username=request.session['username'] user= Users.objects.get(username=username) que= Que.objects.get(question_Id=request.session['pcode']) c['q']="Code Running Successfully!!" c['q1']="You Got "+marks+" marks." c['q4']=str(response.content.decode("utf-8")) check=Rank.objects.filter(username=user,question_Id=que) if not check: r=Rank(username=user,marks=marks,question_Id=que) r.save() else: c['q']="Source code is empty." return render_to_response('code.html',c) else: return HttpResponseRedirect('/')