
    2yiA                       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j4                  ej6                  g      Z eej4                  ej6                  ej8                  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+y)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                  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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)0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                4   || _         || _        ||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x| _        | _        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_tstring_start)selfr   r   r   s       R/var/www/html/content_weaver/venv/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.466d1    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   r0   <lambda>z+FileProcessor.file_tokens.<locals>.<lambda>|   s    T)_ r2   )iterr   listtokenizegenerate_tokens)r/   r7   s    @r0   file_tokenszFileProcessor.file_tokensx   s*     $	H,,-DEFFr2   c                    || _         y)z#Signal the beginning of an fstring.N)r-   r/   linenos     r0   fstring_startzFileProcessor.fstring_start~   
    $r2   c                    || _         y)z#Signal the beginning of an tstring.N)r.   r?   s     r0   tstring_startzFileProcessor.tstring_start   rB   r2   c              #  v  K   |j                   t        k(  r| j                  }n/|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-   r
   r.   startr$   r    rangeendr   )r/   tokenrH   _s       r0   multiline_stringzFileProcessor.multiline_string   s     ::$''EZZ;&''EKKNE  ueiil+ 	"A**T--122!	" s   B7B9c                    d| _         y)z)Reset the blank_before attribute to zero.r   N)r   r/   s    r0   reset_blank_beforez FileProcessor.reset_blank_before   s
    r2   c                    | j                   d= y)z-Delete the first token in the list of tokens.r   N)r(   rO   s    r0   delete_first_tokenz FileProcessor.delete_first_token   s    KKNr2   c                .    | xj                   dz  c_         y)z&Note that we visited a new blank line.rF   N)r   rO   s    r0   visited_new_blank_linez$FileProcessor.visited_new_blank_line   s    Ar2   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   rF   N)r   expand_indentr   r   r   )r/   mapping	start_row	start_col
start_lines        r0   update_statezFileProcessor.update_state   sa    !(AIZZ	A.
)*Zi*@At/// $ 0 0D 0r2   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     r0   update_checker_state_forz&FileProcessor.update_checker_state_for   s9    f///!%!5!5!@!@!!2"D 0r2   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(   rO   s    r0   next_logical_linezFileProcessor.next_logical_line   sO    
 )-):):D&$($5$5D!$$8<8I8I5r2   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        |      }nO|t        t        hv rA|j                  d      |j                  d      z   }dt        |      |z   z  }|
d   |
d   |z   f}
|H|F|	\  }}||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       |
\  }}0 |||fS )z4Build the mapping, comments, and logical line lists.r   N{}xrF   ,z{[(}]) )r(   SKIP_TOKENSr;   COMMENTappendSTRINGmutate_stringr	   r   countr)   r   )r/   logicalcommentsrW   lengthprevious_rowprevious_column
token_typetextrH   rJ   linebrace_offsetrX   start_column	row_indexcolumn_indexprevious_texts                     r0   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'O,G,1)L9, ,q 0I#2Q#6L$(JJy$9,$GM$+%U2t57H!"4&z$4=DDNN4 c$iFNNFC=).1+\?I$	2J '))r2   c                ^    t        j                  dj                  | j                              S )z5Build an abstract syntax tree from the list of lines.r   )astparsejoinr   rO   s    r0   	build_astzFileProcessor.build_ast   s    yy,--r2   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   rF   )r~   r   r!   r,   )r/   rr   rq   mapping_listjoined_commentss        r0   build_logical_linez FileProcessor.build_logical_line   s]    *.*H*H*J''<''(+GGG,(A-( 1 1<??r2   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/   r]   	argumentsretparamrequireds         r0   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(   rm   )r/   rK   s     r0   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 )NrF   r   )rI   r   r   dictfromkeys)r/   min_linemax_line
line_rangejoineds        r0   _noqa_line_rangezFileProcessor._noqa_line_range  s@    8X\2
HqL8<=}}Z00r2   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   tprL   s_linee_lines	            r0   _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     r0   noqa_line_forzFileProcessor.noqa_line_for;  s    
 &&**;77r2   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   rF   Nr   )r    r*   r   r   r   
