
    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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 eej2                  ej4                  g      Z eej2                  ej4                  ej6                  ej8                  g      Zeeeeeef   f      Zeee    ee    ef   Z! G d d      Z"ddZ#ddZ$ddZ%ddZ&ddZ'ddZ(y)zFModule containing our file processor that tokenizes a file for checks.    )annotationsN)Any)	Generator)List)Tuple)defaults)utils)FSTRING_END)FSTRING_MIDDLE)LoadedPluginc                  6   e Zd ZdZdZ	 d	 	 	 	 	 	 	 ddZej                  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(dZd)dZej                  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)/FileProcessora=  Processes a file and holds state.

    This processes a file by generating tokens, logical and physical lines,
    and AST trees. This also provides a way of passing state about the file
    to checks expecting that state. Any public attribute on this object can
    be requested by a plugin. The known public attributes are:

    - :attr:`blank_before`
    - :attr:`blank_lines`
    - :attr:`checker_state`
    - :attr:`indent_char`
    - :attr:`indent_level`
    - :attr:`line_number`
    - :attr:`logical_line`
    - :attr:`max_line_length`
    - :attr:`max_doc_length`
    - :attr:`multiline`
    - :attr:`noqa`
    - :attr:`previous_indent_level`
    - :attr:`previous_logical`
    - :attr:`previous_unindented_logical_line`
    - :attr:`tokens`
    - :attr:`file_tokens`
    - :attr:`total_lines`
    - :attr:`verbose`
    FNc                &   || _         || _        ||n| j                         | _        | j	                          d| _        d| _        i | _        i | _        |j                  | _	        d| _
        d| _        |j                  | _        d| _        d| _        |j                  | _        |j                   | _        d| _        d| _        d| _        d| _        g | _        t-        | j                        | _        |j0                  | _        ddi| _        d| _        y)z]Initialize our file processor.

        :param filename: Name of the file to process
        Nr    Flogical lines)optionsfilename
read_lineslinesstrip_utf_bomblank_beforeblank_lines_checker_stateschecker_statehang_closingindent_charindent_levelindent_sizeline_numberlogical_linemax_line_lengthmax_doc_length	multilineprevious_indent_levelprevious_logical previous_unindented_logical_linetokenslentotal_linesverbose
statistics_fstring_start)selfr   r   r   s       S/var/www/html/brdwt/brdwt/brdwtenv/lib/python3.12/site-packages/flake8/processor.py__init__zFileProcessor.__init__>   s     #/UT__5F
 :<-/#00'+"..&66%44%&" "02-02tzz?*A.     c                p    t        | j                        t        t        j                  fd            S )z-Return the complete set of tokens for a file.c                     t               S N)next)	line_iters   r/   <lambda>z+FileProcessor.file_tokens.<locals>.<lambda>|   s    T)_ r1   )iterr   listtokenizegenerate_tokens)r.   r6   s    @r/   file_tokenszFileProcessor.file_tokensx   s*     $	H,,-DEFFr1   c                    || _         y)z#Signal the beginning of an fstring.N)r-   )r.   linenos     r/   fstring_startzFileProcessor.fstring_start~   s
    $r1   c              #  6  K   |j                   t        k(  r| j                  }n|j                  d   }d| _        || _        t        ||j                  d         D ]5  }| j                  | j
                  dz
      | xj
                  dz  c_        7 d| _        yw)z0Iterate through the lines of a multiline string.r   T   FN)	typer
   r-   startr$   r    rangeendr   )r.   tokenrC   _s       r/   multiline_stringzFileProcessor.multiline_string   s      ::$''EKKNE  ueiil+ 	"A**T--122!	" s   BBc                    d| _         y)z)Reset the blank_before attribute to zero.r   N)r   r.   s    r/   reset_blank_beforez FileProcessor.reset_blank_before   s
    r1   c                    | j                   d= y)z-Delete the first token in the list of tokens.r   N)r(   rJ   s    r/   delete_first_tokenz FileProcessor.delete_first_token   s    KKNr1   c                .    | xj                   dz  c_         y)z&Note that we visited a new blank line.rA   N)r   rJ   s    r/   visited_new_blank_linez$FileProcessor.visited_new_blank_line   s    Ar1   c                    |d   d   \  }}| j                   |dz
     }t        |d|       | _        | j                  | j                  k  r| j                  | _        yy)z:Update the indent level based on the logical line mapping.r   rA   N)r   expand_indentr   r   r   )r.   mapping	start_row	start_col
