
    (phoI                         S r SSKJr  SSKJr  SSKJrJr  SSKJ	r	  SSK
Jr  SSKJrJr  SSKJr  SS	KJr  SS
KJr  SSKJrJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK J!r!  S r"SS jr#S r$S r% " S S\5      r&g)zL
Provides an APIView class that is the base of all views in REST framework.
    )settings)PermissionDenied)connectionsmodels)Http404)HttpResponseBase)cc_delim_repatch_vary_headers)	smart_str)csrf_exempt)View)
exceptionsstatus)Request)Response)DefaultSchema)api_settings)
formattingc                    [        U SS5      nUb  U$ U R                  R                  n[        R                  " US5      n[        R                  " US5      n[        R
                  " U5      n[        U SS5      nU(       a  USU-   -  nU$ )z
Given a view instance, return a textual name to represent the view.
This name is used in the browsable API, and in OPTIONS responses.

This function is the default for the `VIEW_NAME_FUNCTION` setting.
nameNr   ViewSetsuffix )getattr	__class____name__r   remove_trailing_stringcamelcase_to_spaces)viewr   r   s      G/var/www/html/venv/lib/python3.13/site-packages/rest_framework/views.pyget_view_namer!      s     4&D>>""D,,T6:D,,T9=D))$/D T8T*FfK    c                     [        U SS5      nUc  U R                  R                  =(       d    Sn[        R                  " [        U5      5      nU(       a  [        R                  " U5      $ U$ )z
Given a view instance, return a textual description to represent the view.
This name is used in the browsable API, and in OPTIONS responses.

This function is the default for the `VIEW_DESCRIPTION_FUNCTION` setting.
descriptionN )r   r   __doc__r   dedentr   markup_description)r   htmlr$   s      r    get_view_descriptionr*   /   s[     $t4Knn,,2##Ik$:;K,,[99r"   c                      [         R                  " 5        H=  n U R                  S   (       d  M  U R                  (       d  M,  U R	                  S5        M?     g )NATOMIC_REQUESTST)r   allsettings_dictin_atomic_blockset_rollback)dbs    r    r0   r0   A   s<    oo-..23E3E3EOOD!  r"   c                 V   [        U [        5      (       a  [        R                  " U R                  6 n O2[        U [
        5      (       a  [        R
                  " U R                  6 n [        U [        R                  5      (       a  0 n[        U SS5      (       a  U R                  US'   [        U SS5      (       a  SU R                  -  US'   [        U R                  [        [        45      (       a  U R                  nOSU R                  0n[        5         [        X0R                  US9$ g)	a  
Returns the response that should be used for any given exception.

By default we handle the REST framework `APIException`, and also
Django's built-in `Http404` and `PermissionDenied` exceptions.

Any unhandled exceptions may return `None`, which will cause a 500 error
to be raised.
auth_headerNzWWW-Authenticatewaitz%dzRetry-Afterdetail)r   headers)
isinstancer   r   NotFoundargsr   APIExceptionr   r3   r4   r5   listdictr0   r   status_code)exccontextr6   datas       r    exception_handlerrA   G   s     #w!!CHH.	C)	*	*))CHH6#z..//3t,,*-//G&'3%%%)CHH_GM"cjj4,//::Dcjj)D__gFFr"   c                     ^  \ rS rSr\R
                  r\R                  r\R                  r
\R                  r\R                  r\R                  r\R"                  r\R&                  r\r\" 5       r\U 4S j5       r\S 5       r\S 5       rS rS$S jrS rS r S	 r!S
 r"S r#S r$S%S jr%S r&S r'S r(S r)S r*S r+S r,S r-S%S jr.S r/S r0S r1S r2S r3S r4S r5S r6S r7S  r8S! r9S" r:S#r;U =r<$ )&APIViewh   c                    > [        [        U SS5      [        R                  R                  5      (       a  S nX R
                  l        [        TU ]   " S0 UD6nXl	        Xl
        [        U5      $ )z
Store the original class on the view function.

This allows us to discover information about the view when we do URL
reverse lookups.  Used for breadcrumb generation.
querysetNc                      [        S5      e)NzDo not evaluate the `.queryset` attribute directly, as the result will be cached and reused between requests. Use `.all()` or call `.get_queryset()` instead.)RuntimeError r"   r    force_evaluation)APIView.as_view.<locals>.force_evaluation   s    "F r"   rI   )r7   r   r   queryQuerySetrF   
_fetch_allsuperas_viewcls
initkwargsr   )rQ   rR   rJ   r   r   s       r    rP   APIView.as_viewy   s^     gc:t4fll6K6KLL '7LL#w,,$ 4  r"   c                 "    U R                  5       $ )zJ
Wrap Django's private `_allowed_methods` interface in a public property.
)_allowed_methodsselfs    r    allowed_methodsAPIView.allowed_methods   s    
 $$&&r"   c                 |    SSR                  U R                  5      0n[        U R                  5      S:  a  SUS'   U$ )NAllowz,    AcceptVary)joinrX   lenrenderer_classes)rW   r6   s     r    default_response_headers APIView.default_response_headers   sB     TYYt334
 t$$%)&GFOr"   c                 B    [         R                  " UR                  5      e)zi
