o
    ÆÐLeT  ã                   @   sž   d dl Z d dlZejd  dkZerefZnefZddlmZ dd„ Z	dd„ Z
d	i fd
d„ZG dd„ deƒZd	i fdd„Zdd„ Zdd„ Zddd„Zdd„ ZdS )é    Né   é   ©ÚFunctionWrapperc                 C   sn   t | tƒrt| ƒ tj|  } | }| d¡}|d }dd„ }|||ƒ}|dd … D ]	}|}|||ƒ}q(|||fS )NÚ.r   c                 S   sJ   t  | ¡r t  | ¡D ]}|t|ƒv rt|ƒ|   S q
t| |ƒS t| |ƒS ©N)ÚinspectÚisclassZgetmroÚvarsÚgetattr)ÚparentÚ	attributeÚcls© r   ú-lib/python3.10/site-packages/wrapt/patches.pyÚlookup_attribute&   s   
ÿ

z&resolve_path.<locals>.lookup_attributer   )Ú
isinstanceÚstring_typesÚ
__import__ÚsysÚmodulesÚsplit)ÚmoduleÚnamer   Úpathr   r   Úoriginalr   r   r   Úresolve_path   s   





r   c                 C   s   t | ||ƒ d S r   )Úsetattr)r   r   Úreplacementr   r   r   Úapply_patch8   ó   r   r   c           	      C   s6   t | |ƒ\}}}||g|¢R i |¤Ž}t|||ƒ |S r   )r   r   )	r   r   ÚfactoryÚargsÚkwargsr   r   r   Úwrapperr   r   r   Úwrap_object;   s   r%   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚAttributeWrapperc                 C   s   || _ || _|| _|| _d S r   )r   r!   r"   r#   )Úselfr   r!   r"   r#   r   r   r   Ú__init__I   s   
zAttributeWrapper.__init__c                 C   s(   |j | j }| j|g| j¢R i | j¤ŽS r   )Ú__dict__r   r!   r"   r#   )r'   ÚinstanceÚownerÚvaluer   r   r   Ú__get__O   s   zAttributeWrapper.__get__c                 C   s   ||j | j< d S r   ©r)   r   )r'   r*   r,   r   r   r   Ú__set__S   r    zAttributeWrapper.__set__c                 C   s   |j | j= d S r   r.   )r'   r*   r   r   r   Ú
__delete__V   s   zAttributeWrapper.__delete__N)Ú__name__Ú
__module__Ú__qualname__r(   r-   r/   r0   r   r   r   r   r&   G   s
    r&   c           	      C   s<   |  dd¡\}}t| |ƒd }t||||ƒ}t|||ƒ |S )Nr   r   r   )Úrsplitr   r&   r   )	r   r   r!   r"   r#   r   r   r   r$   r   r   r   Úwrap_object_attributeY   s
   r5   c                    s   ‡ fdd„}t ˆ |ƒS )Nc                    sH   |d }|d u rˆ }nt  |¡rˆ  d |¡}nˆ  |t|ƒ¡}t||ƒS )Nr   ©r   r	   r-   Útyper   )Úwrappedr*   r"   r#   Útarget_wrappedÚtarget_wrapper©r$   r   r   Ú_wrapperf   s   

z"function_wrapper.<locals>._wrapperr   ©r$   r<   r   r;   r   Úfunction_wrappere   s   
	r>   c                 C   s   t | |t|fƒS r   ©r%   r   ©r   r   r$   r   r   r   Úwrap_function_wrapperq   r    rA   c                    s   ‡ ‡‡fdd„}|S )Nc                    s   t ˆˆt| ˆ fƒS r   r?   r;   ©Úenabledr   r   r   r   r<   u   s   z(patch_function_wrapper.<locals>._wrapperr   )r   r   rC   r<   r   rB   r   Úpatch_function_wrappert   s   rD   c                    s   ‡ ‡fdd„}|S )Nc                    s   ‡‡‡ fdd„}t ˆ |ƒS )Nc                    sX   |d }|d u rˆ‰ nt  |¡rˆ d |¡‰ nˆ |t|ƒ¡‰ ‡‡‡ fdd„}t||ƒS )Nr   c              
      sR   t ˆ ˆƒ\}}}t|ˆƒ}t|||ƒ z| |i |¤ŽW t|||ƒ S t|||ƒ w r   )r   r   r   )r8   r*   r"   r#   r   r   r   r   )r   r   r:   r   r   Ú_executeƒ   s   
zRtransient_function_wrapper.<locals>._decorator.<locals>._wrapper.<locals>._executer6   )r8   r*   r"   r#   r9   rE   r@   )r:   r   r<   {   s   

z@transient_function_wrapper.<locals>._decorator.<locals>._wrapperr   r=   ©r   r   r;   r   Ú
_decoratorz   s   
z.transient_function_wrapper.<locals>._decoratorr   )r   r   rG   r   rF   r   Útransient_function_wrappery   s   rH   r   )r   r   Úversion_infoZPY2Z
basestringr   ÚstrZ	__wrapt__r   r   r   r%   Úobjectr&   r5   r>   rA   rD   rH   r   r   r   r   Ú<module>   s     )
