Hacked By AnonymousFox
�
�܋f� � � � d Z ddlZddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddl m
Z
ddlmZ dd l
mZ G d
� d� � ZdS )z8The base class and interface for all formatting plugins.� N)�IO)�List)�Optional)�Tuple)�_windows_color)�
Statistics)� Violationc � � e Zd ZdZdej ddfd�Zdd�Zdeddfd�Z deddfd �Z
dd
�Zdd
�Zddde
e fd�Zdd�Zdeeeef ddfd�Zddde
e fd�Zdeddfd�Zde
e de
e ddfd�Zdd�ZdS )�
BaseFormattera" Class defining the formatter interface.
.. attribute:: options
The options parsed from both configuration files and the command-line.
.. attribute:: filename
If specified by the user, the path to store the results of the run.
.. attribute:: output_fd
Initialized when the :meth:`start` is called. This will be a file
object opened for writing.
.. attribute:: newline
The string to add to the end of a line. This is only used when the
output filename has been specified.
�options�returnNc � � || _ |j | _ d| _ d| _ |j dk p4|j dk o)t j � � � ot j
| _ | � � � dS )aM Initialize with the options parsed from config and cli.
This also calls a hook, :meth:`after_init`, so subclasses do not need
to call super to call this method.
:param options:
User specified configuration parsed from both configuration files
and the command-line interface.
N�
�always�auto)r �output_file�filename� output_fd�newline�color�sys�stdout�isattyr �terminal_supports_color�
after_init)�selfr s �g/builddir/build/BUILD/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/flake8/formatting/base.py�__init__zBaseFormatter.__init__% s| � � ����+��
�,0�������]�h�.�
��M�V�#�
7��
�!�!�#�#�
7��6�
�
�
�������� c � � dS )z!Initialize the formatter further.N� �r s r r zBaseFormatter.after_init: � � � � r r c � � dS )z�Notify the formatter that we're starting to process a file.
:param filename:
The name of the file that Flake8 is beginning to report results
from.
Nr! �r r s r � beginningzBaseFormatter.beginning= r# r c � � dS )z�Notify the formatter that we've finished processing a file.
:param filename:
The name of the file that Flake8 has finished reporting results
from.
Nr! r% s r �finishedzBaseFormatter.finishedE r# r c � � | j rst j � t j � | j � � � � }t j |d�� � t
| j d� � | _ dS dS )z}Prepare the formatter to receive input.
This defaults to initializing :attr:`output_fd` if :attr:`filename`
T)�exist_ok�aN)r �os�path�dirname�abspath�makedirs�openr )r r. s r �startzBaseFormatter.startM sg � �
�=� 6��g�o�o�b�g�o�o�d�m�&D�&D�E�E�G��K��$�/�/�/�/�!�$�-��5�5�D�N�N�N� 6� 6r �errorr c � � | � |� � }| � |� � }| � ||� � dS )aD Handle an error reported by Flake8.
This defaults to calling :meth:`format`, :meth:`show_source`, and
then :meth:`write`. To extend how errors are handled, override this
method.
:param error:
This will be an instance of
:class:`~flake8.violation.Violation`.
N)�format�show_source�write)r r3 �line�sources r �handlezBaseFormatter.handleW sB � � �{�{�5�!�!���!�!�%�(�(���
�
�4�� � � � � r c � � t d� � �)a Format an error reported by Flake8.
This method **must** be implemented by subclasses.
:param error:
This will be an instance of
:class:`~flake8.violation.Violation`.
:returns:
The formatted error string.
z3Subclass of BaseFormatter did not implement format.)�NotImplementedError)r r3 s r r5 zBaseFormatter.formatf s � � "�D�
�
�
r �
statisticsr c � � |� � � D ]l}|� |� � }t |� � }|j }|t d� |D � � � � z
}| � |d�d|� d|j � �� � �mdS )z Format and print the statistics.c 3 �$ K � | ]}|j V � �d S )N)�count)�.0�stats r � <genexpr>z0BaseFormatter.show_statistics.<locals>.<genexpr>{ s$ � � � �E�E����E�E�E�E�E�Er z<5� N)�error_codes�statistics_for�nextr@ �sum�_write�message)r r= �
error_code�stats_for_error_code� statisticr@ s r �show_statisticszBaseFormatter.show_statisticsu s� � �$�0�0�2�2� H� H�J�#-�#<�#<�Z�#H�#H� ��1�2�2�I��O�E��S�E�E�0D�E�E�E�E�E�E�E��K�K�5�F�F�F�j�F�F�9�3D�F�F�G�G�G�G� H� Hr �
benchmarksc � � dj }dj }|D ]J\ }}t |t � � r |||�� � }n
|||�� � }| � |� � �KdS )z Format and print the benchmarks.z{value:<10.3} {statistic}z{value:<10} {statistic})rM �valueN)r5 �
isinstance�intrI )r rO �float_format�
int_formatrM rQ � benchmarks r �show_benchmarkszBaseFormatter.show_benchmarks~ s� � � 3�9��.�5�
� *� #� #��I�u��%��%�%�
K�&�J��%�H�H�H� � �(�L�9�E�J�J�J� ��K�K� �"�"�"�"� #� #r c � � | j j r|j �dS d� d� |j d|j dz
� D � � � � }|j � |� d�S )a� Show the physical line generating the error.
This also adds an indicator for the particular part of the line that
is reported as generating the problem.
:param error:
This will be an instance of
:class:`~flake8.violation.Violation`.
:returns:
The formatted error string if the user wants to show the source.
If the user does not want to show the source, this will return
``None``.
N� c 3 �F K � | ]}|� � � r|nd V � �dS )rD N)�isspace)rA �cs r rC z,BaseFormatter.show_source.<locals>.<genexpr>� sG � � � �
�
�� �����%�A�A�#�
�
�
�
�
�
r � �^)r r6 �
physical_line�join�
column_number)r r3 �indents r r6 zBaseFormatter.show_source� s~ � � �|�'� �5�+>�+F��2� ���
�
��(�)B�5�+>��+B�)B�C�
�
�
�
�
�� �%�0�v�0�0�0�0r �outputc �" � | j �"| j � || j z � � | j �| j j rRt
j j � |� � � | j � � � z � � dS dS )z9Handle logic of whether to use an output file or print().N) r r7 r r �teer r �buffer�encode)r rc s r rI zBaseFormatter._write� s{ � ��>�%��N� � ��$�,�!6�7�7�7��>�!�T�\�%5�!��J��#�#�F�M�M�O�O�d�l�6I�6I�6K�6K�$K�L�L�L�L�L� "�!r r8 r9 c �f � |r| � |� � |r| � |� � dS dS )a� Write the line either to the output file or stdout.
This handles deciding whether to write to a file or print to standard
out for subclasses. Override this if you want behaviour that differs
from the default.
:param line:
The formatted string to print or write.
:param source:
The source code that has been formatted and associated with the
line of output.
N)rI )r r8 r9 s r r7 zBaseFormatter.write� sH � � � ��K�K������ ��K�K������� � r c �X � | j �"| j � � � d| _ dS dS )z%Clean up after reporting is finished.N)r �closer"