Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    def getStream(self, _id, stream):
        """ Fetch raw stream

        :param _id: submission id
        :type _id: integer
        :param stream: name of the stream, source|input|output|error|cmpinfo
        :type stream: string
        :returns: submission details
        :rtype: json
        :raises SphereEngineException
        """

        if not _id:
            raise SphereEngineException('empty _id value', 400)

        if stream not in ["source", "input", "output", "error", "cmpinfo"]:
            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,
                                            response_type='file')

        return response
Exemplo n.º 3
0
    def create(self,
               source_code,
               compiler_id=1,
               _input='',
               priority=None,
               experimental=None):
        """ Create submission

        :param source_code: source code
        :type source_code: string
        :param compiler_id: id of the compiler (default 1, i.e. C++)
        :type compiler_id: 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
        :param experimental: execute in experimental mode (default false)
        :type : bool
        :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 source_code:
            raise SphereEngineException('empty source code', 400)

        try:
            c_id = int(compiler_id)
        except:
            raise SphereEngineException('compilerId should be integer', 400)

        resource_path = '/submissions'
        method = 'POST'
        post_params = {
            'sourceCode': source_code,
            'compilerId': c_id,
            'input': _input
        }
        if priority != None:
            post_params['priority'] = priority

        if experimental != None:
            post_params['experimental'] = bool(experimental)

        response = self.api_client.call_api(
            resource_path,
            method,
            {},
            {},
            {},
            post_params=post_params,
        )

        if 'id' not in response:
            raise SphereEngineException('invalid or empty response', 422)

        return response
Exemplo n.º 4
0
    def update(self, _id, name=None, masterjudge_id=None, body=None, type_id=None, interactive=None,
               active_testcases=None):
        """ Update an existing problem

        :param _id: problem id
        :type _id: integer
        :param name: problem name (default None)
        :type name: string
        :param masterjudge_id: masterjudge id (default None)
        :type masterjudge_id: integer
        :param body: problem body (default None)
        :type body: string
        :param type_id: problem type id (0-binary, 1-minimize, 2-maximize) (default None)
        :type type_id: string
        :param interactive: interactive problem flag (default None)
        :type interactive: bool
        :param active_testcases: list of active testcases IDs (default None)
        :type active_testcases: List[integer]
        :returns: void
        :rtype: json
        :raises SphereEngineException
        """

        if _id == '':
            raise SphereEngineException('empty id', 400)

        if name == '':
            raise SphereEngineException('empty name', 400)

        path_params = {
            'id': _id
        }

        resource_path = '/problems/{id}'
        method = 'PUT'

        post_params = {}
        if name != None:
            post_params['name'] = name
        if body != None:
            post_params['body'] = body
        if type_id != None:
            if type_id not in [0,1,2]:
                raise SphereEngineException('wrong type id', 400)
            post_params['typeId'] = type_id
        if interactive != None:
            post_params['interactive'] = 1 if interactive else 0
        if masterjudge_id != None:
            post_params['masterjudgeId'] = masterjudge_id
        if active_testcases != None:
            post_params['activeTestcases'] = ','.join(map(str, active_testcases))

        response = self.api_client.call_api(resource_path, method, path_params, {}, {}, post_params)

        if not isinstance(response, dict) or response:
            raise SphereEngineException('unexpected error', 400)

        return response
Exemplo n.º 5
0
    def create(self,
               problem_code,
               source,
               compiler_id=None,
               user_id=None,
               priority=None,
               experimental=None):
        """ Create a new submission

        :param problem_code: problem code
        :type problem_code: string
        :param source: submission source code
        :type source: string
        :param compiler_id: compiler id
        :type compiler_id: integer
        :param user_id: user id
        :type user_id: integer
        :param priority: priority of the submission (default normal priority, eg. 5 for range 1-9)
        :type : integer
        :param experimental: execute in experimental mode (default false)
        :type : bool
        :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': problem_code,
            'compilerId': compiler_id,
            'source': source
        }

        if user_id != None:
            post_params['userId'] = user_id

        if priority != None:
            post_params['priority'] = priority

        if experimental != None:
            post_params['experimental'] = bool(experimental)

        response = self.api_client.call_api(resource_path, method, {}, {}, {},
                                            post_params)

        if 'id' not in response:
            raise SphereEngineException('invalid or empty response', 422)

        return response
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    def get(self,
            _id,
            with_source=False,
            with_input=False,
            with_output=False,
            with_stderr=False,
            with_cmpinfo=False):
        """ Get submission details

        :param _id: number of problems to get (default 10)
        :type _id: integer
        :param with_source: determines whether source code of the submission
                            should be returned (default False)
        :type with_source: bool
        :param with_input: determines whether input data of the submission
                          should be returned (default False)
        :type with_input: bool
        :param with_output: determines whether output produced by the program
                           should be returned (default False)
        :type with_output: bool
        :param with_stderr: determines whether stderr
                           should be returned (default False)
        :type with_stderr: bool
        :param with_cmpinfo: determines whether compilation information
                            should be returned (default False)
        :type with_cmpinfo: 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(with_source),
            'withInput': int(with_input),
            'withOutput': int(with_output),
            'withStderr': int(with_stderr),
            'withCmpinfo': int(with_cmpinfo),
        }

        response = self.api_client.call_api(
            resource_path,
            method,
            {'id': _id},
            query_data,
        )

        if 'status' not in response:
            raise SphereEngineException('invalid or empty response', 422)

        return response
Exemplo n.º 8
0
    def __create(self, source='', compiler_id=1, _input='', priority=None, files={}, time_limit=None, memory_limit=None):
        """ Create submission

        :param source: source code (default '')
        :type source: string
        :param compiler_id: id of the compiler (default 1, i.e. C++)
        :type compiler_id: 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
        """
        
        try:
            c_id = int(compiler_id)
        except:
            raise SphereEngineException('compilerId should be integer', 400)
    
        resource_path = '/submissions'
        method = 'POST'
        post_params = {
            'source': source,
            'compilerId': c_id,
            'input': _input
        }
        files_params = {}

        if priority != None:
            post_params['priority'] = priority

        if len(files):
            for k, v in files.items():
                if not isinstance(v, six.string_types):
                    continue
                files_params['files['+k+']'] = (k, v);
            post_params['source'] = ''

        if time_limit != None:
            post_params['timeLimit'] = time_limit
            
        if memory_limit != None:
            post_params['memoryLimit'] = memory_limit

        response = self.api_client.call_api(resource_path, method, {}, {}, {},
            post_params=post_params, files_params=files_params)

        if 'id' not in response:
            raise SphereEngineException('unexpected error', 400)

        return response
Exemplo n.º 9
0
    def update(self, _id, source_code=None, compiler_id=None, name=None, shared=None, compiler_version_id=None):
        """ Update judge

        :param _id: judge id
        :type _id: integer
        :param source_code: judge source code(default None)
        :type source_code: string
        :param compiler_id: compiler id (default None)
        :type compiler_id: integer
        :param name: judge name (default None)
        :type name: string
        :param shared: shared (default False)
        :type shared: bool
        :param compiler_version_id: id of the compiler version (default: default for api v4)
        :type compiler_version_id: integer
        :returns: void
        :rtype: json
        :raises SphereEngineException
        """

        resource_path = '/judges/{id}'
        method = 'PUT'

        if source_code != None and source_code == '':
            raise SphereEngineException('empty source', 400)

        host_params = {
            'id': _id
        }

        post_params = {}
        if source_code != None:
            post_params['source'] = source_code
        if compiler_id != None:
            post_params['compilerId'] = compiler_id
        if name != None:
            post_params['name'] = name
        if shared != None:
            post_params['shared'] = shared

        if compiler_version_id != None:
            post_params['compilerVersionId'] = compiler_version_id

        response = self.api_client.call_api(resource_path, method, host_params, {}, {}, post_params)

        if not isinstance(response, dict) or response:
            raise SphereEngineException('unexpected error', 400)

        return response
Exemplo n.º 10
0
    def create(self, name, masterjudge_id, body='', type_id=0, interactive=False, code=None):
        """ Create a new problem

        :param name: problem name
        :type name: string
        :param masterjudge_id: masterjudge id
        :type masterjudge_id: integer
        :param body: problem body
        :type body: string
        :param type_id: problem type id (0-binary, 1-minimize, 2-maximize) (default 0)
        :type type_id: string
        :param interactive: interactive problem flag (default False)
        :type interactive: bool
        :param code: problem code
        :type code: string
        :returns: code of created problem
        :rtype: json
        :raises SphereEngineException
        """

        resource_path = '/problems'
        method = 'POST'

        if code == '':
            raise SphereEngineException('empty code', 400)

        if name == '':
            raise SphereEngineException('empty name', 400)

        if type_id not in [0, 1, 2]:
            raise SphereEngineException('wrong type', 400)

        post_params = {
            'name': name,
            'body': body,
            'typeId': type_id,
            'interactive': interactive,
            'masterjudgeId': masterjudge_id
        }

        if code is not None:
            post_params['code'] = code

        response = self.api_client.call_api(resource_path, method, {}, {}, {}, post_params)

        if 'id' not in response:
            raise SphereEngineException('unexpected error', 400)

        return response
Exemplo n.º 11
0
    def getJudgeFile(self, _id, filename):
        """ Retrieve a judge file

        :param _id: judge id
        :type _id: integer
        :param filename: filename (source)
        :type filename: string
        :returns: file content
        :rtype: string
        :raises SphereEngineException
        """
        
        resource_path = '/judges/{id}/{filename}'
        method = 'GET'

        if filename not in ['source']:
            raise SphereEngineException('non existing file', 404)

        path_params = {
            'id': _id,
            'filename': filename
        }

        response = self.api_client.call_api(resource_path, method, path_params,
                                            response_type='file')

        return response
Exemplo n.º 12
0
    def all(self, limit=10, offset=0, type_id=0):
        """ 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
        :param type_id: type id of judge to be retrieved (0-test case, 1-master)
        :type type_id: integer
        :returns: list of judges
        :rtype: json
        :raises SphereEngineException
        """

        resource_path = '/judges'
        method = 'GET'

        query_params = {
            'limit': limit,
            'offset': offset,
            'typeId': type_id
        }

        response = self.api_client.call_api(resource_path, method, {}, query_params)

        if 'items' not in response:
            raise SphereEngineException('unexpected error', 400)

        return response
Exemplo n.º 13
0
    def get(self, _id, short_body=False):
        """ Retrieve an existing problem

        :param _id: problem id
        :type _id: integer
        :param short_body: determines whether shortened body should be returned (default False)
        :type short_body: bool
        :returns: problem details
        :rtype: json
        :raises SphereEngineException
        """

        resource_path = '/problems/{id}'
        method = 'GET'

        path_params = {
            'id': _id
        }
        query_params = {
            'shortBody': int(short_body)
        }

        response = self.api_client.call_api(resource_path, method, path_params, query_params)

        if 'id' not in response:
            raise SphereEngineException('unexpected error', 400)

        return response
Exemplo n.º 14
0
    def deleteTestcase(self, problem_id, number):
        """ Delete the problem testcase

        :param problem_id: problem id
        :type problem_id: integer
        :param number: testcase number
        :type number: integer
        :returns: void
        :rtype: json
        :raises SphereEngineException
        """

        resource_path = '/problems/{problemId}/testcases/{number}'
        method = 'DELETE'

        path_params = {
            'problemId': problem_id,
            'number': number
        }

        response = self.api_client.call_api(resource_path, method, path_params)

        if not isinstance(response, dict) or response:
            raise SphereEngineException('unexpected error', 400)

        return response
Exemplo n.º 15
0
    def getTestcase(self, problem_id, number):
        """ Retrieve problem testcase

        :param problem_id: problem id
        :type problem_id: integer
        :param number: testcase number
        :type number: integer
        :returns: testcase details
        :rtype: json
        :raises SphereEngineException
        """

        resource_path = '/problems/{problemId}/testcases/{number}'
        method = 'GET'

        path_params = {
            'problemId': problem_id,
            'number': number
        }

        response = self.api_client.call_api(resource_path, method, path_params)

        if 'number' not in response:
            raise SphereEngineException('unexpected error', 400)

        return response
Exemplo n.º 16
0
    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)
Exemplo n.º 17
0
    def update(self, _id):
        """ Update an existing submission

        :param _id: submission id
        :type _id: integer
        :returns: void
        :rtype: json
        :raises SphereEngineException
        """

        path_params = {
            'id': _id
        }

        resource_path = '/submissions/{id}'
        method = 'PUT'

        post_params = {}

        response = self.api_client.call_api(resource_path, method, path_params, {}, {}, post_params)

        if not isinstance(response, dict) or response:
            raise SphereEngineException('unexpected error', 400)

        return response
Exemplo n.º 18
0
    def getTestcaseFile(self, problem_id, number, filename):
        """ Retrieve a problem testcase file

        :param problem_id: problem code
        :type problem_id: integer
        :param number: testcase number
        :type number: integer
        :param filename: filename (input|output)
        :type filename: string
        :returns: file content
        :rtype: string
        :raises SphereEngineException
        """

        resource_path = '/problems/{problemId}/testcases/{number}/{filename}'
        method = 'GET'

        if filename not in ['input', 'output']:
            raise SphereEngineException('non existing file', 404)

        path_params = {
            'problemId': problem_id,
            'number': number,
            'filename': filename
        }

        response = self.api_client.call_api(resource_path, method, path_params,
                                            response_type='file')

        return response
Exemplo n.º 19
0
    def getSubmissionFile(self, _id, filename):
        """ Retrieve a submission file

        :param _id: submission id
        :type _id: integer
        :param filename: filename (source|output|error|cmpinfo|debug)
        :type filename: string
        :returns: file content
        :rtype: string
        :raises SphereEngineException
        """
        
        resource_path = '/submissions/{id}/{filename}'
        method = 'GET'

        if filename not in ['source', 'output', 'error', 'cmpinfo', 'debug']:
            raise SphereEngineException('non existing file', 404)

        path_params = {
            'id': _id,
            'filename': filename
        }

        response = self.api_client.call_api(resource_path, method, path_params,
                                            response_type='file')

        return response
Exemplo n.º 20
0
    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)) is False:
            raise ValueError(
                "getSubmissions method accepts only list or integer.")

        if isinstance(ids, (list)):
            ids = ','.join(
                [str(x) for x in set(ids) if isinstance(x, int) and x > 0])

        resource_path = '/submissions'
        method = 'GET'

        params = {'ids': ids}

        response = self.api_client.call_api(resource_path, method, {}, params)

        if 'items' not in response:
            raise SphereEngineException('invalid or empty response', 422)

        return response
Exemplo n.º 21
0
    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')
Exemplo n.º 22
0
    def deleteTestcase(self, problem_code, 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': problem_code, 'number': number}

        response = self.api_client.call_api(resource_path, method, path_params)

        if not isinstance(response, dict) or response:
            raise SphereEngineException('invalid or empty response', 422)

        return response
Exemplo n.º 23
0
    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}

        response = self.api_client.call_api(
            resource_path,
            method,
            host_params,
        )

        if 'id' not in response:
            raise SphereEngineException('invalid or empty response', 422)

        return response
Exemplo n.º 24
0
    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}

        response = self.api_client.call_api(
            resource_path,
            method,
            host_params,
        )

        if 'id' not in response:
            raise SphereEngineException('invalid or empty response', 422)

        return response
Exemplo n.º 25
0
    def all(self, limit=10, offset=0, short_body=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 short_body: determines whether shortened body should be returned (default False)
        :type short_body: 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(short_body)
        }

        response = self.api_client.call_api(resource_path, method, {},
                                            query_params)

        if 'paging' not in response:
            raise SphereEngineException('invalid or empty response', 422)

        return response
Exemplo n.º 26
0
    def get(self, code, short_body=False):
        """ Retrieve an existing problem

        :param code: problem code
        :type code: string
        :param short_body: determines whether shortened body should be returned (default False)
        :type short_body: 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(short_body)}

        response = self.api_client.call_api(resource_path, method, path_params,
                                            query_params)

        if 'code' not in response:
            raise SphereEngineException('invalid or empty response', 422)

        return response
