HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib64/python3.10/site-packages/__pycache__/mccabe.cpython-310.pyc
o

we�)�@sdZddlmZddlZddlZddlZddlmZzddlZddlm	Z	Wne
y7ddlmZm	Z	YnwdZGdd	�d	e
�ZGd
d�de
�ZGdd
�d
e
�ZGdd�de�ZGdd�de
�Zddd�Zddd�Zdd�Zd dd�Zedkr�eejdd��dSdS)!z� Meager code path measurement tool.
    Ned Batchelder
    http://nedbatchelder.com/blog/200803/python_code_complexity_microtool.html
    MIT License.
�)�with_statementN)�defaultdict)�iter_child_nodes)�astrz0.7.0c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�
ASTVisitorz'Performs a depth-first walk of the AST.cCsd|_i|_dS�N)�node�_cache��self�r�?/home/arjun/projects/env/lib/python3.10/site-packages/mccabe.py�__init__�
zASTVisitor.__init__cGs$t|�D]}|j|g|�R�qdSr)r�dispatch)rr�args�childrrr
�defaults�zASTVisitor.defaultcGsT||_|j}|j�|�}|dur"|j}t|jd||j�}||j|<||g|�R�S)N�visit)r�	__class__r	�get�__name__�getattr�visitorr)rrr�klass�meth�	classNamerrr
r!s
zASTVisitor.dispatchcGs$||_|j|_|j|g|�R�dS)z&Do preorder walk of tree using visitorN)rrr)r�treerrrrr
�preorder+szASTVisitor.preorderN)r�
__module__�__qualname__�__doc__rrrrrrrr
rs
rc@s&eZdZd	dd�Zdd�Zdd�ZdS)
�PathNode�circlecCs||_||_dSr)�name�look)rr$r%rrr
r3rzPathNode.__init__cCstd|j|j|��f�dS)Nznode [shape=%s,label="%s"] %d;)�printr%r$�dot_idr
rrr
�to_dot7s�zPathNode.to_dotcCst|�Sr)�idr
rrr
r';szPathNode.dot_idN)r#)rrr rr(r'rrrr
r"2s
r"c@s.eZdZddd�Zdd�Zdd�Zdd	�Zd
S)�	PathGraphrcCs&||_||_||_||_tt�|_dSr)r$�entity�lineno�columnr�list�nodes)rr$r+r,r-rrr
r@s
zPathGraph.__init__cCs|j|�|�g|j|<dSr)r/�append)r�n1�n2rrr
�connectGszPathGraph.connectcCs^td�|jD]}|��q|j��D]\}}|D]}td|��|��f�qqtd�dS)Nz
subgraph {z	%s -- %s;�})r&r/r(�itemsr')rr�nexts�nextrrr
r(Ls

�zPathGraph.to_dotcCs.tdd�|j��D��}t|j�}||dS)zG Return the McCabe complexity for the graph.
            V-E+2
        cSsg|]}t|��qSr)�len)�.0�nrrr
�
<listcomp>Ysz(PathGraph.complexity.<locals>.<listcomp>�)�sumr/�valuesr8)r�	num_edges�	num_nodesrrr
�
complexityUs
zPathGraph.complexityN)r)rrr rr3r(rArrrr
r*?s

	r*cs�eZdZdZ�fdd�Zdd�Zdd�Zdd	�ZeZd
d�Z	dd
�Z
dd�Z�fdd�Zdd�Z
e
ZZZdd�Zddd�Zdd�Zdd�ZeZdd�ZeZ�ZS) �PathGraphingAstVisitorz\ A visitor for a parsed Abstract Syntax Tree which finds executable
        statements.
    cs&tt|���d|_i|_|��dS)N�)�superrBr�	classname�graphs�resetr
�rrr
rcszPathGraphingAstVisitor.__init__cCsd|_d|_dSr)�graph�tailr
rrr
rGirzPathGraphingAstVisitor.resetcCs|D]}|�|�qdSr)r)r�	node_listrrrr
�
dispatch_listms�z$PathGraphingAstVisitor.dispatch_listcCs�|jrd|j|jf}n|j}d|j|j|f}|jdurE|�|�}||_|�|j�t	ddd�}|j�
|j|�|j�
||�||_dSt|||j|j�|_t	|�}||_|�|j�|j|jd|j|jf<|�
�dS)N�%s%sz	%d:%d: %rrC�point�r%)rEr$r,�
col_offsetrI�appendPathNoderJrL�bodyr"r3r*rFrG)rrr+r$�pathnode�bottomrrr
�visitFunctionDefqs$


z'PathGraphingAstVisitor.visitFunctionDefcCs0|j}|j|jd7_|�|j�||_dS)N�.)rEr$rLrR)rr�
old_classnamerrr
�
visitClassDef�s
z$PathGraphingAstVisitor.visitClassDefcCs,|jsdSt|�}|j�|j|�||_|Sr)rJr"rIr3)rr$rSrrr
rQ�sz%PathGraphingAstVisitor.appendPathNodecCs,|jdurd}n|j}d|}|�|�dS)NrzStmt %d)r,rQ)rrr,r$rrr
�visitSimpleStatement�s