start_lines        r/   update_statezFileProcessor.update_state   sa    !(AIZZ	A.
)*Zi*@At/// $ 0 0D 0r1   c                x    d|j                   v r,| j                  j                  |j                  i       | _        yy)z2Update the checker_state attribute for the plugin.r   N)
parametersr   
setdefault
entry_namer   )r.   plugins     r/   update_checker_state_forz&FileProcessor.update_checker_state_for   s9    f///!%!5!5!@!@!!2"D 0r1   c                    | j                   r?| j                  | _        | j                   | _        | j                  s| j                   | _        d| _        g | _        y)zoRecord the previous logical line.

        This also resets the tokens list and the blank_lines count.
        r   N)r!   r   r%   r&   r'   r   r(   rJ   s    r/   next_logical_linezFileProcessor.next_logical_line   sO    
 )-):):D&$($5$5D!$$8<8I8I5r1   c                   g }g }g }d}dx}}| j                   D ]&  \  }}}	}
}|t        v r|sd|	fg}|t        j                  k(  r|j	                  |       ?|t        j
                  k(  rt        |      }nJ|t        k(  rA|j                  d      |j                  d      z   }dt        |      |z   z  }|
d   |
d   |z   f}
|rF|	\  }}||k7  r/|dz
  }|dz
  }| j                  |   |   }|dk(  s|dvr|d	vrd
| }n||k7  r||| |z   }|j	                  |       |t        |      z  }|j	                  ||
f       |
\  }}) |||fS )z4Build the mapping, comments, and logical line lists.r   N{}xrA   ,z{[(}]) )r(   SKIP_TOKENSr:   COMMENTappendSTRINGmutate_stringr   countr)   r   )r.   logicalcommentsrR   lengthprevious_rowprevious_column
token_typetextrC   rE   linebrace_offsetrS   start_column	row_indexcolumn_indexprevious_texts                     r/   build_logical_line_tokensz'FileProcessor.build_logical_line_tokens   s   #%)--26++ !	2.JeS$[(u:,X---%X__,$T*~-
  $zz#C@c$i,671vs1v45,1)L9, ,q 0I#2Q#6L$(JJy$9,$GM$+%U2t57H!"4&z$4=DDNN4 c$iFNNFC=).1+\?C!	2D '))r1   c                ^    t        j                  dj                  | j                              S )z5Build an abstract syntax tree from the list of lines.r   )astparsejoinr   rJ   s    r/   	build_astzFileProcessor.build_ast   s    yy,--r1   c                    | j                         \  }}}dj                  |      }dj                  |      | _        | j                  dxx   dz  cc<   || j                  |fS )z2Build a logical line from the current tokens list.r   r   rA   )ry   r}   r!   r,   )r.   rm   rl   mapping_listjoined_commentss        r/   build_logical_linez FileProcessor.build_logical_line   s]    *.*H*H*J''<''(+GGG,(A-( 1 1<??r1   c                    i }|j                         D ]  \  }}||v r	 t        | |      ||<    |S # t        $ r |r t        j	                  d|       Y Cw xY w)z8Generate the keyword arguments for a list of parameters.zPPlugin requested optional parameter "%s" but this is not an available parameter.)itemsgetattrAttributeErrorLOGwarning)r.   rX   	argumentsretparamrequireds         r/   keyword_arguments_forz#FileProcessor.keyword_arguments_for   sx     )//1 	OE8	!
