
    ^fYI                         d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZ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 ddlmZ ddlmZ ddlmZ ddl m!Z! d Z"ddZ#d Z$d Z% G d de          Z&dS )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                     t          | dd          }||S | j        j        }t          j        |d          }t          j        |d          }t          j        |          }t          | dd          }|r|d|z   z  }|S )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      F/var/www/html/env/lib/python3.11/site-packages/rest_framework/views.pyget_view_namer!      s     4&&D>"D,T6::D,T9==D)$//D T8T**F fK    Fc                     t          | dd          }|| j        j        pd}t          j        t          |                    }|rt          j        |          S |S )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*   /   sa     $t44Kn,2#Ik$:$:;;K :,[999r"   c                      t          j                    D ]+} | j        d         r| j        r|                     d           ,d S )NATOMIC_REQUESTST)r   allsettings_dictin_atomic_blockset_rollback)dbs    r    r0   r0   A   sQ    o " "-. 	"23E 	"OOD!!!" "r"   c                     t          | t                    rt          j                    } n(t          | t                    rt          j                    } t          | t          j                  ri }t          | dd          r
| j        |d<   t          | dd          rd| j        z  |d<   t          | j	        t          t          f          r| j	        }n	d| j	        i}t                       t          || j        |          S dS )	a4  
    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   NotFoundr   APIExceptionr   r3   r4   r5   listdictr0   r   status_code)exccontextr6   datas       r    exception_handlerr@   G   s     #w ,!##	C)	*	* ,)++#z.// G3t,, 	:*-/G&'3%% 	5%)CH_GM"cj4,// 	*:DDcj)DS_gFFFF4r"   c                       e Zd Zej        Zej        Zej        Z	ej
        Zej        Zej        Zej        Zej        ZeZ e            Ze fd            Zed             Zed             Zd Zd$dZd Zd Zd	 Z d
 Z!d Z"d Z#d%dZ$d Z%d Z&d Z'd Z(d Z)d Z*d Z+d Z,d%dZ-d Z.d Z/d Z0d Z1d Z2d Z3d Z4d Z5d  Z6d! Z7d" Z8d# Z9 xZ:S )&APIViewc                     t          t          | dd          t          j        j                  rd }|| j        _         t                      j        di |}| |_	        ||_
        t          |          S )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                       t          d          )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_evaluationz)APIView.as_view.<locals>.force_evaluation   s    "F  r"   rG   )r7   r   r   queryQuerySetrD   
_fetch_allsuperas_viewcls
initkwargsr   )rN   rO   rH   r   r   s       r    rM   zAPIView.as_viewy   s|     gc:t44fl6KLL 	7   '7CL#uww,,,,$ 4   r"   c                 *    |                                  S )zZ
        Wrap Django's private `_allowed_methods` interface in a public property.
        )_allowed_methodsselfs    r    allowed_methodszAPIView.allowed_methods   s    
 $$&&&r"   c                 x    dd                     | j                  i}t          | j                  dk    rd|d<   |S )NAllowz,    AcceptVary)joinrT   lenrenderer_classes)rS   r6   s     r    default_response_headersz APIView.default_response_headers   sE     TYYt344
 t$%%))&GFOr"   c                 4    t          j        |j                  )z
        If `request.method` does not correspond to a handler method,
        determine what kind of exception to raise.
        )r   MethodNotAllowedmethod)rS   requestargskwargss       r    http_method_not_allowedzAPIView.http_method_not_allowed   s    
 )'.999r"   Nc                 p    |j         r|j        st          j                    t          j        ||          )zY
        If request is not permitted, determine what kind of exception to raise.
        )r5   code)authenticatorssuccessful_authenticatorr   NotAuthenticatedr   )rS   ra   messagerf   s       r    permission_deniedzAPIView.permission_denied   s>     ! 	0'*J 	0-///)tDDDDr"   c                 *    t          j        |          )zU
        If request is throttled, determine what kind of exception to raise.
        )r   	Throttled)rS   ra   r4   s      r    	throttledzAPIView.throttled   s     "4(((r"   c                 h    |                                  }|r|d                             |          S dS )z
        If a request is unauthenticated, determine the WWW-Authenticate
        header to use for 401 responses, if any.
        r   N)get_authenticatorsauthenticate_header)rS   ra   rg   s      r    get_authenticate_headerzAPIView.get_authenticate_header   sC    
 0022 	B!!$88AAA	B 	Br"   c                 J    | t          | dd          t          | di           dS )z|
        Returns a dict that is passed through to Parser.parse(),
        as the `parser_context` keyword argument.
        rb   rG   rc   )r   rb   rc   r   )rS   http_requests     r    get_parser_contextzAPIView.get_parser_context   s4     D&"--dHb11
 
 	
