o
    ɂh'                     @  s  U d dl mZ d dlZd dlm  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Zd dlmZ d dlmZ d	d
lmZm Z  d	dl!m"Z" d	dl#m$Z$ e	j%dk rsd dl&m'Z' da(de)d< da*de)d< d a+dRddZ,edSddZ-dTd#d$Z.dUd'd(Z/ej0d)d*dVd/d0Z1ej0d)d1dWd6d7Z2ej0d)d1dXd:d;Z3ej4d<e d=dYd>d?Z5ej4dZd@dAZ6ej4d[dBdCZ7G dDdE dEZ8ej4dFdGd\dHdIZ9ej4dFdGd\dJdKZ:ej4d]dNdOZ;ej4d^dPdQZ<dS )_    )annotationsN)Callable	GeneratorIterator)	ExitStackcontextmanager)isasyncgenfunctioniscoroutinefunctionismethod)Anycast)
SubRequest)Exit   )get_all_backendsget_async_backend)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$   S/var/www/html/flask_server/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jd d u r"tj| }ttjj	| |p%i }t
||a td7 azRt V  W td8 atsd }t|u}|sutd|fdt|fdt v sZttr_ttndt|d }dd|i }tt|d  }}t  d  aa d S d S td8 atsd }t|u}|std|fdt|fdt v sttrttndt|d }dd|i }tt|d  }}t  d  aa w )Nr   )is not)z%(py0)s is not %(py3)sr   )py0py3zassert %(py5)spy5)r   r   r   r   sniffiocurrent_async_library_cvargetsetcallbackresetenter_contextcreate_test_runner_runner_leases
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationclose)r'   r(   asynclibtoken@py_assert2@py_assert1@py_format4@py_format6r$   r$   r%   
get_runner%   s2   xx
rG   parserpytest.ParserNonec                 C  s   | j ddddd d S )N
anyio_modestrictz-AnyIO plugin mode (either "strict" or "auto")string)defaulthelptype)addini)rH   r$   r$   r%   pytest_addoptionC   s   
rR   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.rK   autoasyncioasyncio_modezlAnyIO auto mode has been enabled together with pytest-asyncio auto mode. This may cause unexpected behavior.r   )addinivalue_linegetinipluginmanager
has_pluginissue_config_time_warningpytestPytestConfigWarning)rS   r$   r$   r%   pytest_configureL   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   rc   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 )Nre   rc   )instancer
   rP   __self____func____get__r&   rG   r   run_asyncgen_fixturerun_fixture)re   rc   rf   
local_funcr'   r(   runnerfunchas_backend_arghas_request_argr$   r%   wrappera   s(   "z%pytest_fixture_setup.<locals>.wrapperre   rc   )re   r   rc   r   rf   r   r   r   )rp   r   r	   fixturenamesargnames)rb   rc   rs   original_argnamer$   ro   r%   pytest_fixture_setup_   s$   
ry   )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
hypothesisrK   rV   anyio
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>re   )istestfunctionhasattrr   
inner_testr	   rS   rZ   get_closest_markergetattranyr^   markusefixtures)r{   r}   r~   
inner_funcanyio_auto_moder   own_markersr$   r$   r%   pytest_pycollect_makeitem   s    
r   
pyfuncitembool | Nonec                   s  d fdd}| j d}|rt|\ 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 sw   Y  dS d S )Nrf   r   r   rJ   c                    s<   t  }||  W d    d S 1 sw   Y  d S N)rG   run_test)rf   rn   )r'   r(   original_funcr$   r%   run_with_hypothesis   s   "z/pytest_pyfunc_call.<locals>.run_with_hypothesisre   r   c                   s   i | ]}| | qS r$   r$   )r   arg)funcargsr$   r%   
<dictcomp>   s    z&pytest_pyfunc_call.<locals>.<dictcomp>T)rf   r   r   rJ   )r   r1   r&   r   r~   r   r   __qualname__r	   _fixtureinforw   rG   r   r   r   r   r   KeyboardInterrupt
SystemExit)r   r   r   testargsrn   excgrpexcr$   )r'   r(   r   r   r%   pytest_pyfunc_call   s<   





r   module)scopeparamsc                 C     | j S r   )paramru   r$   r$   r%   re         re   c                 C  s   t | tr| S | d S )Nr   r   r   rt   r$   r$   r%   anyio_backend_name      
r   c                 C  s   t | tri S | d S )Nr   r   rt   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   rJ   c                 C  s   || _ tt  | _d S r   )_kindr2   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

        )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  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_ipv6appendAF_INET6r   r5   r   bindOSErrorgetsocknamer   add)r   r   familiesportstacksockaddrr$   r$   r%   __call__   s4   
 zFreePortFactory.__call__)r   r   r   rJ   )r   r   r   )r   r   r   r   )__name__
__module__r   __doc__r   propertyr   r   r$   r$   r$   r%   r      s    
r   session)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   r(   r)   r   r*   )rH   rI   r   rJ   )rS   rT   r   rJ   )rb   r   rc   r   r   rd   )r{   r|   r}   r   r~   r   r   rJ   )r   r   r   r   )rc   r   r   r   )re   r   r   r   )re   r   r   r)   )r   r   )r   r   r   r   )r   r   r   r   )=
__future__r   builtinsr:   _pytest.assertion.rewrite	assertionrewriter8   r   syscollections.abcr   r   r   
contextlibr   r   inspectr   r	   r
   typingr   r   r^   r/   _pytest.fixturesr   _pytest.outcomesr   _core._eventloopr   r   _core._exceptionsr   abcr   version_infoexceptiongroupr   r   __annotations__r   r7   r&   rG   rR   r`   hookimplry   r   r   fixturere   r   r   r   r   r   r   r   r$   r$   r$   r%   <module>   sZ    "




	

0
$
=
