
    hhE                     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S rSrSrS r\S 5       r\S 5       r\S 5       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                 Z    S U l         [        U5      U l        X l        S U l        S U l        g N)_futurer   applicationscope_input_queue_output_queue)selfr   r   s      JD:\Anime\Ugyen\janka_web_project\venv\Lib\site-packages\asgiref/testing.py__init__ ApplicationCommunicator.__init__   s+    4[A
 !    c                 h    U R                   c  [        R                  " 5       U l         U R                   $ r
   )r   asyncioQueuer   s    r   input_queue#ApplicationCommunicator.input_queue   s(    $ 'D   r   c                 h    U R                   c  [        R                  " 5       U l         U R                   $ r
   )r   r   r   r   s    r   output_queue$ApplicationCommunicator.output_queue   s(    %!(D!!!r   c                 *   U R                   c{  [        R                  " 5       R                  [        R
                  U R                  U R                  U R                  R                  U R                  R                  5      5      U l         U R                   $ r
   )r   contextvarsContextrunr   create_taskr   r   r   getr   putr   s    r   futureApplicationCommunicator.future$   so    <<
 '..044##  JJ 0 0 4 4d6G6G6K6KDL ||r   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.wait3   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                   nUc  g UR                  5       (       d  UR                  5         g U(       a  UR                  5         g g r
   )r   r+   r,   r)   )r   
exceptionsr%   s      r   stopApplicationCommunicator.stopF   s8    >{{}}MMOMMO r   c                 D     U R                  SS9  g ! [         a     g f = f)NF)r0   )r1   RuntimeErrorr   s    r   __del__ApplicationCommunicator.__del__Q   s'    	III' 		s    
c                    #    U R                   R                  5       (       a  U R                   R                  5         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)   r   r$   )r   messages     r   
send_input"ApplicationCommunicator.send_inputY   sF     
 ;;KK  ""7+++s   AA"A A"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_outputd   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                   #    U R                   R                  5       (       a  U R                   R                  5         [        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)	r%   r+   r)   time	monotonicr   emptyr   sleep)r   r   intervalstarts       r   receive_nothing'ApplicationCommunicator.receive_nothing{   s     
 ;;KK   nn&0$$**,,--))) nn&0   &&(( *s   B$C%&C#' C%	C%)r   r   r   r   r   N)r   )T)g?g{Gz?)__name__
__module____qualname____firstlineno____doc__r   propertyr   r   r%   r-   r1   r5   r9   r>   rG   __static_attributes__ r   r   r   r   	   sf    
" ! !
 " "
  &		,.)r   r   )r   r   rA   compatibilityr   r   r(   r   rP   r   r   <module>rR      s        4 -@) @)r   