r"   c                 j    | t          | dd          t          | di           t          | dd          dS )z
        Returns a dict that is passed through to Renderer.render(),
        as the `renderer_context` keyword argument.
        rb   rG   rc   ra   Nr   rb   rc   ra   rt   rR   s    r    get_renderer_contextzAPIView.get_renderer_context   sC     D&"--dHb11tY55	
 
 	
r"   c                 j    | t          | dd          t          | di           t          | dd          dS )zp
        Returns a dict that is passed through to EXCEPTION_HANDLER,
        as the `context` argument.
        rb   rG   rc   ra   Nrx   rt   rR   s    r    get_exception_handler_contextz%APIView.get_exception_handler_context   sC     D&"--dHb11tY55	
 
 	
r"   c                 0    | j         j        } ||           S )zf
        Return the view name, as used in OPTIONS responses and in the
        browsable API.
        )r   VIEW_NAME_FUNCTION)rS   funcs     r    r!   zAPIView.get_view_name   s    
 }/tDzzr"   Fc                 2    | j         j        } || |          S )z{
        Return some descriptive text for the view, as used in OPTIONS responses
        and in the browsable API.
        )r   VIEW_DESCRIPTION_FUNCTION)rS   r)   r~   s      r    r*   zAPIView.get_view_description   s     
 }6tD$r"   c                 \    | j         j        r|                    | j         j                  S dS )zQ
        Determine if the request includes a '.json' style format suffix
        N)r   FORMAT_SUFFIX_KWARGget)rS   rc   s     r    get_format_suffixzAPIView.get_format_suffix   s5     =, 	A::dm?@@@	A 	Ar"   c                 $    d | j         D             S )zX
        Instantiates and returns the list of renderers that this view can use.
        c                 "    g | ]} |            S rG   rG   ).0renderers     r    
<listcomp>z)APIView.get_renderers.<locals>.<listcomp>      AAAx

AAAr"   )r\   rR   s    r    get_rendererszAPIView.get_renderers        BA4+@AAAAr"   c                 $    d | j         D             S )zV
        Instantiates and returns the list of parsers that this view can use.
        c                 "    g | ]} |            S rG   rG   )r   parsers     r    r   z'APIView.get_parsers.<locals>.<listcomp>
  s    ;;;V;;;r"   )parser_classesrR   s    r    get_parserszAPIView.get_parsers  s     <;t':;;;;r"   c                 $    d | j         D             S )z]
        Instantiates and returns the list of authenticators that this view can use.
        c                 "    g | ]} |            S rG   rG   )r   auths     r    r   z.APIView.get_authenticators.<locals>.<listcomp>  s    ???4???r"   )authentication_classesrR   s    r    rp   zAPIView.get_authenticators  s     @?4#>????r"   c                 $    d | j         D             S )z[
        Instantiates and returns the list of permissions that this view requires.
        c                 "    g | ]} |            S rG   rG   )r   
permissions     r    r   z+APIView.get_permissions.<locals>.<listcomp>  s    GGG

