o
    tBh:                     @   s   d dl Z d dlmZ d dlZd dlZd dlZG dd deZG dd deZdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd ZG dd deZG dd deZdS )    N)IntEnumc                   @   s   e Zd ZdS )VultureInputExceptionN)__name__
__module____qualname__ r   r   d/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/vulture/utils.pyr      s    r   c                   @   s   e Zd ZdZdZdZdZdS )ExitCoder            N)r   r   r   
NoDeadCodeInvalidInputInvalidCmdlineArgumentsDeadCoder   r   r   r   r	      s
    r	   c                    s   t | tjr fdd| jD }t | jtjrt|S t|S t | tjr4t | jtj	r4t
| j   S zt| W S  tyE     Y S w )a  
    Safely evaluate the Boolean expression under the given AST node.

    Substitute `default` for all sub-expressions that cannot be
    evaluated (because variables or functions are undefined).

    We could use eval() to evaluate more sub-expressions. However, this
    function is not safe for arbitrary Python code. Even after
    overwriting the "__builtins__" dictionary, the original dictionary
    can be restored
    (https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html).

    c                    s   g | ]}t | qS r   
_safe_eval).0valuedefaultr   r   
<listcomp>"   s    z_safe_eval.<locals>.<listcomp>)
isinstanceastBoolOpvaluesopAndallanyUnaryOpNotr   operandliteral_eval
ValueError)noder   resultsr   r   r   r      s   r   c                 C   s   t | d S )NTr   	conditionr   r   r   condition_is_always_false0   s   r)   c                 C   s
   t | dS )NFr   r'   r   r   r   condition_is_always_true4   s   
r*   c                 C   s   t | tjot | jtS N)r   r   Constantr   str)r%   r   r   r   is_ast_string8   s   r.   c                 C   s*   z	|  tj W S  ty   |  Y S w r+   )relative_topathlibPathcwdr$   )pathr   r   r   format_path<   s
   r4   c                 C   sz   t | tjr	| j} zg }t | tjr!|| j | j} t | tjs|| j W n t	y3   g }Y nw dd
t| S )N@.)r   r   Callfunc	Attributeappendattrr   idAttributeErrorjoinreversed)	decoratorpartsr   r   r   get_decorator_nameD   s   rB   c                 C   sv   g }| D ]4}|  }| r"|jdkrtd|  q|| q| r/||d qtd| d q|S )zRetrieve Python files to check.

    Loop over all given paths, abort if any ends with .pyc, add the other given
    files (even those not ending with .py) and collect all .py files under the
    given directories.

    z.pycz&Error: *.pyc files are not supported: z*.pyzError: z could not be found.)	resolveis_filesuffixsysexitr:   is_dirextendrglob)pathsmodulesr3   r   r   r   get_modulesR   s   
rM   c              
   C   s^   zt | }| W  d    W S 1 sw   Y  W d S  ttfy. } zt|d }~ww r+   )tokenizeopenreadSyntaxErrorUnicodeDecodeErrorr   )filenameferrr   r   r   	read_filei   s   (rV   c                       (   e Zd Z fddZ fddZ  ZS )LoggingListc                       || _ || _t  S r+   typ_verbosesuper__init__selfr[   verbose	__class__r   r   r^   s      
zLoggingList.__init__c                    s0   | j rtd| j d|j d t | d S )Nzdefine  "")r\   printr[   namer]   r:   )r`   itemrb   r   r   r:   x   s   zLoggingList.append)r   r   r   r^   r:   __classcell__r   r   rb   r   rX   r       rX   c                       rW   )
LoggingSetc                    rY   r+   rZ   r_   rb   r   r   r^      rd   zLoggingSet.__init__c                    s.   | j rtd| j d| d t | d S )Nzuse re   rf   )r\   rg   r[   r]   add)r`   rh   rb   r   r   rm      s   zLoggingSet.add)r   r   r   r^   rm   rj   r   r   rb   r   rl   ~   rk   rl   )r   enumr   r0   rF   rN   	Exceptionr   r	   r   r)   r*   r.   r4   rB   rM   rV   listrX   setrl   r   r   r   r   <module>   s"    	