
    zi@                       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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d>d            Zd?dZd@dZ	dAdZ
dAdZdAdZdBdZdCdZdAdZdDd!ZdEd#ZdFd%ZdGd*ZdHd,ZdId0ZdJd3ZdKd4ZdLd6ZdLd7ZdLd8ZdMd:ZdAd;ZdS )N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| _        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_file_tokens_noqa_line_mapping_fstring_start)selfr   r   r   s       [/var/www/tmov.alphamb/tmov_inventario/venv/lib/python3.11/site-packages/flake8/processor.py__init__zFileProcessor.__init__=   s     #/UUT__5F5F
 :<-/#0'+".&6%4%&" "02-02tz??*A.=A9=     list[tokenize.TokenInfo]c                    | j         =t          | j                  t          t	          j        fd                    | _         | j         S )z-Return the complete set of tokens for a file.Nc                 "    t                     S N)next)	line_iters   r6   <lambda>z+FileProcessor.file_tokens.<locals>.<lambda>   s    i r8   )r2   iterr   listtokenizegenerate_tokens)r5   r>   s    @r6   file_tokenszFileProcessor.file_tokensz   sR     $TZ((I $()@)@)@)@AA! !D   r8   linenointc                    || _         dS )z#Signal the beginning of an fstring.N)r4   )r5   rE   s     r6   fstring_startzFileProcessor.fstring_start   s    $r8   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
   r4   startr)   r%   rangeendr   )r5   rI   rO   _s       r6   multiline_stringzFileProcessor.multiline_string   s       :$$'EEKNE  ueil++ 	" 	"A*T-12222!r8   c                    d| _         dS )z)Reset the blank_before attribute to zero.r   N)r   r5   s    r6   reset_blank_beforez FileProcessor.reset_blank_before   s    r8   c                    | j         d= dS )z-Delete the first token in the list of tokens.r   N)r-   rU   s    r6   delete_first_tokenz FileProcessor.delete_first_token   s    KNNNr8   c                &    | xj         dz  c_         dS )z&Note that we visited a new blank line.rM   N)r   rU   s    r6   visited_new_blank_linez$FileProcessor.visited_new_blank_line   s    Ar8   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   rM   N)r   expand_indentr#   r   r   )r5   r[   	start_row	start_col
start_lines        r6   update_statezFileProcessor.update_state   sg    !(AIZ	A.
)*ZiZ*@AAt/// $ 0D 0/r8   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    )r5   rc   s     r6   update_checker_state_forz&FileProcessor.update_checker_state_for   sA    f///!%!5!@!@!2" "D 0/r8   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-   rU   s    r6   next_logical_linezFileProcessor.next_logical_line   sP    
  	J)-):D&$($5D!$ J8<8I5r8   _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xrM   ,z{[(}]) )
r-   SKIP_TOKENSrB   COMMENTappendSTRINGmutate_stringr   r.   r   )r5   logicalcommentsr[   lengthprevious_rowprevious_column
token_typetextrO   rQ   liner_   start_column	row_indexcolumn_indexprevious_texts                    r6   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+\??'))r8   ast.ASTc                Z    t          j        d                    | j                            S )z5Build an abstract syntax tree from the list of lines.r   )astparsejoinr   rU   s    r6   	build_astzFileProcessor.build_ast   s     y,,---r8    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   rM   )r   r   r&   r1   )r5   rw   rv   mapping_listjoined_commentss        r6   build_logical_linez FileProcessor.build_logical_line   sm    *.*H*H*J*J''<''(++GGG,,(((A-((( 1<??r8   re   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)r5   re   r   retparamrequireds         r6   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)rB   rC   	next_liner/   r-   rs   )r5   rI   s     r6   rC   zFileProcessor.generate_tokens  sj      -dn== 	 	EQx{T---Ku%%%KKKK		 	r8   min_linemax_linedict[int, str]c                    t          ||dz             }d                    | j        |dz
  |                   }t                              ||          S )NrM   r   )rP   r   r   dictfromkeys)r5   r   r   
line_rangejoineds        r6   _noqa_line_rangezFileProcessor._noqa_line_range  sJ    8X\22
HqL8$;<==}}Z000r8   r%   
str | Nonec                ~   | j         	 | j        }i }t          | j                  dz   }d}|D ]\  }}\  }}\  }	}}|t          j        k    r n}t          ||          }t          ||	          }|t          j        t          j	        fv rB|
                    |                     ||                     t          | j                  dz   }d}|dk    r)|
                    |                     ||                     || _         n## t          j        t          f$ r
 i | _         Y nw xY w| j                             |          S )z7Retrieve the line which will be used to determine noqa.Nr   r   )r3   rD   r.   r   rB   	ENDMARKERminmaxNLNEWLINEupdater   