GGGr"   )permission_classesrR   s    r    get_permissionszAPIView.get_permissions  s     HGt/FGGGGr"   c                 $    d | j         D             S )zU
        Instantiates and returns the list of throttles that this view uses.
        c                 "    g | ]} |            S rG   rG   )r   throttles     r    r   z)APIView.get_throttles.<locals>.<listcomp>  r   r"   )throttle_classesrR   s    r    get_throttleszAPIView.get_throttles  r   r"   c                 d    t          | dd          s|                                 | _        | j        S )zN
        Instantiate and return the content negotiation class to use.
        _negotiatorN)r   content_negotiation_classr   rR   s    r    get_content_negotiatorzAPIView.get_content_negotiator  s6     t]D11 	@#==??Dr"   c                     | j         j        S )zD
        Returns the exception handler that this view uses.
        )r   EXCEPTION_HANDLERrR   s    r    get_exception_handlerzAPIView.get_exception_handler&  s     }..r"   c                     |                                  }|                                 }	 |                    ||| j                  S # t          $ r |r|d         |d         j        fcY S  w xY w)zU
        Determine which renderer and media type to use render the response.
        r   )r   r   select_rendererformat_kwarg	Exception
media_type)rS   ra   force	renderersconnegs        r    perform_content_negotiationz#APIView.perform_content_negotiation.  s     &&((	,,..	))'9d>OPPP 	 	 	 ?!!il&=>>>>	s   A !A+)A+c                     |j          dS )a  
        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)rS   ra   s     r    perform_authenticationzAPIView.perform_authentication<  s     	r"   c           
          |                                  D ]N}|                    ||           s6|                     |t          |dd          t          |dd                     OdS )z
        Check if the request should be permitted.
        Raises an appropriate exception if the request is not permitted.
        rj   Nrf   rj   rf   )r   has_permissionrk   r   )rS   ra   r   s      r    check_permissionszAPIView.check_permissionsF  s    
 ..00 	 	J,,Wd;; &&#J	4@@ VT:: '   	 	r"   c           
          |                                  D ]O}|                    || |          s6|                     |t          |dd          t          |dd                     PdS )z
        Check if the request should be permitted for a given object.
        Raises an appropriate exception if the request is not permitted.
        rj   Nrf   r   )r   has_object_permissionrk   r   )rS   ra   objr   s       r    check_object_permissionsz APIView.check_object_permissionsS  s    
 ..00 	 	J33GT3GG &&#J	4@@ VT:: '   	 	r"   c                     g }|                                  D ]?}|                    ||           s'|                    |                                           @|r5d |D             }t	          |d          }|                     ||           dS dS )z|
        Check if request should be throttled.
        Raises an appropriate exception if the request is throttled.
        c                     g | ]}||S )NrG   )r   durations     r    r   z+APIView.check_throttles.<locals>.<listcomp>m  s(       %' '''r"   N)default)r   allow_requestappendr4   maxrn   )rS   ra   throttle_durationsr   	durationsr   s         r    check_throttleszAPIView.check_throttles`  s    
  **,, 	; 	;H))'488 ;"))(--//::: 		. );  I
 9d333HNN7H-----		. 		.r"   c                 b    | j         dS |                                  } |j        |g|R i ||fS )z
        If versioning is being used, then determine any API version for the
        incoming request. Returns a two-tuple of (version, versioning_scheme)
        NNN)versioning_classdetermine_version)rS   ra   rb   rc   schemes        r    r   zAPIView.determine_versionu  sK    
  (<&&((((B4BBB6BBFKKr"   c                     |                      |          }t          ||                                 |                                 |                                 |          S )z5
        Returns the initial request object.
        )parsersrg   
negotiatorparser_context)rv   r   r   rp   r   )rS   ra   rb   rc   r   s        r    initialize_requestzAPIView.initialize_request  sa     0099$$&&22442244)
 
 
 	
r"   c                 6    | j         di || _        |                     |          }|\  |_        |_         | j        |g|R i |\  }}||c|_        |_        |                     |           | 	                    |           | 
                    |           dS )zX
        Runs anything that needs to occur prior to calling the method handler.
        NrG   )r   r   r   accepted_rendereraccepted_media_typer   versionversioning_schemer   r   r   )rS   ra   rb   rc   negr   r   s          r    initialzAPIView.initial  s     3D2<<V<< ..w77AD>!7#> 1$0J4JJJ6JJ5<f22 	##G,,,w'''W%%%%%r"   c                 $   t          |t                    sJ dt          |          z              t          |t                    rht	          |dd          s&|                     |d          }|\  |_        |_        |j        |_        |j        |_        |                                 |_	        | j
                            dd          }|"t          |t          j        |                     | j
                                        D ]
