
    8'h                     :   d dl mZ d dlZej                  j	                  dd      rud dlmZ d dlmZ d dl	m
Z
 d dlmZ d d	lmZ  G d
 dej                        Z G d de      Z G d de      Z G d de      Z G d de      Z G d de
j*                        Zyy)    )absolute_importNUSE_TWISTEDF)sleep)wamp)unittest)defer)servicec                   "    e Zd ZdZd Zd Zd Zy)CaseComponentz
        Application code goes here. This is an example component that calls
        a remote procedure on a WAMP peer, subscribes to a topic to receive
        events, and then stops the world after some events.
        c                     t         j                  j                  | |       |j                  d   | _        d| _        d| _        d| _        y )NtestF   )r   ApplicationSession__init__extrar   stop_loglinefinished)selfconfigs     ]/var/www/html/trade_iq/venv/lib/python3.12/site-packages/autobahn/wamp/test/test_component.pyr   zCaseComponent.__init__.   s=    ##,,T6:V,DIDIDM!DM    c                     t        |      dkD  rdj                  d |D              }nt        |      dk(  r|d   }nd}dj                  | j                  | j                  j
                  |      }| xj                  dz  c_        t        |       y )Nr   z, c              3   2   K   | ]  }t        |        y wN)str).0ss     r   	<genexpr>z$CaseComponent.log.<locals>.<genexpr>7   s     !7Q#a&!7s   r   -z= : {0:>3} : {1:<20} : {2})lenjoinformatr   	__class____name__print)r   argssargsmsgs       r   logzCaseComponent.log5   sr    4y1}		!7$!77TaQ/66t}}dnnF]F]_deCMMQM#Jr   c                     | j                   s-| j                  j                  j                  d        d| _         y t	        d       y )NTzalready finished)r   r   deferredcallbackr&   r   s    r   finishzCaseComponent.finishA   s1    ==		""++D1 $()r   N)r%   
__module____qualname____doc__r   r*   r/    r   r   r   r   '   s    		"
		*r   r   c                   0    e Zd Zej                  d        Zy)Case1_Backendc              #       K    j                  d        fd} j                  |d        j                  d        j                          y w)Njoinedc                 P    j                  dj                  | |             | |z   S )Nzadd2 invoked: {0}, {1}r*   r#   )xyr   s     r   add2z"Case1_Backend.onJoin.<locals>.add2O   s&    188A>?1ur   com.mathservice.add2zadd2 registered)r*   registerr/   )r   detailsr<   s   `  r   onJoinzCase1_Backend.onJoinJ   sD      HHX --&<==HH&'KKMs   AANr%   r0   r1   r   inlineCallbacksr@   r3   r   r   r5   r5   H       				 
	r   r5   c                   0    e Zd Zej                  d        Zy)Case1_Frontendc              #   &  K   | j                  d       	 | j                  ddd      }| j                  dj                  |             | j	                          y # t        $ r*}| j                  dj                  |             Y d }~?d }~ww xY ww)Nr7   r=         zcall result: {0}zcall error: {0})r*   callr#   	Exceptionr/   )r   r?   reses       r   r@   zCase1_Frontend.onJoinZ   s~      HHX9 II&<aCC +22378KKM  6*11!4556s-   BA 1B	B$ B	B	BBNrA   r3   r   r   rE   rE   X   rC   r   rE   c                   0    e Zd Zej                  d        Zy)Case2_Backendc              #   P   K    j                  d        fd} fd}d fd	}d fd	} fd} j                  |d        j                  |d        j                  |d	        j                  |d
        j                  |d        j                  d       y w)Nr7   c                  (     j                  d       y )Nzping() is invokedr*   r.   s   r   pingz"Case2_Backend.onJoin.<locals>.pingo   s    ,-r   c                 4    j                  d| |       | |z   S )Nzadd2() is invokedrQ   )abr   s     r   r<   z"Case2_Backend.onJoin.<locals>.add2s   s    ,a31ur   c                 N    j                  d| |       dj                  | |      S )Nzstars() is invokedz{0} starred {1}xr9   )nickstarsr   s     r   rX   z#Case2_Backend.onJoin.<locals>.starsw   s'    -tU;*11$>>r   c                     j                  d| |       t        d      D cg c]  }dj                  |       c}d | S c c}w )Nzorders() is invoked2   zProduct {0})r*   ranger#   )productlimitir   s      r   ordersz$Case2_Backend.onJoin.<locals>.orders{   s>    .?:?)DQ--a0DVeLLDs   A c                  V    j                  d| |       t        |       t        |      gS )Nzarglen() is invoked)r*   r!   )r'   kwargsr   s     r   arglenz$Case2_Backend.onJoin.<locals>.arglen   s'    .f=D	3v;//r   com.arguments.pingcom.arguments.add2com.arguments.starscom.arguments.orderscom.arguments.arglenzprocedures registered)somebodyr   )   )r*   r>   )r   r?   rR   r<   rX   r_   rb   s   `      r   r@   zCase2_Backend.onJoinj   s      HHX?M0 --&;<<--&;<<--'=>>--(?@@--(?@@HH,-s   B#B&NrA   r3   r   r   rN   rN   h   s    				. 
	.r   rN   c                   0    e Zd Zej                  d        Zy)Case2_Frontendc           	   #   j  K   | j                  d       t        d       | j                  d       | j                  d       | j                  ddd      }| j                  dj                  |             | j                  d	      }| j                  d
