
    Hwg                     j    d Z ddlmZmZmZ  G d de      Zd Zd ZddZ	d Z
d	 Zd
 Zd Zd Zd Zy)zCFunctions that help with dynamically creating decorators for views.    )partialupdate_wrapperwrapsc                         e Zd Zd fd	Z xZS )classonlymethodc                 >    |t        d      t        | 	  ||      S )Nz=This method is available only on the class, not on instances.)AttributeErrorsuper__get__)selfinstancecls	__class__s      N/var/www/horilla/myenv/lib/python3.12/site-packages/django/utils/decorators.pyr   zclassonlymethod.__get__   s,     O  wx--    N)__name__
__module____qualname__r   __classcell__)r   s   @r   r   r      s    . .r   r   c                 ,    |d        }t        | |       y )Nc                       y r    )argskwargss     r   dummyz%_update_method_wrapper.<locals>.dummy   s    r   )r   )_wrapper	decoratorr   s      r   _update_method_wrapperr      s"       8U#r   c                      t         d      r	 ddd    n g  fd} D ]  }t        ||        t        |       |S )z
    Decorate `method` with one or more function decorators. `decorators` can be
    a single decorator or an iterable of decorators.
    __iter__Nc           
           t              t        j                  | t        |                         }D ]
  } ||      }  ||i |S r   )r   r   r   type)r   r   r   bound_methoddec
decoratorsmethods        r   r   z!_multi_decorate.<locals>._wrapper&   sR    
 %uV}WV^^D$t*-M%NO 	-C|,L	-T,V,,r   )hasattrr   r   )r'   r(   r   r&   s   ``  r   _multi_decorater*      sW    
 z:&  "%
 \
-  .x-. 8V$Or   c                       fd}t         d      st        |        t         d      r n j                  }d|j                  z  |_        |S )z>
    Convert a function decorator into a method decorator
    c           	      
   t        | t              st        |       S rt        |       st	        d| dd      t        |       }t        |      st        dd| d|d      t        |      }t        | |       | S )NzQThe keyword argument `name` must be the name of a method of the decorated class: z. Got 'z
' instead.zCannot decorate 'z&' as it isn't a callable attribute of z (z).)	
isinstancer$   r*   r)   
ValueErrorgetattrcallable	TypeErrorsetattr)objr(   r   r   names      r   _deczmethod_decorator.<locals>._decA   s    #t$"9c22d+CFN  d#"C1  #9f5T8$
r   r!   r   zmethod_decorator(%s))r)   r   r   r   )r   r4   r5   r3   s   ``  r   method_decoratorr6   8   sI    ( 9j)tY'y*5)9;N;NC*S\\9DMKr   c                     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_classs    r   #decorator_from_middleware_with_argsr<   ]   s     %%566r   c                 "     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.
    r8   r:   s    r   decorator_from_middlewarer>   m   s     7$%5688r   c                       fd}|S )Nc                        fd}|S )Nc                 L       gi t                fd       }|S )Nc                 $    t        d      rj                         }||S t        d      rj                   ||      }||S 	   g|i |}t        |d      rXt        |j                        rCt        d      rj                   |      }t        d      r fd}|j                  |       |S t        d      rj                   |      S |S # t        $ r-}t        d      rj	                   |      }||cY d }~S  d }~ww xY w)Nprocess_requestprocess_viewprocess_exceptionrenderprocess_template_responseprocess_responsec                 (    j                  |       S r   )rH   )response
middlewarerequests    r   callbackzomake_middleware_decorator.<locals>._make_decorator.<locals>._decorator.<locals>._wrapper_view.<locals>.callback   s    #-#>#>w#QQr   )
r)   rC   rD   	ExceptionrE   r0   rF   rG   add_post_render_callbackrH   )	rL   r   r   resultrJ   erM   rK   	view_funcs	   `      r   _wrapper_viewz]make_middleware_decorator.<locals>._make_decorator.<locals>._decorator.<locals>._wrapper_view{   s0   :'89'77@F)%:~6'44WivVF)%(B4B6BH 8X.8HOO3Lz+FG#-#G#G#X$
 z+=>R !99(C   z+=>)::7HMM- ! z+>?!+!=!=gq!I!-#)Ms$   	C 	D"!D
D	D

D)r   )rR   rS   rK   m_argsm_kwargsr;   s   ` @r   
_decoratorzFmake_middleware_decorator.<locals>._make_decorator.<locals>._decoratorx   s7    ))IfIIJ9!  ! F ! r   r   )rT   rU   rV   r;   s   `` r   _make_decoratorz2make_middleware_decorator.<locals>._make_decoratorw   s    '	!R r   r   )r;   rW   s   ` r   r9   r9   v   s    *X r   c                 "    d| _         d| _        | S )zj
    Mark a middleware factory as returning a hybrid middleware supporting both
    types of request.
    Tsync_capableasync_capablefuncs    r   sync_and_async_middlewarer^      s    
 DDKr   c                 "    d| _         d| _        | S )z\
    Mark a middleware factory as returning a sync middleware.
    This is the default.
    TFrY   r\   s    r   sync_only_middlewarer`      s    
 DDKr   c                 "    d| _         d| _        | S )z;Mark a middleware factory as returning an async middleware.FTrY   r\   s    r   async_only_middlewarerb      s    DDKr   N) )__doc__	functoolsr   r   r   classmethodr   r   r*   r6   r<   r>   r9   r^   r`   rb   r   r   r   <module>rg      sI    E 4 4.k .$>"J7 9-`r   