
    ;3he2              
       $   d dl Z d dlZd dlZd dlZd dlmZmZmZmZm	Z	m
Z
mZmZmZ d dlZddlmZmZmZmZmZmZmZmZ ddlmZmZmZ ddlmZ 	 d dlZ G d de      Z! G d	 d
e      Z" G d de      Z#d Z$d Z%ejL                  d        Z'ejL                  d        Z(ejR                  d        Z*ejR                  d&d       Z+d Z,d Z-d Z.ejL                  deg e j^                  f   de0de0de	e j^                     fd       Z1ejL                  de	e j^                     fd       Z2ejL                  deg e3f   deg e3f   fd       ZejL                  deg e3f   fd       Z4ejL                  de j^                  de	e"   fd        Z5ejL                  d!        Z6ejL                  de j^                  de	e#   fd"       Z7ejL                  d#        Z8ejL                  de j^                  de	e!   fd$       Z9ejL                  d%        Z:y# e $ r dZY w xY w)'    N)	Any	AwaitableCallableDictIteratorOptionalProtocolUnionoverload   )BaseTestServerRawTestServer
TestClient
TestServerloop_contextsetup_test_loopteardown_test_loopunused_port)ApplicationBaseRequestRequest)_RequestHandlerc                       e Zd Zedddedeeeef      dede	e
ef   fd       Zedddedeeeef      dede	edf   fd       Zy)	AiohttpClientNserver_kwargs_AiohttpClient__paramr   kwargsreturnc                   K   y wN selfr   r   r   s       U/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/aiohttp/pytest_plugin.py__call__zAiohttpClient.__call__'   s      ,/   c                   K   y wr!   r"   r#   s       r%   r&   zAiohttpClient.__call__/   s      ),r'   )__name__
__module____qualname__r   r   r   r   strr   r   r   r&   r   r   r"       r%   r   r   &   s    
 37	//  S#X/	/
 / 
G[(	)/ / 
 37	,,  S#X/	,
 , 
K%	&, ,r-   r   c            
       6    e Zd Zdddedee   dedee   fdZ	y)AiohttpServerNportappr1   r   r   c                     y r!   r"   )r$   r2   r1   r   s       r%   r&   zAiohttpServer.__call__:   s     #r-   )
r)   r*   r+   r   r   intr   r   r   r&   r"   r-   r%   r/   r/   9   s3    9=$$)1#$IL$	:	$r-   r/   c            
       6    e Zd Zdddedee   dedee   fdZ	y)AiohttpRawServerNr0   handlerr1   r   r   c                     y r!   r"   )r$   r7   r1   r   s       r%   r&   zAiohttpRawServer.__call__@   s    #&r-   )
r)   r*   r+   r   r   r4   r   r   r   r&   r"   r-   r%   r6   r6   ?   s3    AE'&'19#'QT'	=	!'r-   r6   c                     | j                  dddd       | j                  dddd	       | j                  d
ddd       y )N--aiohttp-fast
store_trueFz*run tests faster by disabling extra checks)actiondefaulthelpz--aiohttp-loopstorepyloopz3run tests with specific loop: pyloop, uvloop or all--aiohttp-enable-loop-debugzenable event loop debug mode)	addoption)parsers    r%   pytest_addoptionrD   E   sc    
9	   B	   %+	  r-   c                     | j                   t        j                        rdnt        j                        rdnydd| j                  vr| xj                  dz  c_        dfd}|| _         y)zjSet up pytest fixture.

    Allow fixtures to be coroutines. Run coroutine fixtures in an event loop.
    TFNrequestrF   c                     |d   }r|d= d|j                   vrt        d      |j                  d      r> | i |fd}|j                  |       j	                  j                               S j	                   | i |      S )NrF   loopz^Asynchronous fixtures must depend on the 'loop' fixture or be used in tests depending from it.c                  b    	  j                  j                               S # t        $ r Y y w xY wr!   )run_until_complete	__anext__StopAsyncIteration)_loopgens   r%   	finalizerz8pytest_fixture_setup.<locals>.wrapper.<locals>.finalizer   s1     33CMMODD) s   " 	..)fixturenames	ExceptiongetfixturevalueaddfinalizerrK   rL   )	argsr   rF   rP   rN   rO   funcis_async_genstrip_requests	       @@r%   wrapperz%pytest_fixture_setup.<locals>.wrapperp   s    #y!
 ---6 
 ''/ ''C   +++CMMO<<++D$,A&,ABBr-   )rV   inspectisasyncgenfunctioniscoroutinefunctionargnames)
fixturedefrY   rV   rW   rX   s     @@@r%   pytest_fixture_setupr_   Z   sr    
 ??D!!$'		$	$T	* 	M
