PK0J!ˊeetest/test_problems.pyimport os import sys import nose import unittest from random import randrange from array import array from sphere_engine import ProblemsClientV3 from sphere_engine.exceptions import SphereEngineException if os.environ.get('SE_ENDPOINT_PROBLEMS', None) != None and \ os.environ.get('SE_ACCESS_TOKEN_PROBLEMS', None) != None: class TestProblems(unittest.TestCase): def setUp(self): self.client = ProblemsClientV3(os.environ['SE_ACCESS_TOKEN_PROBLEMS'], os.environ['SE_ENDPOINT_PROBLEMS']) def test_autorization_fail(self): self.client = ProblemsClientV3('wrong-access-token', os.environ['SE_ENDPOINT_PROBLEMS']) try: self.client.test() self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 401) def test_autorization_success(self): self.client.test() def test_test_method_success(self): self.assertTrue(len(self.client.test()['message']) > 0, 'Test method should return nonempty message') def test_compilers_method_success(self): self.assertEqual('C++', self.client.compilers()['items'][0]['name']) def test_all_problems_method_success(self): problems = self.client.problems.all() self.assertEquals(10, problems['paging']['limit']) self.assertEquals(0, problems['paging']['offset']) self.assertEquals(False, 'shortBody' in problems['items'][0]) self.assertEquals(True, 'lastModifiedBody' in problems['items'][0]) self.assertEquals(True, 'lastModifiedSettings' in problems['items'][0]) self.assertEquals(11, self.client.problems.all(11)['paging']['limit']) self.assertEquals(False, 'shortBody' in self.client.problems.all(shortBody=False)['items'][0]) self.assertEquals(True, 'shortBody' in self.client.problems.all(shortBody=True)['items'][0]) def test_get_problem_method_success(self): problem = self.client.problems.get('TEST') self.assertEquals('TEST', problem['code']) self.assertEquals(False, 'shortBody' in problem) self.assertEquals(True, 'lastModifiedBody' in problem) self.assertEquals(True, 'lastModifiedSettings' in problem) self.assertEquals(False, 'shortBody' in self.client.problems.get('TEST', False)) self.assertEquals(True, 'shortBody' in self.client.problems.get('TEST', True)) def test_get_problem_method_wrong_code(self): try: self.client.problems.get('NON_EXISTING_PROBLEM') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_create_problem_method_success(self): r = str(randrange(1000000,9999999)) + str(randrange(1000000,9999999)) # 14-digits random string problem_code = 'UT' + r problem_name = 'UT' + r problem_body = 'UT' + r + ' body' problem_type = 'maximize' problem_interactive = True problem_masterjudgeId = 1000 self.assertEquals( problem_code, self.client.problems.create( problem_code, problem_name, problem_body, problem_type, problem_interactive, problem_masterjudgeId )['code'], 'Creation method should return new problem code') p = self.client.problems.get(problem_code) self.assertEquals(problem_code, p['code'], 'Problem code') self.assertEquals(problem_name, p['name'], 'Problem name') self.assertEquals(problem_body, p['body'], 'Problem body') self.assertEquals(problem_type, p['type'], 'Problem type') self.assertEquals(problem_interactive, p['interactive'], 'Problem interactive') self.assertEquals(problem_masterjudgeId, p['masterjudge']['id'], 'Problem masterjudgeId') def test_create_problem_method_code_taken(self): try: self.client.problems.create('TEST', 'Taken problem code') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 400) def test_create_problem_method_code_empty(self): try: self.client.problems.create('', 'Empty problem code') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 400) def test_create_problem_method_code_invalid(self): try: self.client.problems.create('!@#$%^', 'Invalid problem code') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 400) def test_create_problem_method_empty_name(self): try: self.client.problems.create('UNIQUE_CODE', '') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 400) def test_create_problem_method_nonexisting_masterjudge(self): nonexistingMasterjudgeId = 9999 try: self.client.problems.create( 'UNIQUE_CODE', 'Nonempty name', 'body', 'binary', False, nonexistingMasterjudgeId) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_update_problem_method_success(self): r = str(randrange(1000000,9999999)) + str(randrange(1000000,9999999)) # 14-digits random string # create problem to update problem_code = 'UT' + r problem_name = 'UT' + r self.client.problems.create(problem_code, problem_name) new_problem_name = problem_name + 'updated' new_problem_body = 'update' new_problem_type = 'maximize' new_problem_interactive = 1 new_problem_masterjudgeId = 1000 self.client.problems.update( problem_code, new_problem_name, new_problem_body, new_problem_type, new_problem_interactive, new_problem_masterjudgeId) p = self.client.problems.get(problem_code) self.assertEquals(problem_code, p['code'], 'Problem code') self.assertEquals(new_problem_name, p['name'], 'Problem name') self.assertEquals(new_problem_body, p['body'], 'Problem body') self.assertEquals(new_problem_type, p['type'], 'Problem type') self.assertEquals(new_problem_interactive, p['interactive'], 'Problem interactive') self.assertEquals(new_problem_masterjudgeId, p['masterjudge']['id'], 'Problem masterjudgeId') def test_update_problem_method_nonexisting_problem(self): try: self.client.problems.update('NON_EXISTING_CODE', 'Nonexisting problem code') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_update_problem_method_nonexisting_masterjudge(self): nonexistingMasterjudgeId = 9999 try: self.client.problems.update( 'TEST', 'Nonempty name', 'body', 'binary', 0, nonexistingMasterjudgeId) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_update_problem_method_empty_code(self): try: self.client.problems.update('', 'Nonempty name') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 400) def test_update_problem_method_empty_name(self): try: self.client.problems.update('TEST', '') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 400) def test_update_problem_active_testcases_method_success(self): self.client.problems.updateActiveTestcases('TEST', []) self.assertEquals('', self.client.problems.get('TEST')['seq']) self.client.problems.updateActiveTestcases('TEST', [0]) self.assertEquals('#0', self.client.problems.get('TEST')['seq']) def test_all_testcases_method_success(self): self.assertEquals(0, self.client.problems.allTestcases('TEST')['testcases'][0]['number']) def test_get_problem_testcases_method_nonexisting_problem(self): try: self.client.problems.allTestcases('NON_EXISTING_CODE') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_get_problem_testcase_method_success(self): self.assertEquals(0, self.client.problems.getTestcase('TEST', 0)['number']) def test_get_problem_testcase_method_nonexisting_problem(self): try: self.client.problems.getTestcase('NON_EXISTING_CODE', 0) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_get_problem_testcase_method_nonexisting_testcase(self): try: self.client.problems.getTestcase('TEST', 1) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_create_problem_testcase_method_success(self): r = str(randrange(1000000,9999999)) + str(randrange(1000000,9999999)) # 14-digits random string # create problem to create testcases problem_code = 'UT' + r problem_name = 'UT' + r self.client.problems.create(problem_code, problem_name) self.client.problems.createTestcase(problem_code, 'in0', 'out0', 10, 2, 0) ptc = self.client.problems.getTestcase(problem_code, 0) self.assertEquals(0, ptc['number'], 'Testcase number') self.assertEquals(False, ptc['active'], 'Testcase active') self.assertEquals(str(10), ptc['limits']['time'], 'Testcase timelimit') self.assertEquals(3, ptc['input']['size'], 'Testcase input size') self.assertEquals(4, ptc['output']['size'], 'Testcase output size') self.assertEquals(2, ptc['judge']['id'], 'Testcase judge') def test_create_problem_testcase_method_nonexisting_problem(self): try: self.client.problems.createTestcase('NON_EXISTING_CODE', 'in0', 'out0', 10, 2, 1) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_create_problem_testcase_method_nonexisting_judge(self): nonexistingJudge = 9999 try: self.client.problems.createTestcase('TEST', 'in0', 'out0', 10, nonexistingJudge, 1) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_update_problem_testcase_method_success(self): r = str(randrange(1000000,9999999)) + str(randrange(1000000,9999999)) # 14-digits random string # create problem and testcase to update the testcase problem_code = 'UT' + r problem_name = 'UT' + r self.client.problems.create(problem_code, problem_name) self.client.problems.createTestcase(problem_code, 'in0', 'out0', 1, 1, 1) new_testcase_input = 'in0updated' new_testcase_output = 'out0updated' new_testcase_timelimit = 10 new_testcase_judge = 2 new_testcase_active = 0 self.client.problems.updateTestcase( problem_code, 0, new_testcase_input, new_testcase_output, new_testcase_timelimit, new_testcase_judge, new_testcase_active) ptc = self.client.problems.getTestcase(problem_code, 0) self.assertEquals(0, ptc['number'], 'Testcase number') self.assertEquals(False, ptc['active'], 'Testcase active') self.assertEquals(str(new_testcase_timelimit), ptc['limits']['time'], 'Testcase timelimit') self.assertEquals(len(new_testcase_input), ptc['input']['size'], 'Testcase input size') self.assertEquals(len(new_testcase_output), ptc['output']['size'], 'Testcase output size') self.assertEquals(new_testcase_judge, ptc['judge']['id'], 'Testcase judge') def test_update_problem_testcase_method_nonexisting_problem(self): try: self.client.problems.updateTestcase('NON_EXISTING_CODE', 0, 'updated input') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_update_problem_testcase_method_nonexisting_testcase(self): try: self.client.problems.updateTestcase('TEST', 1, 'updated input') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_update_problem_testcase_method_nonexisting_judge(self): nonexistingJudge = 9999 try: self.client.problems.updateTestcase('TEST', 0, 'updated input', 'updated output', 1, nonexistingJudge, 0) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_delete_problem_testcase_method_success(self): r = str(randrange(1000000,9999999)) + str(randrange(1000000,9999999)) # 14-digits random string # create problem and testcase to delete the testcase problem_code = 'UT' + r problem_name = 'UT' + r self.client.problems.create(problem_code, problem_name) self.client.problems.createTestcase(problem_code, 'in0', 'out0', 1, 1, 1) self.client.problems.createTestcase(problem_code, 'in1', 'out1', 1, 1, 1) self.client.problems.deleteTestcase(problem_code, 0) p = self.client.problems.get(problem_code) self.assertEquals(1, len(p['testcases'])) self.client.problems.deleteTestcase(problem_code, 1) p = self.client.problems.get(problem_code) self.assertEquals(0, len(p['testcases'])) def test_delete_problem_testcase_method_nonexisting_problem(self): try: self.client.problems.deleteTestcase('NON_EXISTING_CODE', 0) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_delete_problem_testcase_method_nonexisting_testcase(self): try: self.client.problems.deleteTestcase('TEST', 1) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_get_problem_testcase_file_method_success(self): r = str(randrange(1000000,9999999)) + str(randrange(1000000,9999999)) # 14-digits random string # create problem and testcase to retrieve file problem_code = 'UT' + r problem_name = 'UT' + r self.client.problems.create(problem_code, problem_name) self.client.problems.createTestcase(problem_code, 'in0', 'out0', 1, 1, 1) self.assertEquals('in0', self.client.problems.getTestcaseFile(problem_code, 0, 'input')) self.assertEquals('out0', self.client.problems.getTestcaseFile(problem_code, 0, 'output')) def test_get_problem_testcase_file_method_nonexisting_problem(self): try: self.client.problems.getTestcaseFile('NON_EXISTING_CODE', 0, 'input') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_get_problem_testcase_file_method_nonexisting_testcase(self): try: self.client.problems.getTestcaseFile('TEST', 1, 'input') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_get_problem_testcase_file_method_nonexisting_file(self): try: self.client.problems.getTestcaseFile('TEST', 0, 'fakefile') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_all_judges_method_success(self): self.assertEquals(10, self.client.judges.all()['paging']['limit']) self.assertEquals(11, self.client.judges.all(11)['paging']['limit']) def test_get_judge_method_success(self): self.assertEquals(1, self.client.judges.get(1)['id']) def test_get_judge_method_nonexisting_judge(self): nonexistingJudge = 9999 try: self.client.judges.get(nonexistingJudge) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_create_judge_method_success(self): judge_source = 'source' judge_compiler = 1 judge_type = 'testcase' judge_name = 'UT judge' response = self.client.judges.create( judge_source, judge_compiler, judge_type, judge_name) judge_id = response['id'] self.assertTrue(judge_id > 0, 'Creation method should return new judge ID') j = self.client.judges.get(judge_id) self.assertEquals(judge_source, j['source'], 'Judge source') self.assertEquals(str(judge_compiler), j['compiler']['id'], 'Judge compiler ID') self.assertEquals(judge_type, j['type'], 'Judge type') self.assertEquals(judge_name, j['name'], 'Judge name') def test_create_judge_method_empty_source(self): try: self.client.judges.create('', 1, 'testcase', '') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 400) def test_create_judge_method_nonexisting_compiler(self): nonexistingCompiler = 9999 try: self.client.judges.create('nonempty source', nonexistingCompiler, 'testcase', '') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_update_judge_method_success(self): response = self.client.judges.create('source', 1, 'testcase', 'UT judge') judge_id = response['id'] new_judge_source = 'updated source' new_judge_compiler = 11 new_judge_name = 'UT judge updated' self.client.judges.update( judge_id, new_judge_source, new_judge_compiler, new_judge_name) j = self.client.judges.get(judge_id) self.assertEquals(new_judge_source, j['source'], 'Judge source') self.assertEquals(str(new_judge_compiler), j['compiler']['id'], 'Judge compiler ID') self.assertEquals(new_judge_name, j['name'], 'Judge name') def test_update_judge_method_empty_source(self): response = self.client.judges.create('source', 1, 'testcase', 'UT judge') judgeId = response['id'] try: self.client.judges.update(judgeId, '', 1, '') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 400) def test_update_judge_method_nonexisting_judge(self): nonexistingJudge = 99999999 try: self.client.judges.update(nonexistingJudge, 'nonempty source', 1, '') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_update_judge_method_nonexisting_compiler(self): response = self.client.judges.create('source', 1, 'testcase', 'UT judge') judgeId = response['id'] nonexistingCompiler = 9999 try: self.client.judges.update(judgeId, 'nonempty source', nonexistingCompiler, '') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_update_judge_method_foreign_judge(self): response = self.client.judges.create('source', 1, 'testcase', 'UT judge') judgeId = response['id'] nonexistingCompiler = 9999 try: self.client.judges.update(1, 'nonempty source', 1, '') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 403) def test_get_submission_method_success(self): self.assertEquals(1, self.client.submissions.get(1)['id']) def test_get_submission_method_nonexisting_submission(self): nonexistingSubmission = 9999999999 try: self.client.submissions.get(nonexistingSubmission) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_get_submissions_method_success(self): response = self.client.submissions.getMulti([2, 1]) self.assertTrue('items' in response) self.assertEquals(2, len(response['items'])) self.assertTrue('id' in response['items'][0]) self.assertTrue('id' in response['items'][1]) def test_get_submissions_method_nonexisting_submission(self): response = self.client.submissions.getMulti([9999999999]) self.assertTrue('items' in response) self.assertEquals(0, len(response['items'])) def test_get_submissions_method_valid_param(self): try: self.client.submissions.getMulti(1) self.client.submissions.getMulti([1]) self.client.submissions.getMulti([1, 2]) self.assertTrue(True) except ValueError: self.assertTrue(False) def test_get_submissions_method_invalid_param(self): try: self.client.submissions.getMulti('1') self.client.submissions.getMulti((1, 2)) self.client.submissions.getMulti(array('l', [1, 2])) self.assertTrue(False) except ValueError: self.assertTrue(True) def test_create_submission_method_success(self): submission_problem_code = 'TEST' submission_source = 'source' submission_compiler = 1 response = self.client.submissions.create( submission_problem_code, submission_source, submission_compiler) submission_id = response['id'] self.assertTrue(submission_id > 0, 'Creation method should return new submission ID') s = self.client.submissions.get(submission_id) self.assertEquals(submission_problem_code, s['problem']['code'], 'Submission problem code') self.assertEquals(submission_source, s['source'], 'Submission source') self.assertEquals(submission_compiler, s['compiler']['id'], 'Submission compiler ID') def test_create_submission_method_empty_source(self): try: self.client.submissions.create('TEST', '', 1) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 400) def test_create_submission_method_nonexisting_problem(self): try: self.client.submissions.create('NON_EXISTING_CODE', 'nonempty source', 1) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_create_submission_method_nonexisting_compiler(self): nonexistingCompiler = 9999 try: self.client.submissions.create('TEST', 'nonempty source', nonexistingCompiler) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_create_submission_method_nonexisting_user(self): nonexistingUser = 9999999999 try: self.client.submissions.create('TEST', 'nonempty source', 1, nonexistingUser) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) PKpHtest/__init__.pyPK0Jn,QQtest/test_compilers.pyimport os import sys import nose import unittest from array import array from sphere_engine import CompilersClientV3 from sphere_engine.exceptions import SphereEngineException if os.environ.get('SE_ENDPOINT_COMPILERS', None) != None and \ os.environ.get('SE_ACCESS_TOKEN_COMPILERS', None) != None: class TestCompilers(unittest.TestCase): client = None def setUp(self): self.client = CompilersClientV3(os.environ['SE_ACCESS_TOKEN_COMPILERS'], os.environ['SE_ENDPOINT_COMPILERS']) def test_autorization_fail(self): self.client = CompilersClientV3('wrong-access-token', os.environ['SE_ENDPOINT_COMPILERS']) with self.assertRaises(SphereEngineException): self.client.test() def test_autorization_success(self): self.client.test() def test_test_method_success(self): ret = self.client.test() self.assertTrue('pi' in ret) def test_compilers_method_success(self): ret = self.client.compilers() self.assertEqual('C', ret['11'][0]) def test_get_submission_method_success(self): ret = self.client.submissions.get(2, True) self.assertEquals('abc', ret['source'], 'Submission source') self.assertEquals(11, ret['compiler']['id'], 'Submission compiler') def test_get_submission_method_not_existing(self): nonexistingSubmission = 3 try: self.client.submissions.get(nonexistingSubmission) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_get_submission_method_access_denied(self): foreignSubmission = 1 try: self.client.submissions.get(foreignSubmission) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 403) def test_get_submissions_method_success(self): response = self.client.submissions.getMulti([1, 2]) self.assertTrue('items' in response) self.assertEquals(2, len(response['items'])) self.assertTrue('id' in response['items'][0]) self.assertTrue('id' in response['items'][1]) def test_get_submissions_method_nonexisting_submission(self): response = self.client.submissions.getMulti([9999999999]) self.assertTrue('items' in response) self.assertEquals(0, len(response['items'])) def test_get_submissions_method_valid_param(self): try: self.client.submissions.getMulti(1) self.client.submissions.getMulti([1]) self.client.submissions.getMulti([1, 2]) self.assertTrue(True) except ValueError: self.assertTrue(False) def test_get_submissions_method_invalid_param(self): try: self.client.submissions.getMulti('1') self.client.submissions.getMulti((1, 2)) self.client.submissions.getMulti(array('l', [1, 2])) self.assertTrue(False) except ValueError: self.assertTrue(True) def test_get_submission_stream_method_success(self): ret = self.client.submissions.getStream(2, 'source') self.assertEquals('abc', ret, 'Submission source') def test_get_submission_stream_method_not_existing_submission(self): nonexistingSubmission = 3 try: self.client.submissions.getStream(nonexistingSubmission, 'output') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_get_submission_stream_method_not_existing_stream(self): try: self.client.submissions.getStream(2, 'nonexistingstream') self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) def test_create_submission_method_success(self): submission_source = 'unit test' submission_compiler = 11 submission_input = 'unit test input' response = self.client.submissions.create(submission_source, submission_compiler, submission_input) submission_id = int(response['id']) self.assertTrue(submission_id > 0, 'New submission id should be greater than 0') s = self.client.submissions.get(submission_id, True, True) self.assertEquals(submission_source, s['source'], 'Submission source') self.assertEquals(submission_input, s['input'], 'Submission input') self.assertEquals(submission_compiler, s['compiler']['id'], 'Submission compiler ID') def test_create_submission_method_wrong_compiler(self): wrongCompilerId = 9999 try: self.client.submissions.create('unit_test', wrongCompilerId) self.assertTrue(False) except SphereEngineException as e: self.assertTrue(e.code == 404) PK;NGm_sphere_engine/exceptions.py class SphereEngineException(Exception): code = 0 def __init__(self, message, code=0): super(Exception, self).__init__(message) self.code = code PKpH555sphere_engine/__init__.py from .api import CompilersClientV3, ProblemsClientV3PKpHqGGsphere_engine/api.py# # Copyright 2015 Sphere Research Sp z o.o. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # from .apis.compilers import CompilersApi from .apis.problems import ProblemsApi from .api_client import ApiClient class CompilersClientV3(CompilersApi): """ Client for Sphere Engine Compilers - version 3 """ _version = 'v3' _access_token = None _endpoint = None def __init__(self, access_token, endpoint, **options): """ :param access_token: string :param endpoint: string """ self._access_token = access_token self._endpoint = endpoint api_client = ApiClient(self._access_token, self._endpoint, self._version, 'compilers') CompilersApi.__init__(self, api_client) class ProblemsClientV3(ProblemsApi): """ Client for Sphere Engine Problems - version 3 """ _version = 'v3' _access_token = None _endpoint = None def __init__(self, access_token, endpoint, **options): """ :param access_token: string :param endpoint: string """ self._access_token = access_token self._endpoint = endpoint api_client = ApiClient(self._access_token, self._endpoint, self._version, 'problems') ProblemsApi.__init__(self, api_client) PK0Jk6JX)X)sphere_engine/api_client.py# coding: utf-8 """ Copyright 2015 SmartBear Software Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ref: https://github.com/swagger-api/swagger-codegen """ from __future__ import absolute_import import os import sys import json import mimetypes from datetime import datetime from datetime import date # python 2 and python 3 compatibility library from six import iteritems import requests import sphere_engine import simplejson try: # for python3 from urllib.parse import quote except ImportError: # for python2 from urllib import quote class ApiClient(object): access_token = None endpoint = None version = None host = None host_protocol = 'http' default_headers = {} """ Generic API client for Swagger client library builds. Swagger generic API client. This client handles the client- server communication, and is invariant across implementations. Specifics of the methods and models for each application are generated from the Swagger templates. NOTE: This class is auto generated by the swagger code generator program. Ref: https://github.com/swagger-api/swagger-codegen Do not edit the class manually. """ def __init__(self, access_token, endpoint, version, api_type): """ Constructor of the class. :param host: The base path for the server to call. :param header_name: a header to pass when making calls to the API. :param header_value: a header value to pass when making calls to the API. """ self.access_token = access_token self.endpoint = endpoint self.version = version self.host = self.create_host(api_type, endpoint, version) # Set default User-Agent. self.user_agent = 'SphereEngine/3.0.0' def create_host(self, api_type, endpoint, version): if '.' not in endpoint: host = '%s://%s.%s.sphere-engine.com/api/%s' % ( self.host_protocol, endpoint, 'compilers' if api_type == 'compilers' else 'problems', version ) else: host = '%s://%s/api/%s' % ( self.host_protocol, endpoint, version ) return host def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None, post_params=None, files=None, response_type=None, auth_settings=None, callback=None): """ Call method @param resource_path: sdfasdf :param resource_path dfawef :param method GET|POST :param path_params :param query_params """ # headers parameters header_params = header_params or {} header_params.update(self.default_headers) #if self.cookie: # header_params['Cookie'] = self.cookie if header_params: header_params = self.sanitize_for_serialization(header_params) # path parameters if path_params: for k, v in iteritems(path_params): replacement = quote(str(self.to_path_value(v))) resource_path = resource_path.replace('{' + k + '}', replacement) # query parameters #if query_params: # query_params = {k: self.to_path_value(v) # for k, v in iteritems(query_params)} if not query_params: query_params = {} if self.access_token: query_params['access_token'] = self.access_token # post parameters if post_params or files: post_params = self.sanitize_for_serialization(post_params) ## body #if body: # body = self.sanitize_for_serialization(body) # request url url = self.host + resource_path # perform request and return response response_data = self.request(method, url, query_params=query_params, headers=header_params, post_params=post_params)#, body=body) try: if response_type == 'file': data = response_data.text else: data = response_data.json() except simplejson.scanner.JSONDecodeError as e: raise sphere_engine.exceptions.SphereEngineException(e) return data """ # deserialize response data if response_type: deserialized_data = self.deserialize(response_data, response_type) else: deserialized_data = None if callback: callback(deserialized_data) else: return deserialized_data """ def request(self, method, url, query_params=None, headers=None, post_params=None, body=None): """ Makes the HTTP request using requests library. :raise requests.exceptions.RequestException :raise sphere_engine.exceptions.SphereEngineException """ r = None if method == "GET": r = requests.get(url, params=query_params, headers=headers) elif method == "HEAD": r = requests.head(url, params=query_params, headers=headers) #elif method == "OPTIONS": # return self.rest_client.OPTIONS(url, # query_params=query_params, # headers=headers, # post_params=post_params, # body=body) elif method == "POST": r = requests.post(url, params=query_params, headers=headers, data=post_params, ) elif method == "PUT": r = requests.put(url, params=query_params, headers=headers, data=post_params, ) #elif method == "PATCH": # return self.rest_client.PATCH(url, # query_params=query_params, # headers=headers, # post_params=post_params, # body=body) elif method == "DELETE": r = requests.delete(url, params=query_params, headers=headers) else: raise ValueError( "http method must be `GET`, `HEAD`," " `POST`, `PATCH`, `PUT` or `DELETE`." ) if r.status_code not in range(200, 206): from sphere_engine.exceptions import SphereEngineException raise SphereEngineException(r.reason, r.status_code) #print r.text #print r.status_code return r @property def user_agent(self): """ Gets user agent. """ return self.default_headers['User-Agent'] @user_agent.setter def user_agent(self, value): """ Sets user agent. """ self.default_headers['User-Agent'] = value def set_default_header(self, header_name, header_value): self.default_headers[header_name] = header_value def to_path_value(self, obj): """ Takes value and turn it into a string suitable for inclusion in the path, by url-encoding. :param obj: object or string value. :return string: quoted value. """ if type(obj) == list: return ','.join(obj) else: return str(obj) def sanitize_for_serialization(self, obj): """ Builds a JSON POST object. If obj is None, return None. If obj is str, int, float, bool, return directly. If obj is datetime.datetime, datetime.date convert to string in iso8601 format. If obj is list, sanitize each element in the list. If obj is dict, return the dict. If obj is swagger model, return the properties dict. :param obj: The data to serialize. :return: The serialized form of data. """ types = (str, int, float, bool, tuple) if sys.version_info < (3,0): types = types + (unicode,) if isinstance(obj, type(None)): return None elif isinstance(obj, types): return obj elif isinstance(obj, list): return [self.sanitize_for_serialization(sub_obj) for sub_obj in obj] elif isinstance(obj, (datetime, date)): return obj.isoformat() else: if isinstance(obj, dict): obj_dict = obj else: # Convert model obj to dict except # attributes `swagger_types`, `attribute_map` # and attributes which value is not None. # Convert attribute name to json key in # model definition for request. obj_dict = {obj.attribute_map[attr]: getattr(obj, attr) for attr, _ in iteritems(obj.swagger_types) if getattr(obj, attr) is not None} return {key: self.sanitize_for_serialization(val) for key, val in iteritems(obj_dict)} def deserialize(self, response, response_type): """ Deserializes response into an object. :param response: RESTResponse object to be deserialized. :param response_type: class literal for deserialzied object, or string of class name. :return: deserialized object. """ # handle file downloading # save response body into a tmp file and return the instance if "file" == response_type: return self.__deserialize_file(response) # fetch data from response object try: data = json.loads(response.data) except ValueError: data = response.data return data PK0Jxsphere_engine/apis/compilers.py# # Sphere Engine API # # LICENSE # # # @copyright Copyright (c) 2015 Sphere Research Labs (http://sphere-research.com) # @license link do licencji # @version 0.6 from .base import AbstractApi from sphere_engine.exceptions import SphereEngineException class CompilersApiSubmissions(AbstractApi): def create(self, sourceCode, compilerId=1, _input='', priority=None): """ Create submission :param sourceCode: source code :type : string :param compilerId: id of the compiler (default 1, i.e. C++) :type : integer :param _input: input for the program (default '') :type : string :param priority: priority of the submission (default normal priority, eg. 5 for range 1-9) :type : integer :returns: submission id :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 400 for empty source code :raises SphereEngineException: code 400 for non integer compilerId """ if not sourceCode: raise SphereEngineException('empty source code', 400) try: _cId = int(compilerId) except: raise SphereEngineException('compilerId should be integer', 400) resource_path = '/submissions' method = 'POST' post_params = { 'sourceCode': sourceCode, 'compilerId': compilerId, 'input': _input } if priority != None: post_params['priority'] = priority response = self.api_client.call_api(resource_path, method, {}, {}, {}, post_params=post_params, ) return response def get(self, _id, withSource=False, withInput=False, withOutput=False, withStderr=False, withCmpinfo=False): """ Get submission details :param _id: number of problems to get (default 10) :type _id: integer :param withSource: determines whether source code of the submission should be returned (default False) :type withSource: bool :param withInput: determines whether input data of the submission should be returned (default False) :type withInput: bool :param withOutput: determines whether output produced by the program should be returned (default False) :type withOutput: bool :param withStderr: determines whether stderr should be returned (default False) :type withStderr: bool :param withCmpinfo: determines whether compilation information should be returned (default False) :type withCmpinfo: bool :returns: submission details :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 400 for empty source code :raises SphereEngineException: code 404 for non existing submission """ if not _id: raise SphereEngineException('empty _id value', 400) resource_path = '/submissions/{id}' method = 'GET' query_data = { 'withSource': int(withSource), 'withInput': int(withInput), 'withOutput': int(withOutput), 'withStderr': int(withStderr), 'withCmpinfo': int(withCmpinfo), } response = self.api_client.call_api(resource_path, method, {'id': _id}, query_data, ) return response def getMulti(self, ids): """ Fetches status of multiple submissions (maximum 20 ids) Results are sorted ascending by id. :param ids: submission ids :type ids: integer|list :returns: submissions details :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises ValueError: for invalid _ids param """ if isinstance(ids, (list, int)) == False: raise ValueError("getSubmissions method accepts only list or integer.") if isinstance(ids, (list)): ids = ','.join(list(map(str, filter(lambda x: isinstance(x, (int)) and x > 0, set(ids))))) resource_path = '/submissions' method = 'GET' params = { 'ids': ids } return self.api_client.call_api(resource_path, method, {}, params) def getStream(self, _id, stream): """ Fetch raw stream :param _id: number of problems to get (default 10) :type _id: integer :param stream: name of the stream, input|output|stderr|cmpinfo|source :type stream: string :returns: submission details :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 400 for empty id value :raises SphereEngineException: code 404 for non existing submission or non existing stream """ if not _id: raise SphereEngineException('empty _id value', 400) if not stream in ["input", "stdin", "output", "stdout", "stderr", "error", "cmpinfo", "source"]: raise SphereEngineException('stream doesn\'t exist', 404) resource_path = '/submissions/{id}/{stream}' method = 'GET' path_params = { 'id': _id, 'stream': stream } response = self.api_client.call_api(resource_path, method, path_params ) return response class CompilersApi(AbstractApi): @property def submissions(self): """ :return: CompilersApiSubmissions """ return self._submissions def __init__(self, api_client): super(CompilersApi, self).__init__(api_client) self._submissions = CompilersApiSubmissions(api_client) def test(self): """ Test API connection :returns: Test message :rtype: json :raises SphereEngineException: code 401 for invalid access token """ resource_path = '/test' method = 'GET' response = self.api_client.call_api(resource_path, method, ) return response def compilers(self): """ Get available compilers :returns: List of compilers :rtype: json :raises SphereEngineException: code 401 for invalid access token """ resource_path = '/compilers' method = 'GET' response = self.api_client.call_api(resource_path, method) return response PK0BGsphere_engine/apis/__init__.pyPKNGOsphere_engine/apis/base.py from sphere_engine.api_client import ApiClient class AbstractApi(object): api_client = None # :type ApiClient def __init__(self, api_client): self.api_client = api_client PK0J҆K2wZwZsphere_engine/apis/problems.py# # Sphere Engine API # # LICENSE # # # @copyright Copyright (c) 2015 Sphere Research Labs (http://sphere-research.com) # @license link do licencji # @version 0.6 from .base import AbstractApi from sphere_engine.exceptions import SphereEngineException class ProblemsApiProblems(AbstractApi): def all(self, limit=10, offset=0, shortBody=False): """ Get all problems :param limit: number of problems to get (default 10) :type limit: integer :param offset: starting number (default 0) :type offset: integer :param shortBody: determines whether shortened body should be returned (default False) :type shortBody: bool :returns: list of problems :rtype: json :raises SphereEngineException: code 401 for invalid access token """ resource_path = '/problems' method = 'GET' query_params = { 'limit': limit, 'offset': offset, 'shortBody': int(shortBody) } return self.api_client.call_api(resource_path, method, {}, query_params) def create(self, code, name, body='', _type='bin', interactive=False, masterjudgeId=1001): """ Create a new problem :param code: problem code :type code: string :param name: problem name :type name: string :param body: problem body :type body: string :param _type: problem type (default 'bin') :type _type: string ('binary', 'min' or 'max') :param interactive: interactive problem flag (default False) :type interactive: bool :param masterjudgeId: masterjudge id (default 1001, i.e. Score is % of correctly solved testcases) :type masterjudgeId: integer :returns: code of created problem :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 400 for empty problem code :raises SphereEngineException: code 400 for empty problem name :raises SphereEngineException: code 400 for not unique problem code :raises SphereEngineException: code 400 for invalid problem code :raises SphereEngineException: code 400 for invalid type :raises SphereEngineException: code 404 for non existing masterjudge """ resource_path = '/problems' method = 'POST' if code == '': raise SphereEngineException('empty code', 400) if name == '': raise SphereEngineException('empty name', 400) if _type not in ['min', 'max', 'bin', 'minimize', 'maximize', 'binary']: raise SphereEngineException('wrong type', 400) post_params = { 'code': code, 'name': name, 'body': body, 'type': _type, 'interactive': interactive, 'masterjudgeId': masterjudgeId } return self.api_client.call_api(resource_path, method, {}, {}, {}, post_params) def get(self, code, shortBody=False): """ Retrieve an existing problem :param code: problem code :type code: string :param shortBody: determines whether shortened body should be returned (default False) :type shortBody: bool :returns: problem details :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 404 for non existing problem """ resource_path = '/problems/{code}' method = 'GET' path_params = { 'code': code } query_params = { 'shortBody': int(shortBody) } return self.api_client.call_api(resource_path, method, path_params, query_params) def update(self, code, name=None, body=None, _type=None, interactive=None, masterjudgeId=None, activeTestcases=None): """ Update an existing problem :param code: problem code :type code: string :param name: problem name (default None) :type name: string :param body: problem body (default None) :type body: string :param _type: problem type (default None) :type _type: string ('binary', 'min' or 'max') :param interactive: interactive problem flag (default None) :type interactive: bool :param masterjudgeId: masterjudge id (default None) :type masterjudgeId: integer :param activeTestcases: list of active testcases IDs (default None) :type activeTestcases: List[integer] :returns: code of created problem :rtype: json :returns: void :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 403 for modifying foreign problem :raises SphereEngineException: code 400 for empty problem code :raises SphereEngineException: code 400 for empty problem name :raises SphereEngineException: code 404 for non existing problem :raises SphereEngineException: code 404 for non existing masterjudge """ if code == '': raise SphereEngineException('empty code', 400) if name == '': raise SphereEngineException('empty name', 400) path_params = { 'code': code }; resource_path = '/problems/{code}' method = 'PUT' post_params = {} if name != None: post_params['name'] = name; if body != None: post_params['body'] = body if _type != None: if _type not in ['min', 'max', 'bin', 'minimize', 'maximize', 'binary']: raise SphereEngineException('wrong type', 400) post_params['type'] = _type if interactive != None: post_params['interactive'] = 1 if interactive else 0 if masterjudgeId != None: post_params['masterjudgeId'] = masterjudgeId if activeTestcases != None: post_params['activeTestcases'] = ','.join(map(str, activeTestcases)) return self.api_client.call_api(resource_path, method, path_params, {}, {}, post_params) def updateActiveTestcases(self, code, activeTestcases): """ Update active testcases related to the problem :param code: problem code :type code: string :param activeTestcases: list of active testcases IDs :type activeTestcases: List[integer] :returns: void :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 403 for modifying foreign problem :raises SphereEngineException: code 400 for empty problem code :raises SphereEngineException: code 404 for non existing problem """ self.update(code, activeTestcases=activeTestcases) def allTestcases(self, problemCode): """ Retrieve list of problem testcases :param problemCode: problem code :type problemCode: string :returns: problem testcases :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 403 for retrieving testcases of foreign problem :raises SphereEngineException: code 404 for non existing problem """ resource_path = '/problems/{problemCode}/testcases' method = 'GET' path_params = { 'problemCode': problemCode }; return self.api_client.call_api(resource_path, method, path_params) def createTestcase(self, problemCode, _input='', output='', timelimit=1, judgeId=1, active=True): """ Create a problem testcase :param problemCode: problem code :type problemCode: string :param _input: model input data (default '') :type _input: string :param output: model output data (default '') :type output: string :param timelimit: time limit in seconds (default 1) :type timelimit: double :param judgeId: judge id (default 1, i.e. Ignore extra whitespaces) :type judgeId: integer :param active: if test should be active (default True) :type active: bool :returns: number of created testcase :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 403 for adding a testcase to foreign problem :raises SphereEngineException: code 404 for non existing problem :raises SphereEngineException: code 404 for non existing judge """ resource_path = '/problems/{problemCode}/testcases' method = 'POST' path_params = { 'problemCode': problemCode }; post_params = { 'input': _input, 'output': output, 'timelimit': timelimit, 'judgeId': judgeId, 'active': active }; return self.api_client.call_api(resource_path, method, path_params, {}, {}, post_params) def getTestcase(self, problemCode, number): """ Retrieve problem testcase :param problemCode: problem code :type problemCode: string :param number: testcase number :type number: integer :returns: testcase details :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 403 for retrieving a testcase of foreign problem :raises SphereEngineException: code 404 for non existing problem :raises SphereEngineException: code 404 for non existing testcase """ resource_path = '/problems/{problemCode}/testcases/{number}' method = 'GET' path_params = { 'problemCode': problemCode, 'number': number }; return self.api_client.call_api(resource_path, method, path_params) def updateTestcase(self, problemCode, number, _input=None, output=None, timelimit=None, judgeId=None, active=None): """ Update the problem testcase :param problemCode: problem code :type problemCode: string :param number: testcase number :type number: integer :param _input: model input data (default None) :type _input: string :param output: model output data (default None) :type output: string :param timelimit: time limit in seconds (default None) :type timelimit: double :param judgeId: judge id (default None) :type judgeId: integer :param active: if test should be active (default None) :type active: bool :returns: void :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 403 for adding a testcase to foreign problem :raises SphereEngineException: code 404 for non existing problem :raises SphereEngineException: code 404 for non existing testcase :raises SphereEngineException: code 404 for non existing judge """ resource_path = '/problems/{problemCode}/testcases/{number}' method = 'PUT' path_params = { 'problemCode': problemCode, 'number': number } post_params = {} if input != None: post_params['input'] = _input if output != None: post_params['output'] = output if timelimit != None: post_params['timelimit'] = timelimit if judgeId != None: post_params['judgeId'] = judgeId if active != None: post_params['active'] = active return self.api_client.call_api(resource_path, method, path_params, {}, {}, post_params) def deleteTestcase(self, problemCode, number): """ Delete the problem testcase :param problemCode: problem code :type problemCode: string :param number: testcase number :type number: integer :returns: void :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 403 for retrieving a testcase of foreign problem :raises SphereEngineException: code 404 for non existing problem :raises SphereEngineException: code 404 for non existing testcase """ resource_path = '/problems/{problemCode}/testcases/{number}' method = 'DELETE' path_params = { 'problemCode': problemCode, 'number': number }; return self.api_client.call_api(resource_path, method, path_params) def getTestcaseFile(self, problemCode, number, filename): """ Retrieve a problem testcase file :param problemCode: problem code :type problemCode: string :param number: testcase number :type number: integer :param filename: filename :type filename: string :returns: file content :rtype: string :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 403 for retrieving a testcase of foreign problem :raises SphereEngineException: code 404 for non existing problem :raises SphereEngineException: code 404 for non existing testcase :raises SphereEngineException: code 404 for non existing file """ resource_path = '/problems/{problemCode}/testcases/{number}/{filename}' method = 'GET' if filename not in ['input', 'output']: raise SphereEngineException('nonexisting file', 404) path_params = { 'problemCode': problemCode, 'number': number, 'filename': filename } return self.api_client.call_api(resource_path, method, path_params, response_type='file') class ProblemsApiJudges(AbstractApi): def all(self, limit=10, offset=0, type='testcase'): """ List of all judges :param limit: number of judges to get (default 10) :type limit: integer :param offset: starting number (default 0) :type offset: integer :returns: list of judges :rtype: json :raises SphereEngineException: code 401 for invalid access token """ resource_path = '/judges' method = 'GET' query_params = { 'limit': limit, 'offset': offset } return self.api_client.call_api(resource_path, method, {}, query_params) def create(self, sourceCode, compilerId=1, type='testcase', name=''): """ Create a new judge :param sourceCode: judge source code :type sourceCode: string :param compilerId: compiler id (default 1, i.e. C++) :type compilerId: integer :param type: judge type :type type: string ('testcase' or 'master') :param name: judge name (default '') :type name: string :returns: id of created judge :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 400 for empty source code :raises SphereEngineException: code 404 for non existing compiler """ resource_path = '/judges' method = 'POST' if sourceCode == '': raise SphereEngineException("empty source", 400) post_params = { 'source': sourceCode, 'compilerId': compilerId, 'type': type, 'name': name, } return self.api_client.call_api(resource_path, method, {}, {}, {}, post_params) def get(self, _id): """ Get judge details :param _id: judge id :type _id: integer :returns: judge details :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 403 for retrieving foreign judge details :raises SphereEngineException: code 404 for non existing judge """ resource_path = '/judges/{id}' method = 'GET' host_params = { 'id': _id } return self.api_client.call_api(resource_path, method, host_params, ) def update(self, _id, sourceCode=None, compilerId=None, name=None): """ Update judge :param _id: judge id :type _id: integer :param sourceCode: judge source code(default None) :type sourceCode: string :param compilerId: compiler id (default None) :type compilerId: integer :param name: judge name (default None) :type name: string :returns: void :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 403 for modifying foreign judge :raises SphereEngineException: code 400 for empty source code :raises SphereEngineException: code 404 for non existing judge :raises SphereEngineException: code 404 for non existing compiler """ resource_path = '/judges/{id}' method = 'PUT' if sourceCode != None and sourceCode == '': raise SphereEngineException('empty source', 400) host_params = { 'id': _id } post_params = {} if sourceCode != None: post_params['source'] = sourceCode if compilerId != None: post_params['compilerId'] = compilerId if name != None: post_params['name'] = name return self.api_client.call_api(resource_path, method, host_params, {}, {}, post_params) class ProblemsApiSubmissions(AbstractApi): def get(self, _id): """ Fetch submission details :param id: submission id :type _id: integer :returns: submission details :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 404 for non existing submission """ resource_path = '/submissions/{id}' method = 'GET' host_params = { 'id': _id } return self.api_client.call_api(resource_path, method, host_params, ) def getMulti(self, ids): """ Fetches status of multiple submissions (maximum 20 ids) Results are sorted ascending by id. :param ids: submission ids :type ids: integer|list :returns: submissions details :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises ValueError: for invalid ids param """ if isinstance(ids, (list, int)) == False: raise ValueError("getSubmissions method accepts only list or integer.") if isinstance(ids, (list)): ids = ','.join(list(map(str, filter(lambda x: isinstance(x, (int)) and x > 0, set(ids))))) resource_path = '/submissions' method = 'GET' params = { 'ids': ids } return self.api_client.call_api(resource_path, method, {}, params) def create(self, problemCode, source, compilerId=None, userId=None, priority=None):#, contestCode=None, private=False): """ Create a new submission :param problemCode: problem code :type problemCode: string :param source: submission source code :type source: string :param compilerId: compiler id :type compilerId: integer :param userId: user id :type userId: integer :param priority: priority of the submission (default normal priority, eg. 5 for range 1-9) :type : integer :returns: id of created submission :rtype: json :raises SphereEngineException: code 401 for invalid access token :raises SphereEngineException: code 400 for empty source code :raises SphereEngineException: code 404 for non existing problem :raises SphereEngineException: code 404 for non existing user :raises SphereEngineException: code 404 for non existing compiler """ resource_path = '/submissions' method = 'POST' if source == '': raise SphereEngineException('empty source', 400) post_params = { 'problemCode': problemCode, 'compilerId': compilerId, 'source': source } if userId != None: post_params['userId'] = userId if priority != None: post_params['priority'] = priority #if contestCode != None: # post_params['contestCode'] = contestCode #if private: # post_params['private'] = int(private) return self.api_client.call_api(resource_path, method, {}, {}, {}, post_params) class ProblemsApi(AbstractApi): @property def problems(self): """ :return: ProblemsApiProblems """ return self._problems @property def judges(self): """ :return: ProblemsApiJudges """ return self._judges @property def submissions(self): """ :return: ProblemsApiSubmissions """ return self._submissions def __init__(self, api_client): """ @param api_client: sphere_engine.api_client.ApiClient """ super(ProblemsApi, self).__init__(api_client) self._problems = ProblemsApiProblems(api_client) self._judges = ProblemsApiJudges(api_client) self._submissions = ProblemsApiSubmissions(api_client) def test(self): """ Test API connection :returns: test message :rtype: json :raises SphereEngineException: code 401 for invalid access token """ resource_path = '/test' method = 'GET' response = self.api_client.call_api(resource_path, method, ) return response def compilers(self): """ Get available compilers :returns: list of compilers :rtype: json :raises SphereEngineException: code 401 for invalid access token """ resource_path = '/compilers' method = 'GET' response = self.api_client.call_api(resource_path, method, ) return responsePK0J_~,sphere_engine-0.14.dist-info/DESCRIPTION.rstSphere Engine Problems API allows you to: submit submissions to your problems, run the program with test data on server side in more than 60 programming languages and download results of the execution. PK0JQE&&*sphere_engine-0.14.dist-info/metadata.json{"download_url": "https://github.com/sphere-engine/python-client/archive/master.zip", "extensions": {"python.details": {"contacts": [{"email": "contact@sphere-research.com", "name": "Michal Koperkiewicz, Robert Lewon", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/sphere-engine/python-client"}}}, "extras": [], "generator": "bdist_wheel (0.26.0)", "keywords": ["Sphere", "Research", "Labs", "Sphere", "Engine", "Online", "Compiler", "Problems", "Online", "Judge", "api", "sdk", "online", "compiler", "spoj", "ideone"], "metadata_version": "2.0", "name": "sphere-engine", "run_requires": [{"requires": ["certifi", "python-dateutil", "requests", "six (>=1.9)", "urllib3 (>=1.10)"]}], "summary": "Sphere Engine SDK", "version": "0.14"}PK0J" *sphere_engine-0.14.dist-info/top_level.txtsphere_engine test PK0J''\\"sphere_engine-0.14.dist-info/WHEELWheel-Version: 1.0 Generator: bdist_wheel (0.26.0) Root-Is-Purelib: true Tag: py2-none-any PK0J!!%sphere_engine-0.14.dist-info/METADATAMetadata-Version: 2.0 Name: sphere-engine Version: 0.14 Summary: Sphere Engine SDK Home-page: https://github.com/sphere-engine/python-client Author: Michal Koperkiewicz, Robert Lewon Author-email: contact@sphere-research.com License: UNKNOWN Download-URL: https://github.com/sphere-engine/python-client/archive/master.zip Keywords: Sphere Research Labs,Sphere Engine,Online Compiler,Problems,Online Judge,api,sdk,online compiler,spoj,ideone Platform: UNKNOWN Requires-Dist: certifi Requires-Dist: python-dateutil Requires-Dist: requests Requires-Dist: six (>=1.9) Requires-Dist: urllib3 (>=1.10) Sphere Engine Problems API allows you to: submit submissions to your problems, run the program with test data on server side in more than 60 programming languages and download results of the execution. PK0J8 #sphere_engine-0.14.dist-info/RECORDsphere_engine/__init__.py,sha256=Gt_s4FOps7mT0QZfYdHblxHsw5cwWDg57gsmiC9fB_0,53 sphere_engine/api.py,sha256=W02JfhdIfoT-1fPSGUC7YMFhTlcPPuRCuiDId9PtJso,1863 sphere_engine/api_client.py,sha256=hx-6t5VBFm0LhRcDvEUU3b0U6L5EryWnD8bmVWH1Myw,10584 sphere_engine/exceptions.py,sha256=fAO8oW-6Tao5i5Qm0GwavYCrJVlKhTlGggWwGlc5Ol0,179 sphere_engine/apis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 sphere_engine/apis/base.py,sha256=i7NaCTTOhvmqafN7ecsN7j04UhkGD3KE8tLO5_2kbC0,208 sphere_engine/apis/compilers.py,sha256=kOubRHzfzm0RVuFtK5qXJ1hK-n7TEZMR4C4-h5_AC54,7152 sphere_engine/apis/problems.py,sha256=rxlL_wTNbw1k8g2LA2pmo6oWtuQoAgN1nIrD7jOvZpM,23159 sphere_engine-0.14.dist-info/DESCRIPTION.rst,sha256=Q9vMUdOfU3k9O6gAVci5Yio5AooHLasJCZc_m91thw0,204 sphere_engine-0.14.dist-info/METADATA,sha256=zztGGBDELJjN-de4VK0cXC9XhIEggArIBBDxvwBk8pA,801 sphere_engine-0.14.dist-info/RECORD,, sphere_engine-0.14.dist-info/WHEEL,sha256=JTb7YztR8fkPg6aSjc571Q4eiVHCwmUDlX8PhuuqIIE,92 sphere_engine-0.14.dist-info/metadata.json,sha256=TWf9i0c2YBGNwmsFfrVCycl7yydcxLrI2ogDs7wvexM,806 sphere_engine-0.14.dist-info/top_level.txt,sha256=B6IoQESK9MM0limxRsEJ8jVmefKOeLxLFgp_RiO-ptE,19 test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 test/test_compilers.py,sha256=kg1H-l8ZhAqLOxpRjU_qv5c6CBnU_D4riXG2ibGa3T4,5457 test/test_problems.py,sha256=GFf_qsVThpL4T7HQq6T3cw7_4mDZWQ0et83QPHDD8l8,25994 PK0J!ˊeetest/test_problems.pyPKpHetest/__init__.pyPK0Jn,QQetest/test_compilers.pyPK;NGm_p{sphere_engine/exceptions.pyPKpH555\|sphere_engine/__init__.pyPKpHqGG|sphere_engine/api.pyPK0Jk6JX)X)Asphere_engine/api_client.pyPK0Jxҭsphere_engine/apis/compilers.pyPK0BGsphere_engine/apis/__init__.pyPKNGO;sphere_engine/apis/base.pyPK0J҆K2wZwZCsphere_engine/apis/problems.pyPK0J_~,%sphere_engine-0.14.dist-info/DESCRIPTION.rstPK0JQE&&* 'sphere_engine-0.14.dist-info/metadata.jsonPK0J" *z*sphere_engine-0.14.dist-info/top_level.txtPK0J''\\"*sphere_engine-0.14.dist-info/WHEELPK0J!!%q+sphere_engine-0.14.dist-info/METADATAPK0J8 #.sphere_engine-0.14.dist-info/RECORDPK 4