
    8'h@$                     b   d dl mZmZ d dlZd dlZd dlmZ ej                  j                  dd      r>d dl	m
Z
 d dlmZ d dlmZ  ee       G d	 d
e             Z G d dej"                        Zy	 d dlZd dlm
Z
mZ d dlmZ  G d dej"                        Zy# e$ r d dlZd dl	m
Z
mZ Y /w xY w)    )absolute_importprint_functionN)replace_loopUSE_TWISTEDF)patch)implementer)IReactorTimec                   2    e Zd ZdZdZd Zd Zd Zd Zd Z	y)	FakeReactorzP
        This just fakes out enough reactor methods so .run() can work.
        Fc                 .    d| _         || _        g | _        y )NF)stop_calledto_raisedelayed)selfr   s     Z/var/www/html/trade_iq/venv/lib/python3.12/site-packages/autobahn/wamp/test/test_runner.py__init__zFakeReactor.__init__-   s    $D$DMDL    c                     | j                   N)r   r   argskws      r   runzFakeReactor.run2   s    --r   c                     d| _         y )NT)r   )r   s    r   stopzFakeReactor.stop5   s
    #Dr   c                 B    | j                   j                  ||||f       y r   )r   append)r   delayfuncr   kwargss        r   	callLaterzFakeReactor.callLater8   s    LLdF ;<r   c                     t        d      )NzConnectTCP shouldn't get called)RuntimeErrorr   s      r   
connectTCPzFakeReactor.connectTCP;   s    @AAr   N)
__name__
__module____qualname____doc__r   r   r   r   r!   r$    r   r   r   r   &   s(    	 	
	 	$	=	Br   r   c                   T    e Zd Z ed       ed       ed      d                      Zy)TestWampTwistedRunnerztxaio.use_twistedztxaio.start_loggingztxaio.configc                 Z   	 ddl m} ddlm} ddlm}  |dd      } |d      }t        d	t        |            5 }| j                  ||j                  d
 d       | j                  |j                         ddd       y# t        $ r t        j                  d      w xY w# 1 sw Y   yxY w)z
            Ensure the runner doesn't swallow errors and that it exits the
            reactor properly if there is one.
            r   ApplicationRunner)ConnectionRefusedError)reactorz
No twistedzws://localhost:1realmzIt's a trap!ztwisted.internet.reactorc                      y r   r)   )_s    r   <lambda>z:TestWampTwistedRunner.test_connect_error.<locals>.<lambda>[   s    r   T)start_reactorN)autobahn.twisted.wampr.   twisted.internet.errorr/   twisted.internetr0   ImportErrorunittestSkipTestr   r   assertRaisesr   
assertTruer   )r   r   r.   r/   r0   runner	exceptionmockreactors           r   test_connect_errorz(TestWampTwistedRunner.test_connect_errorD   s    6CI4 '':HEF.~>I1;y3IJ 9k!!*JJd " 
  7 789 9  6''5569 9s   A? <B!?B!B*N)r%   r&   r'   r   rA   r)   r   r   r+   r+   >   s7     
"	#	$	%	~		9 
 
& 
$	9r   r+   )r   Mockr-   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	TestApplicationRunnerzI
        Test the autobahn.asyncio.wamp.ApplicationRunner class.
        c                     	 | j                    | j                   } |||g|i | y # t        $ r | j                  }Y %w xY wr   )assertRaisesRegexAttributeErrorassertRaisesRegexp)r   r?   errorr   r   fs         r   _assertRaisesRegexz(TestApplicationRunner._assertRaisesRegexn   sM    +&& **i,,,	 " ,++,s   ( A A c                    t        t                     5 }t        j                  t        d|      5  t        t               t               f      |_        i }t        dd|      }|j                  d       | j                  ||j                  j                  d   d          d	d	d	       d	d	d	       y	# 1 sw Y   xY w# 1 sw Y   y	xY w)
