a
    �˜ëjÍK  ã                   @   sÒ   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„ de	ƒZG d	d
„ d
e	ƒZG dd„ deƒZG dd„ de
ƒZG dd„ dƒZG dd„ deƒZeZddde
dœdd„ZG dd„ deƒZeZdS )zoThis module implements decorators for implementing other decorators
as well as some commonly used decorators.

é    )Úpartial)ÚisclassÚ	signatureé   )ÚBaseObjectProxyÚBoundFunctionWrapperÚCallableObjectProxyÚFunctionWrapper)Úformatargspecc                       sX   e Zd Z‡ fdd„Zedd„ ƒZedd„ ƒZedd„ ƒZed	d
„ ƒZedd„ ƒZ	‡  Z
S )Ú_AdapterFunctionCodec                    s   t t| ƒ |¡ || _d S ©N)Úsuperr   Ú__init__Ú_self_adapter_code)ÚselfZwrapped_codeZadapter_code©Ú	__class__© úO/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/wrapt/decorators.pyr      s    z_AdapterFunctionCode.__init__c                 C   s   | j jS r   )r   Úco_argcount©r   r   r   r   r       s    z _AdapterFunctionCode.co_argcountc                 C   s   | j jS r   )r   Úco_coder   r   r   r   r   $   s    z_AdapterFunctionCode.co_codec                 C   s   | j jS r   )r   Úco_flagsr   r   r   r   r   (   s    z_AdapterFunctionCode.co_flagsc                 C   s   | j jS r   )r   Úco_kwonlyargcountr   r   r   r   r   ,   s    z&_AdapterFunctionCode.co_kwonlyargcountc                 C   s   | j jS r   )r   Úco_varnamesr   r   r   r   r   0   s    z _AdapterFunctionCode.co_varnames)Ú__name__Ú
__module__Ú__qualname__r   Úpropertyr   r   r   r   r   Ú__classcell__r   r   r   r   r      s   



r   c                       sL   e Zd Z‡ fdd„Zedd„ ƒZedd„ ƒZedd„ ƒZed	d
„ ƒZ‡  Z	S )Ú_AdapterFunctionSurrogatec                    s   t t| ƒ |¡ || _d S r   )r   r    r   Ú_self_adapter)r   ÚwrappedÚadapterr   r   r   r   7   s    z"_AdapterFunctionSurrogate.__init__c                 C   s   t | jj| jjƒS r   )r   Ú__wrapped__Ú__code__r!   r   r   r   r   r%   >   s    ÿz"_AdapterFunctionSurrogate.__code__c                 C   s   | j jS r   )r!   Ú__defaults__r   r   r   r   r&   D   s    z&_AdapterFunctionSurrogate.__defaults__c                 C   s   | j jS r   )r!   Ú__kwdefaults__r   r   r   r   r'   H   s    z(_AdapterFunctionSurrogate.__kwdefaults__c                 C   s
   t | jƒS r   )r   r!   r   r   r   r   Ú__signature__L   s    z'_AdapterFunctionSurrogate.__signature__)
r   r   r   r   r   r%   r&   r'   r(   r   r   r   r   r   r    5   s   


r    c                   @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )Ú_BoundAdapterFunctionWrapperc                 C   s   t | jj| jjƒS r   )r    r$   Ú__func__Ú_self_parentr!   r   r   r   r   r*   S   s    ÿz%_BoundAdapterFunctionWrapper.__func__c                 C   s   t | jjƒS r   )r   r+   r!   r   r   r   r   r(   Y   s    z*_BoundAdapterFunctionWrapper.__signature__N)r   r   r   r   r*   r(   r   r   r   r   r)   Q   s   
r)   c                       sP   e Zd ZeZ‡ fdd„Zedd„ ƒZedd„ ƒZedd„ ƒZ	ed	d
„ ƒZ
‡  ZS )Ú_AdapterFunctionWrapperc                    s8   |  d¡}tt| ƒj|i |¤Ž t| j|ƒ| _|| _d S )Nr#   )Úpopr   r,   r   r    r$   Ú_self_surrogater!   )r   ÚargsÚkwargsr#   r   r   r   r   b   s    
z _AdapterFunctionWrapper.__init__c                 C   s   | j jS r   )r.   r%   r   r   r   r   r%   k   s    z _AdapterFunctionWrapper.__code__c                 C   s   | j jS r   )r.   r&   r   r   r   r   r&   o   s    z$_AdapterFunctionWrapper.__defaults__c                 C   s   | j jS r   )r.   r'   r   r   r   r   r'   s   s    z&_AdapterFunctionWrapper.__kwdefaults__c                 C   s   | j jS r   )r.   r(   r   r   r   r   r(   w   s    z%_AdapterFunctionWrapper.__signature__)r   r   r   r)   Z__bound_function_wrapper__r   r   r%   r&   r'   r(   r   r   r   r   r   r,   ^   s   	


