o
    %=jç1  ã                   @  s(  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 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 ddlm Z m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z' ej(dk r~d dl)m*Z* da+de,d< da-de,d< d a.dXdd„Z/edYd!d"„ƒZ0dZd&d'„Z1d[d*d+„Z2ej3d,d-�d\d2d3„ƒZ4ej3d,d4�d]d9d:„ƒZ5d^d=d>„Z6ej3d,d4�d_dAdB„ƒZ7ej8dCeƒ dD�d`dEdF„ƒZ9ej8dadGdH„ƒZ:ej8dbdIdJ„ƒZ;G dKdL„ dLƒZ<ej8d;dM�dcdNdO„ƒZ=ej8d;dM�dcdPdQ„ƒZ>ej8dddTdU„ƒZ?ej8dedVdW„ƒZ@dS )fé    )ÚannotationsN)ÚCallableÚ	GeneratorÚIterator)Ú	ExitStackÚcontextmanager)ÚisasyncgenfunctionÚiscoroutinefunctionÚismethod)ÚAnyÚcast)ÚFuncFixtureInfoÚ
SubRequest)ÚExit)Ú	CallSpec2)ÚScopeé   )Úget_available_backends)Úcurrent_async_libraryÚget_async_backendÚreset_current_async_libraryÚset_current_async_library)Úiterate_exceptions)Ú
TestRunner)é   é   )ÚExceptionGroupz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*   ú]C:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\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-   r.   ZasynclibÚtokenr*   r*   r+   Ú
get_runner-   s2   €
ÿýÿ
r7   Úparserúpytest.ParserÚNonec                 C  s   | j dddd� d S )NÚ
anyio_modeÚstrictz-AnyIO plugin mode (either "strict" or "auto"))ÚdefaultÚhelp)Zaddini)r8   r*   r*   r+   Úpytest_addoptionK   s
   
ýr?   Úconfigúpytest.Configc                 C  sV   |   dd¡ |  d¡dkr%| j d¡r'|  d¡dk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;   ÚautoÚasyncioZasyncio_modezlAnyIO auto mode has been enabled together with pytest-asyncio auto mode. This may cause unexpected behavior.r   )Zaddinivalue_lineÚgetiniZpluginmanagerZ
has_pluginZissue_config_time_warningÚpytestZPytestConfigWarning)r@   r*   r*   r+   Úpytest_configureS   s"   þÿ
þýÿûûrG   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   rI   r   Úkwargsr!   c                 ;  sÆ   � |j rtˆ ƒrtˆ jƒt|j ƒu rˆ j |j ¡}nˆ }t| ƒ\}}ˆr(| |d< ˆr.||d< t||ƒ�&}t|ƒrB| 	||¡E d H  n| 
||¡V  W d   ƒ d S W d   ƒ d S 1 s\w   Y  d S )NrK   rI   )Úinstancer
   ÚtypeÚ__self__Ú__func__Ú__get__r,   r7   r   Zrun_asyncgen_fixtureZrun_fixture)rK   rI   rL   Z
local_funcr-   r.   Úrunner©ÚfuncZhas_backend_argZhas_request_argr*   r+   Úwrapperh   s*   €ÿþýü"þz%pytest_fixture_setup.<locals>.wrapper©rK   ©rI   )rK   r   rI   r   rL   r   r!   r   )rT   r   r	   ÚfixturenamesÚargnames)rH   rI   rU   Zoriginal_argnamer*   rS   r+   Úpytest_fixture_setupf   s$   €
ÿrZ   )ZtryfirstÚ	collectorúpytest.Module | pytest.ClassÚnameÚobjc                 C  sŠ   |   ||¡r?t|dƒr|jjn|}t|ƒrA| j d¡dk}|  d¡}t|ddƒ}|s5|s5t	dd„ |D ƒƒrCt
j d	¡|ƒ d S d S d S d S )
NÚ
hypothesisr;   rC   ÚanyioZ
pytestmarkr*   c                 s  s   � | ]}|j d kV  qdS )r`   N©r]   )Ú.0Úmarkerr*   r*   r+   Ú	<genexpr>¤   s   € z,pytest_pycollect_makeitem.<locals>.<genexpr>rK   )ZistestfunctionÚhasattrr_   Ú
inner_testr	   r@   rE   Úget_closest_markerÚgetattrÚanyrF   ÚmarkZusefixtures)r[   r]   r^   Z
inner_funcZanyio_auto_moderc   Zown_markersr*   r*   r+   Úpytest_pycollect_makeitem—   s    
ÿþýõrk   Ú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`   rK   c                 S  s   h | ]}|j ’qS r*   ra   )rb   Úfr*   r*   r+   Ú	<setcomp>³   s    z+pytest_collection_finish.<locals>.<setcomp>Ú
_arg2scope)ÚparamsÚindicesrp   Z_idlistÚmarks)Úfuncargsrq   rr   Z	arg2scopeZidlistrs   )rY   ÚinitialnamesÚnames_closureÚname2fixturedefsú[ú])r]   ÚcallspecZcallobjZfixtureinfoÚkeywordsÚoriginalnamer   )ÚreversedÚlistÚ	enumerateÚitemsr$   rF   ZFunctionr	   Úfunctionrg   rX   ÚdataclassesÚfieldsr   r)   Úsetr   r   ÚModuleÚ_fixtureinforv   Úappendr   rY   ru   rw   Zfrom_parentÚparentr|   r^   r{   )rl   ÚiÚitemZ	new_itemsZ	cs_fieldsZparam_indexr   rz   ÚfiZnew_names_closureZnew_fixtureinfoZnew_itemr*   r*   r+   Úpytest_collection_finish©   sn   
ÿþýü
ÿûú	

üù	€Ê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 )NrL   r   r!   r:   c                    s<   t ˆ ˆƒ�}| ˆ| ¡ W d   ƒ d S 1 sw   Y  d S ©N)r7   Úrun_test)rL   rR   )r-   r.   Úoriginal_funcr*   r+   Úrun_with_hypothesiså   s   "ÿz/pytest_pyfunc_call.<locals>.run_with_hypothesisrK   r_   c                   s   i | ]}|ˆ | “qS r*   r*   )rb   Úarg)rt   r*   r+   Ú
<dictcomp>ø   s    z&pytest_pyfunc_call.<locals>.<dictcomp>T)rL   r   r!   r:   )rt   Úgetr,   re   r^   r_   rf   Ú__qualname__r	   r†   rY   r7   r�   r   r   r$   r   ÚKeyboardInterruptÚ
SystemExit)r�   r’   r   ZtestargsrR   ZexcgrpÚexcr*   )r-   r.   rt   r‘   r+   Úpytest_pyfunc_callã   s<   


ÿ€ûÿ
þ
ö
rš   Úmodule)Úscoperq   c                 C  ó   | j S r�   )ÚparamrW   r*   r*   r+   rK     ó   rK   c                 C  s   t | tƒr| S | d S )Nr   ©r$   r%   rV   r*   r*   r+   Úanyio_backend_name  ó   
r¡   c                 C  s   t | tƒri S | d S r1   r    rV   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__+  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

        N)r§   )rª   r*   r*   r+   r¥   /  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  qdw |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   r3   r§   ÚbindÚOSErrorÚgetsocknamer©   Úadd)rª   r¬   ZfamiliesÚportÚstackÚsockÚaddrr*   r*   r+   Ú__call__8  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¤     s    
r¤   )rœ   c                   C  ó
   t tjƒS r�   )r¤   r®   ÚSOCK_STREAMr*   r*   r*   r+   Úfree_tcp_port_factoryZ  ó   
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_portd  rŸ   rÇ   c                 C  rÆ   r�   r*   )rÄ   r*   r*   r+   Úfree_udp_porti  rŸ   rÈ   )r   r    r!   r"   )r-   r%   r.   r/   r!   r0   )r8   r9   r!   r:   )r@   rA   r!   r:   )rH   r   rI   r   r!   rJ   )r[   r\   r]   r%   r^   r    r!   r:   )rl   rm   r!   r:   )r�   r   r!   rŽ   )rI   r   r!   r   )rK   r   r!   r%   )rK   r   r!   r/   )r!   r¤   )rÁ   rÅ   r!   r¨   )rÄ   rÅ   r!   r¨   )AÚ
__future__r   r‚   r®   ÚsysÚcollections.abcr   r   r   Ú
contextlibr   r   Úinspectr   r	   r
   Útypingr   r   rF   Z_pytest.fixturesr   r   Z_pytest.outcomesr   Z_pytest.pythonr   Z_pytest.scoper   Ú r   Z_core._eventloopr   r   r   r   Z_core._exceptionsr   Úabcr   Úversion_infoZexceptiongroupr   r   Ú__annotations__r   r4   r,   r7   r?   rG   ZhookimplrZ   rk   rŒ   rš   ZfixturerK   r¡   r£   r¤   rÁ   rÄ   rÇ   rÈ   r*   r*   r*   r+   Ú<module>   sb    






0

:$
=
