$94 GRAYBYTE WORDPRESS FILE MANAGER $95

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/cloudlinux/venv/lib/python3.11/site-packages/prospector/

HOME
Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/prospector//suppression.py
r"""
Each tool has its own method of ignoring errors and warnings.
For example, pylint requires a comment of the form

    # pylint disable=<error codes>

PEP8 will not warn on lines with

    # noqa

Additionally, flake8 follows that convention for pyflakes errors,
but pyflakes itself does not.

Finally, an entire file is ignored by flake8 if this line is found
in the file:

    # flake8\: noqa       (the \ is needed to stop prospector ignoring this file :))

This module's job is to attempt to collect all of these methods into
a single coherent list of error suppression locations.
"""
import re
import warnings
from collections import defaultdict
from pathlib import Path
from typing import List

from prospector import encoding
from prospector.exceptions import FatalProspectorException
from prospector.message import Message

_FLAKE8_IGNORE_FILE = re.compile(r"flake8[:=]\s*noqa", re.IGNORECASE)
_PEP8_IGNORE_LINE = re.compile(r"#\s+noqa", re.IGNORECASE)
_PYLINT_SUPPRESSED_MESSAGE = re.compile(r"^Suppressed \'([a-z0-9-]+)\' \(from line \d+\)$")


def get_noqa_suppressions(file_contents):
    """
    Finds all pep8/flake8 suppression messages

    :param file_contents:
        A list of file lines
    :return:
        A pair - the first is whether to ignore the whole file, the
        second is a set of (0-indexed) line numbers to ignore.
    """
    ignore_whole_file = False
    ignore_lines = set()
    for line_number, line in enumerate(file_contents):
        if _FLAKE8_IGNORE_FILE.search(line):
            ignore_whole_file = True
        if _PEP8_IGNORE_LINE.search(line):
            ignore_lines.add(line_number + 1)
    return ignore_whole_file, ignore_lines


_PYLINT_EQUIVALENTS = {
    # TODO: blending has this info already?
    "unused-import": (
        ("pyflakes", "FL0001"),
        ("frosted", "E101"),
    )
}


def _parse_pylint_informational(messages: List[Message]):
    ignore_files = set()
    ignore_messages: dict = defaultdict(lambda: defaultdict(list))

    for message in messages:
        if message.source == "pylint":
            if message.code == "suppressed-message":
                # this is a message indicating that a message was raised
                # by pylint but suppressed by configuration in the file
                match = _PYLINT_SUPPRESSED_MESSAGE.match(message.message)
                if not match:
                    raise FatalProspectorException(f"Could not parsed suppressed message from {message.message}")
                suppressed_code = match.group(1)
                line_dict = ignore_messages[message.location.path]
                line_dict[message.location.line].append(suppressed_code)
            elif message.code == "file-ignored":
                ignore_files.add(message.location.path)
    return ignore_files, ignore_messages


def get_suppressions(filepaths: List[Path], messages):
    """
    Given every message which was emitted by the tools, and the
    list of files to inspect, create a list of files to ignore,
    and a map of filepath -> line-number -> codes to ignore
    """
    paths_to_ignore = set()
    lines_to_ignore: dict = defaultdict(set)
    messages_to_ignore: dict = defaultdict(lambda: defaultdict(set))

    # first deal with 'noqa' style messages
    for filepath in filepaths:
        try:
            file_contents = encoding.read_py_file(filepath).split("\n")
        except encoding.CouldNotHandleEncoding as err:
            # TODO: this output will break output formats such as JSON
            warnings.warn(f"{err.path}: {err.__cause__}", ImportWarning)
            continue

        ignore_file, ignore_lines = get_noqa_suppressions(file_contents)
        if ignore_file:
            paths_to_ignore.add(filepath)
        lines_to_ignore[filepath] |= ignore_lines

    # now figure out which messages were suppressed by pylint
    pylint_ignore_files, pylint_ignore_messages = _parse_pylint_informational(messages)
    paths_to_ignore |= pylint_ignore_files
    for filepath, line in pylint_ignore_messages.items():
        for line_number, codes in line.items():
            for code in codes:
                messages_to_ignore[filepath][line_number].add(("pylint", code))
                if code in _PYLINT_EQUIVALENTS:
                    for equivalent in _PYLINT_EQUIVALENTS[code]:
                        messages_to_ignore[filepath][line_number].add(equivalent)

    return paths_to_ignore, lines_to_ignore, messages_to_ignore

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
17 Dec 2025 3.08 AM
root / root
0755
__pycache__
--
14 Aug 2025 9.24 PM
root / root
0755
config
--
14 Aug 2025 9.24 PM
root / root
0755
formatters
--
14 Aug 2025 9.24 PM
root / root
0755
profiles
--
14 Aug 2025 9.24 PM
root / root
0755
tools
--
14 Aug 2025 9.24 PM
root / root
0755
__init__.py
0 KB
17 Apr 2025 8.10 PM
root / root
0644
__main__.py
0.069 KB
17 Apr 2025 8.10 PM
root / root
0644
autodetect.py
2.886 KB
17 Apr 2025 8.10 PM
root / root
0644
blender.py
4.34 KB
17 Apr 2025 8.10 PM
root / root
0644
blender_combinations.yaml
6.397 KB
17 Apr 2025 8.10 PM
root / root
0644
compat.py
0.352 KB
17 Apr 2025 8.10 PM
root / root
0644
encoding.py
1.506 KB
17 Apr 2025 8.10 PM
root / root
0644
exceptions.py
1.261 KB
17 Apr 2025 8.10 PM
root / root
0644
finder.py
4.612 KB
17 Apr 2025 8.10 PM
root / root
0644
message.py
2.668 KB
17 Apr 2025 8.10 PM
root / root
0644
pathutils.py
1.275 KB
17 Apr 2025 8.10 PM
root / root
0644
postfilter.py
2.183 KB
17 Apr 2025 8.10 PM
root / root
0644
run.py
7.912 KB
17 Apr 2025 8.10 PM
root / root
0644
suppression.py
4.362 KB
17 Apr 2025 8.10 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF