
    wijI                         d Z ddlmZ ddlmZmZ ddlmZmZm	Z	m
Z
 ddlmZ  G d de	      Z G d	 d
e	      Z G d de      Z G d de
      Z G d d      Z G d de      ZeZddde
ddZ G d de      ZeZy)zoThis module implements decorators for implementing other decorators
as well as some commonly used decorators.

    )partial)isclass	signature   )BaseObjectProxyBoundFunctionWrapperCallableObjectProxyFunctionWrapper)formatargspecc                   n     e Zd Z fdZed        Zed        Zed        Zed        Zed        Z	 xZ
S )_AdapterFunctionCodec                 :    t         t        |   |       || _        y N)superr   __init___self_adapter_code)selfwrapped_codeadapter_code	__class__s      e/var/www/html/emotional.easysim.app/public_html/venv/lib/python3.12/site-packages/wrapt/decorators.pyr   z_AdapterFunctionCode.__init__   s     	"D2<@".    c                 .    | j                   j                  S r   )r   co_argcountr   s    r   r   z _AdapterFunctionCode.co_argcount        &&222r   c                 .    | j                   j                  S r   )r   co_coder   s    r   r   z_AdapterFunctionCode.co_code$   s    &&...r   c                 .    | j                   j                  S r   )r   co_flagsr   s    r   r    z_AdapterFunctionCode.co_flags(   s    &&///r   c                 .    | j                   j                  S r   )r   co_kwonlyargcountr   s    r   r"   z&_AdapterFunctionCode.co_kwonlyargcount,   s    &&888r   c                 .    | j                   j                  S r   )r   co_varnamesr   s    r   r$   z _AdapterFunctionCode.co_varnames0   r   r   )__name__
__module____qualname__r   propertyr   r   r    r"   r$   __classcell__r   s   @r   r   r      sl    / 3 3 / / 0 0 9 9 3 3r   r   c                   ^     e Zd Z fdZed        Zed        Zed        Zed        Z xZ	S )_AdapterFunctionSurrogatec                 :    t         t        |   |       || _        y r   )r   r,   r   _self_adapter)r   wrappedadapterr   s      r   r   z"_AdapterFunctionSurrogate.__init__7   s     	'7@$r   c                 j    t        | j                  j                  | j                  j                        S r   )r   __wrapped____code__r.   r   s    r   r3   z"_AdapterFunctionSurrogate.__code__>   s,    #%%t'9'9'B'B
 	
r   c                 .    | j                   j                  S r   )r.   __defaults__r   s    r   r5   z&_AdapterFunctionSurrogate.__defaults__D   s    !!...r   c                 .    | j                   j                  S r   )r.   __kwdefaults__r   s    r   r7   z(_AdapterFunctionSurrogate.__kwdefaults__H   s    !!000r   c                 ,    t        | j                        S r   )r   r.   r   s    r   __signature__z'_AdapterFunctionSurrogate.__signature__L   s    ++,,r   )
r%   r&   r'   r   r(   r3   r5   r7   r9   r)   r*   s   @r   r,   r,   5   sX    % 
 

 / / 1 1 - -r   r,   c                   ,    e Zd Zed        Zed        Zy)_BoundAdapterFunctionWrapperc                 j    t        | j                  j                  | j                  j                        S r   )r,   r2   __func___self_parentr.   r   s    r   r=   z%_BoundAdapterFunctionWrapper.__func__S   s,    (%%t'8'8'F'F
 	
r   c                 @    t        | j                  j                        S r   )r   r>   r.   r   s    r   r9   z*_BoundAdapterFunctionWrapper.__signature__Y   s    **8899r   N)r%   r&   r'   r(   r=   r9    r   r   r;   r;   Q   s(    
 

 : :r   r;   c                   b     e Zd ZeZ fdZed        Zed        Zed        Z	ed        Z
 xZS )_AdapterFunctionWrapperc                     |j                  d      }t        t        |   |i | t	        | j
                  |      | _        || _        y )Nr0   )popr   rB   r   r,   r2   _self_surrogater.   )r   argskwargsr0   r   s       r   r   z _AdapterFunctionWrapper.__init__b   sE    **Y' 	%t5tFvF89I9I7S$r   c                 .    | j                   j                  S r   )rE   r3   r   s    r   r3   z _AdapterFunctionWrapper.__code__k   s    ##,,,r   c                 .    | j                   j                  S r   )rE   r5   r   s    r   r5   z$_AdapterFunctionWrapper.__defaults__o   s    ##000r   c                 .    | j                   j                  S r   )rE   r7   r   s    r   r7   z&_AdapterFunctionWrapper.__kwdefaults__s   s    ##222r   c                 .    | j                   j                  S r   )rE   r9   r   s    r   r9   z%_AdapterFunctionWrapper.__signature__w   s    ##111r   )r%   r&   r'   r;   __bound_function_wrapper__r   r(   r3   r5   r7   r9   r)   r*   s   @r   rB   rB   ^   s^    !=% - - 1 1 3 3 2 2r   rB   c                       e Zd Zd Zy)AdapterFactoryc                     t               r   )NotImplementedErrorr   r/   s     r   __call__zAdapterFactory.__call__}   s    !##r   N)r%   r&   r'   rR   r@   r   r   rN   rN   |   s    $r   rN   c                   $     e Zd Z fdZd Z xZS )_DelegatedAdapterFactoryc                 8    t         t        |           || _        y r   )r   rT   r   factory)r   rV   r   s     r   r   z!_DelegatedAdapterFactory.__init__   s    &68r   c                 $    | j                  |      S r   )rV   rQ   s     r   rR   z!_DelegatedAdapterFactory.__call__   s    ||G$$r   )r%   r&   r'   r   rR   r)   r*   s   @r   rT   rT      s    
