
    yIf                    x    d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ ddlmZ  G d d	          ZdS )
z8The base class and interface for all formatting plugins.    )annotationsN)IO)_windows_color)
Statistics)	Violationc                  z    e Zd ZdZd dZd!dZd"d
Zd"dZd!dZd#dZ	d$dZ
d%dZd&dZd$dZd'dZd(dZd!dZdS ))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argparse.NamespacereturnNonec                    || _         |j        | _        d| _        d| _        |j        dk    p4|j        dk    o)t          j                                        ot          j
        | _        |                                  dS )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     J/var/www/piapp/venv/lib/python3.11/site-packages/flake8/formatting/base.py__init__zBaseFormatter.__init__$   s|     +)-]h. 
MV# 7
!!##76 	

 	    c                    dS )z!Initialize the formatter further.N r   s    r   r   zBaseFormatter.after_init9         r   r   strc                    dS )zNotify 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   	beginningzBaseFormatter.beginning<   r#   r   c                    dS )zNotify 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   finishedzBaseFormatter.finishedD   r#   r   c                    | j         rst          j                            t          j                            | j                             }t          j        |d           t          | j         d          | _        dS dS )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   startzBaseFormatter.startL   sg    
 = 	6goobgoodm&D&DEEGK$////!$-55DNNN	6 	6r   errorr   c                    |                      |          }|                     |          }|                     ||           dS )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   r4   linesources       r   handlezBaseFormatter.handleV   sB     {{5!!!!%((

4     r   
str | Nonec                     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   r4   s     r   r6   zBaseFormatter.formate   s     "D
 
 	
r   
statisticsr   c                   |                                 D ]l}|                    |          }t          |          }|j        }|t	          d |D                       z  }|                     |dd| d|j                    mdS )z Format and print the statistics.c              3  $   K   | ]}|j         V  d S )N)count).0stats     r   	<genexpr>z0BaseFormatter.show_statistics.<locals>.<genexpr>z   s$      EEEEEEEEr   z<5 N)error_codesstatistics_fornextrB   sum_writemessage)r   r?   
error_codestats_for_error_code	statisticrB   s         r   show_statisticszBaseFormatter.show_statisticst   s    $0022 	H 	HJ#-#<#<Z#H#H 122IOESEE0DEEEEEEEKK5FFFjFF93DFFGGGG	H 	Hr   
benchmarkslist[tuple[str, float]]c                    dj         }dj         }|D ]J\  }}t          |t                    r |||          }n |||          }|                     |           KdS )z Format and print the benchmarks.z{value:<10.3} {statistic}z{value:<10} {statistic})rO   valueN)r6   
isinstanceintrK   )r   rQ   float_format
int_formatrO   rT   	benchmarks          r   show_benchmarkszBaseFormatter.show_benchmarks}   s     39.5
 * 	# 	#Iu%%% K&J%HHH		(L9EJJJ	KK	""""	# 	#r   c                    | j         j        r|j        dS d                    d |j        d|j        dz
           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|nd V  dS )rF   N)isspace)rC   cs     r   rE   z,BaseFormatter.show_source.<locals>.<genexpr>   sG       
 
 %AA#
 
 
 
 
 
r      ^)r
   r7   physical_linejoincolumn_number)r   r4   indents      r   r7   zBaseFormatter.show_source   s~     |' 	5+>+F2  
 
()B5+>+B)BC
 
 
 
 
 %0v0000r   outputc                "   | j         "| j                             || j        z              | j         | j        j        rRt
          j        j                            |                                | j                                        z              dS dS )z9Handle logic of whether to use an output file or print().N)	r   r8   r   r
   teer   r   bufferencode)r   rf   s     r   rK   zBaseFormatter._write   s{    >%N  $,!6777>!T\%5!J##FMMOOdl6I6I6K6K$KLLLLL "!r   r9   r:   c                f    |r|                      |           |r|                      |           dS dS )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)rK   )r   r9   r:   s      r   r8   zBaseFormatter.write   sH      	KK 	 KK	  	 r   c                X    | j         "| j                                          d| _         dS dS )z%Clean up after reporting is finished.N)r   closer"   s    r   stopzBaseFormatter.stop   s1    >%N  """!DNNN &%r   N)r
   r   r   r   )r   r   )r   r$   r   r   )r4   r   r   r   )r4   r   r   r<   )r?   r   r   r   )rQ   rR   r   r   )rf   r$   r   r   )r9   r<   r:   r<   r   r   )__name__
__module____qualname____doc__r   r   r'   r)   r3   r;   r6   rP   rZ   r7   rK   r8   rn   r!   r   r   r	   r	      s*        *   *0 0 0 0      6 6 6 6! ! ! !
 
 
 
H H H H# # # #*1 1 1 16M M M M       $" " " " " "r   r	   )rr   
__future__r   argparser-   r   typingr   flake8.formattingr   flake8.statisticsr   flake8.violationr   r	   r!   r   r   <module>ry      s    > > " " " " " "  				 



       , , , , , , ( ( ( ( ( ( & & & & & &|" |" |" |" |" |" |" |" |" |"r   