a
    ”˜ëj(  ã                   @  sR  U d dl m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 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(dddœdd„Z)e
ddddœdd„ƒZ*dd d!œd"d#„Z+d$d d%œd&d'„Z,ej-d(d)�d*d*d+d,œd-d.„ƒZ.ej-d(d/�d0ddd d1œd2d3„ƒZ/ej-d(d/�d*d4d5œd6d7„ƒZ0ej1d8eƒ d9�d*d*d:œd;d<„ƒZ2ej1d*dd=œd>d?„ƒZ3ej1d*dd=œd@dA„ƒZ4G dBdC„ dCƒZ5ej1dDdE�dCdFœdGdH„ƒZ6ej1dDdE�dCdFœdIdJ„ƒZ7ej1dKdLdMœdNdO„ƒZ8ej1dKdLdPœdQdR„ƒZ9dS )Sé    )ÚannotationsN)ÚCallableÚ	GeneratorÚIterator)Ú	ExitStackÚcontextmanager)ÚisasyncgenfunctionÚiscoroutinefunctionÚismethod)ÚAnyÚcast)Ú
SubRequest)ÚExité   )Ú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Úobjectztuple[str, dict[str, Any]])ÚbackendÚreturnc                 C  sj   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ƒ‚d S )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&   úR/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/anyio/pytest_plugin.pyÚextract_backend_and_options    s    
r(   r!   zdict[str, Any]zIterator[TestRunner])Úbackend_nameÚbackend_optionsr   c                 c  s¶   t d u rLt| ƒ}tƒ atƒ d u r4t| ƒ}t t|¡ |p:i }t | 	|¡¡a t
d7 a
z2t V  W t
d8 a
t
s²td usvJ ‚t ¡  d  aa n*t
d8 a
t
s°td us J ‚t ¡  d  aa 0 d S ©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*   s.    
ÿ
ür1   zpytest.ParserÚNone)Úparserr   c                 C  s   | j dddd� d S )NÚ
anyio_modeÚstrictz-AnyIO plugin mode (either "strict" or "auto"))ÚdefaultÚhelp)Zaddini)r3   r&   r&   r'   Úpytest_addoptionH   s
    ýr8   zpytest.Config)Úconfigr   c                 C  sJ   |   dd¡ |  d¡dkrF| j d¡rF|  d¡dkrF|  t d¡d¡ d S )	NÚmarkerszManyio: mark the (coroutine function) test to be run asynchronously via anyio.r4   ÚautoZ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)r9   r&   r&   r'   Úpytest_configureP   s     þÿ
þýÿûr>   T)Zhookwrapperr   zGenerator[Any])Ú
fixturedefÚrequestr   c                 #  sª   dddddœ‡ ‡‡fdd„}| j ‰ tˆ ƒs2tˆ ƒr¤d|jv r¤|| _ | j}d| jv  ‰sd|  jd7  _d| jv  ‰s€|  jd	7  _zd V W ˆ | _ || _S ˆ | _ || _0 d V S )
Nr   r   )Úanyio_backendr@   Úkwargsr   c                 ;  s²   |j r2tˆ ƒr2tˆ jƒt|j ƒu r2ˆ j |j ¡}nˆ }t| ƒ\}}ˆrN| |d< ˆrZ||d< t||ƒ�:}t|ƒr‚| 	||¡E d H  n| 
||¡V  W d   ƒ n1 s¤0    Y  d S )NrA   r@   )Úinstancer
   ÚtypeÚ__self__Ú__func__Ú__get__r(   r1   r   Zrun_asyncgen_fixtureZrun_fixture)rA   r@   rB   Z
