
    h;                        S r SSKrSSK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5      r " S S\5      r\S 5       r " S S5      rS rS r " S S5      r " S S5      rg)a~  
The Request class is used as a wrapper around the standard request object.

The wrapped request then offers a richer API, in particular :

    - content automatically parsed according to `Content-Type` header,
      and available as `request.data`
    - full support of PUT method, including support for file uploads
    - form overloading of HTTP method, content type and content
    N)contextmanager)settings)HttpRequest	QueryDict)RawPostDataException)MultiValueDictparse_header_parameters)
exceptions)api_settingsc                 >    [        U 5      u  pUS:H  =(       d    US:H  $ )z;
Return True if the media type is a valid form media type.
!application/x-www-form-urlencodedmultipart/form-datar	   )
media_typebase_media_typeparamss      H/var/www/html/env/lib/python3.13/site-packages/rest_framework/request.pyis_form_media_typer      s-     6jAOBB 5446    c                   *    \ rS rSrSrS rS rS rSrg)override_method"   z
A context manager that temporarily overrides the method on a request,
additionally setting the `view.request` attribute.

Usage:

    with override_method(view, request, 'POST') as request:
        ... # Do stuff with `view` and `request`
c                 L    Xl         X l        X0l        [        USS 5      U l        g )Naction)viewrequestmethodgetattrr   )selfr   r   r   s       r   __init__override_method.__init__-   s!    	dHd3r   c                 *   [        U R                  U R                  5      U R                  l        [	        U R                  S0 5      nUR                  U R                  R                  5       5      U R                  l        U R                  R                  $ )N
action_map)clone_requestr   r   r   r   getlowerr   )r   r#   s     r   	__enter__override_method.__enter__3   sa    )$,,D		TYYb9
%>>$++*;*;*=>		yy   r   c                 p    U R                   U R                  l         U R                  U R                  l        g N)r   r   r   )r   argskwargs      r   __exit__override_method.__exit__:   s"     LL		;;		r   )r   r   r   r   N)	__name__
__module____qualname____firstlineno____doc__r    r'   r-   __static_attributes__ r   r   r   r   "   s    4!'r   r   c                       \ rS rSrSrg)WrappedAttributeError?   r5   N)r/   r0   r1   r2   r4   r5   r   r   r7   r7   ?   s    r   r7   c               #      #     Sv   g! [          aA    [        R                  " 5       n [        [	        U S   5      5      nUR                  U S   5      ef = f7f)z
Used to re-raise AttributeErrors caught during authentication, preventing
these errors from otherwise being handled by the attribute access protocol.
N      )AttributeErrorsysexc_infor7   strwith_traceback)infoexcs     r   wrap_attributeerrorsrC   C   sM     * *||~#CQL1  a))*s   A	 AAAAc                       \ rS rSrSrSrg)EmptyQ   zT
Placeholder for unset attributes.
Cannot use `None`, as that may be a valid value.
r5   N)r/   r0   r1   r2   r3   r4   r5   r   r   rE   rE   Q   s     	r   rE   c                 $    [        X5      [        L$ r*   )r   rE   )objnames     r   _hasattrrJ   Y   s    s!U**r   c                    [        U R                  U R                  U R                  U R                  U R
                  S9nU R                  Ul        U R                  Ul        U R                  Ul        U R                  Ul	        U R                  Ul
        Xl        [        U S5      (       a  U R                  Ul        [        U S5      (       a  U R                  Ul        [        U S5      (       a  U R                  Ul        [        U S5      (       a  U R                   Ul        [        U S5      (       a  U R"                  Ul        [        U S5      (       a  U R$                  Ul        [        U S5      (       a  U R&                  Ul        U$ )	z
Internal helper method to clone a request, replacing with a different
HTTP method.  Used for checking permissions against other methods.
)r   parsersauthenticators
negotiatorparser_context_user_auth_authenticatoraccepted_rendereraccepted_media_typeversionversioning_scheme)Request_requestrL   rM   rN   rO   _data_files
_full_data_content_type_streamr   hasattrrP   rQ   rR   rS   rT   rU   rV   )r   r   rets      r   r$   r$   ]   s8   
 '**!//!(!7!7$//!(!7!7	9C
 CICJ''CN--C//CKJw  MM	w  MM	w())$33w+,, ' 9 9w-..")"="=w	""oow+,, ' 9 9Jr   c                   $    \ rS rSrSrS rS rSrg)ForcedAuthentication~   zm
This authentication class is used if the test client or request factory
forcibly authenticated the request.
c                     Xl         X l        g r*   
force_userforce_token)r   re   rf   s      r   r    ForcedAuthentication.__init__   s    $&r   c                 2    U R                   U R                  4$ r*   rd   )r   r   s     r   authenticate!ForcedAuthentication.authenticate   s    !1!122r   )rf   re   N)r/   r0   r1   r2   r3   r    ri   r4   r5   r   r   ra   ra   ~   s    
'3r   ra   c                   @   \ rS rSrSr  SS jrS rS rS r\	S 5       r
\	S	 5       r\	S
 5       r\	S 5       r\	S 5       r\R                  S 5       r\	S 5       r\R                  S 5       r\	S 5       rS rS rS rS rS rS rS r\	S 5       r\	S 5       rS rSrg)rW      aC  
Wrapper allowing to enhance a standard `HttpRequest` instance.

Kwargs:
    - request(HttpRequest). The original request instance.
    - parsers(list/tuple). The parsers to use for parsing the
      request content.
    - authenticators(list/tuple). The authenticators used to try
      authenticating the request's user.
Nc                    [        U[        5      (       d?   SR                  UR                  R                  UR                  R
                  5      5       eXl        U=(       d    SU l        U=(       d    SU l        U=(       d    U R                  5       U l
        XPl        [        U l        [        U l        [        U l        [        U l        [        U l        U R                  c  0 U l        X R                  S'   UR$                  =(       d    [&        R(                  U R                  S'   [+        USS 5      n[+        USS 5      nUc  Ub  [-        Xg5      nU4U l        g g )NzUThe `request` argument must be an instance of `django.http.HttpRequest`, not `{}.{}`.r5   r   encoding_force_auth_user_force_auth_token)
isinstancer   format	__class__r0   r/   rX   rL   rM   _default_negotiatorrN   rO   rE   rY   rZ   r[   r\   r]   rn   r   DEFAULT_CHARSETr   ra   )	r   r   rL   rM   rN   rO   re   rf   forced_auths	            r   r    Request.__init__   s(   ';// 	
6VG%%00'2C2C2L2LM	
/  }",2$B(@(@(B,
"&"$D)-I&*1*:*:*Vh>V>VJ'W&8$?
g':DA![%<.zGK#..D &=r   c           	          SU R                   R                  < SU R                   R                  < SU R                  < SU R	                  5       < S3	$ )N<.z:  >)rs   r0   r/   r   get_full_pathr   s    r   __repr__Request.__repr__   s9    NN%%NN##KK 	" 	"r   c                     U $ r*   r5   )clsr+   kwargss      r   __class_getitem__Request.__class_getitem__   s    
r   c                 ,    [         R                  " 5       $ r*   )r   !DEFAULT_CONTENT_NEGOTIATION_CLASSr~   s    r   rt   Request._default_negotiator   s    ==??r   c                 r    U R                   R                  nUR                  SUR                  SS5      5      $ )NCONTENT_TYPEHTTP_CONTENT_TYPE )rX   METAr%   )r   metas     r   content_typeRequest.content_type   s.    }}!!xx1Db(IJJr   c                 \    [        U S5      (       d  U R                  5         U R                  $ )zC
Returns an object that may be used to stream the request content.
r]   )rJ   _load_streamr]   r~   s    r   streamRequest.stream   s'    
 i((||r   c                 .    U R                   R                  $ )z1
More semantically correct name for request.GET.
)rX   GETr~   s    r   query_paramsRequest.query_params   s    
 }}   r   c                     [        U S5      (       d/  [        5          U R                  5         S S S 5        U R                  $ U R                  $ ! , (       d  f       U R                  $ = f)Nr[   )rJ   rC   _load_data_and_filesr[   r~   s    r   dataRequest.data   sL    l++%'))+ (t ('   A
A&c                     [        U S5      (       d/  [        5          U R                  5         SSS5        U R                  $ U R                  $ ! , (       d  f       U R                  $ = f)z
Returns the user associated with the current request, as authenticated
by the authentication classes provided to the request.
rP   N)r^   rC   _authenticaterP   r~   s    r   userRequest.user   N     tW%%%'""$ (zztzz ('zzr   c                 0    Xl         XR                  l        g)a;  
Sets the user on the current request. This is necessary to maintain
compatibility with django.contrib.auth where the user property is
set in the login and logout functions.

Note that we also set the user on Django's underlying `HttpRequest`
instance, ensuring that it is available to any middleware in the stack.
N)rP   rX   r   r   values     r   r   r      s     
"r   c                     [        U S5      (       d/  [        5          U R                  5         SSS5        U R                  $ U R                  $ ! , (       d  f       U R                  $ = f)zo
Returns any non-user authentication information associated with the
request, such as an authentication token.
rQ   N)r^   rC   r   rQ   r~   s    r   authRequest.auth   r   r   c                 0    Xl         XR                  l        g)zl
Sets any non-user authentication information associated with the
request, such as an authentication token.
N)rQ   rX   r   r   s     r   r   r     s     
"r   c                     [        U S5      (       d/  [        5          U R                  5         SSS5        U R                  $ U R                  $ ! , (       d  f       U R                  $ = f)zp
Return the instance of the authentication instance class that was used
to authenticate the request, or `None`.
rR   N)r^   rC   r   rR   r~   s    r   successful_authenticator Request.successful_authenticator  sU     t-..%'""$ ("""t""" ('"""r   c                    [        U S5      (       d  U R                  5       u  U l        U l        U R                  (       aE  U R                  R	                  5       U l        U R
                  R                  U R                  5        OU R                  U l        [        U R                  5      (       a7  U R                  U R                  l        U R                  U R                  l        ggg)z.
Parses the request content into `self.data`.
rY   N)rJ   _parserY   rZ   copyr[   updater   r   POSTrX   _postFILESr~   s    r   r   Request._load_data_and_files  s     g&&&*kkm#DJ{{"&**//"3&&t{{3"&** "$"3"344&*ii#'+zz$ 5 'r   c           	      x   U R                   R                  n [        UR                  SUR                  SS5      5      5      nUS:X  a  SU l        gU R                   R                  (       d  U R                   U l        g[        R                  " U R                  5      U l        g! [        [
        4 a    Sn Nuf = f)z6
Return the content body of the request, as a stream.
CONTENT_LENGTHHTTP_CONTENT_LENGTHr   N)rX   r   intr%   
ValueError	TypeErrorr]   _read_startedioBytesIObody)r   r   content_lengths      r   r   Request._load_stream)  s     }}!!	 )4884I1+MNN QDL,,==DL::dii0DL I& 	N	s   +B$ $B98B9c                 F   ^ Sm[        U4S jU R                   5       5      $ )z:
Return True if this requests supports parsing form data.
)r   r   c              3   @   >#    U  H  oR                   T;   v   M     g 7fr*   )r   ).0parser
form_medias     r   	<genexpr>1Request._supports_form_parsing.<locals>.<genexpr>D  s     Nv$$
2s   )anyrL   )r   r   s    @r   _supports_form_parsingRequest._supports_form_parsing<  s!    

 NNNNr   c                 |   U R                   n U R                  nUb  UcE  U(       a/  [        U5      (       a  [        SU R                  R                  S9nO0 n[        5       nX44$ U R                  R                  X R                  5      nU(       d  [        R                   " U5      e UR#                  X!U R$                  5      n UR.                  UR0                  4$ ! [         ae    [        U R                  S5      (       d  e U R                  5       (       a.  U R                  R                  U R                  R                  4s $ Sn GN1f = f! [&         aE    [        SU R                  R                  S9U l        [        5       U l        U R(                  U l        e f = f! [2         a    [        5       nXd4s $ f = f)z
Parse the request content, returning a two-tuple of (data, files)

May raise an `UnsupportedMediaType`, or `ParseError` exception.
r   Nr   rn   )r   r   r   r^   rX   r   r   r   r   r   	_encodingr   rN   select_parserrL   r   UnsupportedMediaTypeparserO   	ExceptionrY   rZ   r[   r   filesr<   )r   r   r   
empty_dataempty_filesr   parseds          r   r   Request._parseF  s    &&

	[[F >Z/0<<&rDMM4K4KL

(*K,,..t\\B11*==
	\\&d6I6IJF	)KK..M $ 	4=='22 **,,**DMM,?,?@@F	2  	
 #20G0GHDJ(*DK"jjDO	  	)(*K((	)s7   C (E F! A'EEEAF!F;:F;c                     U R                    H/  n UR                  U 5      nUc  M  Xl        Uu  U l        U l          g   U R	                  5         g! [        R                   a    U R	                  5         e f = f)zQ
Attempt to authenticate the request using each authentication instance
in turn.
N)rM   ri   r   APIException_not_authenticatedrR   r   r   )r   authenticatoruser_auth_tuples      r   r   Request._authenticatez  s|    
 "00M"/"<"<T"B
 *&3#'6$	49 1 	! ** '')s   A&A7c                     SU l         [        R                  (       a  [        R                  " 5       U l        OSU l        [        R                  (       a  [        R                  " 5       U l        gSU l        g)zx
Set authenticator, user & authtoken representing an unauthenticated request.

Defaults are None, AnonymousUser & None.
N)rR   r   UNAUTHENTICATED_USERr   UNAUTHENTICATED_TOKENr   r~   s    r   r   Request._not_authenticated  sL     #,,$99;DIDI--$::<DIDIr   c                      U R                  S5      n[        X!5      $ ! [         a'    [        SU R                  R                   SU S35      ef = f)zy
If an attribute does not exist on this instance, then we also attempt
to proxy it to the underlying HttpRequest object.
rX   'z' object has no attribute ')__getattribute__r   r<   rs   r/   )r   attrrX   s      r   __getattr__Request.__getattr__  s]    
	b,,Z8H8** 	b 1T^^%<%<$==XY]X^^_!`aa	bs	    1Ac                    [        U S5      (       d#  [        5          U R                  5         S S S 5        [        U R                  5      (       a  U R
                  $ [        SU R                  R                  S9$ ! , (       d  f       NR= f)NrY   r   r   )	rJ   rC   r   r   r   rY   r   rX   r   r~   s    r   r   Request.POST  sc     g&&%'))+ (d//00::dmm&=&=>>	 ('s   A99
Bc                     [        U S5      (       d/  [        5          U R                  5         S S S 5        U R                  $ U R                  $ ! , (       d  f       U R                  $ = f)NrZ   )rJ   rC   r   rZ   r~   s    r   r   Request.FILES  sN    
 h''%'))+ ({{t{{ ('{{r   c                 0   ^ U4S jU R                   l        g )Nc                     > T $ r*   r5   )r   s   r   <lambda>0Request.force_plaintext_errors.<locals>.<lambda>  s    r   )rX   is_ajaxr   s    `r   force_plaintext_errorsRequest.force_plaintext_errors  s     !.r   )rQ   rR   r\   rY   rZ   r[   rX   r]   rP   r   rM   rN   rO   rL   r   )NNNN)r/   r0   r1   r2   r3   r    r   r   rt   propertyr   r   r   r   r   setterr   r   r   r   r   r   r   r   r   r   r   r   r4   r5   r   r   rW   rW      s6   	 >B151<"@ K K   ! !     
[[
# 
#   
[[# # # #2$1&O2)h"&$	b ? ?  .r   rW   )r3   r   r=   
contextlibr   django.confr   django.httpr   r   django.http.requestr   django.utils.datastructuresr   django.utils.httpr
   rest_frameworkr   rest_framework.settingsr   r   r   r   r7   rC   rE   rJ   r$   ra   rW   r5   r   r   <module>r      s   	 
 
 %   . 4 6 5 % 06' ':	I 	 
* 
*	 	+B3 3u. u.r   