
    Vh                        d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ  ee	      Zd Z edg      Zde_          edg      Zde_          eddg      Zde_         ddZd Zd Zy)z-
Decorators for views based on HTTP headers.
    N)wraps)iscoroutinefunction)HttpResponseNotAllowed)ConditionalGetMiddleware)timezone)get_conditional_response)decorator_from_middleware)	http_date
quote_etag)log_responsec                       fd}|S )a9  
    Decorator to make a view only accept particular request methods.  Usage::

        @require_http_methods(["GET", "POST"])
        def my_view(request):
            # I can assume now that only GET or POST requests make it this far
            # ...

    Note that request methods should be in uppercase.
    c                 t     t               rt                fd       }|S t                fd       }|S )Nc                    K   | j                   vr1t              }t        d| j                   | j                  ||        |S  | g|i | d {   S 7 wNzMethod Not Allowed (%s): %s)responserequestmethodr   r   pathr   argskwargsr   funcrequest_method_lists       L/home/dcms/DCMS/lib/python3.12/site-packages/django/views/decorators/http.pyinnerz6require_http_methods.<locals>.decorator.<locals>.inner$   s`     >>)<<56IJH 5!) ' $O!';D;F;;;;s   AAAAc                     | j                   vr1t              }t        d| j                   | j                  ||        |S  | g|i |S r   r   r   s       r   r   z6require_http_methods.<locals>.decorator.<locals>.inner4   sV    >>)<<56IJH 5!) ' $OG5d5f55    r   r   )r   r   r   s   ` r   	decoratorz'require_http_methods.<locals>.decorator!   sG    t$4[< <:  4[6 6 r    )r   r    s   ` r   require_http_methodsr"      s    !F r   GETz=Decorator to require that a view only accepts the GET method.POSTz>Decorator to require that a view only accepts the POST method.HEADzIDecorator to require that a view only accepts safe methods: GET and HEAD.c                       fd}|S )ak  
    Decorator to support conditional retrieval (or change) for a view
    function.

    The parameters are callables to compute the ETag and last modified time for
    the requested resource, respectively. The callables are passed the same
    parameters as the view itself. The ETag function should return a string (or
    None if the resource doesn't exist), while the last_modified function
    should return a datetime object (or None if the resource doesn't exist).

    The ETag function should return a complete ETag, including quotes (e.g.
    '"etag"'), since that's the only way to distinguish between weak and strong
    ETags. If an unquoted ETag is returned (e.g. 'etag'), it will be converted
    to a strong ETag by adding quotes.

    This decorator will either pass control to the wrapped view function or
    return an HTTP 304 response (unmodified) or 412 response (precondition
    failed), depending upon the request method. In either case, the decorator
    will add the generated ETag and Last-Modified headers to the response if
    the headers aren't already set and if the request's method is safe.
    c                      fdd t               rt                fd       }|S t                fd       }|S )Nc                 D   d }rj | g|i |x}r\t        j                  |      s.t        j                  |t        j                   j                        }t        |j                               }r | g|i |nd }|t        |      nd }t        | ||      }|||fS )N)etaglast_modified)	r   is_aware
make_awaredatetimeutcint	timestampr   r   )	r   r   r   res_last_modifieddtres_etagr   	etag_funclast_modified_funcs	          r   _pre_process_requestz:condition.<locals>.decorator.<locals>._pre_process_requestk   s     $!+GEdEfEE2E#,,R0%00X5F5F5J5JK(+BLLN(;%>Gy:4:6:TH/7/Cz(+H//H
 X'888r   c                     | j                   dv rK|r)|j                  d      st        |      |j                  d<   |r|j                  j	                  d|       y y y )N)r#   r%   zLast-ModifiedETag)r   
has_headerr
   headers
setdefault)r   r   r3   r1   s       r   _post_process_requestz;condition.<locals>.decorator.<locals>._post_process_request}   sY     ~~0$X-@-@-Q8ABS8TH$$_5$$//A  1r   c                 v   K    | g|i |\  }}}| | g|i | d {   } | |||       |S 7 wNr!   	r   r   r   r   r3   r1   r<   r6   r   s	         r   r   z+condition.<locals>.decorator.<locals>.inner   se     8L9"9&,95($5 #%)'%CD%CF%CCH%gxCTU  Ds   "979c                 Z     | g|i |\  }}}| | g|i |} | |||       |S r>   r!   r?   s	         r   r   z+condition.<locals>.decorator.<locals>.inner   sX    8L9"9&,95($5 ##G=d=f=H%gxCTUr   r   )r   r   r<   r6   r4   r5   s   ` @@r   r    zcondition.<locals>.decoratorj   sT    	9$	B t$4[   *  4[    r   r!   )r4   r5   r    s   `` r   	conditionrA   S   s    .4l r   c                     t        |       S )Nr4   rA   rC   s    r   r)   r)      s    y))r   c                     t        |       S )Nr5   rD   rF   s    r   r*   r*      s    (:;;r   )NN)__doc__r-   	functoolsr   asgiref.syncr   django.httpr   django.middleware.httpr   django.utilsr   django.utils.cacher   django.utils.decoratorsr	   django.utils.httpr
   r   django.utils.logr   conditional_pager"   require_GETrequire_POSTrequire_saferA   r)   r*   r!   r   r   <module>rU      s      , . ; ! 7 = 3 ),-EF /d #E7+U #VH-W #UFO4O  
Mb*<r   