
    h                        S SK r S SKrS SKrS SK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 SKJrJr  S SKJrJr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Jr  S SK J!r!  S SK"J#r#J$r$J%r%  S SK&J'r'  S SK(J)r)J*r*J+r+J,r,  S SK-J.r.  S SK/J0r0  S SK1J2r2  S SK3J4r4  S SK5J6r6  S SK7J8r8  S SK9J:r:  Sr;Sr<S\<-  r=\:" S5      r>\:" S5      r?\@" \
R                  \
R                  \
R                  \
R                  \
R                  /5      rF " S S\G5      rH " S  S!\5      rIS" rJS# rKS$ rL " S% S&\5      rM " S' S(\5      rNS) rOS* rPS+ rQ " S, S-5      rR " S. S/\R5      rS " S0 S15      rT " S2 S3\T\R5      rU " S4 S5\T\S5      rVg)6    N)Iterable)copy)partial)
HTTPStatus)import_module)BytesIOIOBase)unquote_to_bytesurljoinurlparseurlsplit)sync_to_async)settings)ASGIRequest)BaseHandler)LimitedStreamWSGIRequest)DjangoJSONEncoder)got_request_exceptionrequest_finishedrequest_started)close_old_connections)HttpHeadersHttpRequest	QueryDictSimpleCookie)signals)ContextListresolve)force_bytes)SimpleLazyObject)	urlencode)_lazy_re_compile)AsyncClientAsyncRequestFactoryClientRedirectCycleErrorRequestFactoryencode_fileencode_multipartBoUnDaRyStRiNgz multipart/form-data; boundary=%sz.*; charset=([\w-]+);?z^application\/(.+\+)?jsonc                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )r(   ;   z9The test client has been asked to follow a redirect loop.c                 R   > [         TU ]  U5        X l        UR                  U l        g N)super__init__last_responseredirect_chain)selfmessager3   	__class__s      D/var/www/html/env/lib/python3.13/site-packages/django/test/client.pyr2   RedirectCycleError.__init__>   s$    !*+::    )r3   r4   )__name__
__module____qualname____firstlineno____doc__r2   __static_attributes____classcell__r7   s   @r8   r(   r(   ;   s    C; ;r:   r(   c                   B    \ rS rSrSrS
S jrS rSS jrSS jrS r	S	r
g)FakePayloadD   z
A wrapper around BytesIO that restricts what can be read since data from
the network can't be sought and cannot be read outside of its content
length. This makes sure that views can't do anything under the test client
that wouldn't work in real life.
Nc                 h    [        5       U l        SU l        SU l        Ub  U R	                  U5        g g )Nr   F)r   _FakePayload__content_FakePayload__lenread_startedwrite)r5   initial_bytess     r8   r2   FakePayload.__init__L   s1     
!$JJ}% %r:   c                     U R                   $ r0   )rH   )r5   s    r8   __len__FakePayload.__len__S   s    zzr:   c                6   U R                   (       d"  U R                  R                  S5        SU l         US:X  d  Uc  U R                  nU R                  U:  d   S5       eU R                  R	                  U5      nU =R                  [        U5      -  sl        U$ Nr   TzFCannot read more than the available bytes from the HTTP incoming data.)rI   rG   seekrH   readlenr5   sizecontents      r8   rT   FakePayload.readV   s      NN" $D2:::DJJ$	TS	T..%%d+

c'l"
r:   c                6   U R                   (       d"  U R                  R                  S5        SU l         US:X  d  Uc  U R                  nU R                  U:  d   S5       eU R                  R	                  U5      nU =R                  [        U5      -  sl        U$ rQ   )rI   rG   rS   rH   readlinerU   rV   s      r8   r[   FakePayload.readlinec   s      NN" $D2:::DJJ$	TS	T..))$/

