o Ih2@sddlZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z m Z mZmZmZmZddlmZddlmZdd lmZmZdd lmZdd lmZd d ZddZddZddZ dS)N)wraps) sync_to_async)settings)signals) BadRequestPermissionDeniedRequestDataTooBigSuspiciousOperationTooManyFieldsSentTooManyFilesSent)Http404)MultiPartParserError) get_resolver get_urlconf) log_response)debugcs:trtfdd}|Stfdd}|S)a+ Wrap the given get_response callable in exception-to-response conversion. All exceptions will be converted. All known 4xx exceptions (Http404, PermissionDenied, MultiPartParserError, SuspiciousOperation) will be converted to the appropriate response, and all other exceptions will be converted to 500 responses. This decorator is automatically applied to all middleware to ensure that no middleware leaks an exception and that the next middleware in the stack can rely on getting a response instead of an exception. c sVz |IdH}W|Sty*}zttdd||IdH}WYd}~|Sd}~ww)NF)thread_sensitive) Exceptionrresponse_for_exceptionrequestresponseexc get_response@/usr/lib/python3/dist-packages/django/core/handlers/exception.pyinner#s"z,convert_exception_to_response..innerc s@z|}W|Sty}z t||}WYd}~|Sd}~ww)N)rrrrrrr,s )asyncioiscoroutinefunctionr)rrrrrconvert_exception_to_responses r cCst|trtjrt||}nt|ttd|}nt|t r6t|ttd|}t d|j ||t dnt|trRt|ttd|}t d|j ||t dnt|trtjritj|gt Rddi}n t|ttd|}t dt||j ||t dnjt|trt|tttfr|td |jj}|jt|d|d d tjrtj|gt Rddi}n2t|ttd|}n't|tr̂tjjd|d t |ttt }t d|j!|j ||t dt"|d dst#t"|ddr|$}|S)Niiz!Forbidden (Permission denied): %s)rrexc_infoiz.Bad request (Unable to parse request body): %s status_codez%s: %szdjango.security.%s)r"r)extrasenderr is_renderedTrender)% isinstancer rDEBUGrtechnical_404_responseget_exception_responserrrrpathsysr!r rtechnical_500_responsestrr rr r _mark_post_parse_errorlogging getLogger __class____name__error SystemExitrgot_request_exceptionsendhandle_uncaught_exception reason_phrasegetattrcallabler')rrrsecurity_loggerrrrr6sl        rcCsRz||}|||d}W|Sty(tjjd|dt||t}Y|Sw)N) exceptionr$)resolve_error_handlerrrr7r8r9r-r!)rresolverr"r>callbackrrrrr+s  r+cCs2tjrtjrtj|g|RS|d}||S)zm Processing for any otherwise uncaught exceptions (those that will generate HTTP 500 responses). i)rDEBUG_PROPAGATE_EXCEPTIONSr)rr.r?)rr@r!rArrrr9s  r9)!rr1r- functoolsr asgiref.syncr django.confr django.corerdjango.core.exceptionsrrrr r r django.httpr django.http.multipartparserr django.urlsrrdjango.utils.logr django.viewsrr rr+r9rrrrs"         !K