=,dZddlZddlZddlZddlZddlZddlmZddlmZddlm Z ddlm Z ddlm Z ddlm Z dd l mZdd l mZdd lmZejeZeejejgZeejejejejgZe e ee eeffZe e ee eefZGd d Zdej de!fdZ"dej de!fdZ#dej de!fdZ$dededefdZ%dedefdZ&dedefdZ'dS)zFModule containing our file processor that tokenizes a file for checks.N)Any)Dict) Generator)List)Optional)Tuple)defaults)utils) LoadedPluginc |eZdZdZdZ d(dedejdee eddfdZ e de e j fd Zejd eded fd Zd)d Zd)dZd)dZdeddfdZdeddfdZd)dZdefdZdejfdZ de!eeeffdZ"de j deeddffdZ#de$ee%fde$ee&fde$ee&ffdZ'dee j ddffdZ(dedede$eeffd Z)d edeefd!Z*defd"Z+de efd#Z,de efd$Z-de efd%Z.de%fd&Z/d)d'Z0dS)* FileProcessora>Processes a file and holdes 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` FNfilenameoptionslinesreturnc||_||_||n||_|d|_d|_i|_i|_|j |_ d|_ d|_ |j |_ d|_ d|_|j|_|j|_d|_d|_d|_d|_g|_t-|j|_|j|_ddi|_d|_d|_dS)z]Initialice our file processor. :param filename: Name of the file to process NrF logical lines)rr read_linesr strip_utf_bom blank_before blank_lines_checker_states checker_state hang_closing indent_char indent_level indent_size line_number logical_linemax_line_lengthmax_doc_length multilineprevious_indent_levelprevious_logical previous_unindented_logical_linetokenslen total_linesverbose statistics _file_tokens_noqa_line_mapping)selfrrrs /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/flake8/processor.py__init__zFileProcessor.__init__<s    #/UUT__5F5F  :<-/#0*.".&6%4%&" "02-02 tz?? *A.@D<@c|j=t|jtt jfd|_|jS)z-Return the complete set of tokens for a file.Nc"tSN)next) line_itersr/z+FileProcessor.file_tokens..~s ir1)r,iterrlisttokenizegenerate_tokens)r.r6s @r/ file_tokenszFileProcessor.file_tokensxsR   $TZ((I $()@)@)@)@AA!!D   r1r)NNNc#<K||_d|_dVd|_dS)z2Context-manager to toggle the multiline attribute.TNF)rr#)r.rs r/inside_multilinezFileProcessor.inside_multilines+ ' r1cd|_dS)z)Reset the blank_before attribute to zero.rN)rr.s r/reset_blank_beforez FileProcessor.reset_blank_beforesr1c|jd=dS)z-Delete the first token in the list of tokens.rN)r'r@s r/delete_first_tokenz FileProcessor.delete_first_tokens KNNNr1c&|xjdz c_dS)z&Note that we visited a new blank line.N)rr@s r/visited_new_blank_linez$FileProcessor.visited_new_blank_lines Ar1mappingc|dd\}}|j|dz }t|d||_|j|jkr|j|_dSdS)z:Update the indent level based on the logical line mapping.rrEN)r expand_indentrrr)r.rG start_row start_col start_lines r/ update_statezFileProcessor.update_statesg!(AIZ A . )*ZiZ*@AA  t/ / / $ 0D    0 /r1plugincfd|jvr'|j|ji|_dSdS)z2Update the checker_state attribute for the plugin.rN) parametersr setdefault entry_namer)r.rNs r/update_checker_state_forz&FileProcessor.update_checker_state_forsA f/ / /!%!5!@!@!2""D    0 /r1c|jr+|j|_|j|_|js |j|_d|_g|_dS)zoRecord the previous logical line. This also resets the tokens list and the blank_lines count. rN)r rr$r%r&rr'r@s r/next_logical_linezFileProcessor.next_logical_linesP   J)-):D &$($5D !$ J8<8I5 r1cg}g}g}d}dx}}|jD]\}}} } } |tvr|sd| fg}|tjkr||?|tjkrt |}|rO| \} } || kr1|dz }|dz }|j||}|dks|dvr |dvrd|}n|| kr | || |z}|||t|z }||| f| \}}|||fS)z4Build the mapping, comments, and logical line lists.rNrE,z{[(}]) ) r' SKIP_TOKENSr:COMMENTappendSTRING mutate_stringrr()r.logicalcommentsrGlength previous_rowprevious_column token_typetextstartendlinerJ start_column row_index column_index previous_texts r/build_logical_line_tokensz'FileProcessor.build_logical_line_tokenssy#%)-- 26+ 2 2 .JeS$[(( 'u:,X---%%%X_,,$T** E,1)L9,, ,q 0I#2Q#6L$(Jy$9,$GM$++%U22t57H7H)4zz$ 44 <=DD NN4 c$ii F NNFC= ) ) ).1 +\??'))r1cZtjd|jS)z5Build an abstract syntax tree from the list of lines.r)astparsejoinrr@s r/ build_astzFileProcessor.build_asts y,,---r1c|\}}}d|}d||_|jdxxdz cc<||j|fS)z2Build a logical line from the current tokens list.rrrE)rmrqr r+)r.r`r_ mapping_listjoined_commentss r/build_logical_linez FileProcessor.build_logical_linesm*.*H*H*J*J''<''(++GGG,, (((A-((( 1<??r1tokenc#Kt|jd|jdD]$}|j|dz V|xjdz c_%dS)z|Split a physical line's line based on new-lines. This also auto-increments the line number for the caller. rrEN)rangerfrgrr)r.rwline_nos r/ split_linezFileProcessor.split_lineseU[^UYq\:: " "G*Wq[) ) ) )    !    " "r1rP argumentsci}|D]L\}}||vr t||||<#t$r!|rtd|YIwxYw|S)z8Generate the keyword arguments for a list of parameters.zPPlugin requested optional parameter "%s" but this is not an available parameter.)itemsgetattrAttributeErrorLOGwarning)r.rPr|retparamrequireds r/keyword_arguments_forz#FileProcessor.keyword_arguments_fors )//11  OE8 !! $T511E !   KKB   s6(A! A!c#Ktj|jD]:}|dd|jkrdS|j||V;dS)z'Tokenize the file and yield the tokens.rN)r:r; next_liner)r'r\)r.rws r/r;zFileProcessor.generate_tokenssj-dn==  EQx{T--- K  u % % %KKKK   r1min_linemax_linect||dz}d|j|dz |}t||S)NrEr)ryrqrdictfromkeys)r.rr line_rangejoineds r/_noqa_line_rangezFileProcessor._noqa_line_rangesJ8X\22 HqL8$;<==}}Z000r1c~|j |j}i}t|jdz}d}|D]\}}\}}\} }}|tjkrn}t ||}t|| }|tjtj fvrB| | ||t|jdz}d}|dkr)| | ||||_n##tj tf$r i|_YnwxYw|j|S)z7Retrieve the line which will be used to determine noqa.Nr)r-r<r(rr: ENDMARKERminmaxNLNEWLINEupdater TokenError SyntaxErrorget) r.rr<rrrtp_s_linee_lines r/ noqa_line_forzFileProcessor.noqa_line_fors_  " * .". tz??Q.:E & &6B;FA QX///"8V44H"8V44Hhk8+;<<< 4#8#88#L#LMMM#&tz??Q#6#% r>>JJt44XxHHIII*-''9'5 - - -+-''' -B&**;777sDD"!D"c|j|jkrdS|j|j}|xjdz c_|j#|ddtjvr |d|_|S)z Get the next line from the list.rrENr)rr)rrr WHITESPACE)r.rhs r/rzFileProcessor.next_line=sj  t/ / /2z$*+ A   #RaRH4G(G(G#AwD  r1c|j |jdkr(|jjpd|_|}n|}|S)z%Read the lines for this file checker.N-stdin)rrstdin_display_nameread_lines_from_stdinread_lines_from_filename)r.rs r/rzFileProcessor.read_linesGsP = DMS$8$8 L;FwDM..00EE1133E r1cJ tj|j5}|cdddS#1swxYwYdS#tt f$rHt|jd5}|cdddcYS#1swxYwYYdSwxYw)zRead the lines for a file.Nzlatin-1)encoding)r:openr readlinesr UnicodeError)r.fds r/rz&FileProcessor.read_lines_from_filenamePs7 &t}-- &||~~ & & & & & & & & & & & & & & & & & &\* & & &dmi888 &B||~~ & & & & & & & & & & & & & & & & & & & & & &sUA < A AA AA 'B"0B B"B B"B B"!B"c(tjS)z Read the lines from standard in.)r stdin_get_linesr@s r/rz#FileProcessor.read_lines_from_stdin[s$&&&r1c|jjs td|jDrdStd|jDrtddSdS)zCheck if ``flake8: noqa`` is in the file to be ignored. :returns: True if a line matches :attr:`defaults.NOQA_FILE`, otherwise False c3TK|]#}tj|V$dSr4)r NOQA_FILEmatch.0rhs r/ z3FileProcessor.should_ignore_file..fsD1 1 /3H  $ $T * *1 1 1 1 1 1 r1Tc3TK|]#}tj|V$dSr4)r rsearchrs r/rz3FileProcessor.should_ignore_file..js3HHT#**400HHHHHHr1z[Detected `flake8: noqa` on line with code. To ignore an error on a line use `noqa` instead.F)r disable_noqaanyrrrr@s r/should_ignore_filez FileProcessor.should_ignore_file_s|( S1 1 7;z1 1 1 . . 4 HHTZHHH H H  KK6   55r1c|jsdSt|jdd}|dvrdS|dkr|jddd|jd<dS|jddddkr|jddd|jd<dSdS)z-Strip the UTF bom from the lines of the file.Nr)rrEu)rord)r. first_bytes r/rzFileProcessor.strip_utf_bomssz  FAq)** ^ + + F    JqM!""-DJqMMM Z]2A2 . 0 0 JqM!""-DJqMMM1 0r1r4)rN)1__name__ __module__ __qualname____doc__noqastrargparse Namespacerrr0propertyr: TokenInfor< contextlibcontextmanagerintrr>rArCrF_LogicalMappingrMr rSrU_LogicalrmroASTrrrrvr{rboolrrr;rrrrrrrrr1r/r r s8 D &* :A:A:A#:AS " :A  :A:A:A:Ax!T("45!!!X! # $1O11111|    !*8!*!*!*!*F.37....@E#sO*C$D@@@@ "' " 3d? # " " " "dOS> c3h .8+=tT+I!J111S#X1111 &8&8#&8&8&8&8P3DI &$s) & & & &'tCy''''D(......r1r rwrc|dtvp1|d|ddddkS)z+Check if the token is an end-of-line token.rrrENz\ )rlstriprws r/ is_eol_tokenrs< 8w  L%(58A;=="9"@"@"B"Bf"LLr1cB|dtjko d|dvS)z$Check if this is a multiline string.r rE)r:r]rs r/is_multiline_stringrs! 8x & ;458+;;r1c |dtvS)z0Check if the token type is a newline token type.r)rrs r/token_is_newliners 8w r1current_parentheses_count token_textc*|dvr|dzS|dvr|dz S|S)z Count the number of parentheses.z([{rErXr)rrs r/count_parenthesesrs4U(1,, u  (1,, $$r1rhcFt|dS)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)rhs r/rIrIs tq!! " ""r1rec||ddz}t|dz }|dddvr |dz }|dz}|d|d||z zz||dzS)zReplace contents with 'xxx' to prevent syntax matching. >>> mutate_string('"abc"') '"xxx"' >>> mutate_string("'''abc'''") "'''xxx'''" >>> mutate_string("r'abc'") "r'xxx'" rrEN)z"""z'''rx)indexr()rerfrgs r/r^r^s{ JJtBx 1 $E d))a-C BCCyN""   q <#u- -STT ::r1)(rrrorloggingr:typingrrrrrrflake8r r flake8.plugins.finderr getLoggerrr frozensetrrINDENTDEDENTrZrrrrr rrrrrrrIr^rr1r/rsLL ......g!! )X[("23 4 4i [("HOX_E uS%S/123 cDI6 7d.d.d.d.d.d.d.d.N M*MtMMMM