@webapi_check_local_site
    @webapi_login_required
    @webapi_response_errors(DOES_NOT_EXIST, NOT_LOGGED_IN, PERMISSION_DENIED,
                            REPO_FILE_NOT_FOUND, INVALID_FORM_DATA,
                            INVALID_REPOSITORY, DIFF_EMPTY, DIFF_TOO_BIG,
                            DIFF_PARSE_ERROR)
    @webapi_request_fields(
        required={
            'repository': {
                'type': six.text_type,
                'description': 'The path or ID of the repository.',
            },
            'path': {
                'type': file,
                'description': 'The main diff file.',
            },
        },
        optional={
            'basedir': {
                'type': six.text_type,
                'description': 'The base directory that will prepended to '
                               'all paths in the diff. This is needed for '
                               'some types of repositories. The directory '
                               'must be between the root of the repository '
                               'and the top directory referenced in the '
                               'diff paths.',
            },
            'parent_diff_path': {
                'type': file,
                'description': 'The optional parent diff to upload.',
            },
            'base_commit_id': {
                'type': six.text_type,
                'description': 'The ID/revision this change is built upon. '
                               'If using a parent diff, then this is the base '
                               'for that diff. This may not be provided for '
                               'all diffs or repository types, depending on '
                               'how the diff was uploaded.',
            },
        }
    )
    def create(self, request, repository, basedir=None, local_site_name=None,
               base_commit_id=None, *args, **kwargs):
        """Validate a diff.

        This API has a similar signature to the ReviewRequest resource POST
        API, but instead of actually creating a review request, will return
        either OK or an error, depending on whether the included diff file
        parsed correctly.
        """
        local_site = self._get_local_site(local_site_name)

        path = request.FILES.get('path')
        parent_diff_path = request.FILES.get('parent_diff_path')

        try:
            query = Q(pk=int(repository), local_site=local_site)
        except ValueError:
            query = (Q(local_site=local_site)
                     & (Q(path=repository)
                        | Q(mirror_path=repository)
                        | Q(name=repository)))

        try:
            repository = Repository.objects.get(query)
        except Repository.DoesNotExist:
            return INVALID_REPOSITORY, {
                'repository': repository
            }
        except Repository.MultipleObjectsReturned:
            msg = ('Too many repositories matched "%s". '
                   'Try specifying the repository by name instead.'
                   % repository)

            return INVALID_REPOSITORY.with_message(msg), {
                'repository': repository,
            }

        if (not repository.get_scmtool().get_diffs_use_absolute_paths() and
            basedir is None):

            return INVALID_FORM_DATA, {
                'fields': {
                    'basedir': ['Given repository requires a base directory'],
                },
            }

        if basedir is None:
            # If we get here, the repository uses absolute paths. Deeper down
            # (where we don't necessarily know about the details of the
            # repository), we do an os.path.join() with the basedir value,
            # which will choke if it's None.
            basedir = ''

        try:
            DiffSet.objects.create_from_upload(
                repository, path, parent_diff_path, None, basedir, request,
                base_commit_id=base_commit_id,
                save=False)
        except FileNotFoundError as e:
            return REPO_FILE_NOT_FOUND, {
                'file': e.path,
                'revision': six.text_type(e.revision),
            }
        except EmptyDiffError:
            return DIFF_EMPTY
        except DiffTooBigError as e:
            return DIFF_TOO_BIG, {
                'reason': six.text_type(e),
                'max_size': e.max_diff_size,
            }
        except DiffParserError as e:
            return DIFF_PARSE_ERROR, {
                'reason': six.text_type(e),
                'linenum': e.linenum,
            }
        except ShortSHA1Error as e:
            return REPO_FILE_NOT_FOUND, {
                'reason': six.text_type(e),
                'file': e.path,
                'revision': six.text_type(e.revision),
            }
        except SCMError as e:
            return DIFF_PARSE_ERROR.with_message(six.text_type(e))
        except Exception as e:
            logging.exception('Unexpected error when validating diff.')

            return DIFF_PARSE_ERROR.with_message(
                e % 'Unexpected error when validating the diff: %s')

        return 200, {}
dataset/ETHPy150Open reviewboard/reviewboard/reviewboard/webapi/resources/validate_diff.py/ValidateDiffResource.create/swapped operands of `%`