%r   rT   Nenabledr0   proxyc               p      dfd	 fd}  |t               S t        t               S )a  
    The decorator should be supplied with a single positional argument
    which is the `wrapper` function to be used to implement the
    decorator. This may be preceded by a step whereby the keyword
    arguments are supplied to customise the behaviour of the
    decorator. The `adapter` argument is used to optionally denote a
    separate function which is notionally used by an adapter
    decorator. In that case parts of the function `__code__` and
    `__defaults__` attributes are used from the adapter function
    rather than those of the wrapped function. This allows for the
    argument specification from `inspect.getfullargspec()` and similar
    functions to be overridden with a prototype for a different
    function than what was wrapped. The `enabled` argument provides a
    way to enable/disable the use of the decorator. If the type of
    `enabled` is a boolean, then it is evaluated immediately and the
    wrapper not even applied if it is `False`. If not a boolean, it will
    be evaluated when the wrapper is called for an unbound wrapper,
    and when binding occurs for a bound wrapper. When being evaluated,
    if `enabled` is callable it will be called to obtain the value to
    be checked. If `False`, the wrapper will not be called and instead
    the original wrapped function will be called directly instead.
    The `proxy` argument provides a way of passing a custom version of
    the `FunctionWrapper` class used in decorating the function.
    c                 (   |rt        |t              r ||       }t        |      sSi }i }t        |t              s t	        |      dk(  r
|d   }|d d }t        | }t        d| d||       |d   }|r||_        t        | |||      S  | ||      S )N   zdef adapterz: passr0   )r/   wrapperrY   r0   )r/   r_   rY   )	
isinstancerN   callablestrlenr   exec__annotations__rB   )r/   r_   rY   r0   nsannotationsrZ   s         r   _buildzdecorator.<locals>._build   s    g~6%g.G(B #%K%gs3w<1,*1"+K&-crlG"/"9;wiv6B? mG #2=/.#Wgw  '7KKr   c                 0    |t               r|s	
 fd}|S |d   }
}t        |      t        u r|s|S d }|t               r         }n<}n9t        |      rj                  d |      }nj                  |t        |            } |||	      S )Nc                 \    }t        |      t        u r|s| S d } di } | ||      S )Nr@   )typebool)target_wrapped_enabledtarget_wrapperrh   r0   rY   rG   r/   s      r   _capturez-decorator.<locals>._wrapper.<locals>._capture   sF      'HH~-'#11#' &-%6v%6N "..(GTTr   r   )r   rk   rl   __get__)r/   instancerF   rG   rp   rm   rn   ro   rh   r0   rY   r_   s   `  `    r   _wrapperzdecorator.<locals>._wrapper   s    * GG$4T
U U2  
 "!WN HH~%))
 7#, &-YN$ &-N 8$. &-__T8%DN0 &-__XtH~%NN ..(GLLr   )r0   rX   )NN)	decoratorr   )r_   rY   r0   rZ   rs   rh   s   ```` @r   rt   rt      s>    4 &	L^f	M^ gx;; y'7%PPr   c                   4     e Zd ZdZdd fd
Zd Zd Z xZS )_StateBindingWrappera<  A descriptor decorator that binds the owner instance to wrappers
    produced by a wrapper factory method.

    When applied on top of a method decorated with ``function_wrapper``
    or ``decorator``, it intercepts the descriptor ``__get__`` so that
    when the method is accessed through an instance, the owner instance
    is automatically attached as an attribute on the resulting wrapper
    via ``__self_setattr__``.

    The *name* keyword argument controls the attribute name under which
    the owner instance is stored on the wrapper (default ``"state"``).
    state)namec                2    t         |   d        || _        y r   )r   r   
_self_name)r   rx   r   s     r   r   z_StateBindingWrapper.__init__  s     	r   c                     || _         | S r   )r2   )r   wrapper_factorys     r   rR   z_StateBindingWrapper.__call__  s     +r   c                 r    | S | j                   j                  |      | j                  fd}|S )Nc                 <     |       }|j                         |S r   )__self_setattr__)funcr_   rr   rx   r|   s     r   _bindz+_StateBindingWrapper.__get__.<locals>._bind  s$    %d+G
 $$T84Nr   )r2   rq   rz   )r   rr   ownerr   rx   r|   s    `  @@r   rq   z_StateBindingWrapper.__get__  s?    
 K
 **228UC	 r   )r%   r&   r'   __doc__r   rR   rq   r)   r*   s   @r   rv   rv     s      ' r   rv   r   )r   	functoolsr   inspectr   r   	__wrapt__r   r   r	   r
   	argumentsr   r   r,   r;   rB   rN   rT   adapter_factoryrt   rv   bind_state_to_wrapperr@   r   r   <module>r      s   
  &  %3. 3<- 3 -8
:#7 
:2o 2<$ $
%~ % +DQ$O DQb7? 7t - r   