
    g`8                       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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Z ej,                  e      Z G d dej2                        Z G d dej2                        Z G d dej2                        Z	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 ddZ G d d      Z G d d      Z  G d d      Z!y)z0Implementation of the StyleGuide used by Flake8.    )annotationsN)	Generator)Sequence)defaults)
statistics)utils)base)	Violation)
StyleGuidec                      e Zd ZdZdZdZy)Selectedz<Enum representing an explicitly or implicitly selected code.zexplicitly selectedzimplicitly selectedN__name__
__module____qualname____doc__
Explicitly
Implicitly     U/var/www/html/brdwt/brdwt/brdwtenv/lib/python3.12/site-packages/flake8/style_guide.pyr   r      s    F&J&Jr   r   c                      e Zd ZdZdZdZy)Ignoredz;Enum representing an explicitly or implicitly ignored code.zexplicitly ignoredzimplicitly ignoredNr   r   r   r   r   r      s    E%J%Jr   r   c                      e Zd ZdZdZdZy)Decisionz?Enum representing whether a code should be ignored or selected.zignored errorzselected errorN)r   r   r   r   r   r   r   r   r   r   r   &   s    IGHr   r   c                J    g | xs g |xs g }t        t        |d            S NT)reversetuplesorted)optionextendrets      r   _explicitly_chosenr%   -   s-    
 -V\r
,fl
,CT*++r   c                `    | g | |xs g }ng |||xs g }t        t        |d            S r   r   )r"   defaultextended_defaultr#   r$   s        r   _select_ignorer)   6   sH     ((&,B(<<*<fl<T*++r   c                  8    e Zd ZdZddZd	dZd	dZd
dZd
dZy)DecisionEnginezA class for managing the decision process around violations.

    This contains the logic for whether a violation should be reported or
    ignored.
    c                   i | _         t        |j                  |j                        | _        t        |j
                  |j                        | _        t        |j                  d|j                  |j                        | _
        t        |j
                  t        j                  |j                  |j                        | _        y)zInitialize the engine.)r"   r#   r   )r"   r'   r(   r#   N)cacher%   selectextend_selectselected_explicitlyignoreextend_ignoreignored_explicitlyr)   extended_default_selectselectedr   IGNOREextended_default_ignoreignored)selfoptionss     r   __init__zDecisionEngine.__init__L   s    *,
#5>>(($
  #5>>((#

 '>>$<<((	
 &>>OO$<<((	
r   c                    |j                  | j                        rt        j                  S |j                  | j                        rt        j
                  S t        j
                  S )a  Determine if the code has been selected by the user.

        :param code: The code for the check that has been run.
        :returns:
            Selected.Implicitly if the selected list is empty,
            Selected.Explicitly if the selected list is not empty and a match
            was found,
            Ignored.Implicitly if the selected list is not empty but no match
            was found.
        )
startswithr0   r   r   r5   r   r   r9   codes     r   was_selectedzDecisionEngine.was_selectedf   sJ     ??4334&&&__T]]+&&&%%%r   c                    |j                  | j                        rt        j                  S |j                  | j                        rt        j
                  S t        j
                  S )a  Determine if the code has been ignored by the user.

        :param code:
            The code for the check that has been run.
        :returns:
            Selected.Implicitly if the ignored list is empty,
            Ignored.Explicitly if the ignored list is not empty and a match was
            found,
            Selected.Implicitly if the ignored list is not empty but no match
            was found.
        )r=   r3   r   r   r8   r   r   r>   s     r   was_ignoredzDecisionEngine.was_ignoredx   sJ     ??4223%%%__T\\*%%%&&&r   c                   | j                        }| j                        }t        j                  d||       t	        |t
              r t	        |t
              rt        j
                  S t	        |t              r t	        |t              rt        j                  S |t
        j                  u r"|t        j                  urt        j
                  S |t
        j                  ur"|t        j                  u rt        j                  S |t        j                  u r"|t
        j                  u rt        j                  S |t
        j                  u r|t        j                  u s$|t
        j                  u r|t        j                  u rst        fd| j                  D              }t        fd| j                  D              }t        |      t        |      kD  rt        j
                  S t        j                  S t        d d| d|       )z-Decide if code should be ignored or selected.z#The user configured %r to be %r, %rc              3  F   K   | ]  }j                  |      s|  y wNr=   .0sr?   s     r   	<genexpr>z/DecisionEngine.make_decision.<locals>.<genexpr>   s     Idooa6H!I   !!c              3  F   K   | ]  }j                  |      s|  y wrE   rF   rG   s     r   rJ   z/DecisionEngine.make_decision.<locals>.<genexpr>   s     HT__Q5G!HrK   zunreachable  )r@   rB   LOGdebug
