bg]?ZUdZddlmZddlZddlZddlmZddlZddlmZm Z ddl m Z ddl m Z ddlmZdd lmZdd lmZejd krdd lmZndd lmZerdd lmZddddddddZded<hdZegdZ d2d3d"ZGd#d$e jZ d4d'Z!d5d+Z"d6d-Z#d7d1Z$dS)8z"Checker for use of Python logging.) annotationsN) TYPE_CHECKING)basesnodes)InferenceResult)checkers)utils) infer_all)MessageDefinitionTuple))Literal)PyLinter)&Use %s formatting in logging functionslogging-not-lazyaUsed when a logging statement has a call form of "logging.(format_string % (format_args...))". Use another type of string formatting instead. You can use % formatting but leave interpolation to the logging function by passing the parameters as arguments. If logging-fstring-interpolation is disabled then you can use fstring formatting. If logging-format-interpolation is disabled then you can use str.format.)rlogging-format-interpolationaUsed when a logging statement has a call form of "logging.(format_string.format(format_args...))". Use another type of string formatting instead. You can use % formatting but leave interpolation to the logging function by passing the parameters as arguments. If logging-fstring-interpolation is disabled then you can use fstring formatting. If logging-not-lazy is disabled then you can use % formatting as normal.)rlogging-fstring-interpolationaUsed when a logging statement has a call form of "logging.(f"...")".Use another type of string formatting instead. You can use % formatting but leave interpolation to the logging function by passing the parameters as arguments. If logging-format-interpolation is disabled then you can use str.format. If logging-not-lazy is disabled then you can use % formatting as normal.)z;Unsupported logging format character %r (%#02x) at index %dlogging-unsupported-formatzWUsed when an unsupported format character is used in a logging statement format string.)zUsed when a logging format string is given too many arguments.)z.Not enough arguments for logging format stringlogging-too-few-argsz=Used when a logging format string is given too few arguments.)W1201W1202W1203E1200E1201E1205E1206z!dict[str, MessageDefinitionTuple]MSGS>infowarndebugerrorfatalwarningcritical exception)z%sz%dz%fz%rfuncbases.BoundMethodtypestuple[str, ...]methodsreturnboolct|tjo=t|jtjo|r|jj|vndo |r |j|vndS)a~Determines if a BoundMethod node represents a method call. Args: func: The BoundMethod AST node to check. types: Optional sequence of caller type names to restrict check. methods: Optional sequence of method names to restrict check. Returns: true if the node represents a method call for the given type and method names, False otherwise. T) isinstanceastroid BoundMethodboundInstancename)r)r+r-s h/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/pylint/checkers/logging.pyis_method_callr8osf 4,-- 8 tz7#3 4 4 8). 8TZ_ % %D 8&- 6TY' ! !$ ceZdZdZdZeZddddddfd d d d d d gddffZd+dZd,dZ d-dZ d.dZ d/dZ d0dZ ed1d#Zed2d%Zd.d&Zd3d)Zd*S)4LoggingCheckerz!Checks use of the logging module.loggingzlogging-modules)r<csvzzcLogging modules to check that the string format arguments are in logging function parameter format.)defaulttypemetavarhelpzlogging-format-styleoldchoiceznewztThe type of string formatting that logging methods do. `old` means using % formatting, `new` is for `{}` formatting.)r>r?r@choicesrA_ nodes.Moduler.Nonec8t|_|jjj}|jjj|_t||_i|_|D]A}| dd}t|dkr|d|j|d<BdS)z?Clears any state left in this checker from last module checked..rN) set_logging_nameslinterconfiglogging_moduleslogging_format_style _format_style_logging_modules _from_importsrsplitlen)selfrF logging_mods logging_modpartss r7 visit_modulezLoggingChecker.visit_modules ),{)9 ![/D #L 1 1' 8 8K&&sA..E5zzA~~/4Qx"58, 8 8r9nodenodes.ImportFromc |j|j}|jD]'\}}||kr|j|p|(dS#t $rYdSwxYw)z;Checks to see if a module uses a non-Python logging module.N)rTmodnamenamesrMaddKeyError)rWr\ logging_namemoduleas_names r7visit_importfromzLoggingChecker.visit_importfroms -dl;L#': ? ?\))'++G,=v>>> ? ?    DD sAA AA nodes.Importcj|jD]*\}}||jvr|j|p|+dS)z.is_logging_namesH49eo66?ty~uz::?IN'4+>> r9tuple[bool, str | None]c\tjD]}t|tjry|jj}t|tjrS| dks+td| Drd|jj fcSdS)Nlogging.Loggerc3FK|]}|dkVdS)rtN)qname).0ancestors r7 zELoggingChecker.visit_call..is_logger_class..sF (%NN,,0@@r9T)FN) r r)r1r2r3_proxiedparentrClassDefrvany ancestorsr6)inferredr{r\s r7is_logger_classz2LoggingChecker.visit_call..is_logger_classs%di00 < <h(;<< <%.5F!&%.99< *:::,2,<,<,>,>; $X%6%;;;;;;r9N)r.r/)r.rr)r)attrname_check_log_method)rWr\rqrr6results`` r7 visit_callzLoggingChecker.visit_calls              ?   9%DD*?,,LFD  tT*****r9r6strc|dkr+|js|jst|jdkrdSd}n%|tvr|js|js|jsdSd}ndS|j|}t |t jr|}|jdk}|jdkrB |s-tfd|j |j fD}|dk}|r. d ||f dSdSt |t jr|dSt |t jr||dSt |t jr?t)|rdS d ||f dSdS) z9Checks calls to logging.log(level, format, *format_args).logNrKr%+c3jK|]-}tj|)dV.dSrKN)_is_operand_literal_strr safe_infer)rwoperandrWs r7ryz3LoggingChecker._check_log_method..sV..33E4DW4M4MNN.......r9rr\argsr)starargskwargsrVrCHECKED_CONVENIENCE_FUNCTIONSr1rBinOpop#_is_node_explicit_str_concatenationsumleftright add_message_helper_stringCall_check_call_funcConst_check_format_string JoinedStrstr_formatting_in_f_string)rWr\r6 format_pos format_argbinopemittotal_number_of_stringss` r7rz LoggingChecker._check_log_methods: 5==}   s49~~/A/A()JJ 2 2 2}   49 JJ FYz* j%+ . . E8s?Dx3t'O'OPU'V'V*-....$)J #<...++' /2   &--d335!    EJ / /   ! !* - - - - -  EK 0 0   % %dJ 7 7 7 7 7  EO 4 4 )*55    /))$//1        r9cpdg}|jd|js|d|jd|js|d|jd|js|dd|S) zGCreate a string that lists the valid types of formatting for this node.zlazy %zlogging-fstring-formattingfstringrz .format()rrz or )rNis_message_enabled fromlinenoappendjoin)rWr\ valid_typess r7rzLoggingChecker._helper_stringsj {-- ($/   *   y ) ) ){-- *DO   ,   { + + +{--.@$/RR $   s # # #{{;'''r9rInferenceResult | Noner/cLt|tjo |jdkS)z;Return True if the operand in argument is a literal string.r)r1rrr6)rs r7rz&LoggingChecker._is_operand_literal_str$s"'5;//IGLE4IIr9 nodes.NodeNGc2t|tjsdSt|jpt|jo=t|jpt|jS)zEReturn True if the node represents an explicitly concatenated string.F)r1rrr;rrrrr\s r7rz2LoggingChecker._is_node_explicit_str_concatenation)s$ ,, 5  2 249 = = MAA$)LL   2 24: > > NAA$*MM  r9c"tj|j}d}d}t|tjrSt |||rDt|js2| d|| |fdSdSdSdS)z8Checks that function call is not format_string.format().)runicode)formatrrN) r rr)r1r2r3r8is_complex_format_strr4rr)rWr\r)r+r-s r7rzLoggingChecker._check_call_func6s **" tW0 1 1 tUG44 *$*55    .))$//1            r9r Literal[0, 1]c Ht|j|dzd}|sdS|j|j}d}t|tr|}t|t r |jdkrtj |\}}}}|rdSnD|jdkr9tj |\}} } td|D} | | z| z}n#tj $rE} || j } |d|| t| | j fYd} ~ dSd} ~ wtj$r|d | YdSwxYw||kr|d | dS||kr|d | dSdS) zChecks that format string tokens match the supplied arguments. Args: node: AST node to be checked. format_arg: Index of the format string in the node arguments. rKNrrBrDcBh|]\}}t|t|Sr()r1int)rwkrFs r7 z6LoggingChecker._check_format_string..is+SSStq! 1c@R@RSSSSr9rrrrrr)_count_supplied_tokensrvaluer1bytesdecoderrRr parse_format_stringparse_format_method_stringrVUnsupportedFormatCharacterindexrordIncompleteFormatString)rWr\rnum_args format_stringrequired_num_args keyword_argsrFkeyword_argumentsimplicit_pos_argsexplicit_pos_argskeyword_args_cntexchars r7rz#LoggingChecker._check_format_stringFs8*$)JN4D4D*EFF  F *-3  mU + + 3)0022M mS ) )!  %..P    G08888";;;; ++++@----^(((("JJJ\J    \   6@6@6@6@6@6@r9r;r\rcbtj|}|4t|tjrt|jt sdS ttj |j}n#t$rYdSwxYwtd|DS)zJReturn whether the node represents a string with complex formatting specs.NTFc3$K|] \}}}}|V dSrmr()rwrF format_specs r7ryz(is_complex_format_str..s+@@51k1{@@@@@@r9) r rr1rrrrliststring Formatterparse ValueErrorr})r\rparseds r7rrs%%H8U[)).8.M.Mtf&((..x~>>?? uu @@@@@ @ @@s8B BBrlist[nodes.NodeNG]rc4td|DS)apCounts the number of tokens in an args list. The Python log functions allow for special keyword arguments: func, exc_info and extra. To handle these cases correctly, we only count arguments that aren't keywords. Args: args: AST nodes that are arguments for a log format string. Returns: Number of AST nodes that aren't keywords. c3NK|] }t|tjdV!dSr)r1rKeyword)rwargs r7ryz)_count_supplied_tokens..s3GGS 3 (F(FGqGGGGGGr9)r)rs r7rrs! GGDGGG G GGr9nodes.JoinedStrc>td|jDS)znDetermine whether the node represents an f-string with string formatting. For example: `f'Hello %s'` c3K|]Gttjdjvot fdt DVHdS)rc3*K|] }|jvVdSrm)r)rwxvals r7ryz7str_formatting_in_f_string...s) P PAci P P P P P Pr9N)r1rrrr}MOST_COMMON_FORMATTING)rwrs @r7ryz-str_formatting_in_f_string..ss  c5; ' ' syPS P P P P9O P P PPPr9)r}valuesrs r7rrs4 ;  r9rNrrHcJ|t|dSrm)register_checkerr;)rNs r7registerrs$ N62233333r9)r(r()r)r*r+r,r-r,r.r/r)rrr.r)r\rr.r/)rNrr.rH)%r __future__rrsystypingrr2rrastroid.typingrpylintrpylint.checkersr pylint.checkers.utilsr pylint.typingr version_infortyping_extensions pylint.lintrr__annotations__r frozensetrr8 BaseCheckerr;rrrrr(r9r7rsG )((""""""  ******!!!!!!++++++000000v))))))%$$$$$$      s>>@@@@F ! ! !##;#;#;<<VX,w@w@w@w@w@X)w@w@w@t A A A A H H H H    444444r9