o
    h                     @  sj   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	 d	ZdS )
z8The base class and interface for all formatting plugins.    )annotationsN)IO)_windows_color)
Statistics)	Violationc                   @  s   e Zd ZdZd-ddZd.dd	Zd/ddZd/ddZd.ddZd0ddZ	d1ddZ
d2ddZd3dd Zd1d!d"Zd4d$d%Zd5d(d)Zd.d*d+Zd,S )6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                 C  sL   || _ |j| _d| _d| _|jdkp|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    r   L/var/www/html/ai/venv/lib/python3.10/site-packages/flake8/formatting/base.py__init__$   s   


zBaseFormatter.__init__c                 C     dS )z!Initialize the formatter further.Nr   r   r   r   r   r   9       zBaseFormatter.after_initr   strc                 C  r   )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   r   r   r   	beginning<   r   zBaseFormatter.beginningc                 C  r   )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!   r   r   r   finishedD   r   zBaseFormatter.finishedc                 C  s@   | j rtjtj| j }tj|d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(   r   r   r   startL   s
   zBaseFormatter.starterrorr   c                 C  s$   |  |}| |}| || 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   r-   linesourcer   r   r   handleV   s   

zBaseFormatter.handle
str | Nonec                 C  s   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   r-   r   r   r   r.   e   s   zBaseFormatter.format
statisticsr   c                 C  s^   |  D ](}||}t|}|j}|tdd |D 7 }| |dd| d|j  qdS )z Format and print the statistics.c                 s  s    | ]}|j V  qd S )N)count).0statr   r   r   	<genexpr>z   s    z0BaseFormatter.show_statistics.<locals>.<genexpr>z<5 N)error_codesstatistics_fornextr7   sum_writemessage)r   r6   
error_codestats_for_error_code	statisticr7   r   r   r   show_statisticst   s   
 zBaseFormatter.show_statistics
benchmarkslist[tuple[str, float]]c                 C  sL   dj }dj }|D ]\}}t|tr|||d}n|||d}| | qdS )z Format and print the benchmarks.z{value:<10.3} {statistic}z{value:<10} {statistic})rD   valueN)r.   
isinstanceintr@   )r   rF   float_format
int_formatrD   rH   	benchmarkr   r   r   show_benchmarks}   s   
zBaseFormatter.show_benchmarksc                 C  sJ   | j jr	|jdu rdS ddd |jd|jd  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                 s  s     | ]}|  r
|nd V  qdS )r;   N)isspace)r8   cr   r   r   r:      s
    
z,BaseFormatter.show_source.<locals>.<genexpr>   ^)r   r/   physical_linejoincolumn_number)r   r-   indentr   r   r   r/      s   
zBaseFormatter.show_sourceoutputc                 C  sR   | j dur| j || j  | j du s| jjr'tjj| | j   dS dS )z9Handle logic of whether to use an output file or print().N)	r   r0   r   r   teer   r   bufferencode)r   rX   r   r   r   r@      s
   
 zBaseFormatter._writer1   r2   c                 C  s$   |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)r@   )r   r1   r2   r   r   r   r0      s
   
zBaseFormatter.writec                 C  s"   | j dur| j   d| _ dS dS )z%Clean up after reporting is finished.N)r   closer   r   r   r   stop   s   


zBaseFormatter.stopN)r   r	   r
   r   )r
   r   )r   r    r
   r   )r-   r   r
   r   )r-   r   r
   r4   )r6   r   r
   r   )rF   rG   r
   r   )rX   r    r
   r   )r1   r4   r2   r4   r
   r   )__name__
__module____qualname____doc__r   r   r"   r#   r,   r3   r.   rE   rN   r/   r@   r0   r]   r   r   r   r   r      s    









	


r   )ra   
__future__r   argparser&   r   typingr   flake8.formattingr   flake8.statisticsr   flake8.violationr   r   r   r   r   r   <module>   s    