
    yIfo>                       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j        ej        g          Z eej        ej        ej        ej        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(dS )#zFModule containing our file processor that tokenizes a file for checks.    )annotationsN)Any)	Generator)List)Tuple)defaults)utils)FSTRING_END)FSTRING_MIDDLE)LoadedPluginc                     e Zd ZdZdZ	 d=d>dZej        d?d            Zd@dZ	dAdZ
dBdZdBdZdBdZdCdZdDdZdBdZdEd!ZdFd#ZdGd%ZdHd*ZdId,ZdJd0Zej        dKd1            ZdLd4ZdMd5ZdNd7ZdNd8ZdNd9ZdOd;ZdBd<ZdS )P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`
    FNfilenamestroptionsargparse.Namespacelineslist[str] | NonereturnNonec                   || _         || _        ||n|                                 | _        |                                  d| _        d| _        i | _        i | _        |j	        | _	        d| _
        d| _        |j        | _        d| _        d| _        |j        | _        |j        | _        d| _        d| _        d| _        d| _        g | _        t-          | j                  | _        |j        | _        ddi| _        d| _        dS )z]Initialize our file processor.

        :param filename: Name of the file to process
        Nr    Flogical lines)r   r   
read_linesr   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       D/var/www/piapp/venv/lib/python3.11/site-packages/flake8/processor.py__init__zFileProcessor.__init__>   s     #/UUT__5F5F
 :<-/#0'+".&6%4%&" "02-02tz??*A.     list[tokenize.TokenInfo]c                t    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   r4   <lambda>z+FileProcessor.file_tokens.<locals>.<lambda>|   s    T)__ r6   )iterr   listtokenizegenerate_tokens)r3   r<   s    @r4   file_tokenszFileProcessor.file_tokensx   s7     $$	H,-D-D-D-DEEFFFr6   linenointc                    || _         dS )z#Signal the beginning of an fstring.N)r2   )r3   rC   s     r4   fstring_startzFileProcessor.fstring_start~   s    $r6   tokentokenize.TokenInfoGenerator[str, None, None]c              #    K   |j         t          k    r| j        }n|j        d         }d| _        || _        t          ||j        d                   D ])}| j        | j        dz
           V  | xj        dz  c_        *d| _        dS )z0Iterate through the lines of a multiline string.r   T   FN)	typer
   r2   startr)   r%   rangeendr   )r3   rG   rM   _s       r4   multiline_stringzFileProcessor.multiline_string   s       :$$'EEKNE  ueil++ 	" 	"A*T-12222!r6   c                    d| _         dS )z)Reset the blank_before attribute to zero.r   N)r   r3   s    r4   reset_blank_beforez FileProcessor.reset_blank_before   s    r6   c                    | j         d= dS )z-Delete the first token in the list of tokens.r   N)r-   rS   s    r4   delete_first_tokenz FileProcessor.delete_first_token   s    KNNNr6   c                &    | xj         dz  c_         dS )z&Note that we visited a new blank line.rK   N)r   rS   s    r4   visited_new_blank_linez$FileProcessor.visited_new_blank_line   s    Ar6   mapping_LogicalMappingc                    |d         d         \  }}| j         |dz
           }t          |d|                   | _        | j        | j        k     r| j        | _        dS dS )z:Update the indent level based on the logical line mapping.r   rK   N)r   expand_indentr#   r   r   )r3   rY   	start_row	start_col
start_lines        r4   update_statezFileProcessor.update_state   sg    !(AIZ	A.
)*ZiZ*@AAt/// $ 0D 0/r6   pluginr   c                f    d|j         v r'| j                            |j        i           | _        dS dS )z2Update the checker_state attribute for the plugin.r    N)
parametersr   
setdefault
entry_namer    )r3   ra   s     r4   update_checker_state_forz&FileProcessor.update_checker_state_for   sA    f///!%!5!@!@!2" "D 0/r6   c                    | j         r+| j        | _        | j         | _        | j        s| j         | _        d| _        g | _        dS )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-   rS   s    r4   next_logical_linezFileProcessor.next_logical_line   sP    
  	J)-):D&$($5D!$ J8<8I5r6   _Logicalc                X   g }g }g }d}dx}}| j         D ]\  }}}	}
}|t          v r|sd|	fg}|t          j        k    r|                    |           @|t          j        k    rt          |          }n|t          k    rdt          |          z  }|rO|	\  }}||k    r1|dz
  }|dz
  }| j	        |         |         }|dk    s|dvr	|dvrd| }n||k    r|||         |z   }|                    |           |t          |          z  }|                    ||
