o
    4˜Žj°2  ã                
   @   sd  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 d dl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 zd dlZW n ey]   dZY nw G dd	„ d	e
ƒZG d
d„ de
ƒZ G dd„ de
ƒZ!dd„ Z"dd„ Z#ej$dd„ ƒZ%ej$dd„ ƒZ&ej'dd„ ƒZ(ej'd7dd„ƒZ)dd„ Z*dd„ Z+dd „ Z,ej$d!eg e j-f de.de.d"ee j- fd#d$„ƒZ/ej$d"ee j- fd%d&„ƒZ0ej$d'eg e1f d"eg e1f fd(d)„ƒZej$d"eg e1f fd*d'„ƒZ2ej$d$e j-d"ee  fd+d,„ƒZ3ej$d-d.„ ƒZ4ej$d$e j-d"ee! fd/d0„ƒZ5ej$d1d2„ ƒZ6ej$d$e j-d"ee fd3d4„ƒZ7ej$d5d6„ ƒZ8dS )8é    N)Ú	AwaitableÚCallableÚIterator)ÚAnyÚProtocolÚoverloadé   )ÚBaseTestServerÚRawTestServerÚ
TestClientÚ
TestServerÚloop_contextÚsetup_test_loopÚteardown_test_loopÚunused_port)ÚApplicationÚBaseRequestÚRequest)Ú_RequestHandlerc                   @   s|   e Zd Zeddœdedeeef dB dedee	ef fdd„ƒZ
eddœdedeeef dB dedeedf fd	d„ƒZ
dS )
ÚAiohttpClientN©Úserver_kwargsÚ_AiohttpClient__paramr   ÚkwargsÚreturnc                Ë   ó   �d S ©N© ©Úselfr   r   r   r   r   úR/var/www/kodo/Anonymous/send/lib/python3.10/site-packages/aiohttp/pytest_plugin.pyÚ__call__   ó   €zAiohttpClient.__call__c                Ë   r   r   r   r   r   r   r    r!   &   r"   )Ú__name__Ú
__module__Ú__qualname__r   r   ÚdictÚstrr   r   r   r!   r	   r   r   r   r   r    r      s.    üþüû
úüþüû
úr   c                
   @   ó4   e Zd ZddœdededB dedee fdd„ZdS )	ÚAiohttpServerN©ÚportÚappr+   r   r   c                K   ó   d S r   r   )r   r,   r+   r   r   r   r    r!   1   ó   zAiohttpServer.__call__)	r#   r$   r%   r   Úintr   r   r   r!   r   r   r   r    r)   0   ó    ÿÿÿÿþr)   c                
   @   r(   )	ÚAiohttpRawServerNr*   Úhandlerr+   r   r   c                K   r-   r   r   )r   r2   r+   r   r   r   r    r!   7   r.   zAiohttpRawServer.__call__)	r#   r$   r%   r   r/   r   r   r
   r!   r   r   r   r    r1   6   r0   r1   c                 C   s:   | j ddddd� | j dddd	d� | j d
dddd� d S )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)Úparserr   r   r    Úpytest_addoption<   s$   üü
ür=   c                    sd   | j ‰ t ˆ ¡rd‰n
t ˆ ¡rd‰ndS d‰d| jvr%|  jd7  _d‰‡ ‡‡fdd„}|| _ dS )zjSet up pytest fixture.

    Allow fixtures to be coroutines. Run coroutine fixtures in an event loop.
    TFNÚrequest©r>   c                     sz   |d }ˆr	|d= d|j vrtdƒ‚| d¡‰ ˆr3ˆ| i |¤Ž‰‡ ‡fdd„}| |¡ ˆ  ˆ ¡ ¡S ˆ  ˆ| i |¤Ž¡S )Nr>   Úloopz^Asynchronous fixtures must depend on the 'loop' fixture or be used in tests depending from it.c                      s&   zˆ   ˆ ¡ ¡W S  ty   Y d S w r   )Úrun_until_completeÚ	__anext__ÚStopAsyncIterationr   ©Ú_loopÚgenr   r    Ú	finalizer|   s
   ÿz8pytest_fixture_setup.<locals>.wrapper.<locals>.finalizer)ÚfixturenamesÚ	ExceptionÚgetfixturevalueÚaddfinalizerrA   rB   )Úargsr   r>   rG   ©ÚfuncÚis_async_genÚstrip_requestrD   r    Úwrapperg   s   
ÿ

z%pytest_fixture_setup.<locals>.wrapper)rN   ÚinspectÚisasyncgenfunctionÚiscoroutinefunctionÚargnames)Ú
fixturedefrQ   r   rM   r    Úpytest_fixture_setupQ   s   



 rW   c                 C   ó   | j  d¡S )z--fast config optionr3   ©ÚconfigÚ	getoptionr?   r   r   r    ÚfastŠ   ó   r\   c                 C   rX   )z!--enable-loop-debug config optionr:   rY   r?   r   r   r    Ú
