
    \Og+@                       S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSKJ
r
  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  \R*                  " \5      r\" \R2                  \R4                  /5      r\" \R2                  \R4                  \R6                  \R8                  /5      r\\\\\\4   4      r\\\    \\    \4   r! " S S5      r"SS jr#SS jr$SS jr%SS jr&SS jr'SS jr(g)zFModule containing our file processor that tokenizes a file for checks.    )annotationsN)Any)	Generator)List)Tuple)defaults)utils)FSTRING_END)FSTRING_MIDDLE)LoadedPluginc                  p   \ rS rSrSrSr S       SS jjr\R                  S S j5       r	S!S jr
    S"S jrS#S	 jrS#S
 jrS#S jrS$S jrS%S jrS#S jrS&S jrS'S jrS(S jr      S)S jrS*S jrS+S jr\R                  S,S j5       rS-S jrS.S jrS/S jrS/S jrS/S jrS0S jrS#S jrSr g)1FileProcessor   a  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                $   X l         Xl        Ub  UOU R                  5       U l        U R	                  5         SU l        SU l        0 U l        0 U l        UR                  U l	        SU l
        SU l        UR                  U l        SU l        SU l        UR                  U l        UR                   U l        SU l        SU l        SU l        SU l        / U l        [-        U R                  5      U l        UR0                  U l        SS0U l        SU l        g)zMInitialize 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       U/Users/admin/workspace/ai/Jarvis/env/lib/python3.13/site-packages/flake8/processor.py__init__FileProcessor.__init__>   s      #/UT__5F
 :<-/#00'+"..&66%44%&" "02-02tzz?*A.     c                t   ^ [        U R                  5      m[        [        R                  " U4S j5      5      $ )z-Return the complete set of tokens for a file.c                    > [        T 5      $ N)next)	line_iters   r0   <lambda>+FileProcessor.file_tokens.<locals>.<lambda>|   s	    T)_r3   )iterr   listtokenizegenerate_tokens)r/   r8   s    @r0   file_tokensFileProcessor.file_tokensx   s*     $	H,,-DEFFr3   c                    Xl         g)z#Signal the beginning of an fstring.N)r.   )r/   linenos     r0   fstring_startFileProcessor.fstring_start~   s    $r3   c              #  8  #    UR                   [        :X  a  U R                  nOUR                  S   nSU l        X l        [        X!R                  S   5       H6  nU R                  U R
                  S-
     v   U =R
                  S-  sl        M8     SU l        g7f)z0Iterate through the lines of a multiline string.r   T   FN)	typer
   r.   startr%   r!   rangeendr   )r/   tokenrH   _s       r0   multiline_stringFileProcessor.multiline_string   s      ::$''EKKNE  uiil+A**T--122! , s   BBc                    SU l         g)z)Reset the blank_before attribute to zero.r   N)r   r/   s    r0   reset_blank_before FileProcessor.reset_blank_before   s
    r3   c                    U R                   S	 g)z-Delete the first token in the list of tokens.r   N)r)   rP   s    r0   delete_first_token FileProcessor.delete_first_token   s    KKNr3   c                .    U =R                   S-  sl         g)z&Note that we visited a new blank line.rF   N)r   rP   s    r0   visited_new_blank_line$FileProcessor.visited_new_blank_line   s    Ar3   c                    US   S   u  p#U R                   US-
     n[        USU 5      U l        U R                  U R                  :  a  U R                  U l        gg)z:Update the indent level based on the logical line mapping.r   rF   N)r   expand_indentr   r   r   )r/   mapping	start_row	start_col
start_lines        r0   update_stateFileProcessor.update_state   s_    !(AZZ	A.
)*Zi*@At/// $ 0 0D 0r3   c                |    SUR                   ;   a,  U R                  R                  UR                  0 5      U l        gg)z2Update the checker_state attribute for the plugin.r   N)
parametersr   
setdefault
entry_namer   )r/   plugins     r0   update_checker_state_for&FileProcessor.update_checker_state_for   s9    f///!%!5!5!@!@!!2"D 0r3   c                    U R                   (       aD  U R                  U l        U R                   U l        U R                  (       d  U R                   U l        SU l        / U l        g)z_Record the previous logical line.