$T51E
		 
 " KKB	s   2"AAc              #     K   t        j                  | j                        D ]8  }|d   d   | j                  kD  r y| j                  j                  |       | : yw)z'Tokenize the file and yield the tokens.   r   N)r:   r;   	next_liner*   r(   rh   )r.   rF   s     r/   r;   zFileProcessor.generate_tokens
  sT     --dnn= 	EQx{T---KKu%K		s   AAc                    t        ||dz         }dj                  | j                  |dz
  |       }t        j	                  ||      S )NrA   r   )rD   r}   r   dictfromkeys)r.   min_linemax_line
line_rangejoineds        r/   _noqa_line_rangezFileProcessor._noqa_line_range  s@    8X\2
HqL8<=}}Z00r1   c                   	 | j                   }i }t        | j                        dz   }d}|D ]  \  }}\  }}\  }}}|t        j                  k(  s|t        j
                  k(  r6t        ||      }t        ||      }|t        j                  t        j                  fv sq|j                  | j                  ||             t        | j                        dz   }d} |S # t        j                  t        f$ r i cY S w xY w)z<Map from line number to the line we'll search for `noqa` in.r   r   )r<   r)   r   r:   	ENDMARKERDEDENTminmaxNLNEWLINEupdater   
TokenErrorSyntaxError)	r.   r<   r   r   r   tprG   s_linee_lines	            r/   _noqa_line_mappingz FileProcessor._noqa_line_mapping  s    	**K C4::*HH6A "2A{KVQ+++rX__/Dx0x0(++x'7'788JJt44XxHI"4::2H!H" J- ##[1 	 I	s   C C:9C:c                8    | j                   j                  |      S )z7Retrieve the line which will be used to determine noqa.)r   get)r.   r    s     r/   noqa_line_forzFileProcessor.noqa_line_for4  s    
 &&**;77r1   c                    | j                   | j                  k\  ry| j                  | j                      }| xj                   dz  c_         | j                  |dd t        j
                  v r
|d   | _        |S )z Get the next line from the list.r   rA   Nr   )r    r*   r   r   r   
WHITESPACE)r.   rs   s     r/   r   zFileProcessor.next_line;  sn    t///zz$**+A#RaH4G4G(G#AwDr1   c                    | j                   dk(  r1| j                  j                  xs d| _         | j                         }|S | j	                         }|S )z%Read the lines for this file checker.-stdin)r   r   stdin_display_nameread_lines_from_stdinread_lines_from_filename)r.   r   s     r/   r   zFileProcessor.read_linesE  sN    ==C LL;;FwDM..0E  113Er1   c                4   	 t        j                  | j                        5 }|j                         cddd       S # 1 sw Y   yxY w# t        t
        f$ rA t        | j                  d      5 }|j                         cddd       cY S # 1 sw Y   Y yxY ww xY w)zRead the lines for a file.Nzlatin-1)encoding)r:   openr   	readlinesr   UnicodeError)r.   fds     r/   r   z&FileProcessor.read_lines_from_filenameN  sz    	&t}}- &||~& & &\* 	& dmmi8 &B||~& & &	&sC   A ;	A A A A &B-B	=
B	B	BBc                *    t        j                         S )z Read the lines from standard in.)r	   stdin_get_linesrJ   s    r/   r   z#FileProcessor.read_lines_from_stdinY  s    $$&&r1   c                    | j                   j                  st        d | j                  D              ryt        d | j                  D              rt        j                  d       yy)zCheck if ``flake8: noqa`` is in the file to be ignored.

        :returns:
            True if a line matches :attr:`defaults.NOQA_FILE`,
            otherwise False
        c              3  Z   K   | ]#  }t         j                  j                  |       % y wr4   )r   	NOQA_FILEmatch.0rs   s     r/   	<genexpr>z3FileProcessor.should_ignore_file.<locals>.<genexpr>d  s&      1
/3H$$T*1
   )+Tc              3  Z   K   | ]#  }t         j                  j                  |       % y wr4   )r   r   searchr   s     r/   r   z3FileProcessor.should_ignore_file.<locals>.<genexpr>h  s!     HT##**40Hr   z[Detected `flake8: noqa` on line with code. To ignore an error on a line use `noqa` instead.F)r   disable_noqaanyr   r   r   rJ   s    r/   should_ignore_filez FileProcessor.should_ignore_file]  sY     ||((S 1
