o
    b:                     @   s   d Z ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZmZ G dd deZG d	d
 d
eZG dd de	jZdd ZdS )z/Module to add McCabe checker class for pylint.     )absolute_import)	PathGraphPathGraphingAstVisitor)checkers)check_messages)HIGHIAstroidCheckerc                       s   e Zd Z fddZ  ZS )r   c                    s    t t| jdddd || _d S )N    )nameentitylineno)superr   __init__rootselfnode	__class__ W/var/www/secure340b-portal/env/lib/python3.10/site-packages/pylint/extensions/mccabe.pyr      s   
zPathGraph.__init__)__name__
__module____qualname__r   __classcell__r   r   r   r   r      s    r   c                       s   e Zd Z fddZdd Zdd Zdd ZeZd	d
 Ze Z	 Z
 Z Z Z Z Z Z Z Z Z Z Z Z Z ZZdd ZeZdd ZdddZdd Z  ZS )r   c                    s   t t|   d| _d S )Nr   )r   r   r   _bottom_counter)r   r   r   r   r      s   
zPathGraphingAstVisitor.__init__c                 G   s$   |  D ]}| j|g|R   qd S N)Zget_childrendispatch)r   r   argschildr   r   r   default    s   zPathGraphingAstVisitor.defaultc                 G   sT   || _ |j}| j|}|d u r"|j}t| jd| | j}|| j|< ||g|R  S )Nvisit)r   r   _cachegetr   getattrvisitorr!   )r   r   r   klassmethZ	classNamer   r   r   r   $   s   
zPathGraphingAstVisitor.dispatchc                 C   s   | j d ur3| |}|| _| |j d| j }|  jd7  _| j | j| | j || || _d S t|| _ || _| |j | j | jd| j	|j
f < |   d S )N%sr
   %s%s)graph_append_nodetaildispatch_listbodyr   connectr   graphs	classnamer   reset)r   r   pathnodebottomr   r   r   visitFunctionDef.   s   




z'PathGraphingAstVisitor.visitFunctionDefc                 C   s   |  | d S r   )r,   r   r   r   r   visitSimpleStatementB   s   z+PathGraphingAstVisitor.visitSimpleStatementc                 C   s   |  | | |j d S r   )r,   r.   r/   r   r   r   r   	visitWith_   s   
z PathGraphingAstVisitor.visitWithc                 C   s$   | j sd S | j| j | || _ |S r   )r-   r+   r0   r   r   r   r   r,   e   s
   z#PathGraphingAstVisitor._append_noder   c                 C   s`   | j du r"t|| _ | ||| | j | jd| j|f < |   dS | | | ||| dS )z?create the subgraphs representing any `if` and `for` statementsNr*   )r+   r   _subgraph_parser1   r2   r3   r,   )r   r   r   extra_blocksr   r   r   	_subgraphl   s   


z PathGraphingAstVisitor._subgraphc                 C   s   g }|| _ | |j || j  |D ]}|| _ | |j || j  q|jr8|| _ | |j || j  n|| |r\d| j }|  jd7  _|D ]	}| j|| qM|| _ dS dS )z@parse the body and any `else` block of `if` and `for` statementsr)   r
   N)r-   r.   r/   appendorelser   r+   r0   )r   r   r4   r:   Z
loose_endsextrar5   ler   r   r   r9   x   s(   


z&PathGraphingAstVisitor._subgraph_parse)r   ) r   r   r   r   r!   r   r6   ZvisitAsyncFunctionDefr7   ZvisitAssertZvisitAssignZvisitAugAssignZvisitDeleteZ
visitPrintZ
visitRaiseZ
visitYieldZvisitImportZ	visitCallZvisitSubscriptZ	visitPassZvisitContinueZ
visitBreakZvisitGlobalZvisitReturnZ	visitExprZ
visitAwaitr8   ZvisitAsyncWithr,   r;   r9   r   r   r   r   r   r      sV    
	
r   c                   @   sD   e Zd ZdZeZdZddiZddddd	d
ffZe	ddd Z
dS )McCabeMethodCheckerzoChecks McCabe complexity cyclomatic threshold in methods and functions
    to validate a too complex code.
    ZdesignZR1260)z*%s is too complex. The McCabe rating is %dtoo-complexzSUsed when a method or function is too complex based on McCabe Complexity Cyclomaticzmax-complexity
   intz<int>z&McCabe complexity cyclomatic threshold)r!   typemetavarhelprA   c                 C   s   t  }|jD ]}||| q|j D ].}| }|j}t|dr(d|j }nd|j	j
  }|| jjkr7q| jd|t||fd qdS )zvisit an astroid.Module node to check too complex rating and
        add message if is greather than max_complexity stored from optionsr   z'%s'z	This '%s'rA   )r   
confidencer   N)r   r/   Zpreorderr1   values
complexityr   hasattrr   r   r   lowerconfigZmax_complexityZadd_messager   )r   r   r&   r    r+   rI   Z	node_namer   r   r   visit_module   s   

z McCabeMethodChecker.visit_moduleN)r   r   r   __doc__r   Z__implements__r   Zmsgsoptionsr   rM   r   r   r   r   r@      s     
r@   c                 C   s   |  t|  dS )zRequired method to auto register this checker.

    :param linter: Main interface object for Pylint plugins
    :type linter: Pylint object
    N)Zregister_checkerr@   )Zlinterr   r   r   register   s   rP   N)rN   
__future__r   Zmccaber   ZMccabe_PathGraphr   ZMccabe_PathGraphingAstVisitorZpylintr   Zpylint.checkers.utilsr   Zpylint.interfacesr   r   ZBaseCheckerr@   rP   r   r   r   r   <module>   s   w1