local_funcr)   r*   Úrunner©ÚfuncZhas_backend_argZhas_request_argr&   r'   Úwrappere   s"    ÿþýz%pytest_fixture_setup.<locals>.wrapperrA   ©rA   r@   ©r@   )rJ   r   r	   ZfixturenamesÚargnames)r?   r@   rK   Zoriginal_argnamer&   rI   r'   Úpytest_fixture_setupc   s(    
ý  ÿrO   )Ztryfirstzpytest.Module | pytest.Class)Ú	collectorÚnameÚobjr   c                 C  s~   |   ||¡rzt|dƒr|jjn|}t|ƒrz| j d¡dk}|  d¡}t|ddƒ}|sj|sjt	dd„ |D ƒƒrzt
j d	¡|ƒ d S )
NÚ
hypothesisr4   r;   ÚanyioZ
pytestmarkr&   c                 s  s   | ]}|j d kV  qdS )rT   N)rQ   )Ú.0Úmarkerr&   r&   r'   Ú	<genexpr>¡   ó    z,pytest_pycollect_makeitem.<locals>.<genexpr>rA   )ZistestfunctionÚhasattrrS   Ú
inner_testr	   r9   r<   Zget_closest_markerÚgetattrÚanyr=   ÚmarkZusefixtures)rP   rQ   rR   Z
inner_funcZanyio_auto_moderV   Zown_markersr&   r&   r'   Úpytest_pycollect_makeitem”   s    
ÿþýr^   zbool | None)Ú
pyfuncitemr   c                   s(  dddœ‡ ‡‡fdd„}| j  d¡}|�r$t|ƒ\‰ ‰t| jdƒrn| jjj‰ˆj|jkrjtˆƒrj|| jj_d S t| jƒ�r$| j ‰‡fdd	„| j	j
D ƒ}tˆ ˆƒ�n}z| | j|¡ W nJ tyþ } z2t|ƒD ]}t|tttfƒrÌ||‚qÌ‚ W Y d }~n
d }~0 0 W d   ƒ n1 �s0    Y  d
S d S )Nr   r2   )rB   r   c                    s:   t ˆ ˆƒ�}| ˆ| ¡ W d   ƒ n1 s,0    Y  d S ©N)r1   Úrun_test)rB   rH   )r)   r*   Úoriginal_funcr&   r'   Úrun_with_hypothesis¨   s    z/pytest_pyfunc_call.<locals>.run_with_hypothesisrA   rS   c                   s   i | ]}|ˆ | “qS r&   r&   )rU   Úarg)Úfuncargsr&   r'   Ú
<dictcomp>»   rX   z&pytest_pyfunc_call.<locals>.<dictcomp>T)re   Úgetr(   rY   rR   rS   rZ   Ú__qualname__r	   Z_fixtureinforN   r1   ra   r   r   r    r   ÚKeyboardInterruptÚ
SystemExit)r_   rc   r   ZtestargsrH   ZexcgrpÚexcr&   )r)   r*   re   rb   r'   Úpytest_pyfunc_call¦   s.    

8rl   Úmodule)ÚscopeÚparams)r@   r   c                 C  s   | j S r`   )ÚparamrM   r&   r&   r'   rA   Ë   s    rA   )rA   r   c                 C  s   t | tƒr| S | d S d S )Nr   ©r    r!   rL   r&   r&   r'   Úanyio_backend_nameÐ   s    
rr   c                 C  s   t | tƒri S | d S d S r+   rq   rL   r&   r&   r'   Úanyio_backend_optionsØ   s    
rs   c                   @  sD   e Zd ZdZdddœdd„Zeddœdd	„ƒZdd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.
    zsocket.SocketKindr2   )Úkindr   c                 C  s   || _ tt ƒ | _d S r`   )Ú_kindÚsetÚintÚ
_generated)Úselfru   r&   r&   r'   Ú__init__î   s    zFreePortFactory.__init__©r   c                 C  s   | j S )z¦
        The type of socket connection (e.g., :data:`~socket.SOCK_STREAM` or
        :data:`~socket.SOCK_DGRAM`) used to bind for checking port availability

        )rv   )rz   r&   r&   r'   ru   ò   s    zFreePortFactory.kindNzsocket.AddressFamily | Nonerx   )Úfamilyr   c              
   C  sî   |dur|g}nt jg}t jr*| t j¡ d}tƒ �¤}|D ]f}| t   || j¡¡}|t jkr`dnd}z| ||f¡ W n t	yŽ   Y  qÊY n0 |s:| 
¡ d }q:|| jvrÊ| j |¡ |W  d  ƒ S W d  ƒ q*1 sÞ0    Y  q*dS )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

        Nr   z::1z	127.0.0.1r   )ÚsocketÚAF_INETÚhas_ipv6ÚappendÚAF_INET6r   r-   rv   ÚbindÚOSErrorÚgetsocknamery   Úadd)rz   r}   ZfamiliesÚportÚstackÚsockÚaddrr&   r&   r'   Ú__call__û   s&    
zFreePortFactory.__call__)N)Ú__name__Ú
__module__rh   Ú__doc__r{   Úpropertyru   r‹   r&   r&   r&   r'   rt   à   s
   rt   Úsession)rn   r|   c                   C  s
   t tjƒS r`   )rt   r~   ÚSOCK_STREAMr&   r&   r&   r'   Úfree_tcp_port_factory  s    r’   c                   C  s
   t tjƒS r`   )rt   r~   Ú
SOCK_DGRAMr&   r&   r&   r'   Úfree_udp_port_factory"  s    r”   zCallable[[], int]rx   )r’   r   c                 C  s   | ƒ S r`   r&   )r’   r&   r&   r'   Úfree_tcp_port'  s    r•   )r”   r   c                 C  s   | ƒ S r`   r&   )r”   r&   r&   r'   Úfree_udp_port,  s    r–   ):Ú
__future__r   r~   ÚsysÚcollections.abcr   r   r   Ú
contextlibr   r   Úinspectr   r	   r
   Útypingr   r   r=   Z_pytest.fixturesr   Z_pytest.outcomesr   Ú r   Z_core._eventloopr   r   r   r   Z_core._exceptionsr   Úabcr   Úversion_infoZexceptiongroupr   r   Ú__annotations__r   r.   r(   r1   r8   r>   ZhookimplrO   r^   rl   ZfixturerA   rr   rs   rt   r’   r”   r•   r–   r&   r&   r&   r'   Ú<module>   sX   


0

$=