c'l"
r:   c                    U R                   (       a  [        S5      e[        U5      nU R                  R	                  U5        U =R
                  [        U5      -  sl        g )Nz.Unable to write a payload after it's been read)rI   
ValueErrorr!   rG   rJ   rH   rU   )r5   brX   s      r8   rJ   FakePayload.writep   sD    MNNa.W%

c'l"
r:   )	__content__lenrI   r0   )rR   )r;   r<   r=   r>   r?   r2   rN   rT   r[   rJ   r@    r:   r8   rD   rD   D   s     &#r:   rD   c              #     #     U  S h  vN   [         R                  " [        5        U" 5         [         R                  " [        5        g  N@! [         R                  " [        5        U" 5         [         R                  " [        5        f = f7fr0   r   
disconnectr   connect)iterablecloses     r8   closing_iterator_wrapperrj   x   s_     8##$9:  !67	 	##$9:  !67s+   BA A
A <B
A =B		Bc                .  #     U   S h  vN nU7v   M   N
 [         R                  " [        5        U" 5         [         R                  " [        5        g ! [         R                  " [        5        U" 5         [         R                  " [        5        f = f7fr0   re   )rh   ri   chunks      r8   aclosing_iterator_wrapperrm      sk     8# 	%K	8 	##$9:  !67 	##$9:  !67s5   BA A A <B=BBc                     SUR                   s=::  a  S:  d  O  UR                   S;   a   UR                  (       a  / Ul        OSUl        U R                  S:X  a!  UR                  (       a	  / Ul        U$ SUl        U$ )z
Simulate the behavior of most web servers by removing the content of
responses for HEAD requests, 1xx, 204, and 304 responses. Ensure
compliance with RFC 9112 Section 6.3.
d      )   i0  r:   HEAD)status_code	streamingstreaming_contentrX   method)requestresponses     r8   conditional_content_removalry      sp     h""(S(H,@,@J,N)+H&"H~~)+H& O  #HOr:   c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )ClientHandler   z
An HTTP Handler that can be used for testing purposes. Use the WSGI
interface to compose requests, but return the raw HttpResponse object with
the originating WSGIRequest attached to its ``wsgi_request`` attribute.
c                 2   > Xl         [        TU ]  " U0 UD6  g r0   enforce_csrf_checksr1   r2   r5   r   argskwargsr7   s       r8   r2   ClientHandler.__init__       #6 $)&)r:   c                    U R                   c  U R                  5         [        R                  " [        5        [        R
                  " U R                  US9  [        R                  " [        5        [        U5      nU R                  (       + Ul
        U R                  U5      n[        X#5        X#l        UR                  (       a`  UR                  (       a'  [!        UR"                  UR$                  5      Ul        U$ ['        UR"                  UR$                  5      Ul         U$ [(        R                  " [        5        UR%                  5         [(        R                  " [        5        U$ )N)senderenviron)_middleware_chainload_middlewarer   rf   r   sendr7   rg   r   r   _dont_enforce_csrf_checksget_responsery   wsgi_requestrt   is_asyncrm   ru   ri   rj   r   )r5   r   rw   rx   s       r8   __call__ClientHandler.__call__   s    !!)  """#89DNNGD 56g&
 150H0H,H) $$W- 	$G6 !(   -F...*  .F...* 	 ''(=>NN$$%:;r:   r   T	r;   r<   r=   r>   r?   r2   r   r@   rA   rB   s   @r8   r{   r{      s    *) )r:   r{   c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )AsyncClientHandler   z"An async version of ClientHandler.c                 2   > Xl         [        TU ]  " U0 UD6  g r0   r~   r   s       r8   r2   AsyncClientHandler.__init__   r   r:   c           	        #    U R                   c  U R                  SS9  SU;   a  UR                  S5      nO[        S5      n[        R
                  " [        5        [        R                  " U R                  US9I S h  vN   [        R                  " [        5        [        U[        U[        U5      5      5      nU R                  (       + Ul        U R                  U5      I S h  vN n[!        X45        X4l        UR$                  (       a`  UR&                  (       a'  [)        UR*                  UR,                  5      Ul        U$ [/        UR*                  UR,                  5      Ul         U$ [0        R
                  " [        5        [3        UR,                  SS9" 5       I S h  vN   [0        R                  " [        5        U$  GNF N N%7f)NT)r   
_body_file )r   scopeF)thread_sensitive)r   r   poprD   r   rf   r   asendr7   rg   r   r   rU   r   r   get_response_asyncry   asgi_requestrt   r   rm   ru   ri   rj   r   r   )r5   r   	body_filerw   rx   s        r8   r   AsyncClientHandler.__call__   sp     !!)  $ /5 		,/I#BI""#89##4>>GGG 56e]9c)n%MN 150H0H,H)0099#G6 !(  -F...*  .F...* 	 ''(=>GIII$$%:;= 	H :& Js8   A<G>G?A'G&G'B<G#G	$!GG	Gr   r   r   rB   s   @r8   r   r      s    ,** *r:   r   c                     U R                  S/ 5      R                  U5        SU ;  a  [        5       U S'   U S   R                  [        U5      5        g)z
Store templates and contexts that are rendered.

The context is copied so that it is an accurate representation at the time
of rendering.
	templatescontextN)
setdefaultappendr   r   )storesignalr   templater   r   s         r8   store_rendered_templatesr   	  sJ     
["%,,X6&=i	)DM*r:   c           	      h  ^ / nS mS nUR                  5        H  u  pEUc  [        SU-  5      eU" U5      (       a  UR                  [        XU5      5        M@  [	        U[
        5      (       do  [	        U[        5      (       aZ  U HR  nU" U5      (       a  UR                  [        XU5      5        M-  UR                  U4S jSU -  SU-  SU4 5       5        MT     M  UR                  U4S jSU -  SU-  SU4 5       5        M     UR                  T" S	U -  5      S
/5        SR                  U5      $ )a  
Encode multipart POST data from a dictionary of form values.

The key will be used as the form data name; the value will be transmitted
as content. If the value is a file, the contents of the file will be sent
as an application/octet-stream; otherwise, str(value) will be sent.
c                 6    [        U [        R                  5      $ r0   r!   r   DEFAULT_CHARSETss    r8   to_bytes"encode_multipart.<locals>.to_bytes       1h6677r:   c                 R    [        U S5      =(       a    [        U R                  5      $ )NrT   )hasattrcallablerT   )things    r8   is_file!encode_multipart.<locals>.is_file$  s    uf%>(5::*>>r:   zeCannot encode None for key '%s' as POST data. Did you mean to pass an empty string or omit the value?c              3   4   >#    U  H  nT" U5      v   M     g 7fr0   rc   .0valr   s     r8   	<genexpr>#encode_multipart.<locals>.<genexpr>7  s"      !$C !$   --%sz)Content-Disposition: form-data; name="%s"r   c              3   4   >#    U  H  nT" U5      v   M     g 7fr0   rc   r   s     r8   r   r   A  s"      C r   z--%s--r:   s   
)items	TypeErrorextendr*   
isinstancestrr   join)boundarydatalinesr   keyvalueitemr   s          @r8   r+   r+     sB    E8? jjl
==?BC  U^^LLXE:;E3''Juh,G,G4==LLXD!ABLL ! #X-G#M 	$! 	  LL  X%?#E	 / #B 
LLX()	
 <<r:   c                    S n[        US5      =(       a    [        UR                  [        5      nU(       a)  [        R
                  R                  UR                  5      OSn[        US5      (       a  UR                  nO#U(       a  [        R                  " U5      S   nOS nUc  SnU=(       d    UnU" SU -  5      U" SU< S	U< S
35      U" SU-  5      SU" UR                  5       5      /$ )Nc                 6    [        U [        R                  5      $ r0   r   r   s    r8   r   encode_file.<locals>.to_bytesU  r   r:   namer   content_typer   application/octet-streamr   z&Content-Disposition: form-data; name="z"; filename=""zContent-Type: %sr:   )r   r   r   r   ospathbasenamer   	mimetypes
guess_typerT   )r   r   filer   file_has_string_namefilenamer   s          r8   r*   r*   T  s    8
 #40OZ		35O.Brww		*Ht^$$((	 ++H5a813H("#JMxX	
 	#l23 r:   c                   $   \ rS rSrSr\SSS.S jrS rS rS r	S	 r
S
 r SSSS.S jjrS\S4SSS.S jjr SSSS.S jjrSSSS.S jjr   SSSS.S jjr   SSSS.S jjr   SSSS.S jjr   SSSS.S jjr   SSSS.S jjrSrg)r)   ir  a6  
Class that lets you create mock Request objects for use in testing.

Usage:

rf = RequestFactory()
get_request = rf.get('/hello/')
post_request = rf.post('/submit/', {'foo': 'bar'})

Once you have a request object you can pass it to any view function,
just as if that view had been hooked up using a URLconf.
N)json_encoderheadersquery_paramsc                   Xl         X@l        [        5       U l        [	        5       U l        U(       a/  U R                  R                  [        R                  " U5      5        U(       a  [        USS9U R                  S'   g g )NTdoseqQUERY_STRING)
r   defaultsr   cookiesr   errorsupdater   to_wsgi_namesr#   )r5   r   r   r   r   s        r8   r2   RequestFactory.__init__  s^     ) #~iMM  !:!:7!CD,5l$,ODMM.) r:   c                     SR                  [        S U R                  R                  5        5       5      5      SSSSSSS	S
S[	        S5      U R
                  SSSS.U R                  EUE$ )z%
The base environment for a request.
z; c              3   \   #    U  H"  nUR                   < S UR                  < 3v   M$     g7f)=N)r   coded_valuer   morsels     r8   r   /RequestFactory._base_environ.<locals>.<genexpr>  s&      "7  &zz6+=+=>"7s   *,/	127.0.0.1GETr   
testserver80zHTTP/1.1)   r   httpr:   TF)HTTP_COOKIE	PATH_INFOREMOTE_ADDRREQUEST_METHODSCRIPT_NAMESERVER_NAMESERVER_PORTSERVER_PROTOCOLzwsgi.versionwsgi.url_scheme
wsgi.inputzwsgi.errorszwsgi.multiprocesszwsgi.multithreadzwsgi.run_once)r   sortedr   valuesrD   r   r   r5   rw   s     r8   _base_environRequestFactory._base_environ  s      99 "&,,"5"5"7  &#')"%%c*;;!% %")
* mm+
, -
 	
r:   c                 8    [        U R                  " S0 UD65      $ )#Construct a generic request object.rc   )r   r	  r  s     r8   rw   RequestFactory.request  s    4--8899r:   c                     U[         L a  [        [        U5      $ [        R	                  U5      nU(       a  US   nO[
        R                  n[        XS9$ )Nr   )encoding)MULTIPART_CONTENTr+   BOUNDARYCONTENT_TYPE_REmatchr   r   r!   )r5   r   r   r  charsets        r8   _encode_dataRequestFactory._encode_data  sL    ,,#Hd33 $)),7E("22t66r:   c                     [         R                  U5      =(       a    [        U[        [        [
        45      nU(       a  [        R                  " XR                  S9$ U$ )z]
Return encoded JSON if data is a dict, list, or tuple and content_type
is application/json.
)cls)	JSON_CONTENT_TYPE_REr  r   dictlisttuplejsondumpsr   )r5   r   r   should_encodes       r8   _encode_jsonRequestFactory._encode_json  sL    
 -22<@ 
Z4u%F
 ;Htzz$$5$56QTQr:   c                     UR                   nUR                  (       a  USUR                  -   -  n[        U5      nUR                  S5      $ )N;
iso-8859-1)r   paramsr
   decode)r5   parsedr   s      r8   	_get_pathRequestFactory._get_path  s@    {{==C&--''D% {{<((r:   Fr   r   c                    U(       a  U(       a  [        S5      eU=(       d    UnUc  0 OUnU R                  " SU4UUUS.UD6$ )zConstruct a GET request.7query_params and data arguments are mutually exclusive.r   securer   r   r^   genericr5   r   r   r.  r   r   extras          r8   getRequestFactory.get  s\     DVWW+|)1r|||
 %
 
 	
r:   c                    U R                  Uc  0 OUU5      nU R                  X#5      nU R                  " SUUU4UUUS.UD6$ )zConstruct a POST request.POSTr-  )r   r  r0  )	r5   r   r   r   r.  r   r   r2  	post_datas	            r8   postRequestFactory.post  sc       t||L%%d9	||		

 %	
 	
 		
r:   c                    U(       a  U(       a  [        S5      eU=(       d    UnUc  0 OUnU R                  " SU4UUUS.UD6$ )zConstruct a HEAD request.r,  rr   r-  r/  r1  s          r8   headRequestFactory.head  s\     DVWW+|)1r|||
 %
 
 	
r:   c                2    U R                   " SU4UUUS.UD6$ )zConstruct a TRACE request.TRACEr-  r0  )r5   r   r.  r   r   r2  s         r8   traceRequestFactory.trace  s3    ||
 %
 
 	
r:   c                6    U R                   " SUUU4UUUS.UD6$ )zConstruct an OPTIONS request.OPTIONSr-  r?  r5   r   r   r   r.  r   r   r2  s           r8   optionsRequestFactory.options  s;     ||		

 %	
 	
 		
r:   c                X    U R                  X#5      nU R                  " SUUU4UUUS.UD6$ )zConstruct a PUT request.PUTr-  r   r0  rD  s           r8   putRequestFactory.put5  sK       4||		

 %	
 	
 		
r:   c                X    U R                  X#5      nU R                  " SUUU4UUUS.UD6$ )zConstruct a PATCH request.PATCHr-  rI  rD  s           r8   patchRequestFactory.patchM  sK       4||		

 %	
 	
 		
r:   c                X    U R                  X#5      nU R                  " SUUU4UUUS.UD6$ )zConstruct a DELETE request.DELETEr-  rI  rD  s           r8   deleteRequestFactory.deletee  sK       4||		

 %	
 	
 		
r:   c                Z   [        [        U5      5      n	[        U[        R                  5      nU R                  U	5      UU(       a  SOSU(       a  SOSS.n
U(       a0  U
R                  [        [        U5      5      U[        U5      S.5        U(       a%  UR                  [        R                  " U5      5        U(       a  [        USS9US	'   U
R                  U5        U
R                  S	5      (       d&  U	S
   R                  5       R                  S5      nXS	'   U R                  " S0 U
D6$ )$Construct an arbitrary HTTP request.443r   httpsr   )r   r   r  r  )CONTENT_LENGTHCONTENT_TYPEr  Tr   r      r$  rc   )r   r   r!   r   r   r(  r   rU   rD   r   r   r#   r3  encoder&  rw   )r5   rv   r   r   r   r.  r   r   r2  r'  rquery_strings               r8   r0  RequestFactory.generic}  s     #d)$4!9!9:/$$*5*0wf	
 HH&)#d)n$0"-d"3 LL227;<$-l$$GE.!	uu^$$!!9++-44\BL ,n|| a  r:   )r   r   r   r   )NF)Fr   r   F)r;   r<   r=   r>   r?   r   r2   r	  rw   r  r   r(  r3  r  r8  r;  r@  rE  rJ  rN  rR  r0  r@   rc   r:   r8   r)   r)   r  s     'P"
B:
7R	) ',
8<4
( &
 
6 ',
8<4
"	
4d 	
 /
 
4 /
 
6 /
 
6 /
 
8 /'! '! '!r:   r)   c                   >    \ rS rSrSrS rS r   S	SSS.S jjrSrg)
r&   i  a  
Class that lets you create mock ASGI-like Request objects for use in
testing. Usage:

rf = AsyncRequestFactory()
get_request = rf.get("/hello/")
post_request = rf.post("/submit/", {"foo": "bar"})

Once you have a request object you can pass it to any view function,
including synchronous ones. The reason we have a separate class here is:
a) this makes ASGIRequest subclasses, and
b) AsyncClient can subclass it.
c           
          SS0SSSS/SSS/ S	.U R                   EUEnUS
   R                  SSR                  [        S U R                  R                  5        5       5      5      45        U$ )zThe base scope for a request.versionz3.0r   z1.1r   r   )r   r   r   )asgitypehttp_versionclientserverschemerv   r   r   s   cookies   ; c              3   z   #    U  H1  nUR                   < S UR                  < 3R                  S5      v   M3     g7f)r   asciiN)r   r   r[  r   s     r8   r   2AsyncRequestFactory._base_scope.<locals>.<genexpr>  s4      &;F %+JJ0B0BCKKGTT&;s   9;)r   r   r   r  r   r  )r5   rw   r   s      r8   _base_scopeAsyncRequestFactory._base_scope  s     &!"A&*
 mm
 
 	i

 &*ll&9&9&; 
	
 r:   c           	          SU;   a  UR                  S5      nO[        S5      n[        U R                  " S0 UD6[	        U[        U5      5      5      $ )r  r   r   rc   )r   rD   r   rl  r   rU   )r5   rw   r   s      r8   rw   AsyncRequestFactory.request  sN    
 7"L1I#BI'w'y#i.)Q
 	
r:   Nr*  c                .   [        [        U5      5      n	[        U[        R                  5      nUU R                  U	5      SU(       a  SOS4U(       a  SOSS/S.n
U(       aX  U
S   R                  S	[        [        U5      5      R                  S
5      4SUR                  S
5      4/5        [        U5      U
S'   U(       a  [        USS9U
S'   O&UR                  SS5      =n(       a  XS'   OU	S   U
S'   U(       a%  UR                  [        R                  " U5      5        U
S==   UR                  5        VVs/ s H5  u  pUR!                  5       R                  S
5      UR                  S5      4PM7     snn-  ss'   U R"                  " S0 U
D6$ s  snnf )rU  r   rV  r   rW  r   )s   hosts
   testserver)rv   r   rg  rh  r   r   s   content-lengthrj  s   content-typer   Tr   r]  r   NrZ  latin1rc   )r   r   r!   r   r   r(  r   rU   r[  rD   r#   r   r   r   to_asgi_namesr   lowerrw   )r5   rv   r   r   r   r.  r   r   r2  r'  r   r]  r   r   s                 r8   r0  AsyncRequestFactory.generic  sr    #d)$4!9!9:NN6*"VE>!'gV01
 iL&CI(=(=g(FG$l&9&9'&BC *$/AlO ),d CAn"YY~t<<\< ,n !'q	AnLL227;<	)#kkm
+
 YY[(%,,x*@A+
 	
 || a  	
s   :<Frc   r_  )	r;   r<   r=   r>   r?   rl  rw   r0  r@   rc   r:   r8   r&   r&     s3    <
$ /,! ,! ,!r:   r&   c                       \ rS rSrSrS rS r\S 5       rS r	S r
S rSS
 jrSS jrS rSS jrSS jrS rS rS rS rSSS	S	S.S jrS rSrg	)ClientMixini  z;
Mixin with common methods between Client and AsyncClient.
c                 8    [         R                  " 5       U l        g)z3Store exceptions when they are generated by a view.N)sysexc_info)r5   r   s     r8   store_exc_infoClientMixin.store_exc_info  s    r:   c                     U R                   Ul         U R                   (       a*  U R                   u  p#nSU l         U R                  (       a  Uegg)z
Look for a signaled exception, clear the current context exception
data, re-raise the signaled exception, and clear the signaled exception
from the local cache.
N)ry  raise_request_exception)r5   rx   _	exc_values       r8   check_exceptionClientMixin.check_exception  sC     !MM=="mmOA! DM++ , r:   c                 \   [        [        R                  5      nU R                  R	                  [        R
                  5      nU(       a  UR                  UR                  5      $ UR                  5       nUR                  5         UR                  U R                  [        R
                  '   U$ )z%Return the current session variables.)
r   r   SESSION_ENGINEr   r3  SESSION_COOKIE_NAMESessionStorer   savesession_keyr5   enginecookiesessions       r8   r  ClientMixin.session'  s|     x667!!(">">?&&v||44%%'5<5H5HX112r:   c                 x  #    [        [        R                  5      nU R                  R	                  [        R
                  5      nU(       a  UR                  UR                  5      $ UR                  5       nUR                  5       I S h  vN   UR                  U R                  [        R
                  '   U$  N-7fr0   )
r   r   r  r   r3  r  r  r   asaver  r  s       r8   asessionClientMixin.asession3  s     x667!!(">">?&&v||44%%'mmo5<5H5HX112 	s   BB:
B8.B:c                 R    SSK Jn  U" S0 UD6nU(       a  U R                  U5        gg)z
Set the Factory to appear as if it has successfully logged into a site.

Return True if login is possible or False if the provided credentials
are incorrect.
r   )authenticateTFrc   )django.contrib.authr  _login)r5   credentialsr  users       r8   loginClientMixin.login=  s)     	5*k*KKr:   c                    #    SSK Jn  U" S0 UD6I Sh  vN nU(       a  U R                  U5      I Sh  vN   gg N& N7f)zSee login().r   )aauthenticateNTFrc   )r  r  _alogin)r5   r  r  r  s       r8   aloginClientMixin.aloginL  s;     5"1[11,,t$$$	 2$s   ?;?=??Nc                 X    Uc  U R                  5       nX!l        U R                  X5        g r0   )_get_backendbackendr  r5   r  r  s      r8   force_loginClientMixin.force_loginV  s&    ?'')GD"r:   c                 t   #    Uc  U R                  5       nX!l        U R                  X5      I S h  vN   g  N7fr0   )r  r  r  r  s      r8   aforce_loginClientMixin.aforce_login\  s/     ?'')Gll4)))s   .868c                 x    SSK Jn  [        R                   H   nU" U5      n[	        US5      (       d  M  Us  $    g )Nr   )load_backendget_user)r  r  r   AUTHENTICATION_BACKENDSr   )r5   r  backend_pathr  s       r8   r  ClientMixin._get_backendb  s2    4$<<L"<0Gw
++## =r:   c                 .   SSK Jn  [        5       nU R                  (       a  U R                  Ul        O.[	        [
        R                  5      nUR                  5       Ul        U" XAU5        UR                  R                  5         U R                  U5        g )Nr   )r  )
r  r  r   r  r   r   r  r  r  _set_login_cookies)r5   r  r  r  rw   r  s         r8   r  ClientMixin._loginj  sh    - -<<"llGO"8#:#:;F$113GOgW%(r:   c                 h  #    SSK Jn  [        5       nU R                  5       I S h  vN nU(       a  XTl        O.[        [        R                  5      nUR                  5       Ul        U" XAU5      I S h  vN   UR                  R                  5       I S h  vN   U R                  U5        g  N N: N7f)Nr   )r  )r  r  r   r  r  r   r   r  r  r  r  )r5   r  r  r  rw   r  r  s          r8   r  ClientMixin._aloginy  s     . -'%O"8#:#:;F$113GOWG,,,oo##%%%( ( 	-%s4   $B2B,AB23B.4!B2B0B2.B20B2c                     [         R                  nUR                  R                  U R                  U'   S S[         R
                  [         R                  =(       d    S S S.nU R                  U   R                  U5        g )Nr   )zmax-ager   domainr.  expires)r   r  r  r  r   SESSION_COOKIE_DOMAINSESSION_COOKIE_SECUREr   )r5   rw   session_cookiecookie_datas       r8   r  ClientMixin._set_login_cookies  se    !55'.'B'B^$4444<
 	^$++K8r:   c                    SSK JnJn  [        5       nU R                  (       a  U R                  Ul        U" U5      Ul        O.[        [        R                  5      nUR                  5       Ul        U" U5        [        5       U l        g)z<Log out the user by removing the cookies and session object.r   )r  logoutN)r  r  r  r   r  r  r   r   r  r  r   r   )r5   r  r  rw   r  s        r8   r  ClientMixin.logout  sZ    8-<<"llGO#G,GL"8#:#:;F$113GOw#~r:   c                 L  #    SSK JnJn  [        5       nU R	                  5       I Sh  vN nU(       a  XCl        U" U5      I Sh  vN Ul        O.[        [        R                  5      nUR                  5       Ul        U" U5      I Sh  vN   [        5       U l        g Nu NZ N7f)zSee logout().r   )	aget_useralogoutN)r  r  r  r   r  r  r  r   r   r  r  r   r   )r5   r  r  rw   r  r  s         r8   r  ClientMixin.alogout  sz     :-'%O!*7!33GL"8#:#:;F$113GOg#~ ( 4 	s4   &B$BB$B AB$	B"
B$ B$"B$c                 F   [        US5      (       d  [        R                  UR                  S5      5      (       d  [	        SUR                  S5      -  5      e[
        R                  " UR                  R                  UR                  5      40 UD6Ul
        UR                  $ )N_jsonzContent-Typez3Content-Type header is "%s", not "application/json")r   r  r  r3  r^   r  loadsrX   r&  r  r  )r5   rx   r2  s      r8   _parse_jsonClientMixin._parse_json  s    x))'--hll>.JKK Ill>23  "ZZ  ''(8(89=BHN ~~r:   r   r   r   r   r   c          	      V   UR                   nUR                  nUR                  XqR                  45        [	        U5      n	U	R
                  (       a  U	R
                  US'   U	R                  (       a  U	R                  US'   U	R                  US'   U	R                  (       a  [        U	R                  5      US'   U	R                  n
U
(       d  U	R                  (       a  Sn
U
R                  S5      (       d  [        UR                  S   U
5      n
UR                  [        R                  [        R                   4;   a>  UR                  S   R#                  5       nUS;  a  U	R$                  US	'   ['        X5      nO#U R(                  n[+        U	R$                  5      nS
nU" U
4UUSUUS.UD6$ )z9Follow a single redirect contained in response using GET.r  r  	HTTP_HOSTr  r   r   r   )r3  r;  r   NF)r   r   followr   r   )urlr4   r   rs   r   rh  hostnameportr   r   netloc
startswithr   rw   r   TEMPORARY_REDIRECTPERMANENT_REDIRECTrs  querygetattrr3  r   )r5   rx   r   r   r   r   r2  response_urlr4   r  r   request_methods               r8   _follow_redirectClientMixin._follow_redirect  ss     ||!00|-A-ABC|$::'*zzE#$<<#&<<E- !$E+88#&sxx=E- xx

Ds##8++K8$?D))))$
 
 &--.>?EEGN_4(+		n%$T:N!XXNSYY'DL
%%
 
 	
r:   c                 z    UR                   nUS   USS ;   a
  [        SUS9e[        U5      S:  a
  [        SUS9eg)zE
Raise a RedirectCycleError if response contains too many redirects.
rR   NzRedirect loop detected.)r3      zToo many redirects.)r4   r(   rU   )r5   rx   r4   s      r8   _ensure_redirects_not_cyclic(ClientMixin._ensure_redirects_not_cyclic  sU     "00"!44 %%>hWW~# %%:(SS	 $r:   )r   ry  r0   )r;   r<   r=   r>   r?   rz  r  propertyr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r@   rc   r:   r8   rv  rv    s{    '  	 	#*$))"9&&
  7
rTr:   rv  c                   `  ^  \ rS rSrSr  SSSS.U 4S jjjrS r   SSSS.U 4S jjjrS\SS4SSS.U 4S	 jjjr	   SSSS.U 4S
 jjjr
    SSSS.U 4S jjjr    SSSS.U 4S jjjr    SSSS.U 4S jjjr    SSSS.U 4S jjjr   SSSS.U 4S jjjr    SS jrSrU =r$ )r'   i	  a  
A class that can act as a client for testing purposes.

It allows the user to compose GET and POST requests, and
obtain the response that the server gave to those requests.
The server Response objects are annotated with the details
of the contexts and templates that were rendered during the
process of serving the request.

Client objects are stateful - they will retain cookie (and
thus session) details for the lifetime of the Client instance.

This is not intended as a replacement for Twill/Selenium or
the like - it is here to allow testing against the
contexts and templates produced by a view, rather than the
HTML rendered to the end-user.
FNr*  c                   > [         TU ]  " SX4S.UD6  [        U5      U l        X l        S U l        S U l        S U l        g Nr*  rc   )r1   r2   r{   handlerr}  ry  r2  r   r5   r   r}  r   r   r   r7   s         r8   r2   Client.__init__  sB     	PPxP$%89'>$
r:   c                    ^^ U R                   " S0 TD6n0 n[        [        U5      nS[        T5      -  n[        R
                  R                  XES9  S[        T5      -  n[        R                  " U R                  US9   U R                  U5      n[        R
                  R                  US9  [        R                  " US9  U R                  U5        Xl        TUl        UR                  S/ 5      Ul        UR                  S5      Ul        [        U R"                  U5      Ul        ['        UR(                  SS5      m[+        UU4S j5      Ul        UR                   (       a-  [/        UR                   5      S	:X  a  UR                   S
   Ul        UR0                  (       a%  U R0                  R3                  UR0                  5        U$ ! [        R
                  R                  US9  [        R                  " US9  f = f)z
Make a generic request. Compose the environment dictionary and pass
to the handler, return the result of the handler. Assume defaults for
the query environment, which can be overridden using the arguments to
the request.
template-render-%sdispatch_uidrequest-exception-%sr   r   urlconfNc                     > [        T S   TS9$ )Nr   r  r   rw   r  s   r8   <lambda> Client.request.<locals>.<lambda>O  s    GGK0'Br:   r   r   rc   )r	  r   r   idr   template_renderedrg   r   rz  r  rf   r  rf  rw   r3  r   r   r  r  r  r   r"   resolver_matchrU   r   r   )	r5   rw   r   r   on_template_render
signal_uidexception_uidrx   r  s	    `      @r8   rw   Client.request,  s    $$/w/ $%=tD)BwK7
!!))*<)V.G<%%d&9&9V	I||G,H%%00j0I!,,-HX&"!XXk2688I. 0 0(;(//DA"2B#
 H$4$4 5 :'//2HLL 0 011 %%00j0I!,,-Hs    G
 
3G=c                   > Xpl         XPl        [        T	U ]  " U4UUUUS.UD6nU(       a  U R                  " U4X%US.UD6nU$ )-Request a response from the server using GET.r   r.  r   r   r   r   r   )r2  r   r1   r3  _handle_redirects
r5   r   r   r  r.  r   r   r2  rx   r7   s
            r8   r3  
Client.get[  sl     
7;
%
 
 --#<SXH r:   c          	         > Xl         X`l        [        T
U ]  " U4UUUUUS.UD6n	U(       a  U R                  " U	4UUUUS.UD6n	U	$ ).Request a response from the server using POST.r   r   r.  r   r   r  )r2  r   r1   r8  r  r5   r   r   r   r  r.  r   r   r2  rx   r7   s             r8   r8  Client.postw  sx     
7<
%%
 
 --)) H r:   c                   > Xpl         XPl        [        T	U ]  " U4UUUUS.UD6nU(       a  U R                  " U4X%US.UD6nU$ ).Request a response from the server using HEAD.r  r  )r2  r   r1   r;  r  r  s
            r8   r;  Client.head  sl     
7<
%
 
 --#<SXH r:   c          	         > Xl         X`l        [        T
U ]  " U4UUUUUS.UD6n	U(       a  U R                  " U	4UUUUS.UD6n	U	$ )1Request a response from the server using OPTIONS.r  r  )r2  r   r1   rE  r  r  s             r8   rE  Client.options  sx     
7?
%%
 
 --)) H r:   c          	         > Xl         X`l        [        T
U ]  " U4UUUUUS.UD6n	U(       a  U R                  " U	4UUUUS.UD6n	U	$ )(Send a resource to the server using PUT.r  r  )r2  r   r1   rJ  r  r  s             r8   rJ  
Client.put  sx     
7;
%%
 
 --)) H r:   c          	         > Xl         X`l        [        T
U ]  " U4UUUUUS.UD6n	U(       a  U R                  " U	4UUUUS.UD6n	U	$ )*Send a resource to the server using PATCH.r  r  )r2  r   r1   rN  r  r  s             r8   rN  Client.patch  sx     
7=
%%
 
 --)) H r:   c          	         > Xl         X`l        [        T
U ]  " U4UUUUUS.UD6n	U(       a  U R                  " U	4UUUUS.UD6n	U	$ )$Send a DELETE request to the server.r  r  )r2  r   r1   rR  r  r  s             r8   rR  Client.delete  sx     
7>
%%
 
 --)) H r:   c                   > Xpl         XPl        [        T	U ]  " U4UUUUS.UD6nU(       a  U R                  " U4X%US.UD6nU$ )#Send a TRACE request to the server.r  r  )r2  r   r1   r@  r  r  s
            r8   r@  Client.traceB  sl     
7=
%
 
 --#<SXH r:   c                     / Ul         UR                  [        ;   aQ  UR                   nU R                  " U4UUUUS.UD6nXql         U R	                  U5        UR                  [        ;   a  MQ  U$ )I
Follow any redirects by requesting responses from the server using GET.
r  r4   rs   REDIRECT_STATUS_CODESr  r  r5   rx   r   r   r   r   r2  r4   s           r8   r  Client._handle_redirects^  s     #%""&;;%44N,,)) H '5#--h7 ""&;; r:   ry  r2  r  r   r}  FTNFFr   r   FFr   FFr   r   NN)r;   r<   r=   r>   r?   r2   rw   r3  r  r8  r;  rE  rJ  rN  rR  r@  r  r@   rA   rB   s   @r8   r'   r'   	  si   ( " $
   -d   > &! ! !L   > /! ! !L /! ! !L /! ! !L /! ! !L   >  r:   r'   c                   `  ^  \ rS rSrSr  SSSS.U 4S jjjrS r   SSSS.U 4S jjjrS\SS4SSS.U 4S	 jjjr	   SSSS.U 4S
 jjjr
    SSSS.U 4S jjjr    SSSS.U 4S jjjr    SSSS.U 4S jjjr    SSSS.U 4S jjjr   SSSS.U 4S jjjr    SS jrSrU =r$ )r%   iz  z
An async version of Client that creates ASGIRequests and calls through an
async request path.

Does not currently support "follow" on its methods.
FNr*  c                   > [         TU ]  " SX4S.UD6  [        U5      U l        X l        S U l        S U l        S U l        g r  )r1   r2   r   r  r}  ry  r2  r   r  s         r8   r2   AsyncClient.__init__  sB     	PPxP)*=>'>$
r:   c                   ^^#    U R                   " S0 TD6n0 n[        [        U5      nS[        T5      -  n[        R
                  R                  XES9  S[        T5      -  n[        R                  " U R                  US9   U R                  U5      I Sh  vN n[        R
                  R                  US9  [        R                  " US9  U R                  U5        Xl        TUl        UR                  S/ 5      Ul        UR                  S5      Ul        [        U R"                  U5      Ul        ['        UR(                  SS5      m[+        UU4S j5      Ul        UR                   (       a-  [/        UR                   5      S	:X  a  UR                   S
   Ul        UR0                  (       a%  U R0                  R3                  UR0                  5        U$  GN>! [        R
                  R                  US9  [        R                  " US9  f = f7f)z
Make a generic request. Compose the scope dictionary and pass to the
handler, return the result of the handler. Assume defaults for the
query environment, which can be overridden using the arguments to the
request.
r  r  r  Nr   r   r  c                     > [        T S   TS9$ )Nr   r  r   r  s   r8   r  %AsyncClient.request.<locals>.<lambda>  s    GGFOW=r:   r   r   rc   )rl  r   r   r  r   r  rg   r   rz  r  rf   r  rf  rw   r3  r   r   r  r  r  r   r"   r  rU   r   r   )	r5   rw   r   r   r  r  r  rx   r  s	    `      @r8   rw   AsyncClient.request  s       +7+ $%=tD)BwK7
!!))*<)V.G<%%d&9&9V	I!\\%00H%%00j0I!,,-HX&"!XXk2688I. 0 0(;(//DA"2=#
 H$4$4 5 :'//2HLL 0 015 1%%00j0I!,,-Hs1   A=HG GG D9HG 3H

Hc                   >#    Xpl         XPl        [        T	U ]  " U4UUUUS.UD6I Sh  vN nU(       a  U R                  " U4X%US.UD6I Sh  vN nU$  N+ N7f)r  r  Nr  )r2  r   r1   r3  _ahandle_redirectsr  s
            r8   r3  AsyncClient.get  s      

%
 
 
 !44#<SX H 
!   &AA$AAAAc          	         >#    Xl         X`l        [        T
U ]  " U4UUUUUS.UD6I Sh  vN n	U(       a   U R                  " U	4UUUUS.UD6I Sh  vN n	U	$  N- N7f)r  r  Nr  )r2  r   r1   r8  r&  r  s             r8   r8  AsyncClient.post  s      

%%
 
 
 !44))  H %
!   'AA&AAAAc                   >#    Xpl         XPl        [        T	U ]  " U4UUUUS.UD6I Sh  vN nU(       a  U R                  " U4X%US.UD6I Sh  vN nU$  N+ N7f)r  r  Nr  )r2  r   r1   r;  r&  r  s
            r8   r;  AsyncClient.head  s      

%
 
 
 !44#<SX H 
r(  c          	         >#    Xl         X`l        [        T
U ]  " U4UUUUUS.UD6I Sh  vN n	U(       a   U R                  " U	4UUUUS.UD6I Sh  vN n	U	$  N- N7f)r  r  Nr  )r2  r   r1   rE  r&  r  s             r8   rE  AsyncClient.options  s      

%%
 
 
 !44))  H %
r+  c          	         >#    Xl         X`l        [        T
U ]  " U4UUUUUS.UD6I Sh  vN n	U(       a   U R                  " U	4UUUUS.UD6I Sh  vN n	U	$  N- N7f)r  r  Nr  )r2  r   r1   rJ  r&  r  s             r8   rJ  AsyncClient.put>  s      

%%
 
 
 !44))  H %
r+  c          	         >#    Xl         X`l        [        T
U ]  " U4UUUUUS.UD6I Sh  vN n	U(       a   U R                  " U	4UUUUS.UD6I Sh  vN n	U	$  N- N7f)r
  r  Nr  )r2  r   r1   rN  r&  r  s             r8   rN  AsyncClient.patcha  s      

