o
    tBh                     @  s   d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	m
Z
mZ ddlmZ G dd dZdddZG dd deZd ddZd!ddZG dd dZdS )"zBasic introspection of modules.    )annotationsN)ProcessQueue)
ModuleTypec                   @  s$   e Zd Z						ddddZdS )ModuleProperties NFnamestrfile
str | Nonepathlist[str] | Noneallis_c_moduleboolsubpackagesreturnNonec                 C  s,   || _ || _|| _|| _|| _|pg | _d S Nr   r
   r   r   r   r   )selfr   r
   r   r   r   r    r   i/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/mypy/moduleinspect.py__init__   s   	zModuleProperties.__init__)r   NNNFN)r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   )__name__
__module____qualname__r   r   r   r   r   r      s    r   moduler   r   r   c                 C  s.   | j dd u r
dS tj| j d d dv S )N__file__T)z.soz.pyd)__dict__getosr   splitext)r   r   r   r   r   "   s   r   c                   @  s   e Zd ZdS )InspectErrorN)r   r   r   r   r   r   r   r$   *   s    r$   
package_idr	   c           	   
     s  zt |  W n ty } ztt||d}~ww t d| }t dd}t dd}t|ts4d}t dd}|durPzt|}W n tyO   d}Y nw t	 }|du rj|rg fddt
 D }ng }ntj| jd d	d
 d}dd |D }t||||||dS )zDUse runtime introspection to get information about a module/package.Nr   r   __path____all__c                   s<   g | ]\}}t |r|j jd  | kr jd  | qS ).)inspectismoduler   ).0r   valpackager   r   
<listcomp>G   s    z*get_package_properties.<locals>.<listcomp>r(   c                 S  s   d S r   r   )rr   r   r   <lambda>Q   s    z(get_package_properties.<locals>.<lambda>)prefixonerrorc                 S  s   g | ]\}}}|qS r   r   )r+   importerqualified_nameispkgr   r   r   r/   S   s    r   )	importlibimport_moduleBaseExceptionr$   r	   getattr
isinstancelist	Exceptionr   r)   
getmemberspkgutilwalk_packagesr   r   )	r%   er   r
   r   pkg_allis_cr   all_packagesr   r-   r   get_package_properties.   s@   

rE   tasks
Queue[str]resultsQueue[str | ModuleProperties]sys_path	list[str]r   c              
   C  s\   |t _	 |  }zt|}W n ty' } z|t| W Y d}~qd}~ww || q)z0The main loop of a worker introspection process.TN)sysr   r!   rE   r$   putr	   )rF   rH   rJ   modproprA   r   r   r   workerY   s   
rP   c                   @  sV   e Zd ZdZdddZdddZddd	ZdddZdddZdddZ	dddZ
dS )ModuleInspecta9  Perform runtime introspection of modules in a separate process.

    Reuse the process for multiple modules for efficiency. However, if there is an
    error, retry using a fresh process to avoid cross-contamination of state between
    modules.

    We use a separate process to isolate us from many side effects. For example, the
    import of a module may kill the current process, and we want to recover from that.

    Always use in a with statement for proper clean-up:

      with ModuleInspect() as m:
          p = m.get_package_properties('urllib.parse')
    r   r   c                 C     |    d S r   )_startr   r   r   r   r   v      zModuleInspect.__init__c                 C  s>   t  | _t  | _tt| j| jtjfd| _| j  d| _	d S )N)targetargsr   )
r   rF   rH   r   rP   rL   r   procstartcounterrT   r   r   r   rS   y   s
   

zModuleInspect._startc                 C  s   | j   dS )zFree any resources used.N)rX   	terminaterT   r   r   r   close   s   zModuleInspect.closer%   r	   r   c                 C  sz   | j | |  }|du r|   td|t|tr4| jdkr0|   |   | 	|S t||  jd7  _|S )zReturn some properties of a module/package using runtime introspection.

        Raise InspectError if the target couldn't be imported.
        NzProcess died when importing r      )
rF   rM   _get_from_queuerS   r$   r;   r	   rZ   r\   rE   )r   r%   resr   r   r   rE      s   


z$ModuleInspect.get_package_propertiesModuleProperties | str | Nonec                 C  sZ   d}d}	 ||krt dz| jjddW S  tjy'   | j s%Y dS Y nw |d7 }q)	z{Get value from the queue.

        Return the value read from the queue, or None if the process unexpectedly died.
        iX  r   TzTimeout waiting for subprocessg?)timeoutNr]   )RuntimeErrorrH   r!   queueEmptyrX   is_alive)r   max_iternr   r   r   r^      s   
zModuleInspect._get_from_queuec                 C  s   | S r   r   rT   r   r   r   	__enter__   s   zModuleInspect.__enter__rW   objectc                 G  rR   r   )r\   )r   rW   r   r   r   __exit__   rU   zModuleInspect.__exit__N)r   r   r%   r	   r   r   )r   r`   )r   rQ   )rW   ri   r   r   )r   r   r   __doc__r   rS   r\   rE   r^   rh   rj   r   r   r   r   rQ   f   s    





rQ   )r   r   r   r   rk   )rF   rG   rH   rI   rJ   rK   r   r   )rl   
__future__r   r7   r)   r"   r?   rc   rL   multiprocessingr   r   typesr   r   r   r=   r$   rE   rP   rQ   r   r   r   r   <module>   s     


+