
    %h                     H    S SK r S SKrS SKrSSKJr  SSKJr   " S S5      rg)    N   )guarantee_single_callable)timeoutc                   R    \ rS rSrSrS rSS jrSS jrS rS r	SS jr
SS	 jrS
rg)ApplicationCommunicator	   zq
Runs an ASGI application in a test mode, allowing sending of
messages to it and retrieval of messages it sends.
c                 x   [        U5      U l        X l        [        R                  " 5       U l        [        R                  " 5       U l        [        R                  " 5       R                  [        R                  U R                  X R
                  R                  U R                  R                  5      5      U l        g N)r   applicationscopeasyncioQueueinput_queueoutput_queuecontextvarsContextruncreate_taskgetputfuture)selfr   r   s      A/var/www/html/env/lib/python3.13/site-packages/asgiref/testing.py__init__ ApplicationCommunicator.__init__   s~    4[A
"==?#MMO
 "))+//U$4$4$8$8$:K:K:O:OP
    c                   #     [        U5       ISh  vN    U R                  I Sh  vN   U R                  R                  5         SSS5      ISh  vN   U R                  R                  5       (       d0  U R                  R                  5          U R                  I Sh  vN   gg N N! [        R                   a     Nzf = f Nr! , ISh  vN  (       d  f       N= f N@! [        R                   a     gf = f! U R                  R                  5       (       dK  U R                  R                  5          U R                  I Sh  vN    f ! [        R                   a     f f = ff = f7f)zF
Waits for the application to stop itself and returns any exceptions.
N)async_timeoutr   resultr   CancelledErrordonecancel)r   r   s     r   waitApplicationCommunicator.wait   s    	$W--++%%KK&&( .- ;;##%%""$++%% & .%-- 	 .--- &-- 	 ;;##%%""$++%%-- 	 &s   E,C= B'C= CB+B)B+C= CC= 9E,C#  C!!C# %E,'C= )B++C?CCCC= CCCC= !C# #C:7E,9C::E,=:E)8EE
EE)E%"E)$E%%E))E,c                     U R                   R                  5       (       d  U R                   R                  5         g U(       a  U R                   R                  5         g g r
   )r   r!   r"   r   )r   
exceptionss     r   stopApplicationCommunicator.stop0   s=    {{!!KK KK  r   c                 D     U R                  SS9  g ! [         a     g f = f)NF)r&   )r'   RuntimeError)r   s    r   __del__ApplicationCommunicator.__del__7   s'    	III' 		s    
c                 V   #    U R                   R                  U5      I Sh  vN   g N7f)z+
Sends a single message to the application
N)r   r   )r   messages     r   
send_input"ApplicationCommunicator.send_input?   s!     
 ""7+++s   )')c                   #    U R                   R                  5       (       a  U R                   R                  5          [        U5       ISh  vN   U R                  R                  5       I Sh  vN sSSS5      ISh  vN   $  N7 N N	! , ISh  vN  (       d  f       g= f! [        R                   a  nU R                   R                  5       (       a  U R                   R                  5         UeU R                   R                  5          U R                   I Sh  vN    Ue! [        R                   a     Uef = fSnAff = f7f)zH
Receives a single message from the application, with optional timeout.
N)
r   r!   r   r   r   r   r   TimeoutErrorr"   r    )r   r   es      r   receive_output&ApplicationCommunicator.receive_outputF   s     
 ;;KK 	$W--!..2244 .--4 .---## 
	{{!!""$ G ""$++%% G -- G
	s   :EB$ BB$ B
.B/B
2B$ >B?B$ EB$ B
B$ 
B!BB!B$  E!B$ $E8AE D%D D%#E %D=9E <D==E  EEc                 \  #    [         R                  " 5       n[         R                  " 5       U-
  U:  a\  U R                  R                  5       (       d  g[        R
                  " U5      I Sh  vN   [         R                  " 5       U-
  U:  a  M\  U R                  R                  5       $  N<7f)z?
Checks that there is no message to receive in the given time.
FN)time	monotonicr   emptyr   sleep)r   r   intervalstarts       r   receive_nothing'ApplicationCommunicator.receive_nothing]   s     
  nn&0$$**,,--))) nn&0   &&(( *s   A+B,-B*. B,B,)r   r   r   r   r   N)r   )T)g?g{Gz?)__name__
__module____qualname____firstlineno____doc__r   r#   r'   r+   r/   r4   r=   __static_attributes__ r   r   r   r   	   s*    

&!,.
)r   r   )r   r   r7   compatibilityr   r   r   r   rE   r   r   <module>rG      s        4 -^) ^)r   