loop_debug�   r]   r^   c               	   c   sx   � t jdd��+} dV  dd„ | D ƒ}|r*td t|ƒt|ƒdkr"dnd	d
 |¡¡ƒ‚W d  ƒ dS 1 s5w   Y  dS )záContext 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)ÚrecordNc                 S   s0   g | ]}|j tkr|j› d |j› d |j› �‘qS )ú:)ÚcategoryÚRuntimeWarningÚfilenameÚlinenoÚmessage)Ú.0Úwr   r   r    Ú
<listcomp>¡   s
    
þz,_runtime_warning_context.<locals>.<listcomp>z{} Runtime Warning{},
{}r   Ú ÚsÚ
)ÚwarningsÚcatch_warningsÚRuntimeErrorÚformatÚlenÚjoin)Ú	_warningsÚrwr   r   r    Ú_runtime_warning_context–   s   €	þ ÿÿÿ"ùrt   Fc                 c   s,   � | r| V  dS t ƒ } | V  t| |d� dS )z–Passthrough loop context.

    Sets up and tears down a loop unless one is passed in via the loop
    argument when it's passed straight through.
    ©r\   N)r   r   )r@   r\   r   r   r    Ú_passthrough_loop_context®   s   €
rv   c                 C   s,   |   |¡rt |¡rt|  ||¡ƒS dS dS )z%Fix pytest collecting for coroutines.N)ÚfuncnamefilterrR   rT   ÚlistÚ_genfunctions)Ú	collectorÚnameÚobjr   r   r    Úpytest_pycollect_makeitem¿   s   ÿr}   c              	      sî   ˆ j  d¡}t ˆ j¡rut dt¡ ˆ j 	d¡p*ˆ j 	d¡p*ˆ j 	d¡p*ˆ j 	dd¡}t
ƒ �= t||d��}‡ fd	d
„ˆ jjD ƒ}| ˆ jdi |¤Ž¡ W d  ƒ n1 sVw   Y  W d  ƒ dS W d  ƒ dS 1 snw   Y  dS dS )zBRun coroutines in an event loop instead of a normal function call.r3   zKaiohttp.pytest_plugin will be removed in v4. Please install pytest-aiohttp.Úproactor_loopÚselector_loopÚuvloop_loopr@   Nru   c                    s   i | ]}|ˆ j | “qS r   )Úfuncargs)rf   Úarg©Ú
pyfuncitemr   r    Ú
<dictcomp>Ö   s    
ÿÿz&pytest_pyfunc_call.<locals>.<dictcomp>Tr   )rZ   r[   rR   rT   Úfunctionrl   ÚwarnÚDeprecationWarningr�   Úgetrt   rv   Ú_fixtureinforU   rA   r|   )r„   r\   Úexisting_looprE   Útestargsr   rƒ   r    Úpytest_pyfunc_callÅ   s8   þ
ÿ
þü
þû
ÿù
ÿøìr�   c                 C   sÀ   d| j vrd S | jjj}dtji}td urtj|d< |dkr d}i }| d¡D ]&}| d¡ }| 	d¡}||vrG|rFt
d	|t| ¡ ƒf ƒ‚q'|| ||< q'| jdt| ¡ ƒt| ¡ ƒd
� d S )NÚloop_factoryr9   ÚuvloopÚallzpyloop,uvloop?ú,ú?z ?z&Unknown loop '%s', available loops: %s)Úids)rH   rZ   ÚoptionÚaiohttp_loopÚasyncioÚnew_event_loopr�   ÚsplitÚendswithÚstripÚ
ValueErrorrx   ÚkeysÚparametrizeÚvalues)ÚmetafuncÚloopsÚavail_factoriesÚ	factoriesr{   Úrequiredr   r   r    Úpytest_generate_testsß   s0   




ÿÿ
ÿr¤   rŽ   r   c                 c   sR   � t | |d��}|r| d¡ t |¡ |V  W d  ƒ dS 1 s"w   Y  dS )z%Return an instance of the event loop.ru   TN)r   Ú	set_debugr–   Úset_event_loop)rŽ   r\   r^   rE   r   r   r    r@   ÿ   s   €

"ür@   c                  c   sF   � t j} t| ƒ�}t  |¡ |V  W d   ƒ d S 1 sw   Y  d S r   )r–   ÚProactorEventLoopr   r¦   )ÚfactoryrE   r   r   r    r~     s   €

