o
    2h"'                     @   s   d Z ddlmZ ddlmZ G dd deZdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd ZG dd deZG dd deZd#d!d"Zd S )$z0Variants of ObjectProxy for different use cases.   )BaseObjectProxy)synchronizedc                       s4   e Zd ZdZedd Z fddZdd Z  ZS )ObjectProxya  A generic object proxy which forwards special methods as needed.
    For backwards compatibility this class adds support for `__iter__()`. If
    you don't need backward compatibility for `__iter__()` support then it is
    preferable to use `BaseObjectProxy` directly. If you want automatic
    support for special dunder methods for callables, iterators, and async,
    then use `AutoObjectProxy`.c                 C   s   t S N)r   self r   H/var/www/html/chatgem/venv/lib/python3.10/site-packages/wrapt/proxies.py__object_proxy__   s   zObjectProxy.__object_proxy__c                    s   t  | S r   super__new__)clsargskwargs	__class__r   r	   r         zObjectProxy.__new__c                 C   
   t | jS r   iter__wrapped__r   r   r   r	   __iter__      
zObjectProxy.__iter__)	__name__
__module____qualname____doc__propertyr
   r   r   __classcell__r   r   r   r	   r   
   s    
r   c                 O   s   | j |i |S r   )r   )r   r   r   r   r   r	   __wrapper_call__!   s   r    c                 C   r   r   r   r   r   r   r	   __wrapper_iter__%   r   r!   c                 C   
   | j  S r   )r   __next__r   r   r   r	   __wrapper_next__)   r   r$   c                 C   r"   r   )r   	__aiter__r   r   r   r	   __wrapper_aiter__-   r   r&   c                    s   | j  I d H S r   )r   	__anext__r   r   r   r	   __wrapper_anext__1      r(   c                 C   r"   r   )r   __length_hint__r   r   r   r	   __wrapper_length_hint__5   r   r+   c                 c   s    | j  E d H S r   )r   	__await__r   r   r   r	   __wrapper_await__9   r)   r-   c                 C      | j ||S r   )r   __get__)r   instanceownerr   r   r	   __wrapper_get__=      r2   c                 C   r.   r   )r   __set__)r   r0   valuer   r   r	   __wrapper_set__A   r3   r6   c                 C   s   | j |S r   )r   
__delete__)r   r0   r   r   r	   __wrapper_delete__E   r   r8   c                 C   r.   r   )r   __set_name__)r   r1   namer   r   r	   __wrapper_set_name__I   r3   r;   c                       s(   e Zd ZdZ fddZdd Z  ZS )AutoObjectProxya  An object proxy which can automatically adjust to the wrapped object
    and add special dunder methods as needed. Note that this creates a new
    class for each instance, so it has much higher memory overhead than using
    `BaseObjectProxy` directly. If you know what special dunder methods you need
    then it is preferable to use `BaseObjectProxy` directly and add them to a
    subclass as needed. If you only need `__iter__()` support for backwards
    compatibility then use `ObjectProxy` instead.
    c                    sJ  i }t |}tt | }t|rd|vrt|d< d|v r$d|vr$t|d< d|v r0d|vr0t|d< d|v r<d|vr<t|d< d|v rHd|vrHt|d< d|v rTd|vrTt|d< d|v r`d|vr`t	|d< d|v rld|vrlt
|d< d	|v rxd	|vrxt|d	< d
|v rd
|vrt|d
< d|v rd|vrt|d< | j}| tu rtj}t t|| f|S )zzInjects special dunder methods into a dynamically created subclass
        as needed based on the wrapped object.
        __call__r   r#   r%   r'   r*   r,   r/   r4   r7   r9   )dirsetcallabler    r!   r$   r&   r(   r+   r-   r2   r6   r8   r;   r   r<   r   r   r   type)r   wrapped	namespacewrapped_attrsclass_attrsr:   r   r   r	   r   W   s:   zAutoObjectProxy.__new__c                 C   s~  t | }tt|}t| jrd|vrt|_nt|ddtu r$t|d t	| jdr2d|vr1t
|_nt|ddt
u r?t|d t	| jdrMd|vrLt|_nt|ddtu rZt|d t	| jdrhd|vrgt|_nt|ddtu rut|d t	| jdrd|vrt|_nt|ddtu rt|d t	| jdrd|vrt|_nt|ddtu rt|d t	| jdrd|vrt|_nt|ddtu rt|d t	| jd	rd	|vrt|_nt|d	dtu rt|d	 t	| jd
rd
|vrt|_nt|d
dtu rt|d
 t	| jdrd|vrt|_nt|ddtu rt|d t	| jdr-d|vr+t|_dS dS t|ddtu r=t|d dS dS )zAdjusts special dunder methods on the class as needed based on the
        wrapped object, when `__wrapped__` is changed.
        r=   Nr   r#   r%   r'   r*   r,   r/   r4   r7   r9   )rA   r?   r>   r@   r   r    r=   getattrdelattrhasattrr!   r   r$   r#   r&   r%   r(   r'   r+   r*   r-   r,   r2   r/   r6   r4   r8   r7   r;   r9   )r   r   rE   r   r   r	   __wrapped_setattr_fixups__   s   













z*AutoObjectProxy.__wrapped_setattr_fixups__)r   r   r   r   r   rI   r   r   r   r   r	   r<   M   s    	6r<   c                       sD   e Zd ZdZd fdd	Zd fdd	ZdZdd	 Zd
d Z  Z	S )LazyObjectProxyzhAn object proxy which can generate/create the wrapped object on demand
    when it is first needed.
    Nc                    s   t  | d S r   r   )r   callbackr   r   r	   r      r3   zLazyObjectProxy.__new__c                    s   |dur|| _ t d dS )a  Initialize the object proxy with wrapped object as `None` but due
        to presence of special `__wrapped_factory__` attribute addded first,
        this will actually trigger the deferred creation of the wrapped object
        when first needed.
        N)__wrapped_factory__r   __init__)r   rK   r   r   r	   rM      s   zLazyObjectProxy.__init__Fc                 C   s   d S r   r   r   r   r   r	   rL      s   z#LazyObjectProxy.__wrapped_factory__c                 C   s`   t t|   | jr| jW  d   S |  | _d| _| jW  d   S 1 s)w   Y  dS )z2Gets the wrapped object, creating it if necessary.NT)r   rA   __wrapped_initialized__r   rL   r   r   r   r	   __wrapped_get__   s   

$zLazyObjectProxy.__wrapped_get__r   )
r   r   r   r   r   rM   rN   rL   rO   r   r   r   r   r	   rJ      s    rJ   Nc                    s    fdd}t |S )aN  Lazily imports the module `name`, returning a `LazyObjectProxy` which
    will import the module when it is first needed. When `name is a dotted name,
    then the full dotted name is imported and the last module is taken as the
    target. If `attribute` is provided then it is used to retrieve an attribute
    from the module.
    c                     s$   t dgd}  d urt|  S | S )N )fromlist)
__import__rF   )module	attributer:   r   r	   _import  s   
zlazy_import.<locals>._import)rJ   )r:   rU   rV   r   rT   r	   lazy_import
  s   rW   r   )r   	__wrapt__r   
decoratorsr   r   r    r!   r$   r&   r(   r+   r-   r2   r6   r8   r;   r<   rJ   rW   r   r   r   r	   <module>   s&     2