a
    5¤Xh  ã                   @   sv   d Z ddlmZmZmZ G dd„ deƒZdd„ Zdd„ Zdd
d„Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )zCFunctions that help with dynamically creating decorators for views.é    )ÚpartialÚupdate_wrapperÚwrapsc                       s   e Zd Zd‡ fdd„	Z‡  ZS )ÚclassonlymethodNc                    s   |d urt dƒ‚tƒ  ||¡S )Nz=This method is available only on the class, not on instances.)ÚAttributeErrorÚsuperÚ__get__)ÚselfÚinstanceÚcls©Ú	__class__© ú\/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/site-packages/django/utils/decorators.pyr      s
    ÿzclassonlymethod.__get__)N)Ú__name__Ú
__module__Ú__qualname__r   Ú__classcell__r   r   r   r   r      s   r   c                 C   s   |dd„ ƒ}t | |ƒ d S )Nc                  _   s   d S ©Nr   )ÚargsÚkwargsr   r   r   Údummy   s    z%_update_method_wrapper.<locals>.dummy)r   )Ú_wrapperÚ	decoratorr   r   r   r   Ú_update_method_wrapper   s    
r   c                    sP   t ˆ dƒrˆ ddd… ‰ nˆ g‰ ‡ ‡fdd„}ˆ D ]}t||ƒ q2t|ˆƒ |S )zŠ
    Decorate `method` with one or more function decorators. `decorators` can be
    a single decorator or an iterable of decorators.
    Ú__iter__Néÿÿÿÿc                    s<   t ˆƒtˆ | t| ƒ¡ƒƒ}ˆ D ]}||ƒ}q ||i |¤ŽS r   )r   r   r   Útype)r	   r   r   Zbound_methodÚdec©Ú
decoratorsÚmethodr   r   r   &   s    
z!_multi_decorate.<locals>._wrapper)Úhasattrr   r   )r    r!   r   r   r   r   r   Ú_multi_decorate   s    

r#   Ú c                    sF   ‡ ‡fdd„}t ˆ dƒs"t|ˆ ƒ t ˆ dƒr0ˆ nˆ j}d|j |_|S )z>
    Convert a function decorator into a method decorator
    c                    sp   t | tƒstˆ | ƒS ˆr"t| ˆƒs2td| ˆf ƒ‚t| ˆƒ}t|ƒsVtdˆ| |f ƒ‚tˆ |ƒ}t| ˆ|ƒ | S )NzfThe keyword argument `name` must be the name of a method of the decorated class: %s. Got '%s' instead.zACannot decorate '%s' as it isn't a callable attribute of %s (%s).)	Ú
isinstancer   r#   r"   Ú
ValueErrorÚgetattrÚcallableÚ	TypeErrorÚsetattr)Úobjr!   r   ©r   Únamer   r   Ú_decA   s$    

ÿÿ
ÿÿ
zmethod_decorator.<locals>._decr   r   zmethod_decorator(%s))r"   r   r   r   )r   r-   r.   r+   r   r,   r   Úmethod_decorator8   s    	

r/   c                 C   s   t | ƒS )a<  
    Like decorator_from_middleware, but return a function
    that accepts the arguments to be passed to the middleware_class.
    Use like::

         cache_page = decorator_from_middleware_with_args(CacheMiddleware)
         # ...

         @cache_page(3600)
         def my_view(request):
             # ...
    ©Úmake_middleware_decorator©Úmiddleware_classr   r   r   Ú#decorator_from_middleware_with_args]   s    r4   c                 C   s
   t | ƒƒ S )zÇ
    Given a middleware class (not an instance), return a view decorator. This
    lets you use middleware functionality on a per-view basis. The middleware
    is created with no params passed.
    r0   r2   r   r   r   Údecorator_from_middlewarem   s    r5   c                    s   ‡ fdd„}|S )Nc                     s   ‡ ‡‡fdd„}|S )Nc                    s0   ˆˆgˆ¢R i ˆ¤Ž‰ t ˆƒ‡ ‡fdd„ƒ}|S )Nc              
      s&  t ˆdƒr ˆ ˆ ¡}|d ur |S t ˆdƒrFˆ ˆ ˆ||¡}|d urF|S zˆˆ g|¢R i |¤Ž}W nT ty´ } z<t ˆdƒržˆ ˆ |¡}|d urž|W  Y d }~S ‚ W Y d }~n
d }~0 0 t |dƒr
t|jƒr
t ˆdƒräˆ ˆ |¡}t ˆdƒr"‡‡ fdd„}| |¡ nt ˆdƒr"ˆ 	ˆ |¡S |S )	NÚprocess_requestÚprocess_viewÚprocess_exceptionÚrenderÚprocess_template_responseÚprocess_responsec                    s   ˆ   ˆ| ¡S r   )r;   )Úresponse)Ú
middlewareÚrequestr   r   Úcallback–   s    zomake_middleware_decorator.<locals>._make_decorator.<locals>._decorator.<locals>._wrapper_view.<locals>.callback)
r"   r6   r7   Ú	Exceptionr8   r(   r9   r:   Zadd_post_render_callbackr;   )r>   r   r   Úresultr<   Úer?   ©r=   Ú	view_func)r>   r   Ú_wrapper_view{   s6    




ÿz]make_middleware_decorator.<locals>._make_decorator.<locals>._decorator.<locals>._wrapper_view)r   )rD   rE   )Úm_argsÚm_kwargsr3   rC   r   Ú
_decoratorx   s    #zFmake_middleware_decorator.<locals>._make_decorator.<locals>._decoratorr   )rF   rG   rH   r2   )rF   rG   r   Ú_make_decoratorw   s    )z2make_middleware_decorator.<locals>._make_decoratorr   )r3   rI   r   r2   r   r1   v   s    ,r1   c                 C   s   d| _ d| _| S )zj
    Mark a middleware factory as returning a hybrid middleware supporting both
    types of request.
    T©Zsync_capableZasync_capable©Úfuncr   r   r   Úsync_and_async_middleware¦   s    rM   c                 C   s   d| _ d| _| S )z\
    Mark a middleware factory as returning a sync middleware.
    This is the default.
    TFrJ   rK   r   r   r   Úsync_only_middleware°   s    rN   c                 C   s   d| _ d| _| S )z;Mark a middleware factory as returning an async middleware.FTrJ   rK   r   r   r   Úasync_only_middlewareº   s    rO   N)r$   )Ú__doc__Ú	functoolsr   r   r   Úclassmethodr   r   r#   r/   r4   r5   r1   rM   rN   rO   r   r   r   r   Ú<module>   s   	

%	0

