o
    æË·e  ã                   @   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__© úN/var/www/ideatree/venv/lib/python3.10/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 r   r   )Ú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||ƒ qt|ˆƒ |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   Ú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ƒrˆ nˆ j}d|j |_|S )z>
    Convert a function decorator into a method decorator
    c                    sp   t | tƒs
tˆ | ƒS ˆrt| ˆƒstd| ˆf ƒ‚t| ˆƒ}t|ƒs+t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   Ú_dec@   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   

r0   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   r5   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.
    r1   r3   r   r   r   Údecorator_from_middlewarel   s   
r6   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ƒr#ˆ ˆ ˆ||¡}|d ur#|S zˆˆ g|¢R i |¤Ž}W n$ tyT } zt ˆdƒrOˆ ˆ |¡}|d urO|W  Y d }~S ‚ d }~ww t |dƒr}t|jƒr}t ˆdƒrjˆ ˆ |¡}t ˆdƒr{‡‡ fdd„}| |¡ |S 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>._wrapped_view.<locals>.callback)
r#   r7   r8   Ú	Exceptionr9   r)   r:   r;   Úadd_post_render_callbackr<   )r?   r   r   Úresultr=   Úer@   ©r>   Ú	view_func)r?   r   Ú_wrapped_viewz   s<   



€û
ÿ


þz]make_middleware_decorator.<locals>._make_decorator.<locals>._decorator.<locals>._wrapped_view)r   )rF   rG   )Úm_argsÚm_kwargsr4   rE   r   Ú
_decoratorw   s   #zFmake_middleware_decorator.<locals>._make_decorator.<locals>._decoratorr   )rH   rI   rJ   r3   )rH   rI   r   Ú_make_decoratorv   s   )z2make_middleware_decorator.<locals>._make_decoratorr   )r4   rK   r   r3   r   r2   u   s   ,r2   c                 C   s   d| _ d| _| S )zj
    Mark a middleware factory as returning a hybrid middleware supporting both
    types of request.
    T©Úsync_capableÚasync_capable©Úfuncr   r   r   Úsync_and_async_middleware¥   ó   rQ   c                 C   ó   d| _ d| _| S )z\
    Mark a middleware factory as returning a sync middleware.
    This is the default.
    TFrL   rO   r   r   r   Úsync_only_middleware¯   rR   rT   c                 C   rS   )z;Mark a middleware factory as returning an async middleware.FTrL   rO   r   r   r   Úasync_only_middleware¹   s   rU   N)r%   )Ú__doc__Ú	functoolsr   r   r   Úclassmethodr   r   r$   r0   r5   r6   r2   rQ   rT   rU   r   r   r   r   Ú<module>   s    	

$	0

