o
    <g#                      @   s   d Z ddlmZmZmZ ddl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wraps)iscoroutinefunctionc                       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__ J/var/www/html/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                    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   _decC   s$   



zmethod_decorator.<locals>._decr   r   zmethod_decorator(%s))r$   r   r   r   )r   r/   r0   r-   r   r.   r   method_decorator:   s   	

r1   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   r6   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.
    r2   r4   r   r   r   decorator_from_middlewareo   s   
r7   c                    s    fdd}|S )Nc                     s    fdd}|S )Nc                    sv   gR i fddfddfdd t r, fdd}n	 fd	d}t|S )
Nc                    sJ   t  dr | }|d ur|S t  dr# | ||}|d ur#|S d S )Nprocess_requestprocess_view)r$   r8   r9   )requestr   r   result)
middleware	view_funcr   r   _pre_process_request}   s   


zdmake_middleware_decorator.<locals>._make_decorator.<locals>._decorator.<locals>._pre_process_requestc                    s$   t  dr | |}|d ur|S  )Nprocess_exception)r$   r?   )r:   	exceptionr;   r<   r   r   _process_exception   s
   
zbmake_middleware_decorator.<locals>._make_decorator.<locals>._decorator.<locals>._process_exceptionc                    sj   t |dr(t|jr(t dr |}t dr& fdd}|| |S t dr3 |S |S )Nrenderprocess_template_responseprocess_responsec                    s     | S r   )rE   )response)r<   r:   r   r   callback   s   zwmake_middleware_decorator.<locals>._make_decorator.<locals>._decorator.<locals>._post_process_request.<locals>.callback)r$   r*   rC   rD   add_post_render_callbackrE   )r:   rF   rG   rA   )r:   r   _post_process_request   s   



zemake_middleware_decorator.<locals>._make_decorator.<locals>._decorator.<locals>._post_process_requestc              
      s   | g|R i |}|d ur|S z| g|R i |I d H }W n# t yE } z| |}|d ur;|W  Y d }~S W Y d }~nd }~ww  | |S r   	Exceptionr:   r   r   r;   rF   erI   r>   rB   r=   r   r   _view_wrapper   s    

z]make_middleware_decorator.<locals>._make_decorator.<locals>._decorator.<locals>._view_wrapperc              
      s   | g|R i |}|d ur|S z| g|R i |}W n# t yA } z| |}|d ur7|W  Y d }~S W Y d }~nd }~ww  | |S r   rJ   rL   rN   r   r   rO      s   

)r   r   )r=   rO   )m_argsm_kwargsr5   )rI   r>   rB   r<   r=   r   
_decoratorz   s   zFmake_middleware_decorator.<locals>._make_decorator.<locals>._decoratorr   )rP   rQ   rR   r4   )rP   rQ   r   _make_decoratory   s   Jz2make_middleware_decorator.<locals>._make_decoratorr   )r5   rS   r   r4   r   r3   x   s   Mr3   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      rY   c                 C      d| _ d| _| S )z\
    Mark a middleware factory as returning a sync middleware.
    This is the default.
    TFrT   rW   r   r   r   sync_only_middleware   rZ   r\   c                 C   r[   )z;Mark a middleware factory as returning an async middleware.FTrT   rW   r   r   r   async_only_middleware   s   r]   N)r&   )__doc__	functoolsr   r   r   asgiref.syncr   classmethodr   r   r%   r1   r6   r7   r3   rY   r\   r]   r   r   r   r   <module>   s    	

%	Q

