o
    b^                     @   s   d Z ddlmZ ddlZddlZddlZdZdd Zdd Ze	d	Z
e	d
Ze	dZdd Ze	dZe	dZdd Zdd Zdd Zdd ZdZdZdZdZdee e eee dZeeeddZG dd dZG d d! d!ZG d"d# d#eZdS )$z9
generic classes/functions for pyreverse core/extensions
    )print_functionNz.pyreversercc                  C   sT   g } t jdd}|r(t j|t}zt|  } W | S  t	y'   Y | S w | S )z5
    Read config file and return list of options
    HOME )
osenvirongetpathjoinRCFILEopenreadsplitIOError)optionshomeZrcfile r   U/var/www/secure340b-portal/env/lib/python3.10/site-packages/pylint/pyreverse/utils.pyget_default_options   s   r   c                  C   s*   t  } |   | D ]	}tjd| q	dS )z'insert default options to sys.argv
       N)r   reversesysargvinsert)r   argr   r   r   insert_default_options*   s
   r   z^__[A-Za-z0-9]+[A-Za-z0-9_]*__$z^__[_A-Za-z0-9]*[A-Za-z0-9]+_?$z^_[_A-Za-z0-9]*$c                 C   s>   t | r	d}|S t| rd}|S t| rd}|S d}|S )zMreturn the visibility from a name: public, protected, private or special
    specialprivate	protectedpublic)SPECIALmatchPRIVATE	PROTECTED)name
visibilityr   r   r   get_visibility:   s   


r%   z^.*Abstract.*z	^[A-Z_]*$c                 C      t | jS )zWreturn true if the given class node correspond to an abstract class
    definition
    )ABSTRACTr    r#   noder   r   r   is_abstractM      r*   c                 C   r&   )zTreturn true if the given class/function node correspond to final
    definition
    )FINALr    r#   r(   r   r   r   is_finalT   r+   r-   c                 C   
   | j dkS )NZ	interfacetyper(   r   r   r   is_interface[      
r1   c                 C   r.   )N	exceptionr/   r(   r   r   r   is_exception`   r2   r4   r            )ALLZPUB_ONLYr   OTHER)r   r   r   r   c                   @       e Zd ZdZdd Zdd ZdS )FilterMixInz;filter nodes according to a mode and nodes' visibility
    c                 C   sd   d}| dD ]%}z|t| 7 }W q ty, } ztd| tjd W Y d}~qd}~ww || _dS )zinit filter modesr   +zUnknown filter mode %s)fileN)r   MODESKeyErrorprintr   stderr_FilterMixIn__mode)selfmoderB   Znummodexr   r   r   __init__}   s   
zFilterMixIn.__init__c                 C   s    t t|d|}| jt| @  S )z2return true if the node should be treated
        r#   )r%   getattrrB   VIS_MOD)rC   r)   r$   r   r   r   	show_attr   s   zFilterMixIn.show_attrN)__name__
__module____qualname____doc__rF   rI   r   r   r   r   r;   y   s    
r;   c                   @   s:   e Zd ZdZdd ZdddZdd Zd	d
 Zdd ZdS )	ASTWalkera  a walker visiting a tree in preorder, calling on the handler:

    * visit_<class name> on entering a node, where class name is the class of
    the node in lower case

    * leave_<class name> on leaving a node, where class name is the class of
    the node in lower case
    c                 C   s   || _ i | _d S N)handler_cache)rC   rP   r   r   r   rF      s   
zASTWalker.__init__Nc                 C   s   |du rt  }||v rtt|||jf|| | | | D ]}||us+J | || q#| | |j|us>J dS )<walk on the tree from <node>, getting callbacks from handlerN)	setAssertionErroridparentaddvisitZget_childrenwalkleave)rC   r)   _done
child_noder   r   r   rY      s   


zASTWalker.walkc                 C   s   |j }| j|}|du r8| j}|j }t|d| t|dd}t|d| t|dd}||f| j|< ||fS |\}}||fS )z/get callbacks from handler for the visited nodeNzvisit_%sZvisit_defaultzleave_%sZleave_default)	__class__rQ   r   rP   rJ   lowerrG   )rC   r)   klassmethodsrP   kidZe_methodZl_methodr   r   r   get_callbacks   s   
zASTWalker.get_callbacksc                 C   &   |  |d }|dur|| dS dS )rR   r   Nrb   rC   r)   methodr   r   r   rX         zASTWalker.visitc                 C   rc   )rR   r   Nrd   re   r   r   r   rZ      rg   zASTWalker.leaverO   )	rJ   rK   rL   rM   rF   rY   rb   rX   rZ   r   r   r   r   rN      s    	
rN   c                   @   r:   )LocalsVisitorz3visit a project by traversing the locals dictionaryc                 C   s   t | |  i | _d S rO   )rN   rF   _visited)rC   r   r   r   rF      s   
zLocalsVisitor.__init__c                 C   sx   || j v rdS d| j |< | |}|d dur|d | t|dr.| D ]}| | q&|d dur:|d |S dS )z-launch the visit starting from the given nodeNr   r   locals)ri   rb   hasattrvaluesrX   )rC   r)   r`   Z
local_noder   r   r   rX      s   



zLocalsVisitor.visitN)rJ   rK   rL   rM   rF   rX   r   r   r   r   rh      s    rh   )rM   
__future__r   r   rer   r
   r   r   compiler   r!   r"   r%   r'   r,   r*   r-   r1   r4   Z_CONSTRUCTORZ_SPECIALZ
_PROTECTEDZ_PRIVATEr>   rH   r;   rN   rh   r   r   r   r   <module>   sF   





;