f           |
\  }}|||fS )	z4Build the mapping, comments, and logical line lists.r   NxrK   ,z{[(}]) )
r-   SKIP_TOKENSr@   COMMENTappendSTRINGmutate_stringr   r.   r   )r3   logicalcommentsrY   lengthprevious_rowprevious_column
token_typetextrM   rO   liner]   start_column	row_indexcolumn_indexprevious_texts                    r4   build_logical_line_tokensz'FileProcessor.build_logical_line_tokens   s   #%)--26+ 	2 	2.JeS$[(( 'u:,X---%%%X_,,$T**~--SYY E,1)L9,, ,q 0I#2Q#6L$(Jy$9,$GM$++%U22t57H7H)4zz$44 <=DDNN4   c$iiFNNFC=))).1+\??'))r6   ast.ASTc                Z    t          j        d                    | j                            S )z5Build an abstract syntax tree from the list of lines.r   )astparsejoinr   rS   s    r4   	build_astzFileProcessor.build_ast   s     y,,---r6    tuple[str, str, _LogicalMapping]c                    |                                  \  }}}d                    |          }d                    |          | _        | j        dxx         dz  cc<   || j        |fS )z2Build a logical line from the current tokens list.r   r   rK   )r   r   r&   r1   )r3   ru   rt   mapping_listjoined_commentss        r4   build_logical_linez FileProcessor.build_logical_line   sm    *.*H*H*J*J''<''(++GGG,,(((A-((( 1<??r6   rc   dict[str, bool]	argumentsdict[str, Any]c                    i }|                                 D ]L\  }}||v r
	 t          | |          ||<   # t          $ r! |r t                              d|           Y Iw xY w|S )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)r3   rc   r   retparamrequireds         r4   keyword_arguments_forz#FileProcessor.keyword_arguments_for   s     )//11 	 	OE8	!!
$T511E

!    KKB    	 
s   6(A! A!)Generator[tokenize.TokenInfo, None, None]c              #     K   t          j        | j                  D ]:}|d         d         | j        k    r dS | j                            |           |V  ;dS )z'Tokenize the file and yield the tokens.   r   N)r@   rA   	next_liner/   r-   rq   )r3   rG   s     r4   rA   zFileProcessor.generate_tokens  sj      -dn== 	 	EQx{T---Ku%%%KKKK		 	r6   min_linemax_linedict[int, str]c                    t          ||dz             }d                    | j        |dz
  |                   }t                              ||          S )NrK   r   )rN   r   r   dictfromkeys)r3   r   r   
line_rangejoineds        r4   _noqa_line_rangezFileProcessor._noqa_line_range  sJ    8X\22
HqL8$;<==}}Z000r6   c                   	 | j         }i }t          | j                  dz   }d}|D ]\  }}\  }}\  }}}|t          j        k    s|t          j        k    r/t          ||          }t          ||          }|t          j        t          j	        fv rB|
                    |                     ||                     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   )rB   r.   r   r@   	ENDMARKERDEDENTminmaxNLNEWLINEupdater   
TokenErrorSyntaxError)	r3   rB   r   r   r   tprP   s_linee_lines	            r4   _noqa_line_mappingz FileProcessor._noqa_line_mapping  s   	*K C4:*HH6A " "2A{KVQ+++rX_/D/Dx00x00(+x'7888JJt44XxHHIII"4:2H!HJ- #[1 	 	 	 III	s   C C/.C/r%   
str | Nonec                6    | j                             |          S )z7Retrieve the line which will be used to determine noqa.)r   get)r3   r%   s     r4   noqa_line_forzFileProcessor.noqa_line_for.  s    
 &**;777r6   c                    | j         | j        k    rdS | 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   rK   Nr   )r%   r/   r   r"   r   
WHITESPACE)r3   r{   s     r4   r   zFileProcessor.next_line5  sj    t///2z$*+A#RaRH4G(G(G#AwDr6   	list[str]c                    | j         dk    r(| j        j        pd| _         |                                 }n|                                 }|S )z%Read the lines for this file checker.-stdin)r   r   stdin_display_nameread_lines_from_stdinread_lines_from_filename)r3   r   s     r4   r   zFileProcessor.read_lines?  sI    =C L;FwDM..00EE1133Er6   c                J   	 t          j        | j                  5 }|                                cddd           S # 1 swxY w Y   dS # t          t
          f$ rH t          | j        d          5 }|                                cddd           cY S # 1 swxY w Y   Y dS w xY w)zRead the lines for a file.Nzlatin-1)encoding)r@   openr   	readlinesr   UnicodeError)r3   fds     r4   r   z&FileProcessor.read_lines_from_filenameH  s7   	&t}-- &||~~& & & & & & & & & & & & & & & & & &\* 	& 	& 	& dmi888 &B||~~& & & & & & & & & & & & & & & & & & & & &	&sU   A	 <A	 A  A	 A A	 	'B"0BB"B	B"B	B"!B"c                (    t          j                    S )z Read the lines from standard in.)r	   stdin_get_linesrS   s    r4   r   z#FileProcessor.read_lines_from_stdinS  s    $&&&r6   boolc                    | j         j        s t          d | j        D                       rdS t          d | j        D                       rt                              d           dS dS )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  T   K   | ]#}t           j                            |          V  $d S r:   )r   	NOQA_FILEmatch.0r{   s     r4   	<genexpr>z3FileProcessor.should_ignore_file.<locals>.<genexpr>^  sD       1
 1
