o
    ý§Ýj´8  ã                   @  sp  U d dl m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 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 d dlmZ d d	lmZ d
dlmZ d
dlmZm Z m!Z!m"Z" d
dl#m$Z$ erqd
dl%m&Z& ej'dk r|d dl(m)Z) er…d dl*m+Z, nzd dl*m,Z, W n e-yœ   d dl*m+Z, Y nw da.de/d< da0de/d< d a1d]dd„Z2ed^d"d#„ƒZ3d_d'd(„Z4d`d-d.„Z5dad/d0„Z6ej7d1d2�dbd7d8„ƒZ8ej7d1d9�dcd>d?„ƒZ9dddBdC„Z:ej7d1d9�dedFdG„ƒZ;ej<dHeƒ dI�dfdJdK„ƒZ=ej<dgdLdM„ƒZ>ej<dhdNdO„ƒZ?G dPdQ„ dQƒZ@ej<d@dR�didSdT„ƒZAej<d@dR�didUdV„ƒZBej<djdYdZ„ƒZCej<dkd[d\„ƒZDdS )lé    )ÚannotationsN)ÚCallableÚ	GeneratorÚIterator)Ú	ExitStackÚcontextmanager)ÚisasyncgenfunctionÚiscoroutinefunctionÚismethod)ÚTYPE_CHECKINGÚAnyÚcast)ÚFuncFixtureInfoÚ
SubRequest)ÚExit)ÚScopeé   )Úget_available_backends)Úcurrent_async_libraryÚget_async_backendÚreset_current_async_libraryÚset_current_async_library)Úiterate_exceptions)Ú
TestRunner)é   é   )ÚExceptionGroup)Ú	CallSpec2)ÚCallSpeczTestRunner | NoneÚ_current_runnerzExitStack | NoneÚ_runner_stackÚbackendÚobjectÚreturnútuple[str, dict[str, Any]]c                 C  sf   t | tƒr	| i fS t | tƒr/t| ƒdkr/t | d tƒr/t | d tƒr/ttttttf f | ƒS tdƒ‚)Né   r   r   z@anyio_backend must be either a string or tuple of (string, dict))Ú
isinstanceÚstrÚtupleÚlenÚdictr   r   Ú	TypeError)r!   © r,   úN/var/www/html/chatgpt/venv/lib/python3.10/site-packages/anyio/pytest_plugin.pyÚextract_backend_and_options/   s   
r.   Úbackend_namer'   Úbackend_optionsúdict[str, Any]úIterator[TestRunner]c                 c  sº   � t d u r't| ƒ}tƒ atƒ d u rt| ƒ}t t|¡ |pi }t | 	|¡¡a t
d7 a
zt V  W t
d8 a
t
sFtd us<J ‚t ¡  d  aa d S d S t
d8 a
t
s\td usTJ ‚t ¡  d  aa w ©Nr   )r   r   r   r    r   r   Úcallbackr   Úenter_contextZcreate_test_runnerÚ_runner_leasesÚclose)r/   r0   ZasynclibÚtokenr,   r,   r-   Ú
get_runner9   s2   €
ÿýÿ
r9   Úparserúpytest.ParserÚNonec                 C  s0   |   d¡}| jdddd� |jdd ddd� d S )	NÚanyioÚ
anyio_modeÚstrictz-AnyIO plugin mode (either "strict" or "auto"))ÚdefaultÚhelpz--anyio-modezÛ
        'auto'   - All async test functions will be handled by AnyIO pytest plugin
        'strict' - Disabling autoprocessing(useful when anyio tests
            need to coexist with other async test plugins)
        )r@   ÚdestrA   )ZgetgroupZaddiniZ	addoption)r:   Úgroupr,   r,   r-   Úpytest_addoptionW   s   
ý
ürD   Úconfigúpytest.ConfigÚmodeÚboolc                 C  s    | j |d d�dkp|  |¡dkS )N)r@   Úauto)Z	getoptionZgetini)rE   rG   r,   r,   r-   Ú_is_auto_modej   s   ÿrJ   c                 C  sN   |   dd¡ t| dƒr!| j d¡r#t| dƒr%|  t d¡d¡ d S d S d S d S )NÚmarkerszManyio: mark the (coroutine function) test to be run asynchronously via anyio.r>   ZasyncioZasyncio_modezlAnyIO auto mode has been enabled together with pytest-asyncio auto mode. This may cause unexpected behavior.r   )Zaddinivalue_linerJ   ZpluginmanagerZ
has_pluginZissue_config_time_warningÚpytestZPytestConfigWarning)rE   r,   r,   r-   Úpytest_configurep   s"   þÿ
þýÿûûrM   T)ZhookwrapperÚ
fixturedefr   ÚrequestúGenerator[Any]c                 #  s¢   � d‡ ‡‡fdd„}| j ‰ tˆ ƒstˆ ƒrNd|jv rN|| _ | j}d| jv  ‰s.|  jd	7  _d| jv  ‰s<|  jd
7  _z
d V W ˆ | _ || _S ˆ | _ || _w d V S )NÚanyio_backendr   rO   r   Úkwargsr#   c                 ;  sÖ   � |j rtˆ ƒrtˆ jƒt|j ƒu rˆ j |j ¡}nˆ }t| ƒ\}}ˆr(| |d< ˆr.||d< t||ƒ�.}| ¡ r<t	dƒ‚t
|ƒrJ| ||¡E d H  n| ||¡V  W d   ƒ d S W d   ƒ d S 1 sdw   Y  d S )NrQ   rO   z�Cannot schedule a coroutine in the test runner while another is already running; likely caused by request.getfixturevalue() on an async fixture.)Úinstancer
   ÚtypeÚ__self__Ú__func__Ú__get__r.   r9   Z
is_runningÚRuntimeErrorr   Zrun_asyncgen_fixtureZrun_fixture)rQ   rO   rR   Z
local_funcr/   r0   Úrunner©ÚfuncZhas_backend_argZhas_request_argr,   r-   Úwrapper…   s0   €ÿþÿð"òz%pytest_fixture_setup.<locals>.wrapper©rQ   ©rO   )rQ   r   rO   r   rR   r   r#   r   )r[   r   r	   ÚfixturenamesÚargnames)rN   rO   r\   Zoriginal_argnamer,   rZ   r-   Úpytest_fixture_setupƒ   s$   €&
ÿra   )ZtryfirstÚ	collectorúpytest.Module | pytest.ClassÚnameÚobjc                 C  s†   |   ||¡r=t|dƒr|jjn|}t|ƒr?t| jdƒ}|  d¡}t|ddƒ}|s3|s3t	dd„ |D ƒƒrAt
j d¡|ƒ d S d S d S d S )	NÚ
hypothesisr>   r=   Z
pytestmarkr,   c                 s  s   � | ]}|j d kV  qdS )r=   N©rd   )Ú.0Úmarkerr,   r,   r-   Ú	<genexpr>Í   s   € z,pytest_pycollect_makeitem.<locals>.<genexpr>rQ   )ZistestfunctionÚhasattrrf   Ú
inner_testr	   rJ   rE   Úget_closest_markerÚgetattrÚanyrL   ÚmarkZusefixtures)rb   rd   re   Z
inner_funcZanyio_auto_moderi   Zown_markersr,   r,   r-   Úpytest_pycollect_makeitemÀ   s    
ÿþýõrq   Úsessionúpytest.Sessionc                 C  sl  t tt| jƒƒƒD ]ª\}}t|tjƒr³t|jƒr³| 	d¡d ur³d|j
vr³g }zdd„ t t¡D ƒ}W n ty>   tƒ }Y nw ttƒ ƒD ]e\}}d|v r^td|id|idtji|gg d�}nti d|id|idtji|gg d�}|j}t|jƒ}	d|	vr�|	 d¡ t|j|j|	|jd�}
tjj|j|j› d	|› d
�||j|
|j|jd�}| |¡ qD|| j||d …< q	d S )Nr=   rQ   c                 S  s   h | ]}|j ’qS r,   rg   )rh   Úfr,   r,   r-   Ú	<setcomp>Ü   s    z+pytest_collection_finish.<locals>.<setcomp>Ú
_arg2scope)ÚparamsÚindicesrv   Z_idlistÚmarks)Úfuncargsrw   rx   Z	arg2scopeZidlistry   )r`   ÚinitialnamesÚnames_closureÚname2fixturedefsú[ú])rd   ÚcallspecZcallobjZfixtureinfoÚkeywordsÚoriginalnamer   )ÚreversedÚlistÚ	enumerateÚitemsr&   rL   ÚFunctionr	   Úfunctionrm   r_   ÚdataclassesÚfieldsr   r+   Úsetr   r   ÚModuleÚ_fixtureinfor|   Úappendr   r`   r{   r}   Zfrom_parentÚparentr‚   re   r�   )rr   ÚiÚitemZ	new_itemsZ	cs_fieldsZparam_indexr!   r€   ÚfiZnew_names_closureZnew_fixtureinfoZnew_itemr,   r,   r-   Úpytest_collection_finishÒ   sj   
ÿþ

ÿûú	

üù	€Êr“   Ú
pyfuncitemúbool | Nonec                   s  d‡ ‡‡fdd„}| j  d¡}|r‡t|ƒ\‰ ‰t| jdƒr3| jjj‰ˆj|jkr1tˆƒr1|| jj_d S t| jƒr‡| j ‰‡fd	d
„| j	j
D ƒ}tˆ ˆƒ�2}z	| | j|¡ W n tyt } zt|ƒD ]}t|tttfƒrn||‚qa‚ d }~ww W d   ƒ dS 1 s€w   Y  dS d S )NrR   r   r#   r<   c                    s<   t ˆ ˆƒ�}| ˆ| ¡ W d   ƒ d S 1 sw   Y  d S ©N)r9   Úrun_test)rR   rY   )r/   r0   Úoriginal_funcr,   r-   Úrun_with_hypothesis  s   "ÿz/pytest_pyfunc_call.<locals>.run_with_hypothesisrQ   rf   c                   s   i | ]}|ˆ | “qS r,   r,   )rh   Úarg)rz   r,   r-   Ú
<dictcomp>!  s    z&pytest_pyfunc_call.<locals>.<dictcomp>T)rR   r   r#   r<   )rz   Úgetr.   rk   re   rf   rl   Ú__qualname__r	   r�   r`   r9   r—   r   r   r&   r   ÚKeyboardInterruptÚ
SystemExit)r”   r™   r!   ZtestargsrY   ZexcgrpÚexcr,   )r/   r0   rz   r˜   r-   Úpytest_pyfunc_call  s<   


