
    ^jA                       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)	Generator)Any)defaults)utils)FSTRING_END)FSTRING_MIDDLE)TSTRING_END)TSTRING_MIDDLE)LoadedPluginc                     e Zd ZdZdZ	 d>d?dZej        d@d            ZdAdZ	dAdZ
dBdZdCdZdCdZdCdZdDdZdEdZdCd ZdFd"ZdGd$ZdHd&ZdId+ZdJd-ZdKd1Zej        dLd2            ZdMd5ZdNd6ZdOd8ZdOd9ZdOd:ZdPd<ZdCd=ZdS )Q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x| _        | _        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_tstring_start)selfr   r   r   s       T/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/flake8/processor.py__init__zFileProcessor.__init__>   s     #/UUT__5F5F
 :<-/#0'+".&6%4%&" "02-02tz??*A.466d111    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   r5   <lambda>z+FileProcessor.file_tokens.<locals>.<lambda>|   s    T)__ r7   )iterr   listtokenizegenerate_tokens)r4   r=   s    @r5   file_tokenszFileProcessor.file_tokensx   s7     $$	H,-D-D-D-DEEFFFr7   linenointc                    || _         dS )z#Signal the beginning of an fstring.N)r2   r4   rD   s     r5   fstring_startzFileProcessor.fstring_start~       $r7   c                    || _         dS )z#Signal the beginning of an tstring.N)r3   rG   s     r5   tstring_startzFileProcessor.tstring_start   rI   r7   tokentokenize.TokenInfoGenerator[str]c              #  8  K   |j         t          k    r| j        }n%|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   r
   r3   startr)   r%   rangeendr   )r4   rL   rR   _s       r5   multiline_stringzFileProcessor.multiline_string   s      :$$'EEZ;&&'EEKNE  ueil++ 	" 	"A*T-12222!r7   c                    d| _         dS )z)Reset the blank_before attribute to zero.r   N)r   r4   s    r5   reset_blank_beforez FileProcessor.reset_blank_before   s    r7   c                    | j         d= dS )z-Delete the first token in the list of tokens.r   N)r-   rX   s    r5   delete_first_tokenz FileProcessor.delete_first_token   s    KNNNr7   c                &    | xj         dz  c_         dS )z&Note that we visited a new blank line.rP   N)r   rX   s    r5   visited_new_blank_linez$FileProcessor.visited_new_blank_line   s    Ar7   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   rP   N)r   expand_indentr#   r   r   )r4   r^   	start_row	start_col
start_lines        r5   update_statezFileProcessor.update_state   sg    !(AIZ	A.
)*ZiZ*@AAt/// $ 0D 0/r7   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    )r4   rf   s     r5   update_checker_state_forz&FileProcessor.update_checker_state_for   sA    f///!%!5!@!@!2" "D 0/r7   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-   rX   s    r5   next_logical_linezFileProcessor.next_logical_line   sP    
  	J)-):D&$($5D!$ J8<8I5r7   _Logicalc                   g }g }g }d}dx}}| j         D ]Y\  }}}	}
}|t          v r|sd|	fg}|t          j        k    r|                    |           @|t          j        k    rt          |          }nc|t          t          hv rS|	                    d          |	                    d          z   }dt          |          |z   z  }|
d         |
d         |z   f}
|Q|O|	\  }}||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{}xrP   ,z{[(}]) )r-   SKIP_TOKENSrA   COMMENTappendSTRINGmutate_stringr	   r   countr.   r   )r4   logicalcommentsr^   lengthprevious_rowprevious_column
token_typetextrR   rT   linebrace_offsetrb   start_column	row_indexcolumn_indexprevious_texts                     r5   build_logical_line_tokensz'FileProcessor.build_logical_line_tokens   s   #%)--26+ $	2 $	2.JeS$[(( 'u:,X---%%%X_,,$T**     $zz#C@c$ii,671vs1v45'O,G,1)L9,, ,q 0I#2Q#6L$(Jy$9,$GM$++%U22t57H7H)4zz$44 <=DDNN4   c$iiFNNFC=))).1+\??'))r7   ast.ASTc                Z    t          j        d                    | j                            S )z5Build an abstract syntax tree from the list of lines.r   )astparsejoinr   rX   s    r5   	build_astzFileProcessor.build_ast   s     y,,---r7    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   rP   )r   r   r&   r1   )r4   r}   r|   mapping_listjoined_commentss        r5   build_logical_linez FileProcessor.build_logical_line   sm    *.*H*H*J*J''<''(++GGG,,(((A-((( 1<??r7   rh   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)r4   rh   r   retparamrequireds         r5   keyword_arguments_forz#FileProcessor.keyword_arguments_for   s     )//11 	 	OE8	!!
$T511E