/3H$$T**1
 1
 1
 1
 1
 1
r6   Tc              3  T   K   | ]#}t           j                            |          V  $d S r:   )r   r   searchr   s     r4   r   z3FileProcessor.should_ignore_file.<locals>.<genexpr>b  s3      HHT#**400HHHHHHr6   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   rS   s    r4   should_ignore_filez FileProcessor.should_ignore_fileW  s     |( 	S 1
 1
7;z1
 1
 1
 .
 .
 	 4HHTZHHHHH 	KK6   55r6   c                    | j         sdS | j         d         dd         dk    r| j         d         dd         | j         d<   dS | j         d         dd         dk    r| j         d         dd         | j         d<   dS dS )z-Strip the UTF bom from the lines of the file.Nr   rK   u   ﻿   u   ï»¿)r   rS   s    r4   r   zFileProcessor.strip_utf_bomk  s    z 	F :a=!(( JqM!""-DJqMMMZ]2A2.00 JqM!""-DJqMMM 10r6   r:   )r   r   r   r   r   r   r   r   )r   r7   )rC   rD   r   r   )rG   rH   r   rI   )r   r   )rY   rZ   r   r   )ra   r   r   r   )r   ri   )r   r   )r   r   )rc   r   r   r   r   r   )r   r   )r   rD   r   rD   r   r   )r   r   )r%   rD   r   r   )r   r   )r   r   )r   r   )__name__
__module____qualname____doc__noqar5   	functoolscached_propertyrB   rF   rQ   rT   rV   rX   r`   rf   rh   r   r   r   r   rA   r   r   r   r   r   r   r   r   r    r6   r4   r   r      s9        8 D #'	8! 8! 8! 8! 8!t G G G G
% % % %   $         1 1 1 1      #* #* #* #*J. . . .@ @ @ @   .   1 1 1 1
    88 8 8 8      	& 	& 	& 	&' ' ' '   (
. 
. 
. 
. 
. 
.r6   r   rG   rH   r   r   c                    | d         t           v p1| d         | d         d         d                                         dk    S )z+Check if the token is an end-of-line token.r      r   rK   Nz\
)r   lstriprG   s    r4   is_eol_tokenr   x  s<    8wL%(58A;=="9"@"@"B"Bf"LLr6   c                ^    | j         t          k    p| j         t          j        k    od| j        v S )z$Check if this is a multiline string.
)rL   r
   r@   rr   stringr   s    r4   is_multiline_stringr   }  s.    :$ 
ho%>$%,*>r6   c                     | d         t           v S )z0Check if the token type is a newline token type.r   )r   r   s    r4   token_is_newliner     s    8wr6   current_parentheses_countrD   
token_textr   c                *    |dv r| dz   S |dv r| dz
  S | S )z Count the number of parentheses.z([{rK   rm   r   )r   r   s     r4   count_parenthesesr     s4    U(1,,	u		(1,,$$r6   r{   c                F    t          |                     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)r{   s    r4   r\   r\     s     tq!!"""r6   rz   c                    |                      | 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   rK   N)z"""z'''r   rk   )indexr.   )rz   rM   rO   s      r4   rs   rs     s{     JJtBx  1$E
d))a-CBCCyN""
q<#u--STT
::r6   )rG   rH   r   r   )r   rD   r   r   r   rD   )r{   r   r   rD   )rz   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   ro   rD   rZ   r   ri   r   r   r   r   r   r\   rs   r   r6   r4   <module>r      s.   L L " " " " " "  



                                           & & & & & & ) ) ) ) ) ) . . . . . .g!!
)X[("23
4
4i[("HOX_E  uS%S/123cDI67V. V. V. V. V. V. V. V.r
M M M M
      
% % % %# # # #(; ; ; ; ; ;r6   