o
    Á¿i=	  ã                   @   sd   d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 G dd	„ d	e
ƒZdS )
é    )ÚPathN)ÚCodeType)Ú
ModuleType)ÚFunctionDiscovery)ÚModuleHookType)ÚModuleWatchdogc                       sÈ   e Zd ZU eƒ Zee ed< dededefdd„Z	e
dededd	f‡ fd
d„ƒZe
dededd	f‡ fdd„ƒZe
dededd	f‡ fdd„ƒZe
dededd	f‡ fdd„ƒZe
dedd	fdd„ƒZ‡  ZS )ÚDebuggerModuleWatchdogÚ
_locationsÚcodeÚmoduleÚreturnc                 C   s   t  ||¡S ©N)r   Útransformer)Úselfr
   r   © r   úM/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/debugging/_import.pyÚ	transform   s   z DebuggerModuleWatchdog.transformÚoriginÚhookNc                    sJ   || j v r|  |¡}|d ur||ƒ d S | j  t|ƒ¡ tƒ  ||¡ d S r   )r	   Úget_by_originÚaddÚstrÚsuperÚregister_origin_hook)Úclsr   r   r   ©Ú	__class__r   r   r      s   

z+DebuggerModuleWatchdog.register_origin_hookc                    s8   z
| j  t|ƒ¡ W n
 ty   Y d S w tƒ  ||¡S r   )r	   Úremover   ÚKeyErrorr   Úunregister_origin_hook)r   r   r   r   r   r   r       s   þz-DebuggerModuleWatchdog.unregister_origin_hookc                    sH   || j v rtj |¡}|d ur||ƒ d S | j  |¡ tƒ  ||¡ d S r   )r	   ÚsysÚmodulesÚgetr   r   Úregister_module_hook)r   r   r   Úmodr   r   r   r#   *   s   
z+DebuggerModuleWatchdog.register_module_hookc                    s4   z| j  |¡ W n
 ty   Y d S w tƒ  ||¡S r   )r	   r   r   r   Úunregister_module_hook)r   r   r   r   r   r   r%   9   s   þz-DebuggerModuleWatchdog.unregister_module_hookc                 C   s   | j d ur| j  |¡ d S d S r   )Ú	_instanceÚafter_import)r   r   r   r   r   Úon_run_moduleC   s   
ýz$DebuggerModuleWatchdog.on_run_module)Ú__name__Ú
__module__Ú__qualname__Úsetr	   r   Ú__annotations__r   r   r   Úclassmethodr   r   r   r   r#   r%   r(   Ú__classcell__r   r   r   r   r      s   
 		r   )Úpathlibr   r    Útypesr   r   Ú%ddtrace.debugging._function.discoveryr   Úddtrace.internal.moduler   r   r   r   r   r   r   Ú<module>   s    