o
    ¼>h†  ã                   @   s¾   d dl Z e j dd¡r]d 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
„ d
ejƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ dejƒZdS dS )é    NÚUSE_TWISTEDF)Úsleep)Úwamp)Úunittest)Údefer)Úservicec                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú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                 C   s0   t j | |¡ |jd | _d| _d| _d| _d S )NÚtestFé   )r   ÚApplicationSessionÚ__init__Úextrar	   ÚstopÚ_loglineÚfinished)ÚselfÚconfig© r   ú†/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/autobahn/wamp/test/test_wamp_component.pyr   ,   s
   
zCaseComponent.__init__c                 G   sj   t |ƒdkrd dd„ |D ƒ¡}nt |ƒdkr|d }nd}d | j| jj|¡}|  jd7  _t|ƒ d S )Nr
   z, c                 s   s    | ]}t |ƒV  qd S ©N)Ústr)Ú.0Úsr   r   r   Ú	<genexpr>5   s   € z$CaseComponent.log.<locals>.<genexpr>r   ú-z= : {0:>3} : {1:<20} : {2})ÚlenÚjoinÚformatr   Ú	__class__Ú__name__Úprint)r   ÚargsÚsargsÚmsgr   r   r   Úlog3   s   
zCaseComponent.logc                 C   s*   | j s| jj d ¡ d| _ d S tdƒ d S )NTzalready finished)r   r	   ÚdeferredÚcallbackr    ©r   r   r   r   Úfinish?   s   
zCaseComponent.finishN)r   Ú
__module__Ú__qualname__Ú__doc__r   r$   r(   r   r   r   r   r   %   s
    r   c                   @   ó   e Zd Zejdd„ ƒZdS )ÚCase1_Backendc                 #   s<    ˆ   d¡ ‡ fdd„}ˆ  |d¡V  ˆ   d¡ ˆ  ¡  d S )NÚjoinedc                    s   ˆ   d | |¡¡ | | S )Nzadd2 invoked: {0}, {1}©r$   r   )ÚxÚyr'   r   r   Úadd2M   s   z"Case1_Backend.onJoin.<locals>.add2úcom.mathservice.add2zadd2 registered)r$   Úregisterr(   )r   Údetailsr2   r   r'   r   ÚonJoinH   s   €

zCase1_Backend.onJoinN©r   r)   r*   r   ÚinlineCallbacksr6   r   r   r   r   r-   F   ó    r-   c                   @   r,   )ÚCase1_Frontendc              
   c   sr    |   d¡ z