%%
 
 
 !44))  H %
r+  c          	         >#    Xl         X`l        [        T
U ]  " U4UUUUUS.UD6I Sh  vN n	U(       a   U R                  " U	4UUUUS.UD6I Sh  vN n	U	$  N- N7f)r  r  Nr  )r2  r   r1   rR  r&  r  s             r8   rR  AsyncClient.delete  s      

%%
 
 
 !44))  H %
r+  c                   >#    Xpl         XPl        [        T	U ]  " U4UUUUS.UD6I Sh  vN nU(       a  U R                  " U4X%US.UD6I Sh  vN nU$  N+ N7f)r  r  Nr  )r2  r   r1   r@  r&  r  s
            r8   r@  AsyncClient.trace  s      

%
 
 
 !44#<SX H 
r(  c                    #    / Ul         UR                  [        ;   aY  UR                   nU R                  " U4UUUUS.UD6I Sh  vN nXql         U R	                  U5        UR                  [        ;   a  MY  U$  N37f)r  r  Nr  r  s           r8   r&  AsyncClient._ahandle_redirects  s      #%""&;;%44N!22))  H '5#--h7 ""&;; s   AA;A9/A;7A;r  r  r  r  r  r  )r;   r<   r=   r>   r?   r2   rw   r3  r  r8  r;  rE  rJ  rN  rR  r@  r&  r@   rA   rB   s   @r8   r%   r%   z  si    " $
   ,b   > &! ! !L   > /! ! !L /! ! !L /! ! !L /! ! !L   >  r:   r%   )Wr  r   r   rx  collections.abcr   r   	functoolsr   r   r   	importlibr   ior   r	   urllib.parser
   r   r   r   asgiref.syncr   django.confr   django.core.handlers.asgir   django.core.handlers.baser   django.core.handlers.wsgir   r   django.core.serializers.jsonr   django.core.signalsr   r   r   	django.dbr   django.httpr   r   r   r   django.testr   django.test.utilsr   django.urlsr    django.utils.encodingr!   django.utils.functionalr"   django.utils.httpr#   django.utils.regex_helperr$   __all__r  r  r  r  	frozensetMOVED_PERMANENTLYFOUND	SEE_OTHERr  r  r  	Exceptionr(   rD   rj   rm   ry   r{   r   r   r+   r*   r)   r&   rv  r'   r%   rc   r:   r8   <module>rU     sk     	 
 $    #  F F &   1 1 @ : X X + I I  )  - 4 ' 6 6A "#<='(DE !$$%%%% ; ;1#& 1#h88&4K 4n1 1h
+;|<r! r!j	g!. g!TuT uTpn[. nbb+2 br:   