If `request.method` does not correspond to a handler method,
determine what kind of exception to raise.
)r   MethodNotAllowedmethod)rW   requestr9   kwargss       r    http_method_not_allowedAPIView.http_method_not_allowed   s    
 ))'..99r"   c                     UR                   (       a&  UR                  (       d  [        R                  " 5       e[        R                  " X#S9e)zI
If request is not permitted, determine what kind of exception to raise.
)r5   code)authenticatorssuccessful_authenticatorr   NotAuthenticatedr   )rW   rg   messagerl   s       r    permission_deniedAPIView.permission_denied   s5     !!'*J*J--//))DDr"   c                 .    [         R                  " U5      e)zE
If request is throttled, determine what kind of exception to raise.
)r   	Throttled)rW   rg   r4   s      r    	throttledAPIView.throttled   s     ""4((r"   c                 Z    U R                  5       nU(       a  US   R                  U5      $ g)zj
If a request is unauthenticated, determine the WWW-Authenticate
header to use for 401 responses, if any.
r   N)get_authenticatorsauthenticate_header)rW   rg   rm   s      r    get_authenticate_headerAPIView.get_authenticate_header   s0    
 002!!$88AA r"   c                 :    U [        U SS5      [        U S0 5      S.$ )zd
Returns a dict that is passed through to Parser.parse(),
as the `parser_context` keyword argument.
r9   rI   rh   )r   r9   rh   r   )rW   http_requests     r    get_parser_contextAPIView.get_parser_context   s)     D&"-dHb1
 	
r"   c                 R    U [        U SS5      [        U S0 5      [        U SS5      S.$ )zi
Returns a dict that is passed through to Renderer.render(),
as the `renderer_context` keyword argument.
r9   rI   rh   rg   Nr   r9   rh   rg   r}   rV   s    r    get_renderer_contextAPIView.get_renderer_context   s5     D&"-dHb1tY5	
 	
r"   c                 R    U [        U SS5      [        U S0 5      [        U SS5      S.$ )zX
Returns a dict that is passed through to EXCEPTION_HANDLER,
as the `context` argument.
r9   rI   rh   rg   Nr   r}   rV   s    r    get_exception_handler_context%APIView.get_exception_handler_context   s5     D&"-dHb1tY5	
 	
r"   c                 >    U R                   R                  nU" U 5      $ )zN
Return the view name, as used in OPTIONS responses and in the
browsable API.
)r   VIEW_NAME_FUNCTION)rW   funcs     r    r!   APIView.get_view_name   s    
 }}//Dzr"   c                 >    U R                   R                  nU" X5      $ )zc
Return some descriptive text for the view, as used in OPTIONS responses
and in the browsable API.
)r   VIEW_DESCRIPTION_FUNCTION)rW   r)   r   s      r    r*   APIView.get_view_description   s    
 }}66Dr"   c                     U R                   R                  (       a%  UR                  U R                   R                  5      $ g)zA
Determine if the request includes a '.json' style format suffix
N)r   FORMAT_SUFFIX_KWARGget)rW   rh   s     r    get_format_suffixAPIView.get_format_suffix   s/     ==,,::dmm??@@ -r"   c                 N    U R                    Vs/ s H	  o" 5       PM     sn$ s  snf )zH
Instantiates and returns the list of renderers that this view can use.
)ra   )rW   renderers     r    get_renderersAPIView.get_renderers   &     ,0+@+@A+@x
+@AAA   "c                 N    U R                    Vs/ s H	  o" 5       PM     sn$ s  snf )zF
Instantiates and returns the list of parsers that this view can use.
)parser_classes)rW   parsers     r    get_parsersAPIView.get_parsers  s&     (,':':;':V':;;;r   c                 N    U R                    Vs/ s H	  o" 5       PM     sn$ s  snf )zM
Instantiates and returns the list of authenticators that this view can use.
)authentication_classes)rW   auths     r    rx   APIView.get_authenticators  s&     $(#>#>?#>4#>???r   c                 N    U R                    Vs/ s H	  o" 5       PM     sn$ s  snf )zK
Instantiates and returns the list of permissions that this view requires.
)permission_classes)rW   
permissions     r    get_permissionsAPIView.get_permissions  s&     04/F/FG/F
/FGGGr   c                 N    U R                    Vs/ s H	  o" 5       PM     sn$ s  snf )zE
Instantiates and returns the list of throttles that this view uses.
)throttle_classes)rW   throttles     r    get_throttlesAPIView.get_throttles  r   r   c                 h    [        U SS5      (       d  U R                  5       U l        U R                  $ )z>
Instantiate and return the content negotiation class to use.
_negotiatorN)r   content_negotiation_classr   rV   s    r    get_content_negotiatorAPIView.get_content_negotiator  s0     t]D11#==?Dr"   c                 .    U R                   R                  $ )z4
Returns the exception handler that this view uses.
)r   EXCEPTION_HANDLERrV   s    r    get_exception_handlerAPIView.get_exception_handler&  s     }}...r"   c                     U R                  5       nU R                  5       n UR                  XU R                  5      $ ! [         a    U(       a  US   US   R
                  4s $ e f = f)zE