+++|+C@ JOr-   c                 8    | j                   j                  d      S )z--fast config optionr:   config	getoptionrG   s    r%   fastrd      s     >>##$455r-   c                 8    | j                   j                  d      S )z!--enable-loop-debug config optionrA   ra   rG   s    r%   
loop_debugrf      s     >>##$ABBr-   c            
   #   f  K   t        j                  d      5 } d | D cg c]'  }|j                  t        k(  rdj	                  |      ) }}|rDt        dj	                  t        |      t        |      dk(  rdnd	d
j                  |                  	 ddd       yc c}w # 1 sw Y   yxY ww)zContext manager which checks for RuntimeWarnings.

    This exists specifically to
    avoid "coroutine 'X' was never awaited" warnings being missed.

    If RuntimeWarnings occur in the context a RuntimeError is raised.
    T)recordNz#{w.filename}:{w.lineno}:{w.message})wz{} Runtime Warning{},
{}r    s
)warningscatch_warningscategoryRuntimeWarningformatRuntimeErrorlenjoin)	_warningsri   rws      r%   _runtime_warning_contextrw      s      
	 	 	-  
zz^+ 28818=
 

 +22G3r7a<RS$))B-   
 s.   B1	B%,B AB%	B1 B%%B.*B1c              #   P   K   | r|  yt               } |  t        | |       yw)zPassthrough loop context.

    Sets up and tears down a loop unless one is passed in via the loop
    argument when it's passed straight through.
    rd   N)r   r   )rI   rd   s     r%   _passthrough_loop_contextrz      s)      
  
4d+s   $&c                     | j                  |      r1t        j                  |      rt        | j	                  ||            S yy)z%Fix pytest collecting for coroutines.N)funcnamefilterrZ   r\   list_genfunctions)	collectornameobjs      r%   pytest_pycollect_makeitemr      s>    %'*E*Ec*JI++D#677 +K%r-   c           	         | j                   j                  d      }t        j                  | j                        r| j
                  j                  d      xsV | j
                  j                  d      xs9 | j
                  j                  d      xs | j
                  j                  dd      }t               5  t        ||      5 }| j                  j                  D ci c]  }|| j
                  |    }}|j                   | j                  d	i |       ddd       ddd       yyc c}w # 1 sw Y   xY w# 1 sw Y   yxY w)
zBRun coroutines in an event loop instead of a normal function call.r:   proactor_loopselector_loopuvloop_looprI   Nry   Tr"   )rb   rc   rZ   r\   functionfuncargsgetrw   rz   _fixtureinfor]   rK   r   )
pyfuncitemrd   existing_looprN   argtestargss         r%   pytest_pyfunc_callr      sB   &&'78D"":#6#67##O4 5""&&75""&&}55 ""&&vt4	 	 &' 	E*=tD E  *66?? ,,S11  (()C()CDE	E ! 8E E	E s6   8D<D0D+6#D0D<+D00D9	5D<<Ec           
      .   d| j                   vry | j                  j                  j                  }dt        j
                  i}t        t        j
                  |d<   |dk(  rd}i }|j                  d      D ]\  }|j                  d       }|j                  d      }||vr+|r(t        d	|d
t        |j                                     U||   ||<   ^ | j                  dt        |j                               t        |j                                      y )Nloop_factoryr@   uvloopallzpyloop,uvloop?,?z ?zUnknown loop 'z', available loops: )ids)rQ   rb   optionaiohttp_loopasyncionew_event_loopr   splitendswithstrip
ValueErrorr}   keysparametrizevalues)metafuncloopsavail_factories	factoriesr   requireds         r%   pytest_generate_testsr      s   X222OO""//E!7!78O$*$9$9!~ IC  0}}S))zz$& T).."235 
 )$/	$0 Y--/0d9>>;K6L  r-   r   rd   rf   r   c              #      K   t        | |      5 }|r|j                  d       t        j                  |       | ddd       y# 1 sw Y   yxY ww)z%Return an instance of the event loop.ry   TN)r   	set_debugr   set_event_loop)r   rd   rf   rN   s       r%   rI   rI     sJ      