r,   c                   @   s   e Zd Zdd„ ZdS )ÚAdapterFactoryc                 C   s
   t ƒ ‚d S r   )ÚNotImplementedError©r   r"   r   r   r   Ú__call__}   s    zAdapterFactory.__call__N)r   r   r   r4   r   r   r   r   r1   |   s   r1   c                       s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )Ú_DelegatedAdapterFactoryc                    s   t t| ƒ ¡  || _d S r   )r   r5   r   Úfactory)r   r6   r   r   r   r   ‚   s    z!_DelegatedAdapterFactory.__init__c                 C   s
   |   |¡S r   )r6   r3   r   r   r   r4   ‡   s    z!_DelegatedAdapterFactory.__call__)r   r   r   r   r4   r   r   r   r   r   r5   �   s   r5   N©Úenabledr#   Úproxyc                  sJ   ˆdur6d‡fdd„	‰ ‡ ‡‡‡fdd„}ˆ ˆ|t d�S tt ˆˆˆd�S d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.
    Nc                    sœ   t |tƒr|| ƒ}|rŽt|ƒs~i }i }t |tƒsXt|ƒdkrP|d }|d d… }t|Ž }td|› d�||ƒ |d }|r~||_t| |||d�S ˆ | ||d�S )Né   éÿÿÿÿzdef adapterz: passr#   )r"   Úwrapperr8   r#   )r"   r<   r8   )	Ú
isinstancer1   ÚcallableÚstrÚlenr
   ÚexecÚ__annotations__r,   )r"   r<   r8   r#   ÚnsÚannotations)r9   r   r   Ú_build³   s&    	


ÿzdecorator.<locals>._buildc                    s¢   |d u r,t ˆƒr,|s,‡‡‡‡ ‡fdd„}|S |d }ˆ}t|ƒtu rP|sL|S d }|d u rnt ˆƒrhˆƒ }q”ˆ}n&t |ƒr„ˆ d |¡}nˆ |t|ƒ¡}ˆ|||ˆƒS )Nc                    s8   ˆ}t |ƒtu r|s| S d }ˆf i ˆ¤Ž}ˆ | ||ˆƒS r   )ÚtypeÚbool)Útarget_wrappedÚ_enabledÚtarget_wrapper)rE   r#   r8   r0   r"   r   r   Ú_capture  s    z-decorator.<locals>._wrapper.<locals>._capturer   )r   rF   rG   Ú__get__)r"   Úinstancer/   r0   rK   rH   rI   rJ   )rE   r#   r8   r<   )r0   r"   r   Ú_wrapperê   s"    zdecorator.<locals>._wrapper)r#   r7   )NN)Ú	decoratorr   )r<   r8   r#   r9   rN   r   )rE   r#   r8   r9   r<   r   rO   •   s    7 0rO   c                       s6   e Zd ZdZddœ‡ fdd„
Zdd„ Zdd	„ Z‡  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                   s   t ƒ  d ¡ || _d S r   )r   r   Ú_self_attr_name)r   rR   r   r   r   r   ¼  s    z_StateBindingWrapper.__init__c                 C   s
   || _ | S r   )r$   )r   Úwrapper_factoryr   r   r   r4   Ä  s    z_StateBindingWrapper.__call__c                    s4   ˆ d u r| S | j  ˆ |¡‰| j‰‡ ‡‡fdd„}|S )Nc                    s   ˆ| ƒ}|  ˆˆ ¡ |S r   )Z__self_setattr__)Úfuncr<   ©rM   rR   rT   r   r   Ú_bindÛ  s    z+_StateBindingWrapper.__get__.<locals>._bind)r$   rL   rS   )r   rM   ÚownerrW   r   rV   r   rL   Ì  s    
z_StateBindingWrapper.__get__)r   r   r   Ú__doc__r   r4   rL   r   r   r   r   r   rP   ®  s   rP   )N)rY   Ú	functoolsr   Úinspectr   r   Z	__wrapt__r   r   r   r	   Ú	argumentsr
   r   r    r)   r,   r1   r5   Zadapter_factoryrO   rP   Zbind_state_to_wrapperr   r   r   r   Ú<module>   s    

  :