
    X-Ph                        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          ZddZd dZ G d de          Zd!dZd"dZ G d d          ZdS )#zBasic introspection of modules.    )annotationsN)Queueget_context)
ModuleTypec                  $    e Zd Z	 	 	 	 	 	 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                ^    || _         || _        || _        || _        || _        |pg | _        d S Nr
   r   r   r   r   r   )selfr
   r   r   r   r   r   s          R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/moduleinspect.py__init__zModuleProperties.__init__   s;     			&&,"    )r	   NNNFN)r
   r   r   r   r   r   r   r   r   r   r   r   r   r   )__name__
__module____qualname__r    r   r   r   r      sA         !% $!(,- - - - - - -r   r   moduler   r   r   c                    | j                             d          dS t          j                            | j         d                   d         dv S )N__file__T)z.soz.pydz.dll)__dict__getosr   splitext)r!   s    r   r   r   "   sG    :&&. t7FOJ788<@WWWr   r   r   c                    t          | o<|                     d          o't          j                            | d d                              S )Nz.pycr$   )r   endswithr'   r   exists)r   s    r   is_pyc_onlyr,   *   s?    Pv..Prw~~d3B3i7P7P3PQQQr   c                      e Zd ZdS )InspectErrorN)r   r   r   r    r   r   r.   r.   .   s        Dr   r.   
package_idr   c                ~  	 	 t          j        |           	n/# t          $ r"}t          t	          |                    |d}~ww xY wt          	d|           }t          	dd          }t          	dd          }t          |t                    sd}t          	dd          }|#	 t          |          }n# t          $ r d}Y nw xY wt          	          }|&|r!	fdt          j        	          D             }n/g }n,t          j        |	j        dz   d 	          }d
 |D             }t          ||||||          S )zDUse runtime introspection to get information about a module/package.Nr   r#   __path____all__c                    g | ]<\  }}t          j        |          r#|j        j        d z   |z   k    /j        d z   |z   =S ).)inspectismoduler   ).0r
   valpackages      r   
<listcomp>z*get_package_properties.<locals>.<listcomp>K   se       D##C(( .1\W=MPS=SVZ=Z-Z-Z  3&--Z-Z-Zr   r4   c                    d S r   r    )rs    r   <lambda>z(get_package_properties.<locals>.<lambda>U   s    4 r   )prefixonerrorc                    g | ]\  }}}|	S r    r    )r7   importerqualified_nameispkgs       r   r:   z*get_package_properties.<locals>.<listcomp>W   s    ZZZ*I(NE~ZZZr   r   )	importlibimport_moduleBaseExceptionr.   r   getattr
isinstancelist	Exceptionr   r5   
getmemberspkgutilwalk_packagesr   r   )
r/   er
   r   r   pkg_allis_cr   all_packagesr9   s
            @r   get_package_propertiesrR   2   s   *)*55 * * *3q66"")*7J
33D7J--D$Wj$??DdD!! gy$//G	7mmGG 	 	 	GGG	wD|  
	   !(!3G!<!<  KK KK,)C/
 
 
 [Z\ZZZ4W$T_   s$    
A?A%B5 5CCtasks
Queue[str]resultsQueue[str | ModuleProperties]sys_path	list[str]r   c                   |t           _        	 |                                 }	 t          |          }n9# t          $ r,}|                    t          |                     Y d}~Wd}~ww xY w|                    |           t)z0The main loop of a worker introspection process.TN)sysr   r&   rR   r.   putr   )rS   rU   rW   modproprN   s         r   workerr^   ]   s    CHiikk	)#..DD 	 	 	KKAHHHH	 	Ds   3 
A)"A$$A)c                  J    e Zd ZdZddZddZddZdd
ZddZddZ	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                .    |                                   d S r   )_startr   s    r   r   zModuleInspect.__init__z   s    r   c                x   t           j        dk    rt          d          }nt          d          }|                                | _        |                                | _        |                    t          | j        | j        t           j        f          | _	        | j	        
                                 d| _        d S )Nlinux
forkserverspawn)targetargsr   )rZ   platformr   r   rS   rU   Processr^   r   procstartcounter)r   ctxs     r   rb   zModuleInspect._start}   s    <7""l++CCg&&C!$
69iikkKKvTZsx4XKYY		r   c                8    | j                                          dS )zFree any resources used.N)rl   	terminaterc   s    r   closezModuleInspect.close   s    	r   r/   r   r   c                   | j                             |           |                                 }|&|                                  t	          d|          t          |t                    rW| j        dk    r=|                                  |                                  | 	                    |          S t	          |          | xj        dz  c_        |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      )
rS   r[   _get_from_queuerb   r.   rH   r   rn   rr   rR   )r   r/   ress      r   rR   z$ModuleInspect.get_package_properties   s    
 	
z"""""$$;KKMMMLjLLMMMc3 	$|a 

22:>>>s###
r   ModuleProperties | str | Nonec                    d}d}	 ||k    rt          d          	 | j                            d          S # t          j        $ r | j                                        sY dS Y nw xY w|dz  }h)	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?)timeoutNrt   )RuntimeErrorrU   r&   queueEmptyrl   is_alive)r   max_iterns      r   ru   zModuleInspect._get_from_queue   s    
 	H}}"#CDDD |'''555;      y))++  44     FA	s   7 (A%$A%c                    | S r   r    rc   s    r   	__enter__zModuleInspect.__enter__   s    r   ri   objectc                .    |                                   d S r   )rr   )r   ri   s     r   __exit__zModuleInspect.__exit__   s    

r   N)r   r   r/   r   r   r   )r   rw   )r   r`   )ri   r   r   r   )r   r   r   __doc__r   rb   rr   rR   ru   r   r   r    r   r   r`   r`   j   s            	 	 	 	      .   "        r   r`   )r!   r   r   r   )r   r   r   r   r   )rS   rT   rU   rV   rW   rX   r   r   )r   
__future__r   rD   r5   r'   rL   r{   rZ   multiprocessingr   r   typesr   r   r   r,   rJ   r.   rR   r^   r`   r    r   r   <module>r      sg   % % " " " " " "      				   



 . . . . . . . .      - - - - - - - -&X X X XR R R R	 	 	 	 	9 	 	 	( ( ( (V
 
 
 
N N N N N N N N N Nr   