
    g                        d Z ddlmZ ddlZddlZddlZddlZddlm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 dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ  ej.                  e      Z G d d      Zy)z3Module containing the application logic for Flake8.    )annotationsN)Sequence)checker)defaults)
exceptions)style_guide)BaseFormatter)debug)
parse_args)finder)reporterc                  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)Applicationz&Abstract our application into a class.c                    t        j                          | _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _	        d| _
        y)zInitialize our application.Nr   F)time
start_timeend_timeplugins	formatterguidefile_checker_manageroptionsresult_counttotal_result_countcatastrophic_failureselfs    Z/var/www/html/brdwt/brdwt/brdwtenv/lib/python3.12/site-packages/flake8/main/application.py__init__zApplication.__init__   sb     ))+&*.2/3 <@
 =A! 37  #$ %*!    c                    | j                   ry| j                  J | j                  j                  ryt        | j                  dkD        S )zReturn the program exit code.   r   )r   r   	exit_zerointr   r   s    r   	exit_codezApplication.exit_code:   sD    $$||'''<<!!t((1,--r    c                    | j                   J | j                  J t        j                  | j                   j                  | j                        | _        y)z3Initialize a formatter based on the parsed options.N)r   r   r   make	reportersr   r   s    r   make_formatterzApplication.make_formatterD   sB    ||'''||'''!t||'='=t||Lr    c                    | j                   J | j                  J t        j                  | j                  | j                         | _        y)zInitialize our StyleGuide.N)r   r   r   StyleGuideManagerr   r   s    r   
make_guidezApplication.make_guideJ   sA    ~~)))||''' 22LL$..

r    c                    | j                   J | j                  J t        j                  | j                   | j                  j                  |      | _        y)z#Initialize our FileChecker Manager.N)r   r   argv)r   r   r   Managercheckersr   r   r.   s     r   make_file_checker_managerz%Application.make_file_checker_managerR   sJ    zz%%%||'''$+OO

LL))%
!r    c                   | j                   J | j                   j                          	 | j                   j                          t        j                  d       | j                   j                          t        j                         | _        y# t        j                  $ r0}t        t        |             t        d       d| _        Y d}~d}~ww xY w)zRun the actual checks with the FileChecker Manager.

        This method encapsulates the logic to make a
        :class:`~flake8.checker.Manger` instance run the checks it is
        managing.
        Nz5Run flake8 with greater verbosity to see more detailsTzFinished running)r   startrunr   PluginExecutionFailedprintstrr   LOGinfostopr   r   )r   plugin_faileds     r   
run_checkszApplication.run_checks\   s     ((444!!'')	-%%))+
 	#$!!&&(		 // 	-#m$%IJ(,D%%	-s   B C &CCc                   | j                   J | j                   j                  sy| j                  J | j                  J | j                  | j                  z
  }d|fg}|j
                  }t        j                  dz   D ]F  }| j                  j                  |   }d| d} |||f       | d} ||t        ||z        f       H | j                  J | j                  j                  |       y)z9Aggregate, calculate, and report benchmarks for this run.Nzseconds elapsed)filesztotal z
 processedz processed per second)r   	benchmarkr   r   r   appendr   STATISTIC_NAMES
statisticsr$   r   show_benchmarks)r   time_elapsedrC   add_statistic	statisticvaluetotal_descriptionper_second_descriptions           r   report_benchmarkszApplication.report_benchmarksp   s   ||'''||%%((444}}(((}}t6(,78
"))!11J> 	OI--88CE"(: >,e45(1{2G%H"13u|7K3LMN	O ~~)))&&z2r    c                    t         j                  d       | j                  J | j                  j                         }|\  | _        | _        t         j                  d| j                  | j
                         y)zReport all the errors found by flake8 3.0.

        This also updates the :attr:`result_count` attribute with the total
        number of errors, warnings, and other messages found.
        zReporting errorsNz.Found a total of %d violations and reported %d)r9   r:   r   reportr   r   )r   resultss     r   report_errorszApplication.report_errors   sh     	#$((444++2245<2!2<##	
r    c                    | j                   J | j                   j                  sy| j                  J | j                  J | j                  j	                  | j                  j
                         y)z.Aggregate and report statistics from this run.N)r   rC   r   r   show_statisticsstatsr   s    r   report_statisticszApplication.report_statistics   s^    ||'''||&&~~)))zz%%%&&tzz'7'78r    c                v   t        |      \  | _        | _        | j                  j                  rZt	        j
                  t        j                  | j                        }t        t        j                  |dd             t        d      | j                          | j                          | j                  |       y)zInitialize the application to be run.

        This finds the plugins, registers their options, and parses the
        command-line arguments.
           T)indent	sort_keysr   N)r   r   r   
bug_reportr
   informationflake8__version__r7   jsondumps
SystemExitr)   r,   r2   )r   r.   r:   s      r   
initializezApplication.initialize   s     &0%5"dl<<""$$V%7%7FD$**T!t<=Q-&&t,r    c                    | j                   J | j                   j                          | j                          | j                          | j	                          | j                   j                          y)z*Report errors, statistics, and benchmarks.N)r   r4   rO   rS   rK   r;   r   s    r   rM   zApplication.report   sV    ~~)))  r    c                f    | j                  |       | j                          | j                          y )N)r_   r=   rM   r1   s     r   _runzApplication._run   s!    r    c                &   	 | j                  |       | j                  J | j                  j                  rt        | j                         yy# t
        $ rF}t        d       t        j                  d       t        j                  |       d| _	        Y d}~yd}~wt        j                  $ r<}t        d       t        |       t        j                  |       d| _	        Y d}~yd}~wt        j                  $ r d| _	        t        d       Y yw xY w)zRun our application.

        This method will also handle KeyboardInterrupt exceptions for the
        entirety of the flake8 application. If it sees a KeyboardInterrupt it
        will forcibly clean up the :class:`~flake8.checker.Manager`.
        Nz... stoppedz#Caught keyboard interrupt from userTz6There was a critical error during execution of Flake8:z"... stopped while processing files)rb   r   countr7   r   KeyboardInterruptr9   critical	exceptionr   r   ExecutionError	EarlyQuit)r   r.   excs      r   r5   zApplication.run   s    	)IIdO <<+++||!!d''( " ! 	-- LL>?MM#(,D%%(( 	-JK#JMM#(,D%%## 	8(,D%67	8s)   A 	D<BD.2C%%(DDN)returnNone)rk   r$   )r.   zSequence[str]rk   rl   )__name__
__module____qualname____doc__r   r%   r)   r,   r2   r=   rK   rO   rS   r_   rM   rb   r5    r    r   r   r      sG    0*<.M

$(3*
 9-"
)r    r   )rp   
__future__r   argparser\   loggingr   typingr   rZ   r   r   r   r   flake8.formatting.baser	   flake8.mainr
   flake8.options.parse_argsr   flake8.pluginsr   r   	getLoggerrm   r9   r   rq   r    r   <module>r{      sX    9 "           0  0 ! # g!~) ~)r    