bgPUdZddlmZddlZddlZddlZddlZddlmZddlm Z m Z ddl m Z ddl Z ddl mZmZmZddlmZdd lmZmZmZmZdd lmZdd lmZdd lmZe rdd lmZej dkrddl m!Z!nddl"m!Z!dZ#hdZ$ej%dd&e$dZ'ej%dd&e$dZ(ej%dd&e$dej)Z*idddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<Z+d=e,d><ej-ej.ej/ej0ej1ej2ej3fZ4dYdEZ5dZdJZ6GdKdLeZ7GdMdNeeZ8d[dRZ9d\dTZ:d]dVZ;d^dWZBFRUbfruBRBrFRFrRBRFRbRfbRbrfRfrrBrFrbrf(|z)?'''z)?"""z)?("|')E1300)z3Unsupported format character %r (%#02x) at index %dbad-format-characterzEUsed when an unsupported format character is used in a format string.E1301)z4Format string ends in middle of conversion specifiertruncated-format-stringzNUsed when a format string terminates before the end of a conversion specifier.E1302)z?Mixing named and unnamed conversion specifiers in format stringmixed-format-stringzUsed when a format string contains both named (e.g. '%(foo)d') and unnamed (e.g. '%d') conversion specifiers. This is also used when a named conversion specifier contains * for the minimum field width and/or precision.E1303)z*Expected mapping for format string, not %sformat-needs-mappingzoUsed when a format string that uses named conversion specifiers is used with an argument that is not a mapping.W1300)z7Format string dictionary key should be a string, not %sbad-format-string-keyzyUsed when a format string that uses named conversion specifiers is used with a dictionary whose keys are not all strings.W1301)z)Unused key %r in format string dictionaryunused-format-string-keyzUsed when a format string that uses named conversion specifiers is used with a dictionary that contains keys not required by the format string.E1304)z*Missing key %r in format string dictionarymissing-format-string-keyzUsed when a format string that uses named conversion specifiers is used with a dictionary that doesn't contain all the keys required by the format string.E1305)z$Too many arguments for format stringtoo-many-format-argsz^Used when a format string that uses unnamed conversion specifiers is given too many arguments.E1306)z&Not enough arguments for format stringtoo-few-format-argsz\Used when a format string that uses unnamed conversion specifiers is given too few argumentsE1307)z)Argument %r does not match format type %rbad-string-format-typezSUsed when a type required by format string is not suitable for actual argument typeE1310)z!Suspicious argument in %s.%s callbad-str-strip-callzFThe argument to a str.{l,r,}strip call contains a duplicate character,W1302)zInvalid format stringbad-format-stringz.Used when a PEP 3101 format string is invalid.W1303)z-Missing keyword argument %r for format stringmissing-format-argument-keyzhUsed when a PEP 3101 format string that uses named fields doesn't receive one or more required keywords.W1304)zUnused format argument %runused-format-string-argumentz}Used when a PEP 3101 format string that uses named fields is used with an argument that is not required by the format string.W1305)zTFormat string contains both automatic field numbering and manual field specificationformat-combined-specificationzUsed when a PEP 3101 format string contains both automatic field numbering (e.g. '{}') and manual field specification (e.g. '{0}').W1306)z2Missing format attribute %r in format specifier %rmissing-format-attributezUsed when a PEP 3101 format string uses an attribute specifier ({0.length}), but the argument passed for formatting doesn't have that attribute.W1307)z2Using invalid lookup key %r in format specifier %rinvalid-format-indexzUsed when a PEP 3101 format string uses a lookup specifier ({a[1]}), but the argument passed for formatting doesn't contain or doesn't have that key as an attribute.)zKDuplicate string formatting argument %r, consider passing as named argument$duplicate-string-formatting-argumentzmUsed when we detect that a string formatting is repeating an argument instead of using named string arguments)z?Using an f-string that does not have any interpolated variablesf-string-without-interpolationzUsed when we detect an f-string that does not use any interpolation variables, in which case it can be either a normal string or a bug in the code.)zKUsing formatting for a string that does not have any interpolated variables#format-string-without-interpolationzUsed when we detect a string that does not have any interpolation variables, in which case it can be either a normal string without formatting or a bug in the code.)W1308W1309W1310z!dict[str, MessageDefinitionTuple]MSGSkeystr | Literal[0]partslist[tuple[bool, str]]returnstrcg}|D]9\}}|r|d| |d|d:t|d|zS)z]Given a list of format specifiers, returns the final access path (e.g. a.b.c[0][1]). .[])appendr`join)r[r]path is_attribute specifiers h/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/pylint/checkers/strings.pyget_access_pathrls| D#(,, i  , KKI ( ( ( ( KK*I*** + + + + s88bggdmm ##arg_typer format_typeboolc|dvrdSt|tjr4|}|dkr|dkS|dkr|dvS|dkrdSdSdS) NsrTrczbuiltins.floatz deEfFgGn%z builtins.intF) isinstanceastroidInstancepytype)rnros rkarg_matches_format_typerxsdt(G,-- ??$$ ~ % %#% % ' ' '+- - ~ % %4u 4rmc eZdZdZdZeZeddddddd d d d d d%dZedd&dZ d&dZ d'dZ d(dZ d)dZ d*d#Zd$S)+StringFormatCheckerzChecks string formatting operations to ensure that the format string is valid and the arguments match the format string. stringr3r5r7r;r?r=rEr9rArCrVnode nodes.BinOpr_Nonec  |jdkrdS|j}|j}t|tjrt|jtsdS|j} tj |\}}}}n#tj $rE} || j } | d|| t| | j fYd} ~ dSd} ~ wtj$r| d|YdSwxYw|s|s| d|dS|r|r| d|dS|rt|tjr{t!} d} |jD]l\} }t| tjrK| j}t|tr| |Q| d ||jd } m| s!|D]}|| vr| d ||| D]}||vr| d |||jD]\}}t|tjs ||jd}tj|}|X|rVt|t*js> Fyz4-- *TZ2M2M  F   )-88  !"""/   %ci0I   &Y;     FFFFF+      6T  B B B FF  %6    B  N N N F o .o    2  > > > > > k  $ ++/ Tuu$  J,,DAq!!U[11 ,g%c3// HHSMMMM ,, 7d-(, #,d?? ,, ;$S- C-//((6T)!% HC%c5;77! "4"8"8D"I"IK$/44H#/$0 *8T5I J J0!8+ N N0 ((4!%"*//"3"3[!A) D; "<== T JJ/   !7d SSSSS T TI$ ,, !,T22 i)<==. )I"9~~HD;U^0L"MNN !F D%*--  +D11h 44 $!) I"9~~HH%+66$!) I HH#HH  #///$$%;$$GGGG 111$$%:$FFF(+I7I(J(J  $C! $/44H   *8T5I J J !8+ N N  ((4!%"*//"3"3[!A)$#  sA44C0:C)C0/C0rUnodes.JoinedStrc0||dSN)_check_interpolationrr|s rkvisit_joinedstrz#StringFormatChecker.visit_joinedstrs !!$'''''rmct|jtjrdS|jD]}t|tjrdS |d|dS)NrUr)rtparentr FormattedValuevaluesr)rr|rs rkrz(StringFormatChecker._check_interpolationsp dk5#7 8 8  F[  E%!566   9EEEEErm nodes.Callctj|j}t|tjrt|jtjr|jjdvr|jdvr|j rtj|j d}t|tj rt|j tsdSt|j tt|j kr+|d||jj|jfdSdS|jdkr|||dSdSdSdSdS)N>r`bytesunicode>striplstriprstriprrGrformat)rrfuncrtru BoundMethodboundrvnamerr rrr`rrr_check_new_format)rr|rrs rk visit_callzStringFormatChecker.visit_calls_ ** tW0 1 1 34:w'788 3 #>>>y999di9&ty|44!#u{33:ciQT;U;UFsy>>SSY%8%888$$,!"joty9%98 h&&&&tT22222! 3 3 3 3?>'&rmpositional_argumentslist[SuccessfulInferenceResult]ctjd|D}|D]%\}}|dkr |d||f&dS)Nc3XK|]%}t|tj|jV&dSr)rtr rr).0rs rk zAStringFormatChecker._detect_vacuous_formatting..sI& &  3 8S8S& H& & & & & & rmrrTr) collectionsrrr)rr|rcounterrcounts rk_detect_vacuous_formattingz.StringFormatChecker._detect_vacuous_formattings%& & 4& & &   #==??  KD%zz   6T       rmrbases.BoundMethodc~t|jtjr&t|jjtjsdS|js|jrdS t|j }n#tj $rYdSwxYwt|tjrt|j tsdS tjj|}n#tj $rYdSwxYw t%j|j \}}}n-#t$j$r|d|YdSwxYw|j}|j} d|D} |r|r|d|dSd} |t1d| Dz }| ro| D]!} | r| | vr|d|| f "| D]} | | vr|d || f  |p|}|s|r t3d | D } | s| rd } nd } | rt|p|}|s|d |dSt5||kr|d|n*t5||kr|d|||||||| dS)z Check the new string formatting.NrIrcTh|]%}t|dt|d&S)r)rtr`rfields rk z8StringFormatChecker._check_new_format..s/RRRU 58S8Q8QRaRRRrmrOFc3K|]}|dV dS)rNrs rkrz8StringFormatChecker._check_new_format..s'AAe5AAAAAAArmrKrrMc3K|]}|VdSrrrs rkrz8StringFormatChecker._check_new_format..s"@@%@@@@@@rmTrVrArC)rtrr AttributeexprrstarargskwargsnextrinferruInferenceErrorrr` argumentsCallSite from_callrparse_format_method_stringrrrkeyword_argumentssumallrr_check_new_format_specifiers)rr|rstrnode call_sitefieldsr manual_posrnamed_arguments named_fields check_argsremptys rkrz%StringFormatChecker._check_new_formats di 1 1 * INEK; ;   F = DK  F 4:++--..GG%    FF 7EK00 Z s5S5S  F )2<>BB $C00DDD%%&EEr(list[tuple[str, list[tuple[bool, str]]]]named$dict[str, SuccessfulInferenceResult]c|D]\}}|sd}t|tr, tj||}n"#tj$rYGwxYw||vrP||}|t|t jru tj|}n#tj $rYwxYw|r|s|j r t|j tj r|}g} |D]\} } t|t jrn| | | f| r || d}n]#tj$rWt!|dr|rYn`t%|| } |d| | f|Yn2wxYwd} t!|dr |tj| }n?#tjtjtjf$rd} Yntj $rYnwxYwt|t jrnn/ |d n#tj$rd} YnwxYw| r,t%|| } |d | | f|n: t3|}#tj $rYnwxYwdS) z^Check attribute and index access in the format string ("{0.a}" and "{0[a]}"). rNhas_dynamic_getattrrQ)rr|FgetitemT __getitem__rS)rtintrget_argument_from_callNoSuchArgumentErrorr rrrurrr Argumentsrfgetattr NotFoundErrorhasattrrrlrrrAstroidIndexErrorAstroidTypeErrorAttributeInferenceErrorrr)rr|rrr[ specifiersargnameargumentpreviousparsedrirjrh warn_errors rkrz0StringFormatChecker._check_new_format_specifierss &Y Y OC #s## %#:4EEGG0He##**Wd6J"K"K  +G44)     X  :hou#O#O H-/F+58 8 ' ih(<==E |Y7888.#+#3#3I#>#>q#A"0   #H.CDD" ( < < > >" "EE.sF;;((6"+T!2!%)  "'Jx33. "'/'7'7 I8N8N'O'OHH#5#4#; ... *.JJJ&5"""!EE"%h0DEE"!E".%,,];;;!E&4...)-JJJ.!.sF;;((2)T9JQU)#HNN$4$455HH-EEoY Y su9A  A 9BB B D//3F&*FF+'G(H=HH0III !J00KKN)r|r}r_r~)r|rr_r~r|rr_r~)r|rrrr_r~)r|rrrr_r~)r|rrrrrr_r~)r __module__ __qualname____doc__rrZmsgsrrrrrrrrrrmrkrzrzs% D D !#" -  MMM  M^  @AA(((BA(FFFF3333(    RIRIRIRIjccccccrmrzceZdZdZdZddddddd gifd d d Zd dddddfddddddffZdZdZd@fd Z dAdZ dBd!Z e ddCd#Z e ddDd%Ze ddEd'Ze ddFd)ZdGd+ZdHd-ZdId2ZdJd7ZdKd;Ze d<dLd>ZdLd?ZxZS)MStringConstantCheckerzCheck string literals.r{)zRAnomalous backslash in string: '%s'. String constant might be missing an r prefix.anomalous-backslash-in-stringzBUsed when a backslash is in a literal string but not as an escape.)zaAnomalous Unicode escape in byte string: '%s'. String constant might be missing an r or u prefix."anomalous-unicode-escape-in-stringzSUsed when an escape like \u is encountered in a byte string where it has no effect.z)Implicit string concatenation found in %simplicit-str-concatziString literals are implicitly concatenated in a literal iterable definition : maybe a comma is missing ? old_names)W1403zimplicit-str-concat-in-sequence)z=3.0redundant-u-string-prefixzUsed when we detect a string with a u prefix. These prefixes were necessary in Python 2 to indicate a string was Unicode, but since Python 3.0 strings are Unicode by default.)W1401W1402W1404W1405W1406z check-str-concat-over-line-jumpsFynzzThis flag controls whether the implicit-str-concat should generate a warning on implicit string concatenation in sequences defined over several lines.)defaultrmetavarhelpzcheck-quote-consistencyzThis flag controls whether inconsistent-quotes generates a warning when the character used as a quote delimiter is used inconsistently within a module.zabfnrtvx \'"01234567uUNlinterrr_r~cXt|i|_dSr)super__init__ string_tokens)rr% __class__s rkr(zStringConstantChecker.__init__s0       ;:rmr| nodes.Modulec"d|jv|_dS)Nunicode_literals)future_imports_unicode_literalsrs rkprocess_modulez$StringConstantChecker.process_modules!3t7J!Jrmtokenslist[tokenize.TokenInfo]c*d}t|D]W\}\}}}}}|tjkr|}|tjkr'|||d|d|dz} | t |krx|| jtjtjtj fvrH| dz } | t |kr0|| jtjtjtj fvH| t |kr|| nd} |dkr8|dt |d|d |f}t|| f|j |<Y|j jjr||dSdS)Nasciirr) enumeratetokenizeENCODINGSTRINGprocess_string_tokenrrNEWLINENLCOMMENTencodestr_evalr)r%configcheck_quote_consistency&check_for_consistent_string_delimiters) rr1encodingi token_typetokenstartrlinej next_tokens rkprocess_tokensz$StringConstantChecker.process_tokenss6?6G6G J J 2A2 E5!TX... x..))%q58DDDE#f++oo&).$K$=++ FA #f++oo&).$K$=++ +,c&kk//VAYYt w&&#1Xs4 %( +;+B+B8+L+L'M'MNE-5e__j,I"5) ;  5 @  7 7 ? ? ? ? ? @ @rmrc<||jddS)Ncall)check_for_concatenated_stringsrrs rkrz StringConstantChecker.visit_call  ++DIv>>>>>rm nodes.Listc<||jddS)NlistrMrrs rk visit_listz StringConstantChecker.visit_listrNrm nodes.Setc<||jddS)NrrRrs rk visit_setzStringConstantChecker.visit_sets  ++DIu=====rm nodes.Tuplec<||jddS)NtuplerRrs rk visit_tuplez!StringConstantChecker.visit_tuples  ++DIw?????rm nodes.Assignct|jtjr=t|jjtr ||jgddSdSdS)N assignment)rtrr rr`rMrs rk visit_assignz"StringConstantChecker.visit_assignsi dj%+ . . L:dj>NPS3T3T L  / / l K K K K K L L L LrmIterable[tokenize.TokenInfo]ctj}|D]D\}}}}}|tjkr,t |r|t |xxdz cc<Et |dkr|ddd}|D]^\}}}}}|tjkrt |}t |r%||kr|d|d|f]dSdS)a\Adds a message for each string using inconsistent quote delimiters. Quote delimiters are used inconsistently if " and ' are mixed in a module's shortstrings without having done so to avoid escaping an internal quote character. Args: tokens: The tokens to be checked against for consistent usage. rrr)rGrN) rrr6r8!_is_quote_delimiter_chosen_freely_get_quote_delimiterr most_commonr) rr1string_delimiterstok_typerErmost_common_delimiterrFquote_delimiters rkrAz f    - -CKK',6        rmr}rstring_start_colcd} |d|}|dkrd S||dz}|||dz}|dd|}|dkr|} ||z} n"||dd|z} ||z dz } ||jvr%d|vrnCd |vrn>|d | |f| n#||jvr|d | |f| |dz })aJCheck for bad escapes in a non-raw string. prefix: lowercase string of string prefix markers ('ur'). string_body: the un-parsed body of the string, not including the quote marks. start_row: line number in the source. string_start_col: col number of the string start in the source. rT\r rrr)rGrrnrN)findrfindrUNICODE_ESCAPE_CHARACTERSrESCAPE_CHARACTERS) rr}rrtrr next_charmatch last_newlinerGrns rkryz2StringConstantChecker.process_non_raw_string_token^sY&( $$T511E{{$EAI.I 12E',,T1e<>>76>  566@@@76@LLLL    D>4<<<<|  ;<<///=</ rmrr%rr~c|t||t|dSr)register_checkerrzr)r%s rkregisterrsB /77888 1&99:::::rmrEc|dddvr |dd}n&|ddvr |dd}|dddvr |dd S|dd S) a!Mostly replicate `ast.literal_eval(token)` manually to avoid any performance hit. This supports f-strings, contrary to `ast.literal_eval`. We have to support all string literal notations: https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals rr>r+r/N>rrrrr>"""'''rwr)rx)rEs rkr>r>s QqSz\))abb  q  _ , ,abb  QqSz^##QrT{ 2;rm string_tokenctt|pt|S)arIs this string token a "longstring" (is it triple-quoted)? Long strings are triple-quoted as defined in https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals This function only checks characters up through the open quotes. Because it's meant to be applied only to tokens that represent string literals, it doesn't bother to check for close-quotes (demonstrating that the literal is a well-formed string). Args: string_token: The string token to be parsed. Returns: A boolean representing whether this token matches a longstring regex. )rpSINGLE_QUOTED_REGEXrDOUBLE_QUOTED_REGEX)rs rk_is_long_stringrs=" !!,// 3  $ $\ 2 2  rmct|}|std|d|dS)a}Returns the quote character used to delimit this token string. This function checks whether the token is a well-formed string. Args: string_token: The token to be parsed. Returns: A string containing solely the first quote delimiter character in the given string. Raises: ValueError: No quote delimiter characters are present. z string token z is not a well-formed stringr)QUOTE_DELIMITER_REGEXr ValueErrorgroup)rrs rkrbrbsJ " ' ' 5 5E USSSSTTT ;;q>>rmct|}|dkrdnd}t|o t| o|t|vS)aWas there a non-awkward option for the quote delimiter? Args: string_token: The quoted string whose delimiters are to be checked. Returns: Whether there was a choice in this token's quote character that would not have involved backslash-escaping an interior quote character. Long strings are excepted from this analysis under the assumption that their quote characters are set by policy. '")rbrprr>)rrgunchosen_delimiters rkrarasb+<88O /3 6 6C  = -- - = h|&<&< <  rm)r[r\r]r^r_r`)rnr ror`r_rpr)rEr`r_r`)rr`r_rp)rr`r_r`)>r __future__rrresysr6rcollections.abcrrtypingrrurr r astroid.typingr pylint.checkersr r rrpylint.checkers.utilsrpylint.interfacesr pylint.typingr pylint.lintr version_infortyping_extensionsrm _PREFIXEScompilergrrDOTALLrrZ__annotations__rListLambda FunctionDefListCompSetComp GeneratorExprrlrxrzrrr>rrbrarrmrkrs 0//"""""" ........ &&&&&&&&&&444444TTTTTTTTTTTT<<<<<<""""""000000%$$$$$$v))))))Q    4!bj!?SXXi%8%8!?!?!?@@ bj!BSXXi%8%8!B!B!BCC" #Dsxx ':':#D#D#DbiPP     ( )4 5@ AN O\ ]h it u@ AJ KT U` an o~ L MZ  sAAAAH K J L  N M   $ $ $ $&JJJJJ+JJJZ kkkkk,.@kkk\ ;;;;     .*rm