o
    øT·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,   úV/home/dinkstrade/pdmp-scanner/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_contextÚcreate_test_runnerÚ_runner_leasesÚclose)r/   r0   ÚasynclibÚtokenr,   r,   r-   Ú
get_runner9   s2   €
ÿýÿ
r;   Ú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)
        )rB   ÚdestrC   )ÚgetgroupÚaddiniÚ	addoption)r<   Úgroupr,   r,   r-   Úpytest_addoptionW   s   
ý
ürI   Úconfigúpytest.ConfigÚmodeÚboolc                 C  s    | j |d d�dkp|  |¡dkS )N)rB   Úauto)Ú	getoptionÚgetini)rJ   rL   r,   r,   r-   Ú_is_auto_modej   s   ÿrQ   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@   ÚasyncioÚasyncio_modezlAnyIO auto mode has been enabled together with pytest-asyncio auto mode. This may cause unexpected behavior.r   )Úaddinivalue_linerQ   ÚpluginmanagerÚ
has_pluginÚissue_config_time_warningÚpytestÚPytestConfigWarning)rJ   r,   r,   r-   Úpytest_configurep   s"   þÿ
þýÿûûr[   T)Ú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   r^   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 )Nr`   r^   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.   r;   Ú
is_runningÚRuntimeErrorr   Úrun_asyncgen_fixtureÚrun_fixture)r`   r^   ra   Ú
local_funcr/   r0   Úrunner©ÚfuncÚhas_backend_argÚhas_request_argr,   r-   Úwrapper…   s0   €ÿþÿð"òz%pytest_fixture_setup.<locals>.wrapper©r`   ©r^   )r`   r   r^   r   ra   r   r#   r   )rn   r   r	   ÚfixturenamesÚargnames)r]   r^   rq   Úoriginal_argnamer,   rm   r-   Úpytest_fixture_setupƒ   s$   €&
ÿrw   )Ú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?   Ú
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>r`   )ÚistestfunctionÚhasattrr}   Ú
inner_testr	   rQ   rJ   Úget_closest_markerÚgetattrÚanyrY   ÚmarkÚusefixtures)ry   r{   r|   Ú
inner_funcÚanyio_auto_moder�   Úown_markersr,   r,   r-   Úpytest_pycollect_makeitemÀ   s    
ÿþýõrŽ   Ú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?   r`   c                 S  s   h | ]}|j ’qS r,   r   )r€   Úfr,   r,   r-   Ú	<setcomp>Ü   s    z+pytest_collection_finish.<locals>.<setcomp>Ú
_arg2scope)ÚparamsÚindicesr“   Ú_idlistÚmarks)Úfuncargsr”   r•   Ú	arg2scopeÚidlistr—   )ru   ÚinitialnamesÚnames_closureÚname2fixturedefsú[ú])r{   ÚcallspecÚcallobjÚfixtureinfoÚkeywordsÚoriginalnamer   )ÚreversedÚlistÚ	enumerateÚitemsr&   rY   ÚFunctionr	   Úfunctionr†   rt   ÚdataclassesÚfieldsr   r+   Úsetr   r   ÚModuleÚ_fixtureinforœ   Úappendr   ru   r›   r�   Úfrom_parentÚparentr¤   r|   r£   )r�   ÚiÚitemÚ	new_itemsÚ	cs_fieldsÚparam_indexr!   r    ÚfiÚnew_names_closureÚnew_fixtureinfoÚ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 )Nra   r   r#   r>   c                    s<   t ˆ ˆƒ�}| ˆ| ¡ W d   ƒ d S 1 sw   Y  d S ©N)r;   Úrun_test)ra   rl   )r/   r0   Úoriginal_funcr,   r-   Úrun_with_hypothesis  s   "ÿz/pytest_pyfunc_call.<locals>.run_with_hypothesisr`   r}   c                   s   i | ]}|ˆ | “qS r,   r,   )r€   Úarg)r˜   r,   r-   Ú
<dictcomp>!  s    z&pytest_pyfunc_call.<locals>.<dictcomp>T)ra   r   r#   r>   )r˜   Úgetr.   r„   r|   r}   r…   Ú__qualname__r	   r¯   ru   r;   rÀ   r   r   r&   r   ÚKeyboardInterruptÚ
SystemExit)r½   rÂ   r!   Útestargsrl   ÚexcgrpÚexcr,   )r/   r0   r˜   rÁ   r-   Úpytest_pyfunc_call  s<   


ÿ€ûÿ
þ
ö
rÌ   Úmodule)Úscoper”   c                 C  ó   | j S r¿   )Úparamrs   r,   r,   r-   r`   1  ó   r`   c                 C  s   t | tƒr| S | d S )Nr   ©r&   r'   rr   r,   r,   r-   Úanyio_backend_name6  ó   
rÓ   c                 C  s   t | tƒri S | d S r3   rÒ   rr   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Þ   ÚfamiliesÚportÚstackÚ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>   )rJ   rK   rL   r'   r#   rM   )rJ   rK   r#   r>   )r]   r   r^   r   r#   r_   )ry   rz   r{   r'   r|   r"   r#   r>   )r�   r�   r#   r>   )r½   r   r#   r¾   )r^   r   r#   r   )r`   r   r#   r'   )r`   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   rY   Ú_pytest.fixturesr   r   Ú_pytest.outcomesr   Ú_pytest.scoper   Ú r   Ú_core._eventloopr   r   r   r   Ú_core._exceptionsr   Úabcr   Úversion_infoÚexceptiongroupr   Ú_pytest.pythonr   r   ÚImportErrorr   Ú__annotations__r    r7   r.   r;   rI   rQ   r[   Úhookimplrw   rŽ   r¼   rÌ   Úfixturer`   rÓ   rÕ   rÖ   rõ   rø   rû   rü   r,   r,   r,   r-   Ú<module>   sr    
ÿ






<

:$
=
