o
    èó·i†  ã                   @   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 )é    NZ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   úlC:\Users\psant\Downloads\PAF backend\school\venv\Lib\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   ÚargsZ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   Údetailsr0   r   r%   r   ÚonJoinH   s   €

zCase1_Backend.onJoinN©r   r'   r(   r   ÚinlineCallbacksr4   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,   r1   é   é   zcall error: {0}zcall result: {0})r"   ÚcallÚ	Exceptionr   r&   )r   r3   ÚresÚer   r   r   r4   X   s   €
€ÿzCase1_Frontend.onJoinNr5   r   r   r   r   r8   V   r7   r8   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 invokedr@   )ÚaÚbr%   r   r   r0   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   rG   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)rD   r   )rH   )r"   r2   )r   r3   rA   r0   rG   rO   rQ   r   r%   r   r4   h   s   €
zCase2_Backend.onJoinNr5   r   r   r   r   r?   f   r7   r?   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	   rR   zPinged!rS   r9   r:   z	Add2: {0}rT   zStarred 1: {0}ZHomer)rF   zStarred 2: {0}rH   )rG   zStarred 3: {0}rE   zStarred 4: {0}rU   ZcoffeezOrders 1: {0}é
   )rN   zOrders 2: {0}rV   zArglen 1: {0})rB   rC   ÚczArglen 2: {0}zArglen 3: {0}Z	finishing)r"   r   r;   r   r&   )r   r3   r=   ZstarredrO   Z
arglengthsr   r   r   r4   ‹   s:   €



zCase2_Frontend.onJoinNr5   r   r   r   r   rW   ‰   r7   rW   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 )Nr[   Z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   )r_   r   r`   Úmake)r   ZDeferredr#   r   ZMultiServicer   ZServicer_   Údictr`   ZsetServiceParentZstartServiceZstopService)r   Ú
componentsZappÚ	componentrY   r   r   r   Ú
runOneTestÄ   s   €
üzTestRpc.runOneTestc                 c   ó   � |   ttg¡V  d S r   )rf   r+   r8   r%   r   r   r   Ú
test_case1Õ   ó   €zTestRpc.test_case1c                 c   rg   r   )rf   r?   rW   r%   r   r   r   Ú
test_case2Ù   ri   zTestRpc.test_case2)r   r'   r(   r\   r]   r^   Úskipra   r   r6   rf   rh   rj   r   r   r   r   rZ   º   s    

rZ   )r\   r]   r^   Zautobahn.twisted.utilr   Zautobahn.twistedr   Ztwisted.trialr   Ztwisted.internetr   Ztwisted.applicationr   r
   r   r+   r8   r?   rW   ZTestCaserZ   r   r   r   r   Ú<module>   s   !#1 �â