This also resets the tokens list and the blank_lines count.
r   N)r"   r   r&   r'   r(   r   r)   rP   s    r0   next_logical_lineFileProcessor.next_logical_line   sO    
 )-):):D&$($5$5D!$$8<8I8I5r3   c                   / n/ n/ nSnS=pVU R                    GH7  u  pxpnU[        ;   a  M  U(       d  SU	4/nU[        R                  :X  a  UR	                  U5        MG  U[        R
                  :X  a  [        U5      nOKU[        :X  aA  UR                  S5      UR                  S5      -   nS[        U5      U-   -  nU
S   U
S   U-   4n
U(       aI  U	u  pX]:w  a4  US-
  nUS-
  nU R                  U   U   nUS:X  d  US;  a  US	;  a  S
U 3nOXn:w  a  XU U-   nUR	                  U5        U[        U5      -  nUR	                  XJ45        U
u  pVGM:     X!U4$ )z4Build the mapping, comments, and logical line lists.r   N{}xrF   ,z{[(}]) )r)   SKIP_TOKENSr=   COMMENTappendSTRINGmutate_stringr   countr*   r   )r/   logicalcommentsr[   lengthprevious_rowprevious_column
token_typetextrH   rJ   linebrace_offsetr\   start_column	row_indexcolumn_indexprevious_texts                     r0   build_logical_line_tokens'FileProcessor.build_logical_line_tokens   s~   #%)--26++.Je$[(u:,X---%X__,$T*~-
  $zz#C@c$i,671vs1v45,1), ,q 0I#2Q#6L$(JJy$9,$GM$+%U2t57H!"4&z$4=DDNN4 c$iFNNF=).1+\?C 3>D '))r3   c                `    [         R                  " SR                  U R                  5      5      $ )z5Build an abstract syntax tree from the list of lines.r   )astparsejoinr   rP   s    r0   	build_astFileProcessor.build_ast   s    yy,--r3   c                    U R                  5       u  pnSR                  U5      nSR                  U5      U l        U R                  S==   S-  ss'   X@R                  U4$ )z2Build a logical line from the current tokens list.r   r   rF   )r   r   r"   r-   )r/   ry   rx   mapping_listjoined_commentss        r0   build_logical_line FileProcessor.build_logical_line   sY    *.*H*H*J'<''(+GGG,(A-( 1 1<??r3   c                    0 nUR                  5        H  u  pEXB;   a  M   [        X5      X4'   M     U$ ! [         a"    U(       a  e [        R	                  SU5         MK  f = f)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/   rb   	argumentsretparamrequireds         r0   keyword_arguments_for#FileProcessor.keyword_arguments_for   sk     )//1OE!
$T1
	  2 
 " KKB	s   3(AAc              #     #    [         R                  " U R                  5       H:  nUS   S   U R                  :  a    gU R                  R                  U5        Uv   M<     g7f)z'Tokenize the file and yield the tokens.   r   N)r=   r>   	next_liner+   r)   rt   )r/   rK   s     r0   r>   FileProcessor.generate_tokens
  sN     --dnn=EQx{T---KKu%K	 >s   A A"c                    [        XS-   5      nSR                  U R                  US-
  U 5      n[        R	                  X45      $ )NrF   r   )rI   r   r   dictfromkeys)r/   min_linemax_line
line_rangejoineds        r0   _noqa_line_rangeFileProcessor._noqa_line_range  s<    8\2
HqL8<=}}Z00r3   c                    U R                   n0 n[        U R                  5      S-   nSnU H  u  pVu  pvu  n  nU[        R                  :X  d  U[        R
                  :X  a  M7  [        X75      n[        XH5      nU[        R                  [        R                  4;   d  Ms  UR                  U R                  X45      5        [        U R                  5      S-   nSnM     U$ ! [        R                  [        4 a    0 s $ f = f)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   tprL   s_linee_lines	            r0   _noqa_line_mapping FileProcessor._noqa_line_mapping  s    	**K C4::*HH6A2{KVQ+++rX__/Dx0x0(++x'7'788JJt44XHI"4::2H!H 7B J- ##[1 	 I	s   C C>=C>c                8    U R                   R                  U5      $ )z7Retrieve the line which will be used to determine noqa.)r   get)r/   r!   s     r0   noqa_line_forFileProcessor.noqa_line_for4  s    
 &&**;77r3   c                    U R                   U R                  :  a  gU R                  U R                      nU =R                   S-  sl         U R                  c!  USS [        R
                  ;   a
  US   U l        U$ )z Get the next line from the list.r   rF   Nr   )r!   r+   r   r   r   
WHITESPACE)r/   r   s     r0   r   FileProcessor.next_line;  sn    t///zz$**+A#RaH4G4G(G#AwDr3   c                    U R                   S:X  a6  U R                  R                  =(       d    SU l         U R                  5       nU$ U R	                  5       nU$ )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     r0   r   FileProcessor.read_linesE  sN    ==C LL;;FwDM..0E  113Er3   c                F    [         R                  " U R                  5       nUR                  5       sSSS5        $ ! , (       d  f       g= f! [        [
        4 aC    [        U R                  SS9 nUR                  5       sSSS5        s $ ! , (       d  f        g= ff = f)zRead the lines for a file.Nzlatin-1)encoding)r=   openr   	readlinesr   UnicodeError)r/   fds     r0   r   &FileProcessor.read_lines_from_filenameN  sk    	&t}}-||~ .--\* 	& dmmi8B||~ 9888	&sC    A <	A 
A
A 
A $B 1B
B 
B	B B c                ,    [         R                  " 5       $ )z Read the lines from standard in.)r	   stdin_get_linesrP   s    r0   r   #FileProcessor.read_lines_from_stdinY  s    $$&&r3   c                    U R                   R                  (       d"  [        S U R                   5       5      (       a  g[        S U R                   5       5      (       a  [        R                  S5        gg)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  `   #    U  H$  n[         R                  R                  U5      v   M&     g 7fr6   )r   	NOQA_FILEmatch.0r   s     r0   	<genexpr>3FileProcessor.should_ignore_file.<locals>.<genexpr>d  s'      1
7AtH$$T**z   ,.Tc              3  `   #    U  H$  n[         R                  R                  U5      v   M&     g 7fr6   )r   r   searchr   s     r0   r   r   h  s$     HZT##**400Zr   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   rP   s    r0   should_ignore_file FileProcessor.should_ignore_file]  sa     ||((S 1
7;zz1
 .
 .
 HTZZHHHKK6 r3   c                    U R                   (       d  gU R                   S   SS S:X  a   U R                   S   SS U R                   S'   gU R                   S   SS S:X  a   U R                   S   SS U R                   S'   gg)z-Strip the UTF bom from the lines of the file.Nr   rF   u   ﻿   u   ï»¿)r   rP   s    r0   r   FileProcessor.strip_utf_bomq  sy    zz ::a=!( JJqM!"-DJJqMZZ]2A.0 JJqM!"-DJJqM 1r3   )r   r.   r   r   r   r   r   r   r   r    r!   r   r"   r$   r#   r%   r   r&   r'   r(   r-   r)   r+   r,   r6   )r   strr   zargparse.Namespacer   zlist[str] | NonereturnNone)r   zlist[tokenize.TokenInfo])rB   intr   r   )rK   tokenize.TokenInfor   zGenerator[str, None, None])r   r   )r[   _LogicalMappingr   r   )re   r   r   r   )r   _Logical)r   zast.AST)r   z tuple[str, str, _LogicalMapping])rb   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____firstlineno____doc__noqar1   	functoolscached_propertyr?   rC   rM   rQ   rT   rW   r_   rf   ri   r   r   r   r   r>   r   r   r   r   r   r   r   r   r   __static_attributes__ r3   r0   r   r      s   8 D #'	8!8! $8!  	8!
 
8!t G G
%'	#$1)*V.@# " 
	.1
  88	&'(
.r3   r   c                f    U S   [         ;   =(       d    U S   U S   S   S R                  5       S:H  $ )z+Check if the token is an end-of-line token.r      r   rF   Nz\
)r   lstriprK   s    r0   is_eol_tokenr   ~  s7    8wL%(58A;="9"@"@"Bf"LLr3   c                    U R                   [        :H  =(       d3    U R                   [        R                  :H  =(       a    SU R                  ;   $ )z$Check if this is a multiline string.
)rG   r
   r=   ru   stringr   s    r0   is_multiline_stringr     s6    ::$ 

hoo%>$%,,*>r3   c                    U S   [         ;   $ )z0Check if the token type is a newline token type.r   )r   r   s    r0   token_is_newliner    s    8wr3   c                2    US;   a  U S-   $ US;   a  U S-
  $ U $ )z Count the number of parentheses.z([{rF   rp   r   )current_parentheses_count
token_texts     r0   count_parenthesesr    s.    U(1,,	u	(1,,$$r3   c                6    [        U R                  S5      5      $ )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    r0   rZ   rZ     s     tq!""r3   c                    U R                  U S   5      S-   n[        U 5      S-
  nU SS S;   a
  US-  nUS-  nU SU SX!-
  -  -   XS -   $ )zReplace contents with 'xxx' to prevent syntax matching.

>>> mutate_string('"abc"')
'"xxx"'
>>> mutate_string("'''abc'''")
"'''xxx'''"
>>> mutate_string("r'abc'")
"r'xxx'"
r   rF   N)z"""z'''r   rn   )indexr*   )r~   rH   rJ   s      r0   rv   rv     si     JJtBx 1$E
d)a-CBCyN"
q<#--T
::r3   )rK   r   r   r   )r  r   r  r   r   r   )r   r   r   r   )r~   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   rr   r   r   r   r   r   r   r   r  r  rZ   rv   r   r3   r0   <module>r     s    L "  
          & ) .!
X[[("2"23
4[[(""HOOX__E uS%S/123cDI67\. \.~
M

%#(;r3   