Determine which renderer and media type to use render the response.
r   )r   r   select_rendererformat_kwarg	Exception
media_type)rW   rg   force	renderersconnegs        r    perform_content_negotiation#APIView.perform_content_negotiation.  sl     &&(	,,.	))'d>O>OPP 	!!il&=&=>>	s   > %A'%A'c                     UR                     g)z
Perform authentication on the incoming request.

Note that if you override this and simply 'pass', then authentication
will instead be performed lazily, the first time either
`request.user` or `request.auth` is accessed.
N)user)rW   rg   s     r    perform_authenticationAPIView.perform_authentication<  s     	r"   c           
          U R                  5        HB  nUR                  X5      (       a  M  U R                  U[        USS5      [        USS5      S9  MD     g)zl
Check if the request should be permitted.
Raises an appropriate exception if the request is not permitted.
rp   Nrl   rp   rl   )r   has_permissionrq   r   )rW   rg   r   s      r    check_permissionsAPIView.check_permissionsF  sV    
 ..0J,,W;;&&#J	4@ VT: '  1r"   c           
          U R                  5        HC  nUR                  XU5      (       a  M  U R                  U[        USS5      [        USS5      S9  ME     g)z
Check if the request should be permitted for a given object.
Raises an appropriate exception if the request is not permitted.
rp   Nrl   r   )r   has_object_permissionrq   r   )rW   rg   objr   s       r    check_object_permissions APIView.check_object_permissionsS  sX    
 ..0J33G3GG&&#J	4@ VT: '  1r"   c                 "   / nU R                  5        H:  nUR                  X5      (       a  M  UR                  UR                  5       5        M<     U(       a3  U Vs/ s H
  nUc  M  UPM     nn[	        USS9nU R                  X5        ggs  snf )zd
