o
     h'                     @  s  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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 rfd 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j*d)d*dVd/d0Z+ej*d)d1dWd6d7Z,ej*d)d1dXd:d;Z-ej.d<e d=dYd>d?Z/ej.dZd@dAZ0ej.d[dBdCZ1G dDdE dEZ2ej.dFdGd\dHdIZ3ej.dFdGd\dJdKZ4ej.d]dNdOZ5ej.d^dPdQZ6d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$   U/var/www/html/pro-man-master/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zt V  W td8 atsMtd usCJ t  d  aa d S d S td8 atsctd us[J t  d  aa w Nr   )r   r   r   r   sniffiocurrent_async_library_cvargetsetcallbackresetenter_contextcreate_test_runner_runner_leasesclose)r'   r(   asynclibtokenr$   r$   r%   
get_runner%   s2   
r8   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)r9   r$   r$   r%   pytest_addoptionC   s   
rC   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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)rD   r$   r$   r%   pytest_configureL   s    
rQ   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   rT   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 )NrV   rT   )instancer
   rA   __self____func____get__r&   r8   r   run_asyncgen_fixturerun_fixture)rV   rT   rW   
local_funcr'   r(   runnerfunchas_backend_arghas_request_argr$   r%   wrappera   s(   "z%pytest_fixture_setup.<locals>.wrapperrV   rT   )rV   r   rT   r   rW   r   r   r   )ra   r   r	   fixturenamesargnames)rS   rT   rd   original_argnamer$   r`   r%   pytest_fixture_setup_   s$   
rj   )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<   rG   anyio
pytestmarkr$   c                 s  s    | ]}|j d kV  qdS )rq   N)rn   ).0markerr$   r$   r%   	<genexpr>   s    z,pytest_pycollect_makeitem.<locals>.<genexpr>rV   )istestfunctionhasattrrp   
inner_testr	   rD   rK   get_closest_markergetattranyrO   markusefixtures)rl   rn   ro   
inner_funcanyio_auto_modert   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 )NrW   r   r   r;   c                    s<   t  }||  W d    d S 1 sw   Y  d S N)r8   run_test)rW   r_   )r'   r(   original_funcr$   r%   run_with_hypothesis   s   "z/pytest_pyfunc_call.<locals>.run_with_hypothesisrV   rp   c                   s   i | ]}| | qS r$   r$   )rs   arg)funcargsr$   r%   
<dictcomp>   s    z&pytest_pyfunc_call.<locals>.<dictcomp>T)rW   r   r   r;   )r   r.   r&   rw   ro   rp   rx   __qualname__r	   _fixtureinforh   r8   r   r   r   r   r   KeyboardInterrupt
SystemExit)r   r   r   testargsr_   excgrpexcr$   )r'   r(   r   r   r%   pytest_pyfunc_call   s<   





r   module)scopeparamsc                 C     | j S r   )paramrf   r$   r$   r%   rV         rV   c                 C  s   t | tr| S | d S )Nr   r   r   re   r$   r$   r%   anyio_backend_name      
r   c                 C  s   t | tri S | d S r+   r   re   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

        )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   r2   r   bindOSErrorgetsocknamer   add)r   r   familiesportstacksockaddrr$   r$   r%   __call__   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   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*   )r9   r:   r   r;   )rD   rE   r   r;   )rS   r   rT   r   r   rU   )rl   rm   rn   r   ro   r   r   r;   )r   r   r   r   )rT   r   r   r   )rV   r   r   r   )rV   r   r   r)   )r   r   )r   r   r   r   )r   r   r   r   )7
__future__r   r   syscollections.abcr   r   r   
contextlibr   r   inspectr   r	   r
   typingr   r   rO   r,   _pytest.fixturesr   _pytest.outcomesr   _core._eventloopr   r   _core._exceptionsr   abcr   version_infoexceptiongroupr   r   __annotations__r   r4   r&   r8   rC   rQ   hookimplrj   r   r   fixturerV   r   r   r   r   r   r   r   r$   r$   r$   r%   <module>   sZ    




	

0
$
=