7;zz1
 .
 HTZZHHKK6 r1   c                    | j                   sy| j                   d   dd dk(  r | j                   d   dd | j                   d<   y| j                   d   dd dk(  r | j                   d   dd | j                   d<   yy)z-Strip the UTF bom from the lines of the file.Nr   rA   u   ﻿   u   ï»¿)r   rJ   s    r/   r   zFileProcessor.strip_utf_bomq  sy    zz ::a=!( JJqM!"-DJJqMZZ]2A.0 JJqM!"-DJJqM 1r1   r4   )r   strr   zargparse.Namespacer   zlist[str] | NonereturnNone)r   zlist[tokenize.TokenInfo])r>   intr   r   )rF   tokenize.TokenInfor   zGenerator[str, None, None])r   r   )rR   _LogicalMappingr   r   )r[   r   r   r   )r   _Logical)r   zast.AST)r   z tuple[str, str, _LogicalMapping])rX   zdict[str, bool]r   dict[str, Any]r   r   )r   z)Generator[tokenize.TokenInfo, None, None])r   r   r   r   r   dict[int, str])r   r   )r    r   r   z
str | None)r   r   )r   z	list[str])r   bool)__name__
__module____qualname____doc__noqar0   	functoolscached_propertyr<   r?   rH   rK   rM   rO   rV   r\   r^   ry   r~   r   r   r;   r   r   r   r   r   r   r   r   r    r1   r/   r   r      s   8 D #'	8!8! $8!  	8!
 
8!t G G
%'	#$1)*V.@# " 
	.1
  88	&'(
.r1   r   c                Z    | d   t         v xs | d   | d   d   d j                         dk(  S )z+Check if the token is an end-of-line token.r      r   rA   Nz\
)r   lstriprF   s    r/   is_eol_tokenr   ~  s7    8wL%(58A;="9"@"@"Bf"LLr1   c                    | j                   t        k(  xs- | j                   t        j                  k(  xr d| j                  v S )z$Check if this is a multiline string.
)rB   r
   r:   ri   stringr   s    r/   is_multiline_stringr     s6    ::$ 

hoo%>$%,,*>r1   c                    | d   t         v S )z0Check if the token type is a newline token type.r   )r   r   s    r/   token_is_newliner     s    8wr1   c                *    |dv r| dz   S |dv r| dz
  S | S )z Count the number of parentheses.z([{rA   rd   r   )current_parentheses_count
token_texts     r/   count_parenthesesr     s.    U(1,,	u	(1,,$$r1   c                6    t        | j                  d            S )zReturn the amount of indentation.

    Tabs are expanded to the next multiple of 8.

    >>> expand_indent('    ')
    4
    >>> expand_indent('\t')
    8
    >>> expand_indent('       \t')
    8
    >>> expand_indent('        \t')
    16
       )r)   
expandtabs)rs   s    r/   rQ   rQ     s     tq!""r1   c                    | j                  | d         dz   }t        |       dz
  }| dd dv r
|dz  }|dz  }| d| d||z
  z  z   | |d z   S )zReplace contents with 'xxx' to prevent syntax matching.

    >>> mutate_string('"abc"')
    '"xxx"'
    >>> mutate_string("'''abc'''")
    "'''xxx'''"
    >>> mutate_string("r'abc'")
    "r'xxx'"
    r   rA   N)z"""z'''r   rb   )indexr)   )rr   rC   rE   s      r/   rj   rj     sm     JJtBx 1$E
d)a-CBCyN"
q<#u--ST
::r1   )rF   r   r   r   )r   r   r   r   r   r   )rs   r   r   r   )rr   r   r   r   ))r   
__future__r   argparser{   r   loggingr:   typingr   r   r   r   flake8r   r	   flake8._compatr
   r   flake8.plugins.finderr   	getLoggerr   r   	frozensetr   r   INDENTr   rf   r   r   r   r   r   r   r   r   r   rQ   rj   r   r1   r/   <module>r      s    L "  
          & ) .g!
X[[("2"23
4[[(""HOOX__E uS%S/123cDI67\. \.~
M

%#(;r1   