!    KKB    	 
s   6(A! A!Generator[tokenize.TokenInfo]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)rA   rB   	next_liner/   r-   rx   )r4   rL   s     r5   rB   zFileProcessor.generate_tokens  sj      -dn== 	 	EQx{T---Ku%%%KKKK		 	r7   min_linemax_linedict[int, str]c                    t          ||dz             }d                    | j        |dz
  |                   }t                              ||          S )NrP   r   )rS   r   r   dictfromkeys)r4   r   r   
line_rangejoineds        r5   _noqa_line_rangezFileProcessor._noqa_line_range  sJ    8X\22
HqL8$;<==}}Z000r7   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   )rC   r.   r   rA   	ENDMARKERDEDENTminmaxNLNEWLINEupdater   
TokenErrorSyntaxError)	r4   rC   r   r   r   tprU   s_linee_lines	            r5   _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)r4   r%   s     r5   noqa_line_forzFileProcessor.noqa_line_for;  s    
 &**;777r7   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   rP   Nr   )r%   r/   r   r"   r   
WHITESPACE)r4   r   s     r5   r   zFileProcessor.next_lineB  sj    t///2z$*+A#RaRH4G(G(G#AwDr7   	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)r4   r   s     r5   r   zFileProcessor.read_linesL  sI    =C L;FwDM..00EE1133Er7   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)rA   openr   	readlinesr   UnicodeError)r4   fds     r5   r   z&FileProcessor.read_lines_from_filenameU  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_linesrX   s    r5   r   z#FileProcessor.read_lines_from_stdin`  s    $&&&r7   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     r5   	<genexpr>z3FileProcessor.should_ignore_file.<locals>.<genexpr>k  sD       1
 1
/3H$$T**1
 1
 1
 1
 1
 1
r7   Tc              3  T   K   | ]#}t           j                            |          V  $d S r;   )r   r   searchr   s     r5   r   z3FileProcessor.should_ignore_file.<locals>.<genexpr>o  s3      HHT#**400HHHHHHr7   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   rX   s    r5   should_ignore_filez FileProcessor.should_ignore_filed  s     |( 	S 1
 1
7;z1
 1
 1
 .
 .
 	 4HHTZHHHHH 	KK6   55r7   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   rP   u   ﻿   u   ï»¿)r   rX   s    r5   r   zFileProcessor.strip_utf_bomx  s    z 	F :a=!(( JqM!""-DJqMMMZ]2A2.00 JqM!""-DJqMMM 10r7   r;   )r   r   r   r   r   r   r   r   )r   r8   )rD   rE   r   r   )rL   rM   r   rN   )r   r   )r^   r_   r   r   )rf   r   r   r   )r   rn   )r   r   )r   r   )rh   r   r   r   r   r   )r   r   )r   rE   r   rE   r   r   )r   r   )r%   rE   r   r   )r   r   )r   r   )r   r   ) __name__
__module____qualname____doc__noqar6   	functoolscached_propertyrC   rH   rK   rV   rY   r[   r]   re   rk   rm   r   r   r   r   rB   r   r   r   r   r   r   r   r   r    r7   r5   r   r      sM        8 D #'	87 87 87 87 87t G G G G
% % % %% % % %   $         1 1 1 1      ,* ,* ,* ,*\. . . .@ @ @ @   .   1 1 1 1
    88 8 8 8      	& 	& 	& 	&' ' ' '   (
. 
. 
. 
. 
. 
.r7   r   rL   rM   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   rP   Nz\
)r   lstriprL   s    r5   is_eol_tokenr     s<    8wL%(58A;=="9"@"@"B"Bf"LLr7   c                h    | j         t          t          hv p| j         t          j        k    od| j        v S )z$Check if this is a multiline string.
)rQ   r   r
   rA   ry   stringr   s    r5   is_multiline_stringr     s3    :+{33 
ho%>$%,*>r7   c                     | d         t           v S )z0Check if the token type is a newline token type.r   )r   r   s    r5   token_is_newliner     s    8wr7   current_parentheses_countrE   
token_textr   c                *    |dv r| dz   S |dv r| dz
  S | S )z Count the number of parentheses.z([{rP   rt   r   )r   r   s     r5   count_parenthesesr     s4    U(1,,	u		(1,,$$r7   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    r5   ra   ra     s     tq!!"""r7   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   rP   N)z"""z'''r   rr   )indexr.   )r   rR   rT   s      r5   rz   rz     s{     JJtBx  1$E
d))a-CBCCyN""
q<#u--STT
::r7   )rL   rM   r   r   )r   rE   r   r   r   rE   )r   r   r   rE   )r   r   r   r   ),r   
__future__r   argparser   r   loggingrA   collections.abcr   typingr   flake8r   r   flake8._compatr   r	   r
   r   flake8.plugins.finderr   	getLoggerr   r   	frozensetr   r   INDENTr   rv   r@   tuplerE   r_   r   rn   r   r   r   r   r   ra   rz   r   r7   r5   <module>r
     s.   L L " " " " " "  



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