3
g                 @   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 k	rt dt j||S )Nz=This method is available only on the class, not on instances.)AttributeErrorsuper__get__)selfinstancecls)	__class__ U/var/www/tester-filtro-web/env/lib/python3.6/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 )Nr   )argskwargsr   r   r   dummy   s    z%_update_method_wrapper.<locals>.dummy)r   )_wrapper	decoratorr   r   r   r   _update_method_wrapper   s    r   c                sT   t  dr ddd  n g  fdd}x D ]}t|| q4W 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                s4   t j| t| }x D ]}||}qW |||S )N)r   r   type)r	   r   r   Zbound_methoddec)
decoratorsmethodr   r   r   #   s    
z!_multi_decorate.<locals>._wrapper)hasattrr   r   )r   r   r   r   r   )r   r   r   _multi_decorate   s    


r!    c                sF    fdd}t  ds"t|  t  dr0 n j}d|j |_|S )z>
    Convert a function decorator into a method decorator
    c                sp   t | tst | S o t| s2td| f t| }t|sVt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*   r   method_decorator5   s    

r,   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    r/   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.
    )r-   )r.   r   r   r   decorator_from_middlewarei   s    r0   c                s    fdd}|S )Nc                 s    fdd}|S )Nc                s*   f t  fdd}|S )Nc                s  t dr j }|d k	r |S t drFj ||}|d k	rF|S y f||}W nF tk
r } z*t drj |}|d k	r|S  W Y d d }~X nX t |drt|jrt dr̈j |}t dr fdd}|j| nt drj	 |S |S )	Nprocess_requestprocess_viewprocess_exceptionrenderprocess_template_responseprocess_responsec                s    j | S )N)r6   )response)
middlewarerequestr   r   callback   s    zomake_middleware_decorator.<locals>._make_decorator.<locals>._decorator.<locals>._wrapped_view.<locals>.callback)
r    r1   r2   	Exceptionr3   r&   r4   r5   Zadd_post_render_callbackr6   )r9   r   r   resultr7   er:   )r8   	view_func)r9   r   _wrapped_vieww   s2    





z]make_middleware_decorator.<locals>._make_decorator.<locals>._decorator.<locals>._wrapped_view)r   )r>   r?   )m_argsm_kwargsr.   )r8   r>   r   
_decoratort   s    zFmake_middleware_decorator.<locals>._make_decorator.<locals>._decoratorr   )r@   rA   rB   )r.   )r@   rA   r   _make_decorators   s    #z2make_middleware_decorator.<locals>._make_decoratorr   )r.   rC   r   )r.   r   r-   r   s    %r-   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   s    rG   c             C   s   d| _ d| _| S )z\
    Mark a middleware factory as returning a sync middleware.
    This is the default.
    TF)rD   rE   )rF   r   r   r   sync_only_middleware   s    rH   c             C   s   d| _ d| _| S )z;Mark a middleware factory as returning an async middleware.FT)rD   rE   )rF   r   r   r   async_only_middleware   s    rI   N)r"   )__doc__	functoolsr   r   r   classmethodr   r   r!   r,   r/   r0   r-   rG   rH   rI   r   r   r   r   <module>   s   	
$	)