"þr~   Úaiohttp_unused_portc                 C   ó   t jdtdd� | S )Nz3Deprecated, use aiohttp_unused_port fixture insteadé   ©Ú
stacklevel©rl   r‡   rˆ   )r©   r   r   r    r     ó   ýr   c                   C   s   t S )z1Return a port that is unused on the current host.)Ú_unused_portr   r   r   r    r©      s   c                 #   sZ   � g ‰dddœdt dtdtdB dtdtf
‡ ‡fd	d
„}|V  d‡fdd„}ˆ  |ƒ ¡ dS )z^Factory to create a TestServer instance, given an app.

    aiohttp_server(app, **kwargs)
    z	127.0.0.1N©Úhostr+   r,   r²   r+   r   r   c                ›   s8   �t | ||d�}|jddˆ i|¤ŽI d H  ˆ |¡ |S )Nr±   r@   r   )r   Ústart_serverÚappend)r,   r²   r+   r   Úserver©r@   Úserversr   r    Úgo.  s
   €
zaiohttp_server.<locals>.goc                   “   ó$   �ˆ rˆ   ¡  ¡ I d H  ˆ sd S d S r   ©ÚpopÚcloser   ©r·   r   r    Úfinalize<  ó   €ÿz aiohttp_server.<locals>.finalize©r   N)r   r'   r/   r   r   rA   ©r@   r¸   r¾   r   r¶   r    Úaiohttp_server&  s$   €üÿýüûúrÂ   c                 C   rª   )Nz.Deprecated, use aiohttp_server fixture insteadr«   r¬   r®   )rÂ   r   r   r    Útest_serverC  r¯   rÃ   c              	   #   sT   � g ‰ddœdt dtdB dtdtf‡ ‡fdd„}|V  d‡fd	d
„}ˆ  |ƒ ¡ dS )zpFactory to create a RawTestServer instance, given a web handler.

    aiohttp_raw_server(handler, **kwargs)
    Nr*   r2   r+   r   r   c                ›   s6   �t | |d�}|jddˆ i|¤ŽI d H  ˆ |¡ |S )Nr*   r@   r   )r
   r³   r´   )r2   r+   r   rµ   r¶   r   r    r¸   U  s
   €
zaiohttp_raw_server.<locals>.goc                   “   r¹   r   rº   r   r½   r   r    r¾   _  r¿   z$aiohttp_raw_server.<locals>.finalizerÀ   )r   r/   r   r
   rA   rÁ   r   r¶   r    Úaiohttp_raw_serverM  s   €ÿÿÿÿþrÄ   c                 C   rª   )Nz2Deprecated, use aiohttp_raw_server fixture insteadr«   r¬   r®   )rÄ   r   r   r    Úraw_test_serverf  s   ýrÅ   c                 #   sÜ   � g ‰ t ddœdtdtttf dB dtdtttf fdd„ƒ}t ddœdtdtttf dB dtdttdf fd	d„ƒ}ddœdttB d
tdtttf dB dtdtttf f
‡ ‡fdd„}|V  d‡ fdd„}ˆ 	|ƒ ¡ dS )zžFactory to create a TestClient instance.

    aiohttp_client(app, **kwargs)
    aiohttp_client(server, **kwargs)
    aiohttp_client(raw_server, **kwargs)
    Nr   Ú__paramr   r   r   c                Û   r   r   r   ©rÆ   r   r   r   r   r    r¸   |  ó   €zaiohttp_client.<locals>.goc                Û   r   r   r   rÇ   r   r   r    r¸   „  rÈ   rL   c                Ÿ   sÊ   �t | tƒrt | ttfƒs| ˆg|¢R i |¤Ž} i }n|r!J dƒ‚t | tƒr?|p)i }t| fdˆi|¤Ž}t|fdˆi|¤Ž}nt | tƒrOt| fdˆi|¤Ž}ntdt| ƒ ƒ‚| ¡ I d H  ˆ  	|¡ |S )Nzargs should be emptyr@   zUnknown argument type: %r)
Ú
isinstancer   r   r	   r   r   r›   Útyper³   r´   )rÆ   r   rL   r   rµ   Úclient©Úclientsr@   r   r    r¸   Œ  s"   €ÿ


c                   “   r¹   r   rº   r   )rÍ   r   r    r¾   ©  r¿   z aiohttp_client.<locals>.finalizerÀ   )
r   r   r&   r'   r   r   r   r	   r   rA   rÁ   r   rÌ   r    Úaiohttp_clientr  sN   €ýÿýü
ûýÿýü
û
ýÿþýü
ûrÎ   c                 C   rª   )Nz.Deprecated, use aiohttp_client fixture insteadr«   r¬   r®   )rÎ   r   r   r    Útest_client°  r¯   rÏ   )F)9r–   Ú
contextlibrR   rl   Úcollections.abcr   r   r   Útypingr   r   r   ÚpytestÚ
test_utilsr	   r
   r   r   r   r   r   r   r°   Úwebr   r   r   Úweb_protocolr   r�   ÚImportErrorr   r)   r1   r=   rW   Úfixturer\   r^   Úcontextmanagerrt   rv   r}   r�   r¤   ÚAbstractEventLoopÚboolr@   r~   r/   r©   rÂ   rÃ   rÄ   rÅ   rÎ   rÏ   r   r   r   r    Ú<module>   sv    (
ÿ9


 ÿþýü$	
	
=