TokenErrorSyntaxErrorget)
r5   r%   rD   r   r   r   tprR   s_linee_lines
             r6   noqa_line_forzFileProcessor.noqa_line_for  s_   "*.". tz??Q.:E & &6B;FAQX///"8V44H"8V44Hhk8+;<<<

4#8#88#L#LMMM#&tz??Q#6#%
 r>>JJt44XxHHIII*-''9 '5 - - - +-'''-B &**;777s   D D"!D"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   rM   Nr   )r%   r/   r   r"   r   
WHITESPACE)r5   r}   s     r6   r   zFileProcessor.next_line@  sj    t///2z$*+A#RaRH4G(G(G#AwDr8   	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)r5   r   s     r6   r   zFileProcessor.read_linesJ  sI    =C L;FwDM..00EE1133Er8   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)rB   openr   	readlinesr   UnicodeError)r5   fds     r6   r   z&FileProcessor.read_lines_from_filenameS  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_linesrU   s    r6   r   z#FileProcessor.read_lines_from_stdin^  s    $&&&r8   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     r6   	<genexpr>z3FileProcessor.should_ignore_file.<locals>.<genexpr>i  sD       1
 1
/3H$$T**1
 1
 1
 1
 1
 1
r8   Tc              3  T   K   | ]#}t           j                            |          V  $d S r<   )r   r   searchr   s     r6   r   z3FileProcessor.should_ignore_file.<locals>.<genexpr>m  s3      HHT#**400HHHHHHr8   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   rU   s    r6   should_ignore_filez FileProcessor.should_ignore_fileb  s     |( 	S 1
 1
7;z1
 1
 1
 .
 .
 	 4HHTZHHHHH 	KK6   55r8   c                   | j         sdS t          | j         d         d                   }|dvrdS |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   )     r   rM      u   ï»¿)r   ord)r5   
first_bytes     r6   r   zFileProcessor.strip_utf_bomv  s    z 	FAq)**
^++F  JqM!""-DJqMMMZ]2A2.00 JqM!""-DJqMMM 10r8   r<   )r   r   r   r   r   r   r   r   )r   r9   )rE   rF   r   r   )rI   rJ   r   rK   )r   r   )r[   r\   r   r   )rc   r   r   r   )r   rk   )r   r   )r   r   )re   r   r   r   r   r   )r   r   )r   rF   r   rF   r   r   )r%   rF   r   r   )r   r   )r   r   )r   r   )__name__
__module____qualname____doc__noqar7   propertyrD   rH   rS   rV   rX   rZ   rb   rh   rj   r   r   r   r   rC   r   r   r   r   r   r   r   r    r8   r6   r   r      s        8 D #'	;! ;! ;! ;! ;!z ! ! ! X!% % % %   $         1 1 1 1      #* #* #* #*J. . . .@ @ @ @   .   1 1 1 1
&8 &8 &8 &8P      	& 	& 	& 	&' ' ' '   (. . . . . .r8   r   rI   rJ   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   rM   Nz\
)r   lstriprI   s    r6   is_eol_tokenr     s<    8wL%(58A;=="9"@"@"B"Bf"LLr8   c                ^    | j         t          k    p| j         t          j        k    od| j        v S )z$Check if this is a multiline string.
)rN   r
   rB   rt   stringr   s    r6   is_multiline_stringr     s.    :$ 
ho%>$%,*>r8   c                     | d         t           v S )z0Check if the token type is a newline token type.r   )r   r   s    r6   token_is_newliner     s    8wr8   current_parentheses_countrF   
token_textr   c                *    |dv r| dz   S |dv r| dz
  S | S )z Count the number of parentheses.z([{rM   ro   r   )r   r   s     r6   count_parenthesesr     s4    U(1,,	u		(1,,$$r8   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    r6   r^   r^     s     tq!!"""r8   r|   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   rM   N)z"""z'''r   rm   )indexr.   )r|   rO   rQ   s      r6   ru   ru     s{     JJtBx  1$E
d))a-CBCCyN""
q<#u--STT
::r8   )rI   rJ   r   r   )r   rF   r   r   r   rF   )r}   r   r   rF   )r|   r   r   r   )(r   
__future__r   argparser   loggingrB   typingr   r   r   r   flake8r   r	   flake8._compatr
   r   flake8.plugins.finderr   	getLoggerr   r   	frozensetr   r   INDENTDEDENTrq   rF   r\   r   rk   r   r   r   r   r   r^   ru   r   r8   r6   <module>r     s"   L L " " " " " "  



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