a �DOg�;�@s�ddlZddlZddlZddlZddlmZmZmZgd�Z iZ Gdd�d�Z Gdd�de �Z Gdd �d e �Z d d �Zdd d �Zddd�Zddd�Zd dd�Zdd�Zdd�Zdd�Zdd�Zedkr�e�dS)!�N)�NAME�DEDENT�OP)� readmodule� readmodule_ex�Class�Functionc@seZdZdd�Zdd�ZdS)�_ObjectcCs(||_||_||_||_||_i|_dS�N)�module�name�file�lineno�parent�children��selfr r r rr�r�/usr/lib64/python3.9/pyclbr.py�__init__6s z_Object.__init__cCs||j|<dSr )r)rr �objrrr� _addchild>sz_Object._addchildN)�__name__� __module__� __qualname__rrrrrrr 4sr c@seZdZddd�ZdS)rNcCst�||||||�dSr )r rrrrrrDszFunction.__init__)N)rrrrrrrrrBsrcs&eZdZd�fdd� Zdd�Z�ZS)rNcs0t�||||||�|dur gn||_i|_dSr )r r�super�methods)rr r rr rr�� __class__rrrJszClass.__init__cCs||j|<dSr )r)rr rrrr� _addmethodOszClass._addmethod)N)rrrrr� __classcell__rrrrrHsrcCs:t|j||j||�}|�||�t|t�r6|�||�|Sr )rr r r� isinstancerr)�ob� func_namerZnewfuncrrr�_nest_functionSs    r$cCs&t|j|||j||�}|�||�|Sr )rr r r)r"� class_namerrZnewclassrrr� _nest_class[s r&cCs6i}t||pg���D]\}}t|t�r|||<q|Sr )� _readmodule�itemsr!r)r �path�res�key�valuerrrras   rcCst||p g�Sr )r')r r)rrrrmsrc Cs~|durd||f}n|}|tvr*t|Si}|tjvrL|durL|t|<|S|�d�}|dkr�|d|�}||dd�}t|||�}|dur�d||f}d|vr�td�|���t||d|�Sd} |dur�|} n |tj} tj � || �} | du�rt d|��|d��|t|<| j du�r$| j |d<z| j �|�} Wnttf�yP|YS0| du�r`|S| j �|�} t||| | ||�S) Nz%s.%s�.r��__path__zNo package named {}zno module named )r )�_modules�sys�builtin_module_names�rfindr'� ImportError�formatr)� importlib�util�_find_spec_from_path�ModuleNotFoundError�submodule_search_locations�loader� get_source�AttributeError� get_filename� _create_tree)r r)� inpackage� fullmodule�tree�i�packageZ submoduler�f� search_path�spec�source�fnamerrrr'vsJ            r'c! CsDt�|�}g}t�|j�}�z|D�]�\} } } } } | tkr`| \}}|r^|dd|kr^|d=qBq"| dkr�| \}}|r�|dd|kr�|d=qpt|�dd�\} }} | tkr�q"d}|r�|dd}t|||�}nt ||||�}|||<|� ||f�q"| dk�r�| \}}|�r(|dd|k�r(|d=�qt|�dd�\} }} | tk�rJq"t|�dd�\} } } d}| dk�r�g}d}g}t|�dd�\} } } | dv�r|dk�rd � |�}||v�r�||}nL|� d �}t |�dk�r|d }|d}|tv�rt|}||v�r||}|� |�g}| dk�r0|d7}nZ| d k�rR|d8}|dk�r��q�n8| d k�rh|dk�rhn"| ttfv�rz|dk�rz|� | ��qz|}|�r�|dd}t||||�}nt|||||�}|||<|� ||f�q"| dk�rf| ddk�rft|�}|D]b\}}zJ|du�r t||�n0zt|||�Wnt�yNt|g�Yn0Wn Yn0�qq"| dkr"| ddkr"t|�\}} |r"| dk�r�q"t|�}zt|||�}WnYq"Yn0|D]X\}} ||v�r�|||| �p�|<n0|dk�r�|D] }|ddk�r�||||<�q��q�q"Wnt�y6Yn0|��|S)N�����r.�defr��class�()�)�,�r-�����rOrP�import�from�*�_)�io�StringIO�tokenize�generate_tokens�readliner�nextrr$r�append�join�split�lenr0rr&r� _getnamelistr'r4�_getname� StopIteration�close)!rAr)rIrHrBr@rE�stack�g� tokentype�token�startZ_end�_linerZ thisindentr#Zcur_funcZcur_objr%Zinherit�names�levelr�n�c�m�dZ cur_class�modules�modZ_mod2Zn2rrrr?�s�                    ��         r?cCslg}t|�\}}|sqh|dkr,t|�\}}nd}|�||f�|dkr\d|vr\t|�d}q>|dkrqhq|S)N�asrP� r.)rbr]r\)rfrkr rhZname2rrrraEs racCs�g}t|�dd�\}}|tkr0|dkr0d|fS|�|�t|�dd�\}}|dkrXq�t|�dd�\}}|tkrvq�|�|�q:d�|�|fS)Nr�rUr-)r\rr]r^)rf�partsrgrhrrrrb[s  rbc CsXddl}ztjd}Wnt}Yn0|j�|�rj|j�|�g}|j�|�}|��� d�rn|dd�}ng}t ||�}dd�}t |� �|dd�}d }|�rT|� �}t|t�r�q�t|d �s�d|_t|t�r�t |j� �|dd�}|D]} |j|| _q�|�|�t|t��r,td �d |j|j|j|j��q�t|t�r�td �d |j|j|j��q�dS)Nrr.z.py�����cSs t|dd�S)Nrr)�getattr)�arrr�|�z_main..T)r+�reverseru�indentz{}class {} {} {}� z {}def {} {})�osr1�argv�__file__r)�exists�dirname�basename�lower�endswithr�sorted�values�popr!�list�hasattrr}r r�extendr�printr5r rrr) rrrr)rBZ lineno_keyZobjsZ indent_levelrZnew_objsr"rrr�_mainmsD        �  � r��__main__)N)N)N)N)rWr1�importlib.utilr6rYrhrrr�__all__r0r rrr$r&rrr'r?rarbr�rrrrr�)s*   @&