Ejemplo n.º 1
0
    def __init__(self, parser=None):
        """Initialize the parsed file information.

        Args:
            parser (reviewboard.diffviewer.parser.DiffParser, optional):
                The diff parser that parsed this file.
        """
        if parser is None:
            RemovedInReviewBoard50Warning.warn(
                'Diff parsers must pass themselves as a parameter when'
                'creating a ParsedDiffFile. This will be mandatory in '
                'Review Board 5.0.')

        self.parser = parser
        self.binary = False
        self.deleted = False
        self.moved = False
        self.copied = False
        self.is_symlink = False
        self.insert_count = 0
        self.delete_count = 0
        self.skip = False

        self._data_io = io.BytesIO()
        self._data = None

        self._deprecated_info = {}
Ejemplo n.º 2
0
    def api_post(self, *args, **kwargs):
        """Perform an HTTP POST request to the GitHub API.

        Args:
            *args (tuple):
                Positional arguments to pass down to :py:meth:`http_post`.

            **kwargs (dict):
                Keyword arguments to pass to :py:meth:`get_http_credentials`
                and :py:meth:`http_post`.

        Returns:
            object:
            The deserialized JSON data from the response.

        Raises:
            reviewboard.hostingsvcs.errors.AuthorizationError:
                The repository credentials are invalid.

            reviewboard.hostingsvcs.errors.HostingServiceError:
                There was an error with the request. Details are in the
                response.
        """
        RemovedInReviewBoard50Warning.warn(
            'GitHub.api_post is deprecated and will be removed in '
            'Review Board 5.0. Please use http_post instead.')

        return self.http_post(*args, **kwargs).json
Ejemplo n.º 3
0
    def api_get(self, url, return_headers=False, *args, **kwargs):
        """Perform an HTTP GET request to the GitHub API.

        Deprecated:
            4.0:
            Callers should use :py:meth:`http_delete` instead.

        Args:
            url (unicode):
                The absolute URL for the request.

            return_headers (bool, optional):
                Whether to return HTTP headers in the result.

            *args (tuple):
                Positional arguments to pass down to :py:meth:`http_get`.

            **kwargs (dict):
                Keyword arguments to pass to :py:meth:`get_http_credentials`
                and :py:meth:`http_get`.

        Returns:
            object or tuple:
            If ``return_headers`` is ``False``, this will be the deserialized
            JSON data from the response.

            If ``return_headers`` is ``True``, this will be a tuple containing:

            1. The deserialized JSON data from the response.
            2. A dictionary of returned HTTP headers.

        Raises:
            reviewboard.hostingsvcs.errors.AuthorizationError:
                The repository credentials are invalid.

            reviewboard.hostingsvcs.errors.HostingServiceError:
                There was an error with the request. Details are in the
                response.
        """
        RemovedInReviewBoard50Warning.warn(
            'GitHub.api_get is deprecated and will be removed in '
            'Review Board 5.0. Please use http_get instead.')

        rsp = self.http_get(url, *args, **kwargs)

        if return_headers:
            return rsp.json, rsp.headers
        else:
            return rsp.json
Ejemplo n.º 4
0
    def _warn_old_usage_deprecation(self):
        """Warn that a DiffParser is populating information in an old way."""
        if self.parser is None:
            message = (
                'Diff parsers must be updated to populate attributes on a '
                'ParsedDiffFile, instead of setting the information in a '
                'dictionary. This will be required in Review Board 5.0.')
        else:
            message = (
                '%r must be updated to populate attributes on a '
                'ParsedDiffFile, instead of setting the information in a '
                'dictionary. This will be required in Review Board 5.0.' %
                type(self.parser))

        RemovedInReviewBoard50Warning.warn(message, stacklevel=3)
Ejemplo n.º 5
0
def get_can_enable_dns():
    """Return whether DNS querying support can be enabled.

    Deprecated:
        4.0:
        This is now always true, as ``dnspython`` is a required dependency.

    Returns:
        tuple:
        ``(True, None)``, always.
    """
    RemovedInReviewBoard50Warning.warn(
        'As of Review Board 4.0, get_can_enable_dns() always returns a true '
        'result. It will be removed in Review Board 5.0.')

    return True, None
