o
    "7h                      @   s   d Z ddlmZmZmZ ddl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wraps)iscoroutinefunctionmarkcoroutinefunctionc                       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__ l/var/www/epreuve.sigeris.cm/public_html/epreuve/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                    s`   t  dr ddd  n g  fdd} D ]}t|| qt| tr.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   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   _decG   s$   



zmethod_decorator.<locals>._decr   r   zmethod_decorator(%s))r%   r   r   r   )r   r0   r1   r.   r   r/   r   method_decorator>   s   	

r2   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_argsc   s   r7   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.
    r3   r5   r   r   r   decorator_from_middlewares   s   
r8   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%   r9   r:   )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   )rF   )response)r=   r;   r   r   callback   s   zwmake_middleware_decorator.<locals>._make_decorator.<locals>._decorator.<locals>._post_process_request.<locals>.callback)r%   r+   rD   rE   add_post_render_callbackrF   )r;   rG   rH   rB   )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<   rG   erJ   r?   rC   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   rK   rM   rO   r   r   rP      s   

)r   r   )r>   rP   )m_argsm_kwargsr6   )rJ   r?   rC   r=   r>   r   
_decorator~   s   zFmake_middleware_decorator.<locals>._make_decorator.<locals>._decoratorr   )rQ   rR   rS   r5   )rQ   rR   r   _make_decorator}   s   Jz2make_middleware_decorator.<locals>._make_decoratorr   )r6   rT   r   r5   r   r4   |   s   Mr4   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      rZ   c                 C      d| _ d| _| S )z\
    Mark a middleware factory as returning a sync middleware.
    This is the default.
    TFrU   rX   r   r   r   sync_only_middleware   r[   r]   c                 C   r\   )z;Mark a middleware factory as returning an async middleware.FTrU   rX   r   r   r   async_only_middleware   s   r^   N)r'   )__doc__	functoolsr   r   r   asgiref.syncr   r   classmethodr   r   r&   r2   r7   r8   r4   rZ   r]   r^   r   r   r   r   <module>   s    	

#%	Q

