B
    !]\                 @   s   d Z ddlZddlZejd dkZejd dkZerDddlZefZn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                sJ     d\}}| d}t| tj| }x|D ]}t||}q0W || S )N:.)split
__import__sysmodulesgetattr)modulemodule_nameZfunctionattrscallbackattr)name -lib/python3.7/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 krrtj
	|d }|d k	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_hook0   s     



r"   c                s    fdd}|S )Nc                s8   t  j tj j }x jD ]}t||}qW || S )N)r	   r   r
   r   r   r   )r   r   r   )
entrypointr   r   r   h   s
    
z8_create_import_hook_from_entrypoint.<locals>.import_hookr   )r#   r   r   )r#   r   #_create_import_hook_from_entrypointg   s    r$   c             C   sP   ydd l }W n tk
r    d S X x(|j| dD ]}t|}t||j q0W d S )Nr   )group)pkg_resourcesImportErrorZiter_entry_pointsr$   r"   r   )r%   r&   r#   r   r   r   r   discover_post_import_hooksp   s    r(   c             C   s>   t | dd }t|d }|r:g t|< x|D ]}||  q*W 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 )N)r
   r   r*   )selffullnamer   r   r   r   load_module   s    
z_ImportHookLoader.load_moduleN)r)   
__module____qualname__r.   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 )N)loader)r,   r2   r   r   r   __init__   s    z!_ImportHookChainedLoader.__init__c             C   s   | j |}t| |S )N)r2   r.   r*   )r,   r-   r   r   r   r   r.      s    z$_ImportHookChainedLoader.load_moduleN)r)   r/   r0   r3   r.   r   r   r   r   r1      s   r1   c               @   s&   e Zd Zdd ZeedddZdS )r   c             C   s
   i | _ d S )N)in_progress)r,   r   r   r   r3      s    zImportHookFinder.__init__Nc          	   C   s   |t krd S || jkrd S d| j|< zdtrxydd l}|j|j}W n$ ttfk
rh   |	||}Y nX |rt
|S nt| t S W d | j|= X d S )NTr   )r   r4   PY3importlib.utilutil	find_specr2   r'   AttributeErrorfind_loaderr1   r	   r+   )r,   r-   path	importlibr2   r   r   r   find_module   s"    	



zImportHookFinder.find_module)N)r)   r/   r0   r3   r   _post_import_hooks_lockr=   r   r   r   r   r      s   r   c                s    fdd}|S )Nc                s   t |   | S )N)r"   )r    )r   r   r   register   s    
zwhen_imported.<locals>.registerr   )r   r?   r   )r   r   when_imported   s    r@   )__doc__r
   Z	threadingversion_infoZPY2r5   r<   strr   Z
basestringZ
decoratorsr   r   r   RLockr>   r   r"   r$   r(   r*   r+   r1   r   r@   r   r   r   r   <module>   s*   	7	@