Exemplo n.º 27
0
    def updateTestcase(self,
                       problem_code,
                       number,
                       _input=None,
                       output=None,
                       timelimit=None,
                       judge_id=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': problem_code, '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 judge_id != None:
            post_params['judgeId'] = judge_id
        if active != None:
            post_params['active'] = active

        response = self.api_client.call_api(resource_path, method, path_params,
                                            {}, {}, post_params)

        if not isinstance(response, dict) or response:
            raise SphereEngineException('invalid or empty response', 422)

        return response
Exemplo n.º 28
0
    def update(self, _id, source_code=None, compiler_id=None, name=None):
        """ Update judge

        :param _id: judge id
        :type _id: integer
        :param source_code: judge source code(default None)
        :type source_code: string
        :param compiler_id: compiler id (default None)
        :type compiler_id: 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 source_code != None and source_code == '':
            raise SphereEngineException('empty source', 400)

        host_params = {'id': _id}

        post_params = {}
        if source_code != None:
            post_params['source'] = source_code
        if compiler_id != None:
            post_params['compilerId'] = compiler_id
        if name != None:
            post_params['name'] = name

        response = self.api_client.call_api(resource_path, method, host_params,
                                            {}, {}, post_params)

        if not isinstance(response, dict) or response:
            raise SphereEngineException('invalid or empty response', 422)

        return response
Exemplo n.º 29
0
    def create(self, source_code, compiler_id=1, type_id=0, name='', shared=False, compiler_version_id=None):
        """ Create a new judge

        :param source_code: judge source code
        :type source_code: string
        :param compiler_id: compiler id (default 1, i.e. C++)
        :type compiler_id: integer
        :param type_id: judge type id (0-test case, 1-master)
        :type type_id: integer
        :param name: judge name (default '')
        :type name: string
        :param shared: shared (default False)
        :type shared: bool
        :param compiler_version_id: id of the compiler version (default: default for api v4)
        :type compiler_version_id: integer
        :returns: id of created judge
        :rtype: json
        :raises SphereEngineException
        """

        resource_path = '/judges'
        method = 'POST'

        if source_code == '':
            raise SphereEngineException("empty source", 400)

        post_params = {
            'source': source_code,
            'compilerId': compiler_id,
            'typeId': type_id,
            'name': name,
            'shared': shared
        }

        if compiler_version_id != None:
            post_params['compilerVersionId'] = compiler_version_id

        response = self.api_client.call_api(resource_path, method, {}, {}, {}, post_params)

        if 'id' not in response:
            raise SphereEngineException('unexpected error', 400)

        return response
Exemplo n.º 30
0
    def __create(self, problem_id, source, compiler_id=None, priority=None, files={}, tests=[], compiler_version_id=None):
        """ Create a new submission

        :param problem_id: problem id (or code)
        :type problem_id: integer
        :param source: submission source code
        :type source: string
        :param compiler_id: compiler id
        :type compiler_id: integer
        :param priority: priority of the submission (default normal priority, eg. 5 for range 1-9)
        :type priority: integer
        :param files: files (default {})
        :type tests: dict
        :param tests: tests to run (default [])
        :type tests: list
        :param compiler_version_id: id of the compiler version (default: default for api v4)
        :type compiler_version_id: integer
        :returns: id of created submission
        :rtype: json
        :raises SphereEngineException
        """

        resource_path = '/submissions'
        method = 'POST'

        post_params = {
            'problemId': problem_id,
            'compilerId': compiler_id,
            'source': source
        }
        files_params = {}

        if priority != None:
            post_params['priority'] = priority
            
        if len(files):
            for k, v in files.items():
                if not isinstance(v, six.string_types):
                    continue
                files_params['files['+k+']'] = v
            post_params['source'] = ''

        if len(tests):
            post_params['tests'] = ','.join(tests);

        if compiler_version_id != None:
            post_params['compilerVersionId'] = compiler_version_id

        response = self.api_client.call_api(resource_path, method, {}, {}, {}, post_params, files_params)

        if 'id' not in response:
            raise SphereEngineException('unexpected error', 400)

        return response