l	. %OOD!u%	  s   A-A	AAAc               #      K   t         j                  } t        |       5 }t        j                  |       | d d d        y # 1 sw Y   y xY wwr!   )r   ProactorEventLoopr   r   )factoryrN   s     r%   r   r     sB     ''G	g	 %u%  s   AA	AA
Aaiohttp_unused_portc                 >    t        j                  dt        d       | S )Nz3Deprecated, use aiohttp_unused_port fixture instead   
stacklevelrm   warnDeprecationWarning)r   s    r%   r   r     s    MM=
 r-   c                      t         S )z1Return a port that is unused on the current host.)_unused_portr"   r-   r%   r   r   %  s
     r-   rI   c              #       K   g ddddt         dt        dt        t           dt        dt
        f
 fd	}| dfd
} j                   |              yw)z^Factory to create a TestServer instance, given an app.

    aiohttp_server(app, **kwargs)
    z	127.0.0.1Nhostr1   r2   r   r1   r   r   c                   K   t        | ||      } |j                  ddi| d {    j                  |       |S 7 w)Nr   rI   r"   )r   start_serverappend)r2   r   r1   r   serverrI   serverss        r%   gozaiohttp_server.<locals>.go3  sK      Cd6!f!!6t6v666v 	7s   &AAAc                  j   K    r* j                         j                          d {     r)y y 7 	wr!   popcloser   s   r%   finalizez aiohttp_server.<locals>.finalizeA  *     ++-%%''' '   $3133r   N)r   r,   r   r4   r   r   rK   rI   r   r   r   s   `  @r%   aiohttp_serverr   +  sm      G
  "	

 
 sm	

 
 

 H( 	HJ's   AAc                 >    t        j                  dt        d       | S )Nz.Deprecated, use aiohttp_server fixture insteadr   r   r   )r   s    r%   test_serverr   H      MM8
 r-   c           	   #       K   g dddt         dt        t           dt        dt        f fd}| d	fd} j                   |              yw)
zpFactory to create a RawTestServer instance, given a web handler.

    aiohttp_raw_server(handler, **kwargs)
    Nr0   r7   r1   r   r   c                   K   t        | |      } |j                  ddi| d {    j                  |       |S 7 w)Nr0   rI   r"   )r   r   r   )r7   r1   r   r   rI   r   s       r%   r   zaiohttp_raw_server.<locals>.goZ  sI      wT2!f!!6t6v666v 	7s   %AA Ac                  j   K    r* j                         j                          d {     r)y y 7 	wr!   r   r   s   r%   r   z$aiohttp_raw_server.<locals>.finalized  r   r   r   )r   r   r4   r   r   rK   r   s   `  @r%   aiohttp_raw_serverr   R  s[      G <@ +3C=KN	 H( 	HJ's   AAc                 >    t        j                  dt        d       | S )Nz2Deprecated, use aiohttp_raw_server fixture insteadr   r   r   )r   s    r%   raw_test_serverr   k  s!     MM<
 r-   c              #      K   g t         dddt        dt        t        t        t
        f      dt
        dt        t        t        f   fd       }t         dddt        dt        t        t        t
        f      dt
        dt        t        df   fd       }dddt        t        t        f   d	t
        dt        t        t        t
        f      dt
        dt        t
        t
        f   f
 fd
}| dfd} j                   |              yw)zFactory to create a TestClient instance.

    aiohttp_client(app, **kwargs)
    aiohttp_client(server, **kwargs)
    aiohttp_client(raw_server, **kwargs)
    Nr   __paramr   r   r   c                   K   y wr!   r"   r   r   r   s      r%   r   zaiohttp_client.<locals>.go  s      ,/r'   c                   K   y wr!   r"   r   s      r%   r   zaiohttp_client.<locals>.go  s      ),r'   rU   c                  K   t        | t              r%t        | t        t        f      s | g|i |} i }n	|rJ d       t        | t              r#|xs i }t	        | fdi|}t        |fdi|}n6t        | t              rt        | fdi|}nt        dt        |       z        |j                          d {    j                  |       |S 7 w)Nzargs should be emptyrI   zUnknown argument type: %r)

isinstancer   r   r   r   r   r   typer   r   )r   r   rU   r   r   clientclientsrI   s         r%   r   zaiohttp_client.<locals>.go  s      gx(k>22
 d4T4V4GF3338g{+)/RMDdDmDF<T<V<F0=d=f=F84=HII!!###v 	$s   B;C>C?Cc                  j   K    r* j                         j                          d {     r)y y 7 	wr!   r   )r   s   r%   r   z aiohttp_client.<locals>.finalize  r   r   r   )r   r   r   r   r,   r   r   r   r   r   r
   rK   )rI   r   r   r   s   `  @r%   aiohttp_clientr   w  s.     G 37//  S#X// 	/
 
G[(	)/ /  37,,  S#X/, 	,
 
K%	&, , 37{N23  S#X/ 	
 
CH	6 H( 	HJ's   DDc                 >    t        j                  dt        d       | S )Nz.Deprecated, use aiohttp_client fixture insteadr   r   r   )r   s    r%   test_clientr     r   r-   )F);r   
contextlibrZ   rm   typingr   r   r   r   r   r   r	   r
   r   pytest
test_utilsr   r   r   r   r   r   r   r   r   webr   r   r   web_protocolr   r   ImportErrorr   r/   r6   rD   r_   fixturerd   rf   contextmanagerrw   rz   r   r   r   AbstractEventLoopboolrI   r   r4   r   r   r   r   r   r   r   r"   r-   r%   <module>r      s      
 
 
 	 	 	 3 2 )
,H ,&$H $'x '*6r 6 6
 C C
  . , , 8,@ 
2w8889


 
 g''(	
 
 x 9 9:   Xb#g%6 8BG;L   Xb#g.  
 (22 (x7N ( (8   (W66 (8DT;U ( (0   :(22 :(x7N :( :(z  i  Fs   H HH