o
    Á¿iö  ã                   @   s  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 d dlmZ d dlm	Z	 d dlm
Z
 d d	lmZ eƒ Zed
ƒZe	egef Ze	eegef Zddede	e	ge	f fdd„ZG dd„ dƒZddede	egef fdd„Zdefdd„Zde	g ef de	g ef fdd„ZdS )é    ©Ú	lru_cache)Úwraps)ÚFullArgSpec)Úgetfullargspec)Úisgeneratorfunction)ÚAny©ÚCallable)ÚOptional)ÚTypeVarÚTé   ÚmaxsizeÚreturnc                    s   dt dt f‡ fdd„}|S )NÚfr   c                    s   t ˆ ƒ| ƒS ©Nr   ©r   ©r   © úP/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/internal/utils/cache.pyÚ_   s   zcached.<locals>._r	   )r   r   r   r   r   Úcached   s   r   c                   @   s>   e Zd Zdededdfdd„Zddedee de	fd	d
„Z
dS )ÚCachedMethodDescriptorÚmethodr   r   Nc                 C   s   || _ || _d S r   )Ú_methodÚ_maxsize)Úselfr   r   r   r   r   Ú__init__   s   
zCachedMethodDescriptor.__init__ÚobjÚobjtypec                 C   s,   t | jƒ| j ||¡ƒ}t|| jj|ƒ |S r   )r   r   r   Ú__get__ÚsetattrÚ__name__)r   r   r    Úcached_methodr   r   r   r!      s   zCachedMethodDescriptor.__get__r   )r#   Ú
__module__Ú__qualname__ÚMÚintr   r   r   ÚtypeÚFr!   r   r   r   r   r      s     r   c                    s   dt dtf‡ fdd„}|S )zBDecorator for memoizing methods of a single argument (LFU policy).r   r   c                    s
   t | ˆ ƒS r   )r   r   r   r   r   Úcached_wrapper(   s   
z$cachedmethod.<locals>.cached_wrapper)r'   r   )r   r+   r   r   r   Úcachedmethod%   s   r,   Úargspecc                 C   s,   |j p|jp|jp|jp|jp|jpt| ƒS r   )ÚargsÚvarargsÚvarkwÚdefaultsÚ
kwonlyargsÚkwonlydefaultsr   )r   r-   r   r   r   Úis_not_void_function.   s   ÿþýüûùr4   r   c                    s8   t ˆ ƒ}tˆ |ƒrtdƒ‚tˆ ƒdtf‡ fdd„ƒ}|S )z7Decorator for executing a function only the first time.zIThe callonce decorator can only be applied to functions with no argumentsr   c                     sx   zˆ j \} }W n, ty3   zˆ ƒ } d }W n ty+ } z
d } |}W Y d }~nd }~ww | |fˆ _ Y nw |d ur:|‚| S r   )Ú__callonce_result__ÚAttributeErrorÚ	Exception)ÚretvalÚexcÚer   r   r   r   @   s    €þù	zcallonce.<locals>._)r   r4   Ú
ValueErrorr   r   )r   r-   r   r   r   r   Úcallonce:   s   
r<   N)r   )Ú	functoolsr   r   Úinspectr   r   r   Útypingr   r
   r   r   ÚobjectÚmissr   r*   r'   r(   r   r   r,   r4   r<   r   r   r   r   Ú<module>   s$    	&