o
    @»BiÔ  ã                   @   sÊ   d dl mZ d dlZej dd¡rcd 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 )é    )Úabsolute_importNÚ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   úa/var/www/html/Trade-python/venv/lib/python3.10/site-packages/autobahn/wamp/test/test_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>7   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   Úlog5   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   ÚfinishA   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   Úadd2O   s   z"Case1_Backend.onJoin.<locals>.add2úcom.mathservice.add2zadd2 registered)r%   Úregisterr)   )r   Údetailsr3   r   r(   r   ÚonJoinJ   s   €

zCase1_Backend.onJoinN©r    r*   r+   r   ÚinlineCallbacksr7   r   r   r   r   r.   H   ó    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/   r4   é   é   zcall error: {0}zcall result: {0})r%   ÚcallÚ	Exceptionr   r)   )r   r6   ÚresÚer   r   r   r7   Z   s   €
€ÿzCase1_Frontend.onJoinNr8   r   r   r   r   r;   X   r:   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   Úpingo   s   
z"Case2_Backend.onJoin.<locals>.pingc                    s   ˆ   d| |¡ | | S )Nzadd2() is invokedrC   )ÚaÚbr(   r   r   r3   s   s   z"Case2_Backend.onJoin.<locals>.add2Úsomebodyr   c                    s   ˆ   d| |¡ d | |¡S )Nzstars() is invokedz{0} starred {1}xr0   ©ÚnickÚstarsr(   r   r   rJ   w   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   Úorders{   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)rG   r   )rK   )r%   r5   )r   r6   rD   r3   rJ   rR   rT   r   r(   r   r7   j   s   €
zCase2_Backend.onJoinNr8   r   r   r   r   rB   h   r:   rB   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   rU   zPinged!rV   r<   r=   z	Add2: {0}rW   zStarred 1: {0}ÚHomer)rI   zStarred 2: {0}rK   )rJ   zStarred 3: {0}rH   zStarred 4: {0}rX   ÚcoffeezOrders 1: {0}é
   )rQ   zOrders 2: {0}rY   zArglen 1: {0})rE   rF   ÚczArglen 2: {0}zArglen 3: {0}Ú	finishing)r%   r   r>   r   r)   )r   r6   r@   ÚstarredrR   Ú
arglengthsr   r   r   r7      s:   €



zCase2_Frontend.onJoinNr8   r   r   r   r   rZ   ‹   r:   rZ   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 )Nrc   Ú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
   )rh   r   ri   Úmake)r   ÚDeferredr&   r   ÚMultiServicer   ÚServicerh   Údictri   ÚsetServiceParentÚstartServiceÚstopService)r   Ú
componentsÚappÚ	componentr^   r   r   r   Ú
runOneTestÆ   s   €
üzTestRpc.runOneTestc                 c   ó    |   ttg¡V  d S r   )rv   r.   r;   r(   r   r   r   Ú
test_case1×   ó   €zTestRpc.test_case1c                 c   rw   r   )rv   rB   rZ   r(   r   r   r   Ú
test_case2Û   ry   zTestRpc.test_case2)r    r*   r+   re   rf   rg   Úskiprj   r   r9   rv   rx   rz   r   r   r   r   rb   ¼   s    

rb   )Ú
__future__r   re   rf   rg   Úautobahn.twisted.utilr   Úautobahn.twistedr   Útwisted.trialr   Útwisted.internetr   Útwisted.applicationr   r   r	   r.   r;   rB   rZ   ÚTestCaserb   r   r   r   r   Ú<module>   s    !#1 â