OwlCyberSecurity - MANAGER
Edit File: mccabe.cpython-311.pyc
� ������h�)�����������������������f����d�Z�ddlmZ�ddlZddlZddlZddlmZ� �ddlZddlm Z �n#�e $�r�ddlmZm Z �Y�nw�xY�wdZ�G�d��d e ������������Z�G�d ��de ������������Z�G�d��d e ������������Z�G�d��de������������Z�G�d��de ������������Zdd�Zdd�Zd��Zdd�Zedk����r�eej��������dd�����������������������dS�dS�)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)�astr���z0.7.0c��������������������*�����e�Zd�ZdZd��Zd��Zd��Zd��ZdS�)� ASTVisitorz'Performs a depth-first walk of the AST.c������������������"�����d�|�_���������i�|�_��������d�S��N)�node�_cache��selfs��� �W/builddir/build/BUILD/cloudlinux-venv-1.0.8/venv/lib/python3.11/site-packages/mccabe.py�__init__zASTVisitor.__init__���s�������� ����������c������������������F�����t����������|������������D�]}�|�j��������|g|�R�����d�S�r ���)r����dispatch)r���r����args�childs��� r����defaultzASTVisitor.default���s@������%�d�+�+�� (�� (�E��D�M�%�'�$�'�'�'�'�'� (�� (r���c������������������������||�_���������|j��������}|�j�����������������������������|������������}|�/|j��������}t����������|�j��������d|z���|�j��������������������}||�j��������|<����||g|�R���S�)N�visit)r���� __class__r����get�__name__�getattr�visitorr���)r���r���r����klass�meth� classNames��� r���r���zASTVisitor.dispatch!���sm�������� �����{���u�%�%���<���I��4�<��9�)<�d�l�K�K�D�!%�D�K����t�D� �4� � � � r���c������������������H�����||�_���������|�j��������|_���������|�j��������|g|�R����dS�)z&Do preorder walk of tree using visitorN)r���r���r���)r����treer���r���s��� r����preorderzASTVisitor.preorder+���s2���������� �� ��� �d�"�T�"�"�"�"�"�"r���N)r���� __module__�__qualname__�__doc__r���r���r���r#�����r���r���r���r������sV��������������1�1������(��(��(�!��!��!�#��#��#��#��#r���r���c��������������������"�����e�Zd�Zdd�Zd��Zd��ZdS�)�PathNode�circlec������������������"�����||�_���������||�_��������d�S�r ���)�name�look)r���r,���r-���s��� r���r���zPathNode.__init__3���s�������� ��� � � r���c������������������h�����t����������d|�j��������|�j��������|������������������������������������fz���������������d�S�)Nznode [shape=%s,label="%s"] %d;)�printr-���r,����dot_idr ���s��� r����to_dotzPathNode.to_dot7���s>������ �.��I�t�y�$�+�+�-�-�21��1�� 2�� 2�� 2�� 2�� 2r���c������������������ �����t����������|�������������S�r ���)�idr ���s��� r���r0���zPathNode.dot_id;���s �������$�x�x�r���N)r*���)r���r$���r%���r���r1���r0���r'���r���r���r)���r)���2���sF���������������������2��2��2���������r���r)���c��������������������(�����e�Zd�Zdd�Zd��Zd��Zd��ZdS�)� PathGraphr���c������������������p�����||�_���������||�_��������||�_��������||�_��������t ����������t ����������������������|�_��������d�S�r ���)r,����entity�lineno�columnr����list�nodes)r���r,���r7���r8���r9���s��� r���r���zPathGraph.__init__@���s1�������� ���������� ��&�&�� � � r���c������������������Z�����|�j���������|������������������������������|�������������g�|�j���������|<���d�S�r ���)r;����append)r����n1�n2s��� r����connectzPathGraph.connectG���s+������� �2����b�!�!�!��� �2���r���c������������������8����t����������d�������������|�j��������D�]}|�������������������������������������|�j�������������������������������������������D�]C\��}}|D�];}t����������|������������������������������������d|������������������������������������d���������������<�Dt����������d�������������d�S�)Nz subgraph {z -- �;�})r/���r;���r1����itemsr0���)r���r����nexts�nexts��� r���r1���zPathGraph.to_dotL���s������� �l�����J�� �� �D��K�K�M�M�M�M��:�+�+�-�-�� D�� D�K�D�%��� D�� D���T�[�[�]�]�]�]�D�K�K�M�M�M�M�B�C�C�C�C� D� �c� � � � � r���c�����������������������t����������d��|�j�������������������������������������������D���������������������������}t����������|�j��������������������}||z ��dz���S�)zG Return the McCabe complexity for the graph. V-E+2 c������������������,�����g�|�]}t����������|��������������S�r'���)�len)�.0�ns��� r���� <listcomp>z(PathGraph.complexity.<locals>.<listcomp>Y���s������=�=�=�A��Q���=�=�=r�������)�sumr;����valuesrI���)r���� num_edges� num_nodess��� r���� complexityzPathGraph.complexityU���sK��������=�=���):�):�)<�)<�=�=�=�>�>� ��� �O�O� ��9�$�q�(�(r���N)r���)r���r$���r%���r���r@���r1���rR���r'���r���r���r5���r5���?���sU��������������'��'��'��'������ �����)��)��)��)��)r���r5���c���������������������������e�Zd�ZdZ��fd�Zd��Zd��Zd��ZeZd��Z d��Z d��Z��fd �Zd ��Z e xZxZZd��Zdd �Zd��Zd��ZeZd��ZeZ��xZS�)�PathGraphingAstVisitorz\ A visitor for a parsed Abstract Syntax Tree which finds executable statements. c������������������������t����������t����������|�������������������������������������������������d|�_��������i�|�_��������|�������������������������������������d�S�)N��)�superrT���r���� classname�graphs�reset)r���r���s��� �r���r���zPathGraphingAstVisitor.__init__c���s?������� �$�d�+�+�4�4�6�6�6�������� � �����r���c������������������"�����d�|�_���������d�|�_��������d�S�r ���)�graph�tailr ���s��� r���rZ���zPathGraphingAstVisitor.reseti���s�������� ��� � � r���c������������������:�����|D�]}|�����������������������|��������������d�S�r ���)r���)r���� node_listr���s��� r���� dispatch_listz$PathGraphingAstVisitor.dispatch_listm���s0�������� �� �D��M�M�$����� �� r���c����������������������|�j���������r|�j����������|j����������}n|j��������}d|j��������|j��������|fz��}|�j����������|����������������������|������������}||�_��������|����������������������|j���������������������t����������dd�������������}|�j��������� ��������������������|�j��������|�������������|�j��������� ��������������������||�������������||�_��������d�S�t����������|||j��������|j��������������������|�_��������t����������|������������}||�_��������|����������������������|j���������������������|�j��������|�j��������|�j����������|j����������<���|�� �����������������������������������d�S�)Nz %d:%d: %rrV����point�r-���)rX���r,���r8���� col_offsetr\����appendPathNoder]���r`����bodyr)���r@���r5���rY���rZ���)r���r���r7���r,����pathnode�bottoms��� r����visitFunctionDefz'PathGraphingAstVisitor.visitFunctionDefq���s0������>�� �#�~�~�t�y�y�9�F�F��Y�F��d�k�4�?�F�C�C���:�!��*�*�4�0�0�H� �D�I����t�y�)�)�)��b�w�/�/�/�F��J���t�y�&�1�1�1��J���x��0�0�0��D�I�I�I�"�4����d�o�N�N�D�J���~�~�H� �D�I����t�y�)�)�)�@D� �D�K�$�.�.�$�)�)�<�=��J�J�L�L�L�L�Lr���c�����������������������|�j���������}|�xj���������|j��������dz���z ��c_���������|����������������������|j���������������������||�_���������d�S�)N�.)rX���r,���r`���rf���)r���r���� old_classnames��� r���� visitClassDefz$PathGraphingAstVisitor.visitClassDef����s@�������� ����$�)�c�/�)������4�9�%�%�%�&����r���c�����������������������|�j���������sd�S�t����������|������������}|�j�����������������������������|�j���������|�������������||�_���������|S�r ���)r]���r)���r\���r@���)r���r,���rg���s��� r���re���z%PathGraphingAstVisitor.appendPathNode����sB�������y�� ��F��D�>�>��� ���4�9�h�/�/�/��� ��r���c������������������\�����|j����������d}n|j���������}d|z��}|����������������������|�������������d�S�)Nr���zStmt %d)r8���re���)r���r���r8���r,���s��� r����visitSimpleStatementz+PathGraphingAstVisitor.visitSimpleStatement����s<�������;���F�F��[�F��6�!�����D�!�!�!�!�!r���c������������������������t����������|t����������j��������������������r|����������������������|�������������d�S��t ����������t ����������|�������������j��������|g|�R����d�S�r ���)� isinstancer����stmtrp���rW���rT���r���)r���r���r���r���s��� �r���r���zPathGraphingAstVisitor.default����s^��������d�C�H�%�%�� E��%�%�d�+�+�+�+�+�7�E�(�$�/�/�7��D�t�D�D�D�D�D�Dr���c������������������F�����d|j���������z��}|����������������������||�������������d�S�)NzLoop %d�r8���� _subgraph�r���r���r,���s��� r���� visitLoopz PathGraphingAstVisitor.visitLoop����s(�������4�;�&�����t�T�"�"�"�"�"r���c������������������F�����d|j���������z��}|����������������������||�������������d�S�)NzIf %dru���rw���s��� r����visitIfzPathGraphingAstVisitor.visitIf����s(���������$�����t�T�"�"�"�"�"r���r'���c������������������V����|�j����������ut����������|||j��������|j��������������������|�_���������t ����������|������������}|����������������������|||�������������|�j���������|�j��������|�j���������|��<���|�������������������������������������dS�|�� ��������������������|������������}|����������������������|||�������������dS�)z?create the subgraphs representing any `if` and `for` statementsN) r\���r5���r8���rd���r)����_subgraph_parserY���rX���rZ���re���)r���r���r,����extra_blocksrg���s��� r���rv���z PathGraphingAstVisitor._subgraph����s��������:��"�4��t�{�D�O�L�L�D�J���~�~�H�� � ��x��>�>�>�;?�:�D�K�$�.�.�$�$�7�8��J�J�L�L�L�L�L��*�*�4�0�0�H�� � ��x��>�>�>�>�>r���c������������������(����g�}||�_���������|����������������������|j���������������������|���������������������|�j����������������������|D�]=}||�_���������|����������������������|j���������������������|���������������������|�j�����������������������>|j��������r<||�_���������|����������������������|j���������������������|���������������������|�j����������������������n|���������������������|�������������|r:t����������dd�������������}|D�]}|�j�����������������������������||��������������||�_���������dS�dS�)z@parse the body and any `else` block of `if` and `for` statementsrV���rb���rc���N)r]���r`���rf���r=����orelser)���r\���r@���)r���r���rg���r}���� loose_ends�extrarh����les��� r���r|���z&PathGraphingAstVisitor._subgraph_parse����s,������ ��� ����4�9�%�%�%����$�)�$�$�$�!�� )�� )�E� �D�I����u�z�*�*�*����d�i�(�(�(�(��;�� (� �D�I����t�{�+�+�+����d�i�(�(�(�(����h�'�'�'��� ��b�w�/�/�/�F� �� /�� /��� �"�"�2�v�.�.�.�.��D�I�I�I� �� r���c������������������T�����d|j���������z��}|����������������������|||j����������������������d�S�)NzTryExcept %d)r}���)r8���rv����handlersrw���s��� r����visitTryExceptz%PathGraphingAstVisitor.visitTryExcept����s.���������+�����t�T�� ��>�>�>�>�>r���c������������������x�����d|j���������z��}|����������������������|�������������|����������������������|j���������������������d�S�)NzWith %d)r8���re���r`���rf���rw���s��� r���� visitWithz PathGraphingAstVisitor.visitWith����s>�������4�;�&�����D�!�!�!����4�9�%�%�%�%�%r���)r'���)r���r$���r%���r&���r���rZ���r`���ri����visitAsyncFunctionDefrm���re���rp���r���rx���� visitAsyncFor�visitFor� visitWhilerz���rv���r|���r�����visitTryr�����visitAsyncWith� __classcell__)r���s���@r���rT���rT���^���s4������������������������������� �� �� ������4�-��'��'��'������"��"��"�E��E��E��E��E�#��#��#��-6�5�M�5�H�z�#��#��#�?��?��?��?������,?��?��?���H�&��&��&� ��N�N�N�N�Nr���rT���c��������������������^�����e�Zd�ZdZdZeZdZdZdZ d��Z ed����������������Zed����������������Z d ��Zd S�)� McCabeCheckerz%McCabe cyclomatic complexity checker.�mccabe�C901zC901 %r is too complex (%d)���c�����������������������||�_���������d�S�r ���)r"���)r���r"����filenames��� r���r���zMcCabeChecker.__init__����s �������� � � r���c������������������ ����d}ddt�����������ddd�}t����������|dd�������������}t����������|t����������������������r?|���������������������d��������������|j��������|fi�|���|j�����������������������������d �������������d�S��|j��������|fi�|���d�S�) Nz--max-complexityr�����storezMcCabe complexity threshold�True)r����action�type�help�parse_from_config�config_optionsr����zmax-complexity)�intr���rr���r:����pop� add_optionr����r=���)�cls�parser�flag�kwargs�config_optss��� r����add_optionszMcCabeChecker.add_options����s�������!�����1�!'� �� ����f�&6��=�=���k�4�(�(�� .��J�J�*�+�+�+��F��d�-�-�f�-�-�-��!�(�(�)9�:�:�:�:�:��F��d�-�-�f�-�-�-�-�-r���c������������������8�����t����������|j��������������������|�_��������d�S�r ���)r�����max_complexity)r�����optionss��� r���� parse_optionszMcCabeChecker.parse_options��s������ ��!7�8�8����r���c��������������#����l��K����|�j���������dk�����rd�S�t������������������������}|���������������������|�j��������|�������������|j�������������������������������������������D�]a}|�����������������������������������|�j���������k����rB|�j��������|j��������|�����������������������������������fz��}|j ��������|j ��������|t����������|�������������fV����bd�S�)Nr���)r����rT���r#���r"���rY���rO���rR����_error_tmplr7���r8���r9���r����)r���r���r\����texts��� r����runzMcCabeChecker.run��s��������������"�"��F�(�*�*�������G�,�,�,��^�*�*�,�,�� C�� C�E����!�!�D�$7�7�7��'�5�<��9I�9I�9K�9K�*L�L���l�E�L�$��T� � �B�B�B�B�� C�� Cr���N)r���r$���r%���r&���r,����__version__�version�_coder����r����r����classmethodr����r����r����r'���r���r���r����r��������s���������������/�/��D��G��E�/�K��N��������.��.���[�.�$��9��9���[�9�C��C��C��C��Cr���r���������stdinc���������������������� �t����������|�|dt����������j��������������������}nP#�t����������$�rC�t ����������j����������������������d���������}t����������j�����������������������������d|�d|�d��������������Y�dS�w�xY�wg�}|t����������_ ��������t����������||������������� ����������������������������������D�]"\��}}}} |���������������������d|||fz����������������#t����������|������������dk����rdS�t����������d���������������������|�������������������������t����������|������������S�)N�exec����zUnable to parse z: � r���z%s:%d:1: %s)�compiler���� PyCF_ONLY_AST�SyntaxError�sys�exc_info�stderr�writer����r����r����r=���rI���r/����join) �code� thresholdr����r"����e�complxr8����offsetr�����checks ��� r����get_code_complexityr������s�������t�X�v�s�/@�A�A������������L�N�N�1���� ����x�x�x����C�D�D�D��q�q����� ��F�#,�M� �'4�T�8�'D�'D�'H�'H�'J�'J��@��@�#����e�� � �m�x���&>�>�?�?�?�?� �6�{�{�a����q� �$�)�)�F� � �����v�;�;�s������A A,�+A,c������������������D�����t����������|�������������}t����������|||��������������S�)z"Returns the complexity of a module)r����)�_readr����)�module_pathr����r����s��� r����get_module_complexityr����$��s$����������D��t�Y��E�E�E�Er���c����������������������dt�����������j��������cxk�����rdk�����rAn�n>t����������|�d������������5�}|�����������������������������������cd�d�d��������������S�#�1�swxY�w�Y���d�S�dt�����������j��������cxk����rdk�����r�n�d�S� � �t����������|�d������������5�}t ����������j��������|j��������������������\��}}d�d�d��������������n#�1�swxY�w�Y���n\#�t����������t����������t����������f$�rB�t����������|�d�������������5�}|�����������������������������������cd�d�d��������������cY�S�#�1�swxY�w�Y���Y�nw�xY�wt����������|�d|�������������5�}|�����������������������������������cd�d�d��������������S�#�1�swxY�w�Y���d�S�d�S�) N)rM�������)����r����rU)����r����rbzlatin-1)�encoding�r) r�����version_info�open�read�tokenize�detect_encoding�readline�LookupErrorr�����UnicodeError)r�����fr�����_s��� r���r����r����*��s������ �� �)�)�)�)�6�)�)�)�)�)� �(�D� !� !�� �Q��6�6�8�8� �� �� �� �� �� �� �� �� �� �� �� ����� �� �� �� �� �� � �3�#� ,� ,� ,� ,�f� ,� ,� ,� ,� ,� ,�#� ��h��%�%�� E�� (� 8��� D� D� ��1� E�� E�� E�� E�� E�� E�� E�� E�� E�� E�� E����� E�� E�� E�� E����[�,�7�� �� �� ��h��3�3�3�� �q��v�v�x�x� �� �� �� �� �� �� �� �� �� �� �� �� �� ����� �� �� �� �� �� � ������(�C�(� 3� 3� 3�� �q��6�6�8�8� �� �� �� �� �� �� �� �� �� �� �� ����� �� �� �� �� �� �� -� ,s}����A�A�A�6B;��B/�#B;��/B3�3B;��6B3�7B;��;(D�#D�7 D�D � D� D �D�D�)E � E�Ec������������������^����|��t�����������j��������dd�����������}�t����������j����������������������}|���������������������ddddd��������������|���������������������dd d ddd� �������������|���������������������|�������������\��}}t ����������|d���������������������}t����������||d���������dt����������j ��������������������}t������������������������}|���������������������||�������������|j��������rtt����������d�������������|j�������������������������������������������D�]:}|j��������r|�����������������������������������|j��������k����r|�������������������������������������;t����������d�������������d�S�|j�������������������������������������������D�]F}|�����������������������������������|j��������k����r't����������|j��������|�������������������������������������������������Gd�S�)Nr����z-dz--dot�dotzoutput a graphviz dot file� store_true)�destr����r����z-mz--minr����zminimum complexity for outputr����)r����r����r����r���r���r����zgraph {rC���)r�����argv�optparse�OptionParserr����� parse_argsr����r����r���r����rT���r#���r����r/���rY���rO���r����rR���r1���r,���)r�����oparr����r���r����r"���r���r\���s��� r����mainr����;��s�������|��x����|��� �"�"�D��O�O�D�'��5�l����L��L��L��O�O�D�'��8�u������������O�O�D�)�)�M�G�T���a��>�>�D��4��a��&�#�*;�<�<�D�$�&�&�G����T�7�#�#�#��{�� 6� �i�����^�*�*�,�,�� �� �E��%�� ��$�$�&�&�'�*;�;�;�������� �c� � � � � ��^�*�*�,�,�� 6�� 6�E����!�!�W�%6�6�6��e�j�%�"2�"2�"4�"4�5�5�5�� 6�� 6r����__main__r����)r����r����)r����r ���)r&���� __future__r���r����r����r�����collectionsr���r���r����ImportError�flake8.utilr�����objectr���r)���r5���rT���r����r����r����r����r����r���r����r'���r���r����<module>r�������s������� �&��%��%��%��%��%������� � � � �������#��#��#��#��#��#�2��J�J�J�$�$�$�$�$�$�$����2��2��2�1�1�1�1�1�1�1�1�1�1�2�������#��#��#��#��#���#��#��#�8 �� �� �� �� �v�� �� �� �)��)��)��)��)���)��)��)�>C��C��C��C��C�Z��C��C��C�L*C��*C��*C��*C��*C�F��*C��*C��*C�Z�������&F��F��F��F������"6��6��6��6�<��z����D���!�"�"���������s���� '�� 7�7