
    h
                        d dl Z d dlZd dlmZ d dlZd dlZe j                  j                  dd      rd dlm	Z	 ej                  j                  ej                  dk  d      ej                  j                  d	      d
               Zej                  j                  ej                  dk  d      ej                  j                  d	      d               Zyy)    NUSE_ASYNCIOF)	Component)      zrequires Python 3.5+)reasonT)forbid_global_loopc                   K   t         j                  j                  | t         j                  _        t        ddddg      j	                  |       }| t         j                  _        t        j
                         fd}t        j                  d|       fd	}|j                  |        d {    y 7 w)
Nws://localhost:12/bogus   皙?urlmax_retriesmax_retry_delay
transportsloopc                  d     j                  t        d             t        j                  _        y Nz	timed outset_exceptionAssertionErrortxaioconfigr   finished	orig_loops   f/var/www/Befach/backend/env/lib/python3.12/site-packages/autobahn/wamp/test/test_wamp_component_aio.pyfailz$test_asyncio_component.<locals>.fail;   s"    "">+#>? )ELL    g      @c                 >   	 | j                          j                  t        d             j                  d        t        j                  _        j                  J y # t        $ r1}dt	        |      vrj                  t        d             Y d }~jd }~ww xY w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   s     r   donez$test_asyncio_component.<locals>.done@   s    U
&&~6K'LM % )ELL<<'''   U=SVK**>:R+STUs   *A" "	B+'BB)r   r   r   r   startcreate_future
call_lateradd_done_callback)
event_loopr)   r    r,   r+   r   r   s       @@@r   test_asyncio_componentr2   $   s      LL%%	& 5#$'*
 JJJJ'&&&(	* 	d#		( 	
D!s   B5C:C ;Cc                 x  	
K   t         j                  j                  | t         j                  _         G d dt              } |       	dgd	fd	}t        j
                  j                  | d|      5  || _        t        dddd	g
      }|j                  |       }| t         j                  _        fd}t        j                  d|       t        j                         

fd}t        j                  d|       
fd}|j                  |       
 d{    ddd       y7 # 1 sw Y   yxY ww)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                       e Zd Zd Zd Zy)1test_asyncio_component_404.<locals>.FakeTransportc                      y N )selfs    r   closez7test_asyncio_component_404.<locals>.FakeTransport.closeY       r!   c                      y r7   r8   )r9   datas     r   writez7test_asyncio_component_404.<locals>.FakeTransport.write\   r;   r!   N)__name__
__module____qualname__r:   r>   r8   r!   r   FakeTransportr5   X   s    r!   rB   Nc                     d   4 |        }|d<   |j                         t        j                  |f      S t        j                  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_transports         r   create_connectionz5test_asyncio_component_404.<locals>.create_connectionb   s[    q!)+-%-"((822NH3MNN00>b1cddr!   rO   r
   r   r   r   r   r   c                  :     d    d   j                  d        y y )Nr   )connection_lost)rM   s   r   nuke_transportz2test_asyncio_component_404.<locals>.nuke_transport   s&    "1%1#A&66t< 2r!   c                  d     j                  t        d             t        j                  _        y r   r   r   s   r   r    z(test_asyncio_component_404.<locals>.fail   s"    &&~k'BC$-!r!   g      ?c                 "   	 | j                          j                  t        d             j                  d        t        j                  _        y # t        $ r1}dt	        |      vrj                  t        d             Y d }~\d }~ww xY wr#   )	r$   r   r   r%   r&   r'   r   r   r   )r)   r*   r   r   s     r   r,   z(test_asyncio_component_404.<locals>.done   sw    YHHJ**>:O+PQ ##D)$-!	 $ YAQO ..~>V/WXYs   *A 	B'B		B)NNNNF)r   r   r   objectmockpatchrO   r   r-   r/   r.   r0   )r1   rB   rO   r+   r)   rR   r    r,   rM   rN   r   r   s           @@@@r   test_asyncio_component_404rX   M   s     LL%%	&	F 	 '&	e ZZz+>@QR /	+<J(  9'(+.D 



+A *ELL= S.1**,H. S$'. %NN_/	 /	^ _/	 /	s1   A1D:7B'D.D,D.#	D:,D..D73D:)ossysunittest.mockrV   pytestr   environgetautobahn.asyncio.componentr   markskipifversion_infoasyncior2   rX   r8   r!   r   <module>rd      s   6 
 
   ::>>-'4[[((61:PQ[[D1% 2 R%N [[((61:PQ[[D1K 2 RK] (r!   