
    h                     .   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)    N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     b/var/www/Befach/backend/env/lib/python3.12/site-packages/autobahn/wamp/test/test_wamp_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>5   s     !7Q#a&!7s   r   -z= : {0:>3} : {1:<20} : {2})lenjoinformatr   	__class____name__print)r   argssargsmsgs       r   logzCaseComponent.log3   sr    4y1}		!7$!77TaQ.55dmmT^^E\E\^cdC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.finish?   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>.add2M   s&    188A>?1ur   com.mathservice.add2zadd2 registered)r)   registerr.   )r   detailsr;   s   `  r   onJoinzCase1_Backend.onJoinH   sD      HHX --&<==HH&'KKMs   AANr$   r/   r0   r   inlineCallbacksr?   r2   r   r   r4   r4   F       				 
	r   r4   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)Nr6   r<         zcall result: {0}zcall error: {0})r)   callr"   	Exceptionr.   )r   r>   reses       r   r?   zCase1_Frontend.onJoinX   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Nr@   r2   r   r   rD   rD   V   rB   r   rD   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)Nr6   c                  (     j                  d       y )Nzping() is invokedr)   r-   s   r   pingz"Case2_Backend.onJoin.<locals>.pingm   s    ,-r   c                 4    j                  d| |       | |z   S )Nzadd2() is invokedrP   )abr   s     r   r;   z"Case2_Backend.onJoin.<locals>.add2q   s    ,a31ur   c                 N    j                  d| |       dj                  | |      S )Nzstars() is invokedz{0} starred {1}xr8   )nickstarsr   s     r   rW   z#Case2_Backend.onJoin.<locals>.starsu   s'    -tU;)00u==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>.ordersy   s>    .?9>rCA,,Q/CFUKKCs   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>   rQ   r;   rW   r^   ra   s   `      r   r?   zCase2_Backend.onJoinh   s      HHX>L0 --&:;;--&:;;--'<==--(>??--(>??HH,-s   B#B&Nr@   r2   r   r   rM   rM   f   s    				. 
	.r   rM   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)Nr6   r   rb   zPinged!rc   rF   rG   z	Add2: {0}rd   zStarred 1: {0}Homer)rV   zStarred 2: {0}rh   )rW   zStarred 3: {0})rV   rW   zStarred 4: {0}re   coffeezOrders 1: {0}
   )r\   zOrders 2: {0}rf   zArglen 1: {0})rS   rT   czArglen 2: {0}zArglen 3: {0}	finishing)r)   r   rH   r"   r.   )r   r>   rJ   starredr^   
arglengthss         r   r?   zCase2_Frontend.onJoin   sN     HHX(N))011HHY		"61==CHH['',- II&;<<GHH%,,W56 II&;'IJJGHH%,,W56 II&;1IEEGHH%,,W56 II&;'QRISSGHH%,,W5699%;XFFFHH_++F3499%;XR9PPFHH_++F34#yy)?@@JHH_++J78#yy)?AqIIJHH_++J78#yy)?1QyOOJHH_++J78#yy)?AqAQRVWyXXJHH_++J78HH[!KKMs   J1J3Nr@   r2   r   r   rj   rj      s    			,	 
,	r   rj   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 )Nru   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	componentro   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   r4   rD   r-   s    r   
test_case1zTestRpc.test_case1        //=."ABB   !c              #   F   K   | j                  t        t        g       y wr   )r   rM   rj   r-   s    r   
test_case2zTestRpc.test_case2   r   r   )r$   r/   r0   rx   ry   rz   skipr}   r   rA   r   r   r   r2   r   r   rt   rt      su    ::>>+,4@D	" 
			 
	  
			C 
	C 
			C 
	Cr   rt   )rx   ry   rz   autobahn.twisted.utilr   autobahn.twistedr   twisted.trialr   twisted.internetr   twisted.applicationr   r   r
   r4   rD   rM   rj   TestCasert   r2   r   r   <module>r      s   6 
::>>-'+%&&+*// *B    !. !.F/ /b!C(## !C{ (r   