\  }}|||<   |S )z4
        Returns the final response object.
        zrExpected a `Response`, `HttpResponse` or `HttpStreamingResponse` to be returned from the view, but received a `%s`r   NT)r   rY   )r7   r   typer   r   r   r   r   ry   renderer_contextr6   popr
   r	   splititems)	rS   ra   responserb   rc   r   vary_headerskeyvalues	            r    finalize_responsezAPIView.finalize_response  s%   
 ($455 	
 	
@8nn	
 	
5 h)) 	D7$7>> M66wd6KKILF)7+F)0)BH&+2+FH((,(A(A(C(CH% |''55#x):<)H)HIII,,,.. 	" 	"JC!HSMMr"   c                 `   t          |t          j        t          j        f          r5|                     | j                  }|r||_        nt          j        |_	        | 
                                }|                                 } |||          }||                     |           d|_        |S )zz
        Handle any exception that occurs, by returning an appropriate response,
        or re-raising the error.
        NT)r7   r   ri   AuthenticationFailedrr   ra   r3   r   HTTP_403_FORBIDDENr<   r   r{   raise_uncaught_exception	exception)rS   r=   r3   r@   r>   r   s         r    handle_exceptionzAPIView.handle_exception  s    
 cJ7&;= > > 	< 66t|DDK <"-"("; 66884466$$S'22))#...!r"   c                     t           j        r5| j        }t          |j        d          }|dv}|                    |           |)Nformat)r)   apiadmin)r   DEBUGra   r   r   force_plaintext_errors)rS   r=   ra   renderer_formatuse_plaintext_tracebacks        r    r   z APIView.raise_uncaught_exception  sL    > 	DlG%g&?JJO&5=U&U#**+BCCC	r"   c                    || _         || _         | j        |g|R i |}|| _        | j        | _        	  | j        |g|R i | |j                                        | j	        v r.t          | |j                                        | j                  }n| j        } ||g|R i |}n,# t          $ r}|                     |          }Y d}~nd}~ww xY w | j        ||g|R i || _        | j        S )z
        `.dispatch()` is pretty much the same as Django's regular dispatch,
        but with extra hooks for startup, finalize, and exception handling.
        N)rb   rc   r   ra   r]   r6   r   r`   lowerhttp_method_namesr   rd   r   r   r   r   )rS   ra   rb   rc   handlerr   r=   s          r    dispatchzAPIView.dispatch  sL   
 	)$)'CDCCCFCC4	2DL242226222 ~##%%)???!$(<(<(>(>"&">@ @ 6ww888888HH 	2 	2 	2,,S11HHHHHH	2 /.wR4RRR6RR}s   A2B' '
C1CCc                     | j          | j        |g|R i |S |                                                      ||           }t          |t          j                  S )z<
        Handler method for HTTP 'OPTIONS' request.
        N)r   )metadata_classrd   determine_metadatar   r   HTTP_200_OK)rS   ra   rb   rc   r?   s        r    optionszAPIView.options  sg     &/4/I$III&III""$$77FFV%78888r"   r   F);r   
__module____qualname__r   DEFAULT_RENDERER_CLASSESr\   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classmethodrM   propertyrT   r]   rd   rk   rn   rr   rv   ry   r{   r!   r*   r   r   r   rp   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r   s   @r    rB   rB   h   s        $<!8N)H#<%@ , N!8N#< H]__F! ! ! ! [!0 ' ' X'   X: : :E E E E) ) )B B B
 
 

 
 


 

 

         A A AB B B< < <@ @ @H H HB B B     / / /         . . .*L L L
 
 
& & &&  <  4    :9 9 9 9 9 9 9r"   rB   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   r@   rB   rG   r"   r    <module>r     s    !           3 3 3 3 3 3 ) ) ) ) ) ) ) )       1 1 1 1 1 1 > > > > > > > > + + + + + + 4 4 4 4 4 4 % % % % % % - - - - - - - - * * * * * * , , , , , , 0 0 0 0 0 0 0 0 0 0 0 0 + + + + + +  2   $" " "  Ba9 a9 a9 a9 a9d a9 a9 a9 a9 a9r"   