z
            Ensure that loop.create_connection is called with the exact SSL
            context object that is passed (as ssl) to the __init__ method of
            ApplicationRunner.
            get_event_loopreturn_valuews://127.0.0.1:8080/wsr1   ssl_unused_   rR   Nr   rB   r   objectasynciorun_until_completer.   r   assertIscreate_connection	call_args)r   looprR   r>   s       r   test_explicit_SSLContextz.TestApplicationRunner.test_explicit_SSLContextw   s     df% S\\'+;$O S.2@P.QD+C./H(368FJJz*MM#t'='='G'G'J5'QRSS SS SS Ss#   B?A1B3"B?3B<	8B??Cc                    t        t                     5 }t        j                  t        d|      5  t        t               t               f      |_        t        dd      }|j                  d       | j                  d|j                  j                  d   d          d	d	d	       d	d	d	       y	# 1 sw Y   xY w# 1 sw Y   y	xY w)
z
            Ensure that loop.create_connection is called with ssl=False
            if no ssl argument is passed to the __init__ method of
            ApplicationRunner and the websocket URL starts with "ws:".
            rM   rN   rP   r1   rS   FrT   rR   NrU   r   r\   r>   s      r    test_omitted_SSLContext_insecurez6TestApplicationRunner.test_omitted_SSLContext_insecure   s     df% U\\'+;$O U.2@P.QD+./H(SFJJz*MM%)?)?)I)I!)LU)ST	UU UU UU Us#   B;A-B/B;/B8	4B;;Cc                    t        t                     5 }t        j                  t        d|      5  t        t               t               f      |_        t        dd      }|j                  | j                         | j                  d|j                  j                  d   d          ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)	z
            Ensure that loop.create_connection is called with ssl=True
            if no ssl argument is passed to the __init__ method of
            ApplicationRunner and the websocket URL starts with "wss:".
            rM   rN   zwss://127.0.0.1:8080/wssr1   TrT   rR   N)r   rB   r   rV   rW   rX   r.   r   failrY   rZ   r[   r_   s      r   test_omitted_SSLContext_securez4TestApplicationRunner.test_omitted_SSLContext_secure   s     df% T\\'+;$O T.2@P.QD+./JHUFJJtyy)MM$(>(>(H(H(KE(RS	TT TT TT Ts#   CA7B9(C9C	>CCc                     t        t                     5 }t        t               t               f      |_        t        ddd      }d}| j	                  t
        ||j                  d       ddd       y# 1 sw Y   yxY w)	z
            ApplicationRunner must raise an exception if given an ssl value of True
            but only a "ws:" URL.
            rN   ws://127.0.0.1:8080/wssr1   TrQ   ^ssl argument value passed to ApplicationRunner conflicts with the "ws:" prefix of the url argument\. Did you mean to use "wss:"\?$rS   N)r   rB   rX   r.   rK   	Exceptionr   )r   r\   r>   rI   s       r   "test_conflict_SSL_True_with_ws_urlz8TestApplicationRunner.test_conflict_SSL_True_with_ws_url   ss    
 df% R*.TVTV<L*M'*+Ex/35E ''	5&**jQR R Rs   AA33A<c                 b   ddl }	 |j                   |j                         }t        t	                     5 }t	        t	               t	               f      |_        t        dd|      }d}| j                  t        ||j                  d	       ddd       y# t        $ r d}Y w xY w# 1 sw Y   yxY w)
z
            ApplicationRunner must raise an exception if given an ssl value that is
            an instance of SSLContext, but only a "ws:" URL.
            r   NTrN   re   r1   rQ   rf   rS   )
rR   create_default_contextrG   r   rB   rX   r.   rK   rg   r   )r   rR   contextr\   r>   rI   s         r   $test_conflict_SSLContext_with_ws_urlz:TestApplicationRunner.test_conflict_SSLContext_with_ws_url   s    
 7 ** 446df% R*.TVTV<L*M'*+Ex/68E ''	5&**jQR R " 
R Rs   B AB%B"!B"%B.N)
r%   r&   r'   r(   rK   r]   r`   rc   rh   rl   r)   r   r   rD   rD   j   s*    		-	S	U	T	R	Rr   rD   )
__future__r   r   osr:   txaio.testutilr   environgetmockr   zope.interfacer   twisted.internet.interfacesr	   rV   r   TestCaser+   rW   unittest.mockrB   r9   trolliusautobahn.asyncio.wampr.   rD   r)   r   r   <module>ry      s   6 7 	  '::>>-'*8Bf B B.9 1 1 9D%- 8bR 1 1 bR  % 	#$$	%s   2B B.-B.