Your IP : 216.73.217.111


Current Path : /opt/alt/python37/lib/python3.7/site-packages/pylint/checkers/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/pylint/checkers/__pycache__/logging.cpython-37.pyc

B

A!p\8�@s�dZddlZddlZddlmZddlmZddlmZddlm	Z	ddd	d
ddd
d�Z
ddddddddhZd"dd�ZGdd�dej
�Zdd�Zdd�Zd d!�ZdS)#z"checker for use of Python logging
�N)�checkers)�
interfaces)�utils)�check_messages)z>Specify string format arguments as logging function parameterszlogging-not-lazya�Used when a logging statement has a call form of "logging.<logging method>(format_string % (format_args...))". Such calls should leave string interpolation to the logging method itself and be written "logging.<logging method>(format_string, format_args...)" so that the program may avoid incurring the cost of the interpolation in those cases in which no message will be logged. For more, see http://www.python.org/dev/peps/pep-0282/.)zLUse % formatting in logging functions and pass the % parameters as argumentszlogging-format-interpolationz�Used when a logging statement has a call form of "logging.<logging method>(format_string.format(format_args...))". Such calls should use % formatting instead, but leave interpolation to the logging function by passing the parameters as arguments.)zLUse % formatting in logging functions and pass the % parameters as argumentszlogging-fstring-interpolationz�Used when a logging statement has a call form of "logging.method(f"..."))". Such calls should use % formatting instead, but leave interpolation to the logging function by passing the parameters as arguments.)z;Unsupported logging format character %r (%#02x) at index %dzlogging-unsupported-formatzWUsed when an unsupported format character is used in a logging statement format string.)z<Logging format string ends in middle of conversion specifierzlogging-format-truncatedz`Used when a logging statement format string terminates before the end of a conversion specifier.)z,Too many arguments for logging format stringzlogging-too-many-argsz>Used when a logging format string is given too many arguments.)z.Not enough arguments for logging format stringzlogging-too-few-argsz=Used when a logging format string is given too few arguments.)ZW1201ZW1202ZW1203ZE1200ZE1201ZE1205ZE1206Zcritical�debug�error�	exception�fatal�info�warn�warning�cCs@t|tj�o>t|jtj�o>|r*|jj|kndo>|r<|j|kSdS)a�Determines if a BoundMethod node represents a method call.

    Args:
      func (astroid.BoundMethod): The BoundMethod AST node to check.
      types (Optional[String]): Optional sequence of caller type names to restrict check.
      methods (Optional[String]): Optional sequence of method names to restrict check.

    Returns:
      bool: true if the node represents a method call for the given type and
      method names, False otherwise.
    T)�
isinstance�astroid�BoundMethod�boundZInstance�name)�func�types�methodsr
r
�H/opt/alt/python37/lib/python3.7/site-packages/pylint/checkers/logging.py�is_method_calles
rc@s�eZdZdZejZdZeZ	dddddd�fd	d
ddd
d
gdd�ffZ
dd�Zdd�Zdd�Z
ee�dd��Zdd�Zedd��Zdd�Zdd�Zd S)!�LoggingCheckerz!Checks use of the logging module.�loggingzlogging-modules)rZcsvz<comma separated list>zcLogging modules to check that the string format arguments are in logging function parameter format.)�default�type�metavar�helpzlogging-format-style�old�choicez<old (%) or new ({)>�newzuFormat style used to check logging format string. `old` means using % formatting, while `new` is for `{}` formatting.)rrr�choicesrcCsft�|_|jj}|jj|_t|�|_i|_x6|D].}|�dd�}t	|�dkr0|d|j|d<q0WdS)z?Clears any state left in this checker from last module checked.�.�rN)
�set�_logging_names�configZlogging_modulesZlogging_format_style�
_format_style�_logging_modules�
_from_imports�rsplit�len)�self�nodeZlogging_modsZlogging_mod�partsr
r
r�visit_module�s


