o 3ay@sdZddlmZddlmZddlmZddlmZddl m Z ddl m Z ddl mZmZdd lmZe eZd d Zed gZd e_edgZde_ed dgZde_dddZddZddZdS)z- Decorators for views based on HTTP headers. )timegmwraps)HttpResponseNotAllowed)ConditionalGetMiddleware)get_conditional_response)decorator_from_middleware) http_date quote_etag) log_responsecsfdd}|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. cstfdd}|S)NcsB|jvrt}td|j|j||d|S|g|Ri|S)NzMethod Not Allowed (%s): %s)responserequest)methodrr path)r argskwargsr )funcrequest_method_list>/usr/lib/python3/dist-packages/django/views/decorators/http.pyinners  z6require_http_methods..decorator..innerrrrrrr decorators z'require_http_methods..decoratorr)rrrrrrequire_http_methodss  rGETz=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.Ncsfdd}|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. cstfdd}|S)Ncsfdd}rgRind}|dur t|nd}|}t||d}|dur;gRi}jdvrW|rN|dsNt||jd<|rW|jd||S)Ncs2rgRi}|rt|SdSdS)N)r utctimetuple)dt)rrlast_modified_funcr rrget_last_modifiedQs  zFcondition..decorator..inner..get_last_modified)etag last_modified)rrz Last-ModifiedETag)r rr has_headerr headers setdefault)r rrr"res_etagres_last_modifiedr ) etag_funcrr!)rrr rrNs" z+condition..decorator..innerrrr+r!rrrMs zcondition..decoratorr)r+r!rrr,r condition7s#r-cC t|dS)Nr+r-r/rrrr#t r#cCr.)Nr!r0r2rrrr$xr1r$)NN)__doc__calendarr functoolsr django.httprdjango.middleware.httprdjango.utils.cacherdjango.utils.decoratorsrdjango.utils.httpr r django.utils.logr conditional_pager require_GET require_POST require_safer-r#r$rrrrs(           =