a
    _                     @   s   d Z ddlZddlZejd dkZer.efZnddlZefZddl	m
Z
 i Zdae Zdd Ze
ed	d
 Zdd Zdd Ze
edd ZG dd dZG dd dZG dd dZdd ZdS )zThis module implements a post import hook mechanism styled after what is
described in PEP-369. Note that it doesn't cope with modules being reloaded.

    N      )synchronizedFc                    s    fdd}|S )Nc                    sF     d\}}| d}t| tj| }|D ]}t||}q.|| S )N:.)split
__import__sysmodulesgetattr)modulemodule_nameZfunctionattrscallbackattrname -lib/python3.9/site-packages/wrapt/importer.pyimport_hook%   s    

z4_create_import_hook_from_string.<locals>.import_hookr   )r   r   r   r   r   _create_import_hook_from_string$   s    r   c                 C   s   t | trt| } ts*datjdt  t	|d }|d u rrtj
	|d }|d urfg t|< | | q| gt|< n*|g krtj
| }| | nt| |  d S NTr   )
isinstancestring_typesr   _post_import_hooks_initr	   	meta_pathinsertImportHookFinder_post_import_hooksgetr
   append)hookr   hooksr   r   r   r   register_post_import_hook/   s     



r#   c                    s    fdd}|S )Nc                    s4   t  j tj j } jD ]}t||}q|| S N)r   r   r	   r
   r   r   )r   r   r   
entrypointr   r   r   g   s
    

z8_create_import_hook_from_entrypoint.<locals>.import_hookr   )r&   r   r   r%   r   #_create_import_hook_from_entrypointf   s    r'   c                 C   sL   zdd l }W n ty    Y d S 0 |j| dD ]}t|}t||j q.d S )Nr   )group)pkg_resourcesImportErrorZiter_entry_pointsr'   r#   r   )r(   r)   r&   r   r   r   r   discover_post_import_hookso   s    r+   c                 C   s:   t | dd }t|d }|r6g t|< |D ]}||  q(d S )N__name__)r   r   r   )r   r   r"   r!   r   r   r   notify_module_loaded~   s    r-   c                   @   s   e Zd Zdd ZdS )_ImportHookLoaderc                 C   s   t j| }t| |S r$   )r	   r
   r-   selffullnamer   r   r   r   load_module   s    
z_ImportHookLoader.load_moduleN)r,   
__module____qualname__r2   r   r   r   r   r.      s   r.   c                   @   s   e Zd Zdd Zdd ZdS )_ImportHookChainedLoaderc                 C   s
   || _ d S r$   )loader)r0   r6   r   r   r   __init__   s    z!_ImportHookChainedLoader.__init__c                 C   s   | j |}t| |S r$   )r6   r2   r-   r/   r   r   r   r2      s    z$_ImportHookChainedLoader.load_moduleN)r,   r3   r4   r7   r2   r   r   r   r   r5      s   r5   c                   @   s&   e Zd Zdd ZeedddZdS )r   c                 C   s
   i | _ d S r$   )in_progress)r0   r   r   r   r7      s    zImportHookFinder.__init__Nc              	   C   s   |t vrd S || jv rd S d| j|< z|trBt| t W | j|= S zdd l}|j|j}W n" t	t
fy~   |||}Y n0 |rt|W | j|= S W | j|= n
| j|= 0 d S r   )r   r8   PY2r   r.   importlib.utilutil	find_specr6   r*   AttributeErrorfind_loaderr5   )r0   r1   path	importlibr6   r   r   r   find_module   s*    	

	
zImportHookFinder.find_module)N)r,   r3   r4   r7   r   _post_import_hooks_lockrA   r   r   r   r   r      s   r   c                    s    fdd}|S )Nc                    s   t |   | S r$   )r#   )r!   r   r   r   register   s    
zwhen_imported.<locals>.registerr   )r   rC   r   r   r   when_imported   s    rD   )__doc__r	   Z	threadingversion_infor9   Z
basestringr   r@   strZ
decoratorsr   r   r   RLockrB   r   r#   r'   r+   r-   r.   r5   r   rD   r   r   r   r   <module>   s,   	
6	
A