z+PathGraphingAstVisitor.visitSimpleStatementcs6t|tj�r
|�|�dStt|�j|g|�R�dSr)�
isinstancer�stmtrYrDrBr)rrrrHrr
r�szPathGraphingAstVisitor.defaultcC�d|j}|�||�dS)NzLoop %d�r,�	_subgraph�rrr$rrr
�	visitLoop��
z PathGraphingAstVisitor.visitLoopcCr\)NzIf %dr]r_rrr
�visitIf�razPathGraphingAstVisitor.visitIfrcCsr|jdur+t|||j|j�|_t|�}|�|||�|j|jd|j|f<|��dS|�	|�}|�|||�dS)z?create the subgraphs representing any `if` and `for` statementsNrM)
rIr*r,rPr"�_subgraph_parserFrErGrQ)rrr$�extra_blocksrSrrr
r^�s

z PathGraphingAstVisitor._subgraphcCs�g}||_|�|j�|�|j�|D]}||_|�|j�|�|j�q|jr8||_|�|j�|�|j�n|�|�|rVtddd�}|D]	}|j�||�qG||_dSdS)z@parse the body and any `else` block of `if` and `for` statementsrCrNrON)rJrLrRr0�orelser"rIr3)rrrSrd�
loose_ends�extrarT�lerrr
rc�s&

�z&PathGraphingAstVisitor._subgraph_parsecCs d|j}|j|||jd�dS)NzTryExcept %d)rd)r,r^�handlersr_rrr
�visitTryExcept�s
z%PathGraphingAstVisitor.visitTryExceptcCs$d|j}|�|�|�|j�dS)NzWith %d)r,rQrLrRr_rrr
�	visitWith�s

z PathGraphingAstVisitor.visitWith)r)rrr r!rrGrLrU�visitAsyncFunctionDefrXrQrYrr`�
visitAsyncFor�visitFor�
visitWhilerbr^rcrj�visitTryrk�visitAsyncWith�
__classcell__rrrHr
rB^s(

rBc@sLeZdZdZdZeZdZdZdZ	dd�Z
edd	��Zed
d��Z
dd
�ZdS)�
McCabeCheckerz%McCabe cyclomatic complexity checker.�mccabe�C901zC901 %r is too complex (%d)���cCs
||_dSr)r)rr�filenamerrr
r�s
zMcCabeChecker.__init__cCsld}ddtddd�}t|dd�}t|t�r+|�d�|j|fi|��|j�d	�dS|j|fi|��dS)
Nz--max-complexityrv�storezMcCabe complexity threshold�True)r�action�type�help�parse_from_config�config_optionsr}zmax-complexity)�intrrZr.�pop�
add_optionr~r0)�cls�parser�flag�kwargs�config_optsrrr
�add_options�s�

zMcCabeChecker.add_optionscCst|j�|_dSr)r�max_complexity)r��optionsrrr
�
parse_optionsszMcCabeChecker.parse_optionsccsp�|jdkrdSt�}|�|j|�|j��D]}|��|jkr5|j|j|��f}|j	|j
|t|�fVqdS)Nr)r�rBrrrFr>rA�_error_tmplr+r,r-r{)rrrI�textrrr
�runs�
��zMcCabeChecker.runN)rrr r!r$�__version__�version�_coder�r�r�classmethodr�r�r�rrrr
rs�s

rs��stdinc
Cs�z
t||dtj�}Wnty$t��d}tj�d||f�YdSwg}|t_	t||��
�D]\}}}}	|�d|||f�q1t|�dkrJdSt
d�|��t|�S)N�exec�zUnable to parse %s: %s
rz%s:%d:1: %s�
)�compiler�
PyCF_ONLY_AST�SyntaxError�sys�exc_info�stderr�writersr�r�r0r8r&�join)
�code�	thresholdrwr�e�complxr,�offsetr��checkrrr
�get_code_complexitys�r�cCst|�}t|||d�S)z"Returns the complexity of a module)rw)�_readr�)�module_pathr�r�rrr
�get_module_complexity$sr�cCs<dtjkrdkr(nnt|d��}|��Wd�S1s!wYdSdtjkr3dkr�ndS	zt|d��}t�|j�\}}Wd�n1sPwYWn(ttt	fy~t|dd��}|��Wd�YS1swwYYnwt|d|d��}|��Wd�S1s�wYdSdS)	N)r<�)�r�rU)�r�rbzlatin-1)�encoding�r)
r��version_info�open�read�tokenize�detect_encoding�readline�LookupErrorr��UnicodeError)rw�fr��_rrr
r�*s($���(��$��r�cCs|durtjdd�}t��}|jdddddd�|jdd	d
dddd
�|�|�\}}t|d�}t||ddtj	�}t
�}|�||�|jrgt
d�|j��D]}|jr\|��|jkr`|��qPt
d�dS|j��D]}|��|jkr}t
|j|���qldS)Nr�z-dz--dot�dotzoutput a graphviz dot file�
store_true)�destr|rzz-mz--minr�zminimum complexity for outputr)r�r|r{rrr�zgraph {r4)r��argv�optparse�OptionParserr��
parse_argsr�r�rr�rBrr�r&rFr>r�rAr(r$)r��oparr�rr�rrrIrrr
�main;s8
�
����r��__main__r�)r�r�)r�r)r!�
__future__rr�r�r��collectionsrrr�ImportError�flake8.utilr��objectrr"r*rBrsr�r�r�r�rr�rrrr
�<module>s4�

-

