o
    ^"<f                     @   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/html/kck/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__Nc                    s4   t | t| } D ]}||}q||i |S 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_decorator5   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_argsY   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_middlewarei   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_vieww   s8   







z]make_middleware_decorator.<locals>._make_decorator.<locals>._decorator.<locals>._wrapped_view)r   )rF   rG   )m_argsm_kwargsr4   rE   r   
_decoratort   s   zFmake_middleware_decorator.<locals>._make_decorator.<locals>._decoratorr   )rH   rI   rJ   r3   )rH   rI   r   _make_decorators   s   #z2make_middleware_decorator.<locals>._make_decoratorr   )r4   rK   r   r3   r   r2   r   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    	
$	)