Check if request should be throttled.
Raises an appropriate exception if the request is throttled.
N)default)r   allow_requestappendr4   maxru   )rW   rg   throttle_durationsr   duration	durationss         r    check_throttlesAPIView.check_throttles`  s    
  **,H))'88"))(--/: -  *<);X );  
 9d3HNN7- s   B'Bc                 n    U R                   c  gU R                  5       nUR                  " U/UQ70 UD6U4$ )z
If versioning is being used, then determine any API version for the
incoming request. Returns a two-tuple of (version, versioning_scheme)
NN)versioning_classdetermine_version)rW   rg   r9   rh   schemes        r    r   APIView.determine_versionu  sA    
   (&&(((B4B6BFKKr"   c                     U R                  U5      n[        UU R                  5       U R                  5       U R	                  5       US9$ )z%
Returns the initial request object.
)parsersrm   
negotiatorparser_context)r   r   r   rx   r   )rW   rg   r9   rh   r   s        r    initialize_requestAPIView.initialize_request  sK     009$$&224224)
 	
r"   c                 $   U R                   " S0 UD6U l        U R                  U5      nUu  Ul        Ul        U R
                  " U/UQ70 UD6u  pVXVsUl        Ul        U R                  U5        U R                  U5        U R                  U5        g)zH
Runs anything that needs to occur prior to calling the method handler.
NrI   )r   r   r   accepted_rendereraccepted_media_typer   versionversioning_schemer   r   r   )rW   rg   r9   rh   negr   r   s          r    initialAPIView.initial  s     !22<V< ..w7AD>!7#> 00J4J6J5<22 	##G,w'W%r"   c                    [        U[        5      (       d   S[        U5      -  5       e[        U[        5      (       ah  [	        USS5      (       d  U R                  USS9nUu  Ul        Ul        UR                  Ul        UR                  Ul        U R                  5       Ul	        U R                  R                  SS5      nUb   [        U[        R                  " U5      5        U R                  R                  5        H	  u  pxXU'   M     U$ )z$
Returns the final response object.
zrExpected a `Response`, `HttpResponse` or `StreamingHttpResponse` to be returned from the view, but received a `%s`r   NT)r   r^   )r7   r   typer   r   r   r   r   r   renderer_contextr6   popr
   r	   splititems)	rW   rg   responser9   rh   r   vary_headerskeyvalues	            r    finalize_responseAPIView.finalize_response  s    
 ($455 	
@8n	
5 h))7$7>>66wd6KILF)7+F)0)B)BH&+2+F+FH((,(A(A(CH% ||''5#x):):<)HI,,,,.JC!SM / r"   c                 f   [        U[        R                  [        R                  45      (       a>  U R	                  U R
                  5      nU(       a  X!l        O[        R                  Ul	        U R                  5       nU R                  5       nU" X5      nUc  U R                  U5        SUl        U$ )zb
Handle any exception that occurs, by returning an appropriate response,
or re-raising the error.
T)r7   r   ro   AuthenticationFailedrz   rg   r3   r   HTTP_403_FORBIDDENr=   r   r   raise_uncaught_exception	exception)rW   r>   r3   rA   r?   r   s         r    handle_exceptionAPIView.handle_exception  s    
 cJ77&;;= > > 66t||DK"-"(";"; 668446$S2))#.!r"   c                     [         R                  (       a8  U R                  n[        UR                  S5      nUS;  nUR                  U5        Ue)Nformat)r)   apiadmin)r   DEBUGrg   r   r   force_plaintext_errors)rW   r>   rg   renderer_formatuse_plaintext_tracebacks        r    r    APIView.raise_uncaught_exception  sD    >>llG%g&?&?JO&5=U&U#**+BC	r"   c                    X l         X0l        U R                  " U/UQ70 UD6nXl        U R                  U l         U R                  " U/UQ70 UD6  UR                  R                  5       U R                  ;   a/  [        XR                  R                  5       U R                  5      nOU R                  nU" U/UQ70 UD6nU R                  " X/UQ70 UD6U l        U R                  $ ! [         a  nU R                  U5      n SnANGSnAff = f)z
`.dispatch()` is pretty much the same as Django's regular dispatch,
but with extra hooks for startup, finalize, and exception handling.
N)r9   rh   r   rg   rb   r6   r   rf   lowerhttp_method_namesr   ri   r   r   r   r   )rW   rg   r9   rh   handlerr   r>   s          r    dispatchAPIView.dispatch  s    
 	))'CDCFC44	2LL24262 ~~##%)?)??!$(<(<(>"&">">@ 66w888H
 ..wR4R6R}}	  	2,,S1H	2s   BC' '
D1DDc                     U R                   c  U R                  " U/UQ70 UD6$ U R                  5       R                  X5      n[        U[        R
                  S9$ )z,
Handler method for HTTP 'OPTIONS' request.
)r   )metadata_classri   determine_metadatar   r   HTTP_200_OK)rW   rg   r9   rh   r@   s        r    optionsAPIView.options  sW     &//I$I&II""$77FV%7%788r"   )r   r9   r   r6   rh   rg   r   r   F)=r   
__module____qualname____firstlineno__r   DEFAULT_RENDERER_CLASSESra   DEFAULT_PARSER_CLASSESr   DEFAULT_AUTHENTICATION_CLASSESr   DEFAULT_THROTTLE_CLASSESr   DEFAULT_PERMISSION_CLASSESr   !DEFAULT_CONTENT_NEGOTIATION_CLASSr   DEFAULT_METADATA_CLASSr  DEFAULT_VERSIONING_CLASSr   r   r   schemaclassmethodrP   propertyrX   rb   ri   rq   ru   rz   r   r   r   r!   r*   r   r   r   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  __static_attributes____classcell__)r   s   @r    rC   rC   h   sN    $<<!88N)HH#<<%@@ , N N!88N#<< H_F! !0 ' '  :E)B



 AB<@HB /.*L
&&<4:9 9r"   rC   Nr  )'r&   django.confr   django.core.exceptionsr   	django.dbr   r   django.httpr   django.http.responser   django.utils.cacher	   r
   django.utils.encodingr   django.views.decorators.csrfr   django.views.genericr   rest_frameworkr   r   rest_framework.requestr   rest_framework.responser   rest_framework.schemasr   rest_framework.settingsr   rest_framework.utilsr   r!   r*   r0   rA   rC   rI   r"   r    <module>r4     s\    ! 3 )  1 > + 4 % - * , 0 0 +2$"Ba9d a9r"   