o
    @Bi                     @   s   d dl mZ d dlZd dlZd dlZd dlZd dlZejddrUd dl	m
Z
 ejjejdk ddejjd	d
dd Zejjejdk ddejjd	d
dd ZdS dS )    )absolute_importNUSE_ASYNCIOF)	Component)      zrequires Python 3.5+)reasonT)forbid_global_loopc                    sx   t jj| t j_tddddgd  j| d}| t j_t  fdd}t d	|  fd
d}|| S )Nws://localhost:12/bogus   皙?urlmax_retriesmax_retry_delay
transportsloopc                           td tj_d S Nz	timed outset_exceptionAssertionErrortxaioconfigr    finished	orig_loopr   e/var/www/html/Trade-python/venv/lib/python3.10/site-packages/autobahn/wamp/test/test_component_aio.pyfail=      z$test_asyncio_component.<locals>.failg      @c              
      s~   z|    td W n ty, } zdt|vr"td W Y d }~nd }~ww d  tj_ j	d u s=J d S Nzshould get an errorz(Exhausted all transport connect attemptszwrong exception caught)
resultr   r   RuntimeErrorstr
set_resultr   r   r   _done_ffecompr   r   r   r   doneB   s   
z$test_asyncio_component.<locals>.done)r   r   r   r   startcreate_future
call_lateradd_done_callback)
event_loopr)   r    r-   r   r+   r   test_asyncio_component&   s"   

r3   c                    s   t jj| t j_G dd dt}| dg d fdd	}tj| d|J || _tdd	d
dgd}|j| d}| t j_ fdd}t 	d
| t 
 fdd}t 	d| fdd}|| W  d   S 1 ssw   Y  dS )z
        If something connects but then gets aborted, it should still try
        to re-connect (in real cases this could be e.g. wrong path,
        TLS failure, WebSocket handshake failure, etc)
        c                   @   s   e Zd Zdd Zdd ZdS )z1test_asyncio_component_404.<locals>.FakeTransportc                 S      d S Nr   )selfr   r   r   close[      z7test_asyncio_component_404.<locals>.FakeTransport.closec                 S   r4   r5   r   )r6   datar   r   r   write^   r8   z7test_asyncio_component_404.<locals>.FakeTransport.writeN)__name__
__module____qualname__r7   r:   r   r   r   r   FakeTransportZ   s    r>   NFc                    s@    d d u r|  }| d< |  t|fS ttdS )Nr   z"second connection fails completely)connection_mader   create_future_successcreate_future_errorr$   )protocol_factoryserver_hostnamehostportsslprotocol)actual_protocolfake_transportr   r   create_connectiond   s   
z5test_asyncio_component_404.<locals>.create_connectionrJ   r	   r
   r   r   r   r   c                      s    d  d  d S )Nr   )connection_lostr   )rH   r   r   nuke_transport   s   z2test_asyncio_component_404.<locals>.nuke_transportc                      r   r   r   r   r   r   r   r       r!   z(test_asyncio_component_404.<locals>.failg      ?c              
      sp   z|     td W n ty, } zdt|vr" td W Y d }~nd }~ww  d  tj_d S r"   )	r#   r   r   r$   r%   r&   r   r   r   r(   r   r   r   r-      s   
z(test_asyncio_component_404.<locals>.done)NNNNF)r   r   r   objectmockpatchrJ   r   r.   r0   r/   r1   )r2   r>   rJ   r,   r)   rL   r    r-   r   )rH   rI   r   r   r   test_asyncio_component_404O   s4   	
	$rP   )
__future__r   ossysrN   pytestr   environgetautobahn.asyncio.componentr   markskipifversion_infoasyncior3   rP   r   r   r   r   <module>   s   '