isinstancer   r   r   r   r   nextr5   r8   lenAssertionError)r9   r?   r5   r8   r.   r1   s    `    r   make_decisionzDecisionEngine.make_decision   s   $$T*""4(		1		
 h)j(.K$$$'*z'7/K###+++w111$$$H///7---###+++8;N;N0N###+++7;M;M0M+++7;M;M0M IT]]IIFHT\\HHF6{S[((((''' <vQxj'!KLLr   c                    | j                   j                  |      }|7| j                  |      }|| j                   |<   t        j	                  d||       |S )a  Return the decision for a specific code.

        This method caches the decisions for codes to avoid retracing the same
        logic over and over again. We only care about the select and ignore
        rules as specified by the user in their configuration files and
        command-line flags.

        This method does not look at whether the specific line is being
        ignored in the file itself.

        :param code: The code for the check that has been run.
        z"%s" will be "%s")r-   getrT   rN   rO   )r9   r?   decisions      r   decision_forzDecisionEngine.decision_for   sP     ::>>$'))$/H'DJJtII)4:r   N)r:   argparse.NamespacereturnNone)r?   strrZ   zSelected | Ignoredr?   r\   rZ   r   )	r   r   r   r   r;   r@   rB   rT   rX   r   r   r   r+   r+   E   s"    
4&$'&(MTr   r+   c                      e Zd ZdZ	 d	 	 	 	 	 	 	 d	dZ	 	 	 	 d
dZddZej                  	 	 	 	 dd       Z		 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
y)StyleGuideManagerz.Manage multiple style guides for a single run.Nc                `   || _         || _        t        j                         | _        |xs t        |      | _        g | _        t        ||| j                  |      | _	        | j                  g| j                  |      | _         t        j                  d      | j                        | _        y)SInitialize our StyleGuide.

        .. todo:: Add parameter documentation.
        )deciderN)maxsize)r:   	formatterr   
Statisticsstatsr+   rb   style_guidesr   default_style_guidepopulate_style_guides_with	functools	lru_cache_style_guide_forstyle_guide_for)r9   r:   rd   rb   s       r   r;   zStyleGuideManager.__init__   s     "**,
9."9.0#-Y

G$
  $$
,,W5

  Ay224@!! 
r   c              #     K   t        j                  |j                        }|D ]$  \  }}| j                  j	                  ||       & yw)zGenerate style guides from the per-file-ignores option.

        :param options:
            The original options parsed from the CLI and config file.
        :returns:
            A copy of the default style guide with overridden values.
        )filenameextend_ignore_withN)r   parse_files_to_codes_mappingper_file_ignoresrh   copy)r9   r:   per_filero   
violationss        r   ri   z,StyleGuideManager.populate_style_guides_with   sU      55g6N6NO$, 	 Hj**//!j 0  	s   A
Ac                F    t        fd| j                  D        d       S )z3Find the StyleGuide for the filename in particular.c              3  F   K   | ]  }|j                        s|  y wrE   )
applies_to)rH   gro   s     r   rJ   z5StyleGuideManager._style_guide_for.<locals>.<genexpr>   s     D1Q\\(-CQDrK   c                4    t        | j                  xs d      S )N )rR   ro   )ry   s    r   <lambda>z4StyleGuideManager._style_guide_for.<locals>.<lambda>   s    #ajj.B/ r   )key)maxrg   r9   ro   s    `r   rl   z"StyleGuideManager._style_guide_for   s!    D))D/
 	
r   c              #     K   | j                  |      }|j                  |      5  | ddd       y# 1 sw Y   yxY wwz9Record the fact that we're processing the file's results.N)rm   processing_file)r9   ro   guides      r   r   z!StyleGuideManager.processing_file   s?     
 $$X.""8, 	K	 	 	s   #?3	?<?c                P    | j                  |      }|j                  ||||||      S )  Handle an error reported by a check.

        :param code:
            The error code found, e.g., E123.
        :param filename:
            The file in which the error was found.
        :param line_number:
            The line number (where counting starts at 1) at which the error
            occurs.
        :param column_number:
            The column number (where counting starts at 1) at which the error
            occurs.
        :param text:
            The text of the error message.
        :param physical_line:
            The actual physical line causing the error.
        :returns:
            1 if the error was reported. 0 if it was ignored. This is to allow
            for counting of the number of errors found that were not ignored.
        )rm   handle_error)r9   r?   ro   line_numbercolumn_numbertextphysical_liner   s           r   r   zStyleGuideManager.handle_error  s4    : $$X.!!(Km
 	
r   rE   )r:   rY   rd   base_formatter.BaseFormatterrb   DecisionEngine | NonerZ   r[   )r:   rY   rZ   !Generator[StyleGuide, None, None])ro   r\   rZ   r   ro   r\   rZ   r   r?   r\   ro   r\   r   intr   r   r   r\   r   
str | NonerZ   r   )r   r   r   r   r;   ri   rl   
contextlibcontextmanagerr   r   r   r   r   r_   r_      s    8 *.	
#
 0
 '	

 