ÿ€ûÿ
þ
ö
r¡   Úmodule)Úscoperw   c                 C  ó   | j S r–   )Úparamr^   r,   r,   r-   rQ   1  ó   rQ   c                 C  s   t | tƒr| S | d S )Nr   ©r&   r'   r]   r,   r,   r-   Úanyio_backend_name6  ó   
r¨   c                 C  s   t | tƒri S | d S r3   r§   r]   r,   r,   r-   Úanyio_backend_options>  r©   rª   c                   @  s4   e Zd ZdZddd„Zeddd	„ƒZdddd„Zd
S )ÚFreePortFactoryaO  
    Manages port generation based on specified socket kind, ensuring no duplicate
    ports are generated.

    This class provides functionality for generating available free ports on the
    system. It is initialized with a specific socket kind and can generate ports
    for given address families while avoiding reuse of previously generated ports.

    Users should not instantiate this class directly, but use the
    ``free_tcp_port_factory`` and ``free_udp_port_factory`` fixtures instead. For simple
    uses cases, ``free_tcp_port`` and ``free_udp_port`` can be used instead.
    Úkindúsocket.SocketKindr#   r<   c                 C  s   || _ tt ƒ | _d S r–   )Ú_kindr‹   ÚintÚ
_generated)Úselfr¬   r,   r,   r-   Ú__init__T  s   zFreePortFactory.__init__c                 C  r¤   )z¦
        The type of socket connection (e.g., :data:`~socket.SOCK_STREAM` or
        :data:`~socket.SOCK_DGRAM`) used to bind for checking port availability

        )r®   )r±   r,   r,   r-   r¬   X  s   zFreePortFactory.kindNÚfamilyúsocket.AddressFamily | Noner¯   c              
   C  sè   |dur|g}nt jg}t jr| t j¡ 	 d}tƒ �P}|D ]1}| t   || j¡¡}|t jkr1dnd}z	| ||f¡ W n
 t	yF   Y  nw |sO| 
