
    g                    p    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y)
z8The base class and interface for all formatting plugins.    )annotationsN)IO)_windows_color)
Statistics)	Violationc                  x    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y)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.
    c                   || _         |j                  | _        d| _        d| _        |j
                  dk(  xsA |j
                  dk(  xr0 t        j                  j                         xr t        j                  | _        | j                          y)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)optionsoutput_filefilename	output_fdnewlinecolorsysstdoutisattyr   terminal_supports_color
after_init)selfr   s     Y/var/www/html/brdwt/brdwt/brdwtenv/lib/python3.12/site-packages/flake8/formatting/base.py__init__zBaseFormatter.__init__$   sy     ++)-]]h. 
MMV# 7

!!#766 	

 	    c                     y)z!Initialize the formatter further.N r   s    r   r   zBaseFormatter.after_init9       r   c                     y)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                     y)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                   ryt        j                  j                  t        j                  j	                  | j                               }t        j
                  |d       t        | j                   d      | _        yy)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   sS    
 ==ggoobggoodmm&DEGKK$/!$--5DN r   c                l    | j                  |      }| j                  |      }| j                  ||       y)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   errorlinesources       r   handlezBaseFormatter.handleV   s0     {{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   r4   s     r   r1   zBaseFormatter.formate   s     "D
 	
r   c                    |j                         D ]c  }|j                  |      }t        |      }|j                  }|t	        d |D              z  }| j                  |dd| d|j                          e y)z Format and print the statistics.c              3  4   K   | ]  }|j                     y w)N)count).0stats     r   	<genexpr>z0BaseFormatter.show_statistics.<locals>.<genexpr>z   s     EEs   z<5 N)error_codesstatistics_fornextr<   sum_writemessage)r   
statistics
error_codestats_for_error_code	statisticr<   s         r   show_statisticszBaseFormatter.show_statisticst   s}    $002 	HJ#-#<#<Z#H 12IOOESE0DEEEEKK5*Aj\93D3D2EFG	Hr   c                    dj                   }dj                   }|D ];  \  }}t        |t              r |||      }n
 |||      }| j                  |       = y)z Format and print the benchmarks.z{value:<10.3} {statistic}z{value:<10} {statistic})rJ   valueN)r1   
isinstanceintrE   )r   
benchmarksfloat_format
int_formatrJ   rM   	benchmarks          r   show_benchmarkszBaseFormatter.show_benchmarks}   s\     399.55
 * 	#Iu%%&%H	(9EJ	KK	"	#r   c                    | j                   j                  r|j                  ydj                  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  D   K   | ]  }|j                         r|nd   yw)r@   N)isspace)r=   cs     r   r?   z,BaseFormatter.show_source.<locals>.<genexpr>   s%      
 A#%
s       ^)r   r2   physical_linejoincolumn_number)r   r4   indents      r   r2   zBaseFormatter.show_source   so     ||''5+>+>+F  
(()B5+>+>+BC
 
 %%&vha00r   c                V   | j                   (| j                   j                  || j                  z          | j                   | j                  j                  rSt
        j                  j                  j                  |j                         | j                  j                         z          yy)z9Handle logic of whether to use an output file or print().N)	r   r3   r   r   teer   r   bufferencode)r   outputs     r   rE   zBaseFormatter._write   sr    >>%NN  $,,!67>>!T\\%5%5JJ##FMMOdll6I6I6K$KL &6r   c                R    |r| j                  |       |r| j                  |       yy)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)rE   )r   r5   r6   s      r   r3   zBaseFormatter.write   s'     KKKK r   c                `    | j                   "| j                   j                          d| _         yy)z%Clean up after reporting is finished.N)r   closer   s    r   stopzBaseFormatter.stop   s(    >>%NN  "!DN &r   N)r   zargparse.NamespacereturnNone)ri   rj   )r   strri   rj   )r4   r   ri   rj   )r4   r   ri   
str | None)rG   r   ri   rj   )rP   zlist[tuple[str, float]]ri   rj   )rd   rk   ri   rj   )r5   rl   r6   rl   ri   rj   )__name__
__module____qualname____doc__r   r   r#   r%   r/   r7   r1   rK   rT   r2   rE   r3   rh   r   r   r   r	   r	      sJ    **06!
H#*16M $"r   r	   )rp   
__future__r   argparser)   r   typingr   flake8.formattingr   flake8.statisticsr   flake8.violationr   r	   r   r   r   <module>rw      s,    > "  	 
  , ( &|" |"r   