j                  |             | j                  d	d      }| j                  dj                  |             | j                  d	d      }| j                  dj                  |             | j                  d	dd      }| j                  dj                  |             | j                  dd      }| j                  dj                  |             | j                  ddd      }| j                  dj                  |             | j                  d      }| j                  dj                  |             | j                  dddd      }| j                  dj                  |             | j                  dddd      }| j                  dj                  |             | j                  ddddddd      }| j                  dj                  |             | j                  d       | j	                          y w)Nr7   r   rc   zPinged!rd   rG   rH   z	Add2: {0}re   zStarred 1: {0}Homer)rW   zStarred 2: {0}ri   )rX   zStarred 3: {0})rW   rX   zStarred 4: {0}rf   coffeezOrders 1: {0}
   )r]   zOrders 2: {0}rg   zArglen 1: {0})rT   rU   czArglen 2: {0}zArglen 3: {0}	finishing)r*   r   rI   r#   r/   )r   r?   rK   starredr_   
arglengthss         r   r@   zCase2_Frontend.onJoin   sN     HHX(N))122HHY		"7A>>CHH['',- II&<==GHH%,,W56 II&<8ILLGHH%,,W56 II&<AIFFGHH%,,W56 II&<8STIUUGHH%,,W5699%<iHHFHH_++F3499%<ir9RRFHH_++F34#yy)@AAJHH_++J78#yy)@!QJJJHH_++J78#yy)@AayPPJHH_++J78#yy)@!QQRSWXyYYJHH_++J78HH[!KKMs   J1J3NrA   r3   r   r   rk   rk      s    			,	 
,	r   rk   c                       e Zd Zej                  j                  d      dZd Zej                  d        Z
ej                  d        Zej                  d        Zy)TestRpcWAMP_ROUTER_URLNz`Please provide WAMP_ROUTER_URL environment with url to WAMP router to run WAMP integration testsc                 Z    t         j                  j                  d      | _        d| _        y )Nrv   realm1)osenvirongeturlrealmr.   s    r   setUpzTestRpc.setUp   s    zz~~&78DH"DJr   c              #   `  K   t        j                         | _        t        j                         }|D ]J  }t        j                  | j                  t        |       | j                  |      }|j                  |       L |j                          | j                   |j                          y w)N)r   )r|   r   r}   make)r   Deferredr,   r	   MultiServicer   Servicer|   dictr}   setServiceParentstartServicestopService)r   
componentsapp	componentrp   s        r   
runOneTestzTestRpc.runOneTest   s     !NN,DM&&(C' (	LLD/**"	 ""3'( --OOs   B,B.c              #   F   K   | j                  t        t        g       y wr   )r   r5   rE   r.   s    r   
test_case1zTestRpc.test_case1        //=."ABB   !c              #   F   K   | j                  t        t        g       y wr   )r   rN   rk   r.   s    r   
test_case2zTestRpc.test_case2   r   r   )r%   r0   r1   ry   rz   r{   skipr~   r   rB   r   r   r   r3   r   r   ru   ru      su    ::>>+,4@D	# 
			 
	  
			C 
	C 
			C 
	Cr   ru   )
__future__r   ry   rz   r{   autobahn.twisted.utilr   autobahn.twistedr   twisted.trialr   twisted.internetr   twisted.applicationr	   r   r   r5   rE   rN   rk   TestCaseru   r3   r   r   <module>r      s   6 ' 	::>>-'+%&&+*// *B    !. !.F/ /b!C(## !C{ (r   