|  ddd¡V }W n ty* } z|   d |¡¡ W Y d }~nd }~ww |   d |¡¡ |  ¡  d S )Nr.   r3   é   é   zcall error: {0}zcall result: {0})r$   ÚcallÚ	Exceptionr   r(   )r   r5   ÚresÚer   r   r   r6   X   s   €
€ÿzCase1_Frontend.onJoinNr7   r   r   r   r   r:   V   r9   r:   c                   @   r,   )ÚCase2_Backendc                 #   s     ˆ   d¡ ‡ fdd„}‡ fdd„}d‡ fdd	„	}d‡ fdd„	}‡ fdd„}ˆ  |d¡V  ˆ  |d¡V  ˆ  |d¡V  ˆ  |d¡V  ˆ  |d¡V  ˆ   d¡ d S )Nr.   c                      s   ˆ   d¡ d S )Nzping() is invoked©r$   r   r'   r   r   Úpingm   s   
z"Case2_Backend.onJoin.<locals>.pingc                    s   ˆ   d| |¡ | | S )Nzadd2() is invokedrB   )ÚaÚbr'   r   r   r2   q   s   z"Case2_Backend.onJoin.<locals>.add2Úsomebodyr   c                    s   ˆ   d| |¡ d | |¡S )Nzstars() is invokedz{0} starred {1}xr/   ©ÚnickÚstarsr'   r   r   rI   u   s   z#Case2_Backend.onJoin.<locals>.starsé   c                    s(   ˆ   d| |¡ dd„ tdƒD ƒd |… S )Nzorders() is invokedc                 S   s   g | ]}d   |¡‘qS )zProduct {0})r   )r   Úir   r   r   Ú
<listcomp>{   s    z8Case2_Backend.onJoin.<locals>.orders.<locals>.<listcomp>é2   )r$   Úrange)ÚproductÚlimitr'   r   r   Úordersy   s   z$Case2_Backend.onJoin.<locals>.ordersc                     s   ˆ   d| |¡ t| ƒt|ƒgS )Nzarglen() is invoked)r$   r   )r!   Úkwargsr'   r   r   Úarglen}   s   z$Case2_Backend.onJoin.<locals>.arglenúcom.arguments.pingúcom.arguments.add2úcom.arguments.starsúcom.arguments.ordersúcom.arguments.arglenzprocedures registered)rF   r   )rJ   )r$   r4   )r   r5   rC   r2   rI   rQ   rS   r   r'   r   r6   h   s   €
zCase2_Backend.onJoinNr7   r   r   r   r   rA   f   r9   rA   c                   @   r,   )ÚCase2_Frontendc              	   c   s¬   |   d¡ tdƒV  |  d¡V  |   d¡ |  ddd¡V }|   d |¡¡ |  d	¡V }|   d
 |¡¡ | jd	ddV }|   d |¡¡ | jd	ddV }|   d |¡¡ | jd	dddV }|   d |¡¡ |  dd¡V }|   d |¡¡ | jddddV }|   d |¡¡ |  d¡V }|   d |¡¡ |  dddd¡V }|   d |¡¡ | jdddddV }|   d |¡¡ | jddddddddV }|   d |¡¡ |   d¡ |  ¡  d S )Nr.   r
   rT   zPinged!rU   r;   r<   z	Add2: {0}rV   zStarred 1: {0}ÚHomer)rH   zStarred 2: {0}rJ   )rI   zStarred 3: {0}rG   zStarred 4: {0}rW   ÚcoffeezOrders 1: {0}é
   )rP   zOrders 2: {0}rX   zArglen 1: {0})rD   rE   ÚczArglen 2: {0}zArglen 3: {0}Ú	finishing)r$   r   r=   r   r(   )r   r5   r?   ÚstarredrQ   Ú
arglengthsr   r   r   r6   ‹   s:   €



zCase2_Frontend.onJoinNr7   r   r   r   r   rY   ‰   r9   rY   c                   @   sR   e Zd Zej d¡du rdZdd„ Zej	dd„ ƒZ
ej	dd	„ ƒZej	d
d„ ƒZdS )ÚTestRpcÚWAMP_ROUTER_URLNz`Please provide WAMP_ROUTER_URL environment with url to WAMP router to run WAMP integration testsc                 C   s   t j d¡| _d| _d S )Nrb   Úrealm1)ÚosÚenvironÚgetÚurlÚrealmr'   r   r   r   ÚsetUpÀ   s   
zTestRpc.setUpc                 c   s`    t  ¡ | _t ¡ }|D ]}tj| jt| d| j	|d}| 
|¡ q| ¡  | jV  | ¡  d S )N)r	   )rg   r   rh   Úmake)r   ÚDeferredr%   r   ÚMultiServicer   ÚServicerg   Údictrh   ÚsetServiceParentÚstartServiceÚstopService)r   Ú
componentsÚappÚ	componentr]   r   r   r   Ú
runOneTestÄ   s   €
üzTestRpc.runOneTestc                 c   ó    |   ttg¡V  d S r   )ru   r-   r:   r'   r   r   r   Ú
test_case1Õ   ó   €zTestRpc.test_case1c                 c   rv   r   )ru   rA   rY   r'   r   r   r   Ú
test_case2Ù   rx   zTestRpc.test_case2)r   r)   r*   rd   re   rf   Úskipri   r   r8   ru   rw   ry   r   r   r   r   ra   º   s    

ra   )rd   re   rf   Úautobahn.twisted.utilr   Úautobahn.twistedr   Útwisted.trialr   Útwisted.internetr   Útwisted.applicationr   r   r   r-   r:   rA   rY   ÚTestCasera   r   r   r   r   Ú<module>   s   !#1 â