zLoggingChecker.visit_modulecCsVy<|j|j}x*|jD] \}}||kr|j�|p2|�qWWntk
rPYnXdS)z;Checks to see if a module uses a non-Python logging module.N)r)�modname�namesr%�add�KeyError)r,r-Zlogging_name�module�as_namer
r
r�visit_importfrom�szLoggingChecker.visit_importfromcCs2x,|jD]"\}}||jkr|j�|p&|�qWdS)z<Checks to see if this module uses Python's built-in logging.N)r1r(r%r2)r,r-r4r5r
r
r�visit_import�s
zLoggingChecker.visit_importcsL��fdd�}�fdd�}|�r*�jj}n|�\}}|s<dS���|�dS)z Checks calls to logging methods.cs.t�jtj�o,t�jjtj�o,�jjj�jkS)N)rrr�	Attribute�expr�Namerr%r
)r-r,r
r�is_logging_name�sz2LoggingChecker.visit_call.<locals>.is_logging_namecs�yfx`�j��D]R}t|tj�r|jj}t|tj�r|��dksTt	dd�|�
�D��rd|jjfSqWWntjj
k
r~YnXdS)Nzlogging.Loggercss|]}|��dkVqdS)zlogging.LoggerN)�qname)�.0Zancestorr
r
r�	<genexpr>�szELoggingChecker.visit_call.<locals>.is_logger_class.<locals>.<genexpr>T)FN)rZinferrrrZ_proxied�parentZClassDefr<�anyZ	ancestorsr�
exceptionsZInferenceError)�inferredr?)r-r
r�is_logger_class�sz2LoggingChecker.visit_call.<locals>.is_logger_classN)r�attrname�_check_log_method)r,r-r;rCr�resultr
)r-r,r�
visit_call�s

zLoggingChecker.visit_callcs0|dkr,|js"|js"t|j�dkr&dSd}n(|tkrP|jsF|jsF|jsJdSd}ndSt|j|tj�r�|j|}|jdk}|jdkr�t	�fdd	�|j
|jfD��}|dk}|r��jd
|d�nnt|j|tj
�r��|j|�nJt|j|tj��r��||�n(t|j|tjtjf��r,�jd|d�dS)
z9Checks calls to logging.log(level, format, *format_args).�log�Nr#r�%�+c3s"|]}��t�|��rdVqdS)r#N)�_is_operand_literal_strr�
safe_infer)r=�operand)r,r
rr>�sz3LoggingChecker._check_log_method.<locals>.<genexpr>zlogging-not-lazy)r-zlogging-fstring-interpolation)Zstarargs�kwargsr+�args�CHECKED_CONVENIENCE_FUNCTIONSrrZBinOp�op�sum�left�right�add_messageZCall�_check_call_func�Const�_check_format_stringZFormattedValueZ	JoinedStr)r,r-rZ
format_posZbinop�emitZtotal_number_of_stringsr
)r,rrE�s4



z LoggingChecker._check_log_methodcCst|tj�o|jdkS)zL
        Return True if the operand in argument is a literal string
        �str)rrrXr)rNr
r
rrLsz&LoggingChecker._is_operand_literal_strcCs<t�|j�}d}d}t|||�r8t|j�s8|jd|d�dS)z�Checks that function call is not format_string.format().

        Args:
          node (astroid.node_classes.Call):
            Call AST node to be checked.
        )r[�unicode)�formatzlogging-format-interpolation)r-N)rrMrr�is_complex_format_strrrV)r,r-rrrr
r
rrW	szLoggingChecker._check_call_funcc
CsFt|j|dd��}|sdS|j|j}t|t�s:d}n�yf|jdkrbt�|�\}}}}|r�dSn<|jdkr�t�|�\}}	}
t	t
dd�|D���}||	|
}Wnntjk
r�}z*||j}
|j
d||
t|
�|jfd	�dSd}~XYn&tjk
�r|j
d
|d�dSX||k�r*|j
d|d�n||k�rB|j
d
|d�dS)z�Checks that format string tokens match the supplied arguments.

        Args:
          node (astroid.node_classes.NodeNG): AST node to be checked.
          format_arg (int): Index of the format string in the node arguments.
        r#Nrrr css |]\}}t|t�s|VqdS)N)r�int)r=�k�lr
r
rr>9sz6LoggingChecker._check_format_string.<locals>.<genexpr>zlogging-unsupported-format)r-rPzlogging-format-truncated)r-zlogging-too-many-argszlogging-too-few-args)�_count_supplied_tokensrP�valuerr[r'rZparse_format_stringZparse_format_method_stringr+r$ZUnsupportedFormatCharacter�indexrV�ordZIncompleteFormatString)r,r-Z
format_arg�num_args�
format_stringZrequired_num_argsZkeyword_args�_Zkeyword_argumentsZimplicit_pos_argsZexplicit_pos_argsZkeyword_args_cnt�ex�charr
r
rrYs@





z#LoggingChecker._check_format_stringN)�__name__�
__module__�__qualname__�__doc__rZIAstroidCheckerZ__implements__r�MSGSZmsgs�optionsr/r6r7rrGrE�staticmethodrLrWrYr
r
r
rrys.
$&rcCsrt�|�}|dkst|jt�s"dSytt���|j��}Wnt	k
rNdSXx|D]\}}}}|rVdSqVWdS)z�Checks if node represents a string with complex formatting specs.

    Args:
        node (astroid.node_classes.NodeNG): AST node to check
    Returns:
        bool: True if inferred string uses complex formatting, False otherwise
    NTF)
rrMrrcr[�list�string�	Formatter�parse�
ValueError)r-rB�parsedrh�format_specr
r
rr^Os
r^cCstdd�|D��S)a|Counts 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 (list): AST nodes that are arguments for a log format string.

    Returns:
      int: Number of AST nodes that aren't keywords.
    css|]}t|tj�sdVqdS)r#N)rr�Keyword)r=�argr
r
rr>rsz)_count_supplied_tokens.<locals>.<genexpr>)rS)rPr
r
rrbes
rbcCs|�t|��dS)z.Required method to auto-register this checker.N)Zregister_checkerr)Zlinterr
r
r�registerusr{)r
r
)rnrsr�pylintrrZpylint.checkersrZpylint.checkers.utilsrrorQrZBaseCheckerrr^rbr{r
r
r
r�<module>s6



W