¡ d }q|| jvrd| j |¡ |W  d  ƒ S W d  ƒ n1 snw   Y  q)zµ
        Return an unbound port for the given address family.

        :param family: if omitted, both IPv4 and IPv6 addresses will be tried
        :return: a port number

        NTr   z::1z	127.0.0.1r   )ÚsocketÚAF_INETÚhas_ipv6rŽ   ÚAF_INET6r   r5   r®   ÚbindÚOSErrorÚgetsocknamer°   Úadd)r±   r³   ZfamiliesÚportÚstackZfamÚsockÚaddrr,   r,   r-   Ú__call__a  s4   ÿ€
ò€ þzFreePortFactory.__call__)r¬   r­   r#   r<   )r#   r­   r–   )r³   r´   r#   r¯   )Ú__name__Ú
__module__r�   Ú__doc__r²   Úpropertyr¬   rÁ   r,   r,   r,   r-   r«   F  s    
r«   )r£   c                   C  ó
   t tjƒS r–   )r«   rµ   ÚSOCK_STREAMr,   r,   r,   r-   Úfree_tcp_port_factoryƒ  ó   
rÈ   c                   C  rÆ   r–   )r«   rµ   Ú
SOCK_DGRAMr,   r,   r,   r-   Úfree_udp_port_factoryˆ  rÉ   rË   úCallable[[], int]r¯   c                 C  ó   | ƒ S r–   r,   )rÈ   r,   r,   r-   Úfree_tcp_port�  r¦   rÎ   c                 C  rÍ   r–   r,   )rË   r,   r,   r-   Úfree_udp_port’  r¦   rÏ   )r!   r"   r#   r$   )r/   r'   r0   r1   r#   r2   )r:   r;   r#   r<   )rE   rF   rG   r'   r#   rH   )rE   rF   r#   r<   )rN   r   rO   r   r#   rP   )rb   rc   rd   r'   re   r"   r#   r<   )rr   rs   r#   r<   )r”   r   r#   r•   )rO   r   r#   r   )rQ   r   r#   r'   )rQ   r   r#   r1   )r#   r«   )rÈ   rÌ   r#   r¯   )rË   rÌ   r#   r¯   )EÚ
__future__r   r‰   rµ   ÚsysÚcollections.abcr   r   r   Ú
contextlibr   r   Úinspectr   r	   r
   Útypingr   r   r   rL   Z_pytest.fixturesr   r   Z_pytest.outcomesr   Z_pytest.scoper   Ú r   Z_core._eventloopr   r   r   r   Z_core._exceptionsr   Úabcr   Úversion_infoZexceptiongroupr   Z_pytest.pythonr   r   ÚImportErrorr   Ú__annotations__r    r6   r.   r9   rD   rJ   rM   Zhookimplra   rq   r“   r¡   ZfixturerQ   r¨   rª   r«   rÈ   rË   rÎ   rÏ   r,   r,   r,   r-   Ú<module>   sr    
ÿ






<

:$
=
