o
    gP                     @   s   d Z ddlmZ ddlmZ ddl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.     )nodes)	PathGraph)PathGraphingAstVisitor)checkers)check_messages)HIGHIAstroidCheckerc                       s   e Zd Z fddZ  ZS )r   c                    s   t  jdddd || _d S )N    )nameentitylineno)super__init__rootselfnode	__class__ V/home/ubuntu/cloudmapper/venv/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    d| _d S )Nr   )r   r   _bottom_counter)r   r   r   r   r      s   

zPathGraphingAstVisitor.__init__c                 G   s$   |  D ]}| j|g|R   qd S N)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meth
class_namer   r   r   r   '   s   
zPathGraphingAstVisitor.dispatchc                 C   s   | j d ur2| |}|| _| |j | j }|  jd7  _| j | j| | j || || _d S t|| _ || _| |j | j | j| j	 |j
 < |   d S )Nr
   )graph_append_nodetaildispatch_listbodyr   connectr   graphs	classnamer   reset)r   r   pathnodebottomr   r   r   visitFunctionDef1   s   



z'PathGraphingAstVisitor.visitFunctionDefc                 C   s   |  | d S r   )r,   r   r   r   r   visitSimpleStatementE   s   z+PathGraphingAstVisitor.visitSimpleStatementc                 C   s   |  | | |j d S r   )r,   r.   r/   r   r   r   r   	visitWithb   s   
z PathGraphingAstVisitor.visitWithc                 C   s$   | j sd S | j| j | || _ |S r   )r-   r+   r0   r   r   r   r   r,   h   s
   z#PathGraphingAstVisitor._append_noder   c                 C   s`   | j du r"t|| _ | ||| | j | j| j | < |   dS | | | ||| dS )z?create the subgraphs representing any `if` and `for` statementsN)r+   r   _subgraph_parser1   r2   r3   r,   )r   r   r   extra_blocksr   r   r   	_subgrapho   s   


z PathGraphingAstVisitor._subgraphc                 C   s   g }|| _ | |j || j  |D ]}|| _ | |j || j  q|jr8|| _ | |j || j  n|| |r[| j }|  jd7  _|D ]	}| j|| qL|| _ dS dS )z@parse the body and any `else` block of `if` and `for` statementsr
   N)r-   r.   r/   appendorelser   r+   r0   )r   r   r4   r:   
loose_endsextrar5   endr   r   r   r9   {   s(   

z&PathGraphingAstVisitor._subgraph_parse)r   ) r   r   r   r   r"   r   r6   visitAsyncFunctionDefr7   visitAssertvisitAssignvisitAugAssignvisitDelete
visitPrint
visitRaise
visitYieldvisitImport	visitCallvisitSubscript	visitPassvisitContinue
visitBreakvisitGlobalvisitReturn	visitExpr
visitAwaitr8   visitAsyncWithr,   r;   r9   r   r   r   r   r   r      sV    
	
r   c                   @   sP   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e
jddfddZdS )McCabeMethodCheckerzoChecks McCabe complexity cyclomatic threshold in methods and functions
    to validate a too complex code.
    design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helprW   r   returnNc                 C   s   t  }|jD ]}||| q|j D ]2}| }|j}t|dr*d|j d}n
d|j	j
  d}|| jjkr;q| 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This 'rW   )r   
confidencer    N)r   r/   preorderr1   values
complexityr   hasattrr   r   r   lowerconfigmax_complexityadd_messager   )r   r   r'   r!   r+   rb   	node_namer   r   r   visit_module   s   

z McCabeMethodChecker.visit_module)r   r   r   __doc__r   __implements__r   msgsoptionsr   r   Moduleri   r   r   r   r   rT      s     
rT   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)register_checkerrT   )linterr   r   r   register   s   rq   N)rj   astroidr   mccaber   Mccabe_PathGraphr   Mccabe_PathGraphingAstVisitorpylintr   pylint.checkers.utilsr   pylint.interfacesr   r   BaseCheckerrT   rq   r   r   r   r   <module>   s   u1