o
    ­2úh  ã                   @   s<   d dl Z d dlZddlmZmZ dd„ ZG dd„ deƒZdS )é    Né   )ÚBaseObjectProxyÚ_FunctionWrapperBasec                 C   s(   |j rd S d|_ |d ur||ƒ d S d S )NT)Ú_self_expired)ÚrefÚproxyÚcallback© r	   úI/var/www/html/chatgem/venv/lib/python3.10/site-packages/wrapt/weakrefs.pyÚ_weak_function_proxy_callback   s   ÿr   c                       s.   e Zd ZdZdZd‡ fdd„	Zdd„ Z‡  ZS )	ÚWeakFunctionProxyzA weak function proxy.)r   Ú_self_instanceNc              	      sÜ   |o	t jt| |d}d| _t|tƒr<t |j|¡| _|j	dur.t
t| ƒ t |j	|¡¡ dS t
t| ƒ t ||¡¡ dS zt |j|¡| _t
t| ƒ t |j|¡¡ W dS  tym   d| _t
t| ƒ t ||¡¡ Y dS w )aÃ  Create a proxy to object which uses a weak reference. This is
        similar to the `weakref.proxy` but is designed to work with functions
        and methods. It will automatically rebind the function to the instance
        when called if the function was originally a bound method. This is
        necessary because bound methods are transient objects and applying a
        weak reference to one will immediately result in it being destroyed
        and the weakref callback called. The weak reference is therefore
        applied to the instance the method is bound to and the original
        function. The function is then rebound at the point of a call via the
        weak function proxy.
        )r   r   FN)Ú	functoolsÚpartialr   r   Ú
isinstancer   Úweakrefr   r   Ú_self_parentÚsuperr   Ú__init__r   Ú__self__Ú__func__ÚAttributeError)ÚselfÚwrappedr   Ú	_callback©Ú	__class__r	   r
   r   #   s0   ÿ


ÿ	
ü
ÿ

ÿýzWeakFunctionProxy.__init__c                  O   s`   dd„ }|| Ž \}} |j o|  ¡ }|jo|j}|d u r#|j| i |¤ŽS | |t|ƒ¡| i |¤ŽS )Nc                 W   s   | |fS ©Nr	   )r   Úargsr	   r	   r
   Ú_unpack_self^   s   z0WeakFunctionProxy.__call__.<locals>._unpack_self)r   Ú__wrapped__Ú__get__Útype)r   Úkwargsr   r   ÚinstanceÚfunctionr	   r	   r
   Ú__call__]   s   zWeakFunctionProxy.__call__r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r&   Ú__classcell__r	   r	   r   r
   r      s
    :r   )r   r   Ú	__wrapt__r   r   r   r   r	   r	   r	   r
   Ú<module>   s
    