6)	* 
 	*  %) 
 
  
 	 

  
  
 " 
 
 
r   r_   c                      e Zd ZdZ	 	 d
	 	 	 	 	 	 	 	 	 ddZddZ	 	 d
	 	 	 	 	 ddZej                  	 	 	 	 dd       Z	ddZ
ddZ	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd	Zy)r   z#Manage a Flake8 user's style guide.Nc                    || _         || _        || _        |xs t        |      | _        || _        | j
                  r%t        j                  | j
                        | _        yy)ra   N)r:   rd   rf   r+   rb   ro   r   normalize_path)r9   r:   rd   rf   ro   rb   s         r   r;   zStyleGuide.__init__.  sS     "
9."9 ==!00?DM r   c                "    d| j                    dS )z5Make it easier to debug which StyleGuide we're using.z<StyleGuide [z]>ro   )r9   s    r   __repr__zStyleGuide.__repr__B  s    t}}oR00r   c                   |xs | j                   }t        j                  | j                        }|j                  xs g |_        |j                  j                  |xs g        t        || j                  | j                  |      S )z8Create a copy of this style guide with different values.r   )	ro   rs   deepcopyr:   r2   r#   r   rd   rf   )r9   ro   rp   r:   s       r   rs   zStyleGuide.copyF  so     ,t}}--- ' 5 5 ;$$%7%=2>T^^TZZ(
 	
r   c              #     K   | j                   j                  |       |  | j                   j                  |       ywr   )rd   	beginningfinishedr   s     r   r   zStyleGuide.processing_fileT  s1     
 	  *
)s   <>c                r    | j                   yt        j                  || j                   g| dt              S )a  Check if this StyleGuide applies to the file.

        :param filename:
            The name of the file with violations that we're potentially
            applying this StyleGuide to.
        :returns:
            True if this applies, False otherwise
        Tz! does %(whether)smatch "%(path)s")patternslog_messagelogger)ro   r   matches_filenamerN   r   s     r   rx   zStyleGuide.applies_to]  s>     == %%mm_("CD	
 	
r   c                8    | j                   j                  |      S )a  Determine if the error code should be reported or ignored.

        This method only cares about the select and ignore rules as specified
        by the user in their configuration files and command-line flags.

        This method does not look at whether the specific line is being
        ignored in the file itself.

        :param code:
            The code for the check that has been run.
        )rb   rX   r>   s     r   should_report_errorzStyleGuide.should_report_erroro  s     ||((..r   c                P   | j                   j                  }|sd}t        ||||dz   ||      }| j                  |j                        t
        j                  u }	|j                  |      du }
|	r9|
r7| j                  j                  |       | j                  j                  |       yy)r   r      F)r:   disable_noqar
   r   r?   r   r   is_inline_ignoredrd   handlerf   record)r9   r?   ro   r   r   r   r   r   errorerror_is_selectedis_not_inline_ignoreds              r   r   zStyleGuide.handle_error}  s    : ||00 MA
 $$UZZ0H4E4EE 	 !& 7 7 E N!6NN!!%(JJe$r   )NN)
r:   rY   rd   r   rf   zstatistics.Statisticsro   r   rb   r   )rZ   r\   )ro   r   rp   zSequence[str] | NonerZ   r   r   )ro   r\   rZ   boolr]   rE   r   )r   r   r   r   r;   r   rs   r   r   r   rx   r   r   r   r   r   r   r   +  s    -  $)-@#@ 0@ %	@
 @ '@(1  $37

 1
 
	
 **	** *
$/* %)22 2 	2
 2 2 "2 
2r   r   )r"   list[str] | Noner#   r   rZ   tuple[str, ...])
r"   r   r'   r   r(   z	list[str]r#   r   rZ   r   )"r   
__future__r   argparser   rs   enumrj   loggingtypingr   r   flake8r   r   r   flake8.formattingr	   base_formatterflake8.violationr
   __all__	getLoggerr   rN   Enumr   r   r   r%   r)   r+   r_   r   r   r   r   <module>r      s    6 "            4 &
g!'tyy '&dii & tyy  ,, , 	,,, ,  	,
 , ,B BJ^
 ^
BD Dr   