Ejemplo n.º 6
0
    def clean(self):
        """Clean the form and the sub-form for the selected search backend.

        Returns:
            dict:
            The cleaned data.
        """
        cleaned_data = self.cleaned_data

        if cleaned_data['search_enable']:
            search_backend_id = cleaned_data.get('search_backend_id')

            # The search_backend_id field is only available if the backend
            # passed validation.
            if search_backend_id:
                backend_form = self.search_backend_forms[search_backend_id]

                # Validate the configuration form.
                if backend_form.is_valid():
                    # Validate the search backend, ensuring the configuration
                    # is correct.
                    search_backend = \
                        search_backend_registry.get_search_backend(
                            search_backend_id)
                    configuration = \
                        search_backend.get_configuration_from_form_data(
                            backend_form.cleaned_data)

                    try:
                        if func_accepts_kwargs(search_backend.validate):
                            search_backend.validate(
                                configuration=configuration)
                        else:
                            RemovedInReviewBoard50Warning.warn(
                                '%s.validate() must accept keyword '
                                'arguments. This will be required in '
                                'Review Board 5.0.'
                                % search_backend.__class__.__name__)
                            search_backend.validate()
                    except ValidationError as e:
                        self.add_error('search_backend_id', e.error_list)
                else:
                    # The configuration form had issues.
                    self._errors.update(backend_form.errors)

        return cleaned_data
Ejemplo n.º 7
0
    def __new__(cls, *args, **kwargs):
        """Construct a new instance of the SCMTool.

        This will perform some checks for deprecated function signatures on
        the class, fix them up and emit deprecation warnings if found, and
        then construct and initialize the instance.

        Args:
            *args (tuple):
                Positional arguments passed in during construction.

            **kwargs (dict):
                Keyword arguments passed in during construction.

        Returns:
            SCMTool:
            The new instance.
        """
        # Check for some deprecated method signatures.
        if not hasattr(cls, '__deprecations_checked'):
            for method in (cls.normalize_path_for_display,):
                argspec = inspect.getargspec(method)

                if argspec.keywords is None:
                    method_name = method.__name__

                    RemovedInReviewBoard50Warning.warn(
                        '%s.%s must accept keyword arguments. This '
                        'will be required in Review Board 5.0.'
                        % (cls.__name__, method_name))

                    @functools.wraps(method)
                    def _wrapper(_self, *_args, **_kwargs):
                        return method(_self, *_args)

                    setattr(cls, method_name, _wrapper)

            cls.__deprecations_checked = True

        # Note that we *don't* want to pass in any *args or **kwargs here.
        # Python will take care of passing them to __init__.
        return super(SCMTool, cls).__new__(cls)
Ejemplo n.º 8
0
def get_integration_manager():
    """Return the integrations manager.

    Deprecated:
        4.0:
        This has been deprecated in favor of
        :py:func:`reviewboard.integrations.base.get_integration_manager`.

    Returns:
        djblets.integrations.manager.IntegrationManager:
        The Review Board integrations manager.
    """
    from reviewboard.integrations.base import (get_integration_manager as
                                               _get_integration_manager)

    RemovedInReviewBoard50Warning.warn(
        'reviewboard.integrations.get_integration_manager() is deprecated. '
        'Use reviewboard.integrations.base.get_integration_manager() instead.')

    return _get_integration_manager()
Ejemplo n.º 9
0
    def __new__(cls, name, bases, d):
        """Create the subclass of an integration.

        Args:
            name (str):
                The name of the integration subclass.

            bases (tuple):
                The parent classes.

            d (dict):
                The class dictionary.

        Returns:
            type:
            The new class.
        """
        if bases != (object,):
            # This is a subclass of Integration.
            from reviewboard.integrations.base import (Integration as
                                                       BaseIntegration)

            RemovedInReviewBoard50Warning.warn(
                'reviewboard.integrations.Integration is deprecated. %s '
                'should inherit from reviewboard.integrations.base.'
                'Integration instead.'
                % name)

            new_bases = []

            for base in bases:
                if base is Integration:
                    new_bases.append(BaseIntegration)
                else:
                    new_bases.append(base)

            bases = tuple(new_bases)

        return type.__new__(cls, name, bases, d)