WHITESPACE)r/   rx   s     r0   r   zFileProcessor.next_lineB  sn    t///zz$**+A#RaH4G4G(G#AwDr2   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     r0   r   zFileProcessor.read_linesL  sN    ==C LL;;FwDM..0E  113Er2   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     r0   r   z&FileProcessor.read_lines_from_filenameU  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_linesrO   s    r0   r   z#FileProcessor.read_lines_from_stdin`  s    $$&&r2   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r5   )r   	NOQA_FILEmatch.0rx   s     r0   	<genexpr>z3FileProcessor.should_ignore_file.<locals>.<genexpr>k  s&      1
/3H$$T*1
   )+Tc              3  Z   K   | ]#  }t         j                  j                  |       % y wr5   )r   r   searchr   s     r0   r   z3FileProcessor.should_ignore_file.<locals>.<genexpr>o  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   rO   s    r0   should_ignore_filez FileProcessor.should_ignore_filed  sY     ||((S 1
7;zz1
 .
 HTZZHHKK6 r2   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   rF   u   ﻿   u   ï»¿)r   rO   s    r0   r   zFileProcessor.strip_utf_bomx  sy    zz ::a=!( JJqM!"-DJJqMZZ]2A.0 JJqM!"-DJJqM 1r2   r5   )r   strr   zargparse.Namespacer   zlist[str] | NonereturnNone)r   zlist[tokenize.TokenInfo])r@   intr   r   )rK   tokenize.TokenInfor   zGenerator[str])r   r   )rW   _LogicalMappingr   r   )r`   r   r   r   )r   _Logical)r   zast.AST)r   z tuple[str, str, _LogicalMapping])r]   zdict[str, bool]r   dict[str, Any]r   r   )r   zGenerator[tokenize.TokenInfo])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__noqar1   	functoolscached_propertyr=   rA   rD   rM   rP   rR   rT   r[   ra   rc   r~   r   r   r   r<   r   r   r   r   r   r   r   r   r    r2   r0   r   r      s   8 D #'	8787 $87  	87
 
87t G G
%%$1,*\.@# " 
	.1
  88	&'(
.r2   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   rF   Nz\
)r   lstriprK   s    r0   is_eol_tokenr     s7    8wL%(58A;="9"@"@"Bf"LLr2   c                    | j                   t        t        hv xs- | j                   t        j                  k(  xr d| j
                  v S )z$Check if this is a multiline string.
)rG   r   r
   r;   rn   stringr   s    r0   is_multiline_stringr     s;    ::+{33 

hoo%>$%,,*>r2   c                    | d   t         v S )z0Check if the token type is a newline token type.r   )r   r   s    r0   token_is_newliner     s    8wr2   c                *    |dv r| dz   S |dv r| dz
  S | S )z Count the number of parentheses.z([{rF   ri   r   )current_parentheses_count
token_texts     r0   count_parenthesesr     s.    U(1,,	u	(1,,$$r2   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)rx   s    r0   rV   rV     s     tq!""r2   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   rF   N)z"""z'''r   rg   )indexr)   )rw   rH   rJ   s      r0   ro   ro     sm     JJtBx 1$E
d)a-CBCyN"
q<#u--ST
::r2   )rK   r   r   r   )r   r   r   r   r   r   )rx   r   r   r   )rw   r   r   r   ),r   
__future__r   argparser   r   loggingr;   collections.abcr   typingr   flake8r   r   flake8._compatr   r	   r
   r   flake8.plugins.finderr   	getLoggerr   r   	frozensetr   r   INDENTr   rk   r:   tupler   r   r   r   r   r   r   r   r   rV   ro   r   r2   r0   <module>r     s    L "  
    %    & ) & ) .g!
X[[("2"23
4[[(""HOOX__E uS%S/123cDI67c. c.LM

%#(;r2   