o
    @Bi                     @   st  d dl mZ d dlZd dlZejddrd dlmZmZm	Z	 d dlm
Z
mZmZ d dlmZ d dlZ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mZmZmZmZmZ d dlmZ d dl m!Z!m"Z" d dl m#Z#m$Z$ d dl%m&Z& d dl'm(Z( ere)Z*G dd de+Z,G dd dej-Z.G dd dej-Z/G dd dej-Z0G dd dej-Z1G dd dej-Z2dS dS )    )absolute_importNUSE_TWISTEDF)inlineCallbacksDeferredreturnValue)succeedfailDeferredList)unittest)PY3)util)ApplicationSession)Session)messagerole
serializertypesuriCloseDetails)CallRequest)ApplicationErrorNotAuthorized)
InvalidUriProtocolError)create_authenticator)IAuthenticatorc                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )MockTransportc                 C   sv   d| _ || _t | _i | _i | _i | _| j|  t	
 | _t t d}t| j|}| j| t | _d S )NF)brokerdealer)_log_handlerr   JsonSerializer_serializer_registrations_invocations_subscription_topicsonOpenr   id_my_session_idr   RoleBrokerFeaturesRoleDealerFeaturesr   Welcome	onMessager   _fake_router_session)selfhandlerrolesmsg r2   `/var/www/html/Trade-python/venv/lib/python3.10/site-packages/autobahn/wamp/test/test_protocol.py__init__7   s   

zMockTransport.__init__c                 C   s   | j td| d S )Nr   )r    r,   r   Unregistered)r.   reg_idr2   r2   r3   drop_registrationJ   s   
zMockTransport.drop_registrationc           	      C   s  | j r| j|\}}td| d }t|tjrW|j	dr0|j
r.t|j| jj }n4t|jdkrCttjj|jd}n!|j	drKnttjj|jd}nt|tjr|jdkrltj|jdgd	}n|jd
kr|tj|jg dd	}n|jdkrtj|jg ddddd}n|j	dr| j|j }| jj }|| jv rtd|j| j|< tj|||j|j|jd}nttjj|jd}nt|tjr|j| jv r| j|j }tj||j|j|jd}n{t|tjr|j}|| j v r| j | }n| jj }|| j |< t!|j|}nSt|tj"rt#|j}nEt|tj$r:| jj }|| j|j< t%|j|}n*t|tj&rHt'|j}nt|tjrd| j|j }tjtjj||j(|j|jd}|r| j rz| j|\}}td| | j)*| d S d S )Nz	Send: {0}z	com.myappr   zwamp.error.invalid_uriznoreply.zwamp.error.not_authorizedcom.myapp.procedure1d   argscom.myapp.procedure2         com.myapp.procedure3bar   foobazr;   kwargszcom.myapp.myproczduplicate invocation)r;   rH   receive_progresszwamp.error.no_such_procedure)r;   rH   progresszReceive: {0})+r   r"   	serializeprintformat
isinstancer   Publishtopic
startswithacknowledge	Publishedrequestr-   _request_id_gennextlenErrorMESSAGE_TYPECall	procedureResultr#   r$   r   
Invocationr;   rH   rI   YieldrJ   	Subscriber%   
SubscribedUnsubscribeUnsubscribedRegister
Registered
Unregisterr5   errorr    r,   )	r.   r1   payloadisbinaryreplyregistrationrT   rP   reply_idr2   r2   r3   sendO   s   





zMockTransport.sendc                 C      dS NTr2   r.   r2   r2   r3   isOpen      zMockTransport.isOpenc                 C      d S Nr2   ro   r2   r2   r3   close   rq   zMockTransport.closec                 C   rr   rs   r2   ro   r2   r2   r3   abort   rq   zMockTransport.abortN)	__name__
__module____qualname__r4   r7   rl   rp   rt   ru   r2   r2   r2   r3   r   5   s    Tr   c                   @      e Zd Zdd Zdd ZdS )	TestClosec                 C   s   t  }t| |d d S )NF)r   r   onClose)r.   r/   r2   r2   r3   test_server_abort   s   zTestClose.test_server_abortc                 C   s<   t  }t| tt }tdd|i |jd< |t  d S )Nr>   rE   )r   r   r   	Exceptionr   
_call_reqsonLeaver   )r.   r/   deferredr2   r2   r3   test_reject_pending   s
   
zTestClose.test_reject_pendingN)rv   rw   rx   r|   r   r2   r2   r2   r3   rz      s    rz   c                   @   ry   )TestRegisterDecoratorc                 C      G dd dt }| }t |_|j|dd | dt|jj |jjd }| d|d  | d d d }| d|j	 d S )	Nc                   @   s   e Zd Zeddd ZdS )z1TestRegisterDecorator.test_prefix.<locals>.Prefixmethod_namec                 S   rr   rs   r2   ro   r2   r2   r3   some_method      z=TestRegisterDecorator.test_prefix.<locals>.Prefix.some_methodNrv   rw   rx   r   registerr   r2   r2   r2   r3   Prefix       r   zcom.example.prefix.prefixr>   r   rl   zcom.example.prefix.method_name
r   mockMock
_transportr   assertEqualrW   
mock_calls	call_listr[   )r.   r   sessioncallregr2   r2   r3   test_prefix   s   
z!TestRegisterDecorator.test_prefixc                 C   r   )	Nc                   @   s   e Zd Zeddd ZdS )z3TestRegisterDecorator.test_auto_name.<locals>.MagicNc                 S   rr   rs   r2   ro   r2   r2   r3   r      r   z?TestRegisterDecorator.test_auto_name.<locals>.Magic.some_methodr   r2   r2   r2   r3   Magic   r   r   zcom.example.r   r>   r   rl   zcom.example.some_methodr   )r.   r   r   r   r   r2   r2   r3   test_auto_name   s   
z$TestRegisterDecorator.test_auto_nameN)rv   rw   rx   r   r   r2   r2   r2   r3   r      s    r   c                   @   s   e Zd Zedd Zedd Zedd Zedd Zed	d
 Zedd Z	edd Z
edd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd  Zed!d" Zd#d$ Zed%d& Zd'd( Zd)S )*TestPublisherc                 c   s    t  }t| |dV }| |d  |ddddV }| |d  |jdddddddV }| |d  |jdtjdd	d
V }| |d  |jddddddtjdg dddV }| |d  |jddddddtjdg ddddV }| |d  d S )Ncom.myapp.topic1r>   r?   r@   rC   hellorE   rB   F)
exclude_meoptionsr9      i,  )r   excluderE   rB   r   T)r   r   retain)r   r   publishr   r   PublishOptionsr.   r/   publicationr2   r2   r3   test_publish   s   (*zTestPublisher.test_publishc              
   c   s    t  }t| |jdtjddd}tjddd}||V  z|V  W d S  tyG } z| d|j	 | d|j
 W Y d }~d S d }~ww )Nnoreply.fooTrR   r   testinghow are you?reasonr   )r   r   r   r   r   r   r   r   r   rf   r   )r.   r/   r   detailser2   r2   r3   test_publish_outstanding_errors   s    
z-TestPublisher.test_publish_outstanding_errorsc              
   #   s    t  }t| t  |jdtjddd}g  fdd}|| tjddd	}|| | 	d
t
  d  z|V  W d S  tyd } z| 	d|j | 	d|j W Y d }~d S d }~ww )Nr   Tr   r   c                    s    |   S rs   )append)r   error_d
got_errorsr2   r3   errback(  s   
zLTestPublisher.test_publish_outstanding_errors_async_errback.<locals>.errbackr   r   r   r>   )r   r   r   r   r   r   
addErrbackr   r   r   rW   callbackr   rf   r   )r.   r/   publication_dr   r   r   r2   r   r3   -test_publish_outstanding_errors_async_errback  s,   



z;TestPublisher.test_publish_outstanding_errors_async_errbackc                 c   s(   t  }t| |jdtjdddV }| t|jtt	fv  |jddddtjdddV }| t|jtt	fv  |jdddddd	tjddd
V }| t|jtt	fv  |jdtjddddV }| t|jtt	fv  |jdddddd	tjdg dddd
V }| t|jtt	fv  d S )Nr   Tr   r   r>   r?   r@   rC   r   r   F)r   rR   r   )r   r   rR   )
r   r   r   r   r   
assertTruetyper'   intlongr   r2   r2   r3   test_publish_acknowledgedA  s   "*z'TestPublisher.test_publish_acknowledgedc                 c   sP    t  }t| tjdd}| |jd|dtV  | |jd|dtV  d S NTr   zde.myapp.topic1r   foobar)r   r   r   r   assertFailurer   r   r.   r/   r   r2   r2   r3    test_publish_undefined_exceptionU  s   z.TestPublisher.test_publish_undefined_exceptionc                 c   sd    t  }t| tjdd}|t | |jd|dtV  |t | |jd|dtV  d S r   )	r   r   r   r   definer   r   r   r   r   r2   r2   r3   test_publish_defined_exception_  s   

z,TestPublisher.test_publish_defined_exceptionc              
   c   s    t  }t| |dV }| |d |ddddV }| |d |jdddddddV }| |d |jdtjd	d
dV }| |d |jddddddtjd	d
dV }| |d d S )Nr8   r9   r>   r?   r@   rC   r   r   i'  )timeoutr   r   )r   r   r   r   r   CallOptionsr.   r/   resr2   r2   r3   	test_calll  s   "zTestPublisher.test_callc                 c   s    t  }t| |dV }| |tj | |jd | |ji  |dV }| |tj | |jd | |jddd d S )Nr<   r=   rA   rB   rC   rD   )	r   r   r   assertIsInstancer   
CallResultr   results	kwresultsr   r2   r2   r3   test_call_with_complex_result  s   z+TestPublisher.test_call_with_complex_resultc                 c   s    t  }t| dd }||dV }| t|jttfv  |j|dtj	dddV }| t|jttfv  |j|dtj	ddddV }| t|jttfv  d S )	Nc                  _      t d| | d S Nz	got eventrL   rG   r2   r2   r3   on_event     z.TestPublisher.test_subscribe.<locals>.on_eventr   wildcardmatchr   T)r   get_retained)
r   r   	subscriber   r   r'   r   r   r   SubscribeOptionsr.   r/   r   subscriptionr2   r2   r3   test_subscribe  s   zTestPublisher.test_subscribec                 #   s    t  }t| t  t | fdddV }|fdddV }| |j|jk |jdtjddddV }|	t
|j|j |  jd	 | jd	 d S )
Nc                      
     dS N*   r   r2   event0r2   r3   <lambda>     
 z5TestPublisher.test_double_subscribe.<locals>.<lambda>r   c                      r   NrE   r   r2   event1r2   r3   r     r   TFrR   r   r   Missing callback)r   r   r   r   r   r'   r   r   r   r,   r   Eventcalled)r.   r/   subscription0subscription1r   r2   )r   r   r3   test_double_subscribe  s&   z#TestPublisher.test_double_subscribec                 #   s    t  t fdd}|_t  t  fdddV }fdddV }| |j|jk | V  jdt	j
ddd	d
V }t|j|j |  jd | j d dS )z}
            Make sure we correctly deal with unsubscribing one of our handlers
            from the same topic.
            c                    s   t | tjrJ t | S rs   )rN   r   rb   r   r,   r1   )r/   r2   r3   r,     s   zITestPublisher.test_double_subscribe_single_unsubscribe.<locals>.onMessagec                      r   r   r   r2   r   r2   r3   r     r   zHTestPublisher.test_double_subscribe_single_unsubscribe.<locals>.<lambda>r   c                      r   r   r   r2   r   r2   r3   r     r   TFr   r   r   Second callback fired.N)r   r   r,   r   r   r   r'   unsubscriber   r   r   r   r   r   r.   r,   r   r   r   r2   )r   r   r/   r3   (test_double_subscribe_single_unsubscribe  s,   
z6TestPublisher.test_double_subscribe_single_unsubscribec                 #   s   t  t t fdd}|_t  t  fdddV }fdddV }| |j|jk | V  | V  jsIJ j	dt
jddd	d
V }zt|j|j | d W n	 tyq   Y nw |  j d | j d dS )z
            If we subscribe twice, and unsubscribe twice, we should then get
            an Unsubscribed message.
            c                    s"   t | tjr|  t | S rs   )rN   r   rb   r   r   r,   r   )r/   unsubscribed_dr2   r3   r,     s   
zITestPublisher.test_double_subscribe_double_unsubscribe.<locals>.onMessagec                      r   r   r   r2   r   r2   r3   r     r   zHTestPublisher.test_double_subscribe_double_unsubscribe.<locals>.<lambda>r   c                      r   r   r   r2   r   r2   r3   r     r   TFr   r   zExpected ProtocolErrorzFirst callback fired.r   N)r   r   r   r,   r   r   r'   r   r   r   r   r   r   r   r   r   r   r2   )r   r   r/   r   r3   (test_double_subscribe_double_unsubscribe  s<   


z6TestPublisher.test_double_subscribe_double_unsubscribec                 #   s    t  }t| t  t fdd}| fdddV }||dtjddV }|j|jk |jdtj	dd	d
dV }|
tj|j|jdgd  j j  jd jd dS )z
            Test various error-conditions when we try to add a second
            subscription-handler (its signature must match any
            existing handlers).
            c                     s2    d|v   t|d tj  |  d S )Nboom)r   rN   r   EventDetailsr   )r;   kw)r   r.   r2   r3   second)  s   z:TestPublisher.test_double_subscribe_errors.<locals>.secondc                    s
     | S rs   r   argr   r2   r3   r   1  r   z<TestPublisher.test_double_subscribe_errors.<locals>.<lambda>r   r   details_argTFr   r   arg0r:   )r  N)r   r   r   r   r   r   r   r'   r   r   r,   r   r   r   r   result)r.   r/   r   r   r   r   r2   )r   r   r.   r3   test_double_subscribe_errors  s2   
z*TestPublisher.test_double_subscribe_errorsc                 #   s    t  }t| td t  fdd}||_ fdd}||dV }|jdtjddd	d
V }t	
|j|j}|| | j dS )zK
            Ensure we handle an exception from the user code.
            zwe have a problemc                    s    | j krd d S d S rn   )valuer   r   r1   error_instance	got_err_dr2   r3   observerW  s   
z?TestPublisher.test_publish_callback_exception.<locals>.observerc                          rs   r2   r2   )r  r2   r3   r   \  rq   z;TestPublisher.test_publish_callback_exception.<locals>.boomr   TFr   r   N)r   r   RuntimeErrorr   onUserErrorr   r   r   r   r   r   r'   r,   r   r   )r.   r/   r
  r   subr   r1   r2   r  r3   test_publish_callback_exceptionL  s    
z-TestPublisher.test_publish_callback_exceptionc                 c   4    t  }t| dd }||dV }| V  d S )Nc                  _   r   r   r   rG   r2   r2   r3   r   s  r   z0TestPublisher.test_unsubscribe.<locals>.on_eventr   )r   r   r   r   r   r2   r2   r3   test_unsubscriben     zTestPublisher.test_unsubscribec                 c   st    t  }t| dd }||dV }| t|jttfv  |j|dtj	dddV }| t|jttfv  d S )Nc                  _   r   Nzgot callr   rG   r2   r2   r3   on_call~  r   z,TestPublisher.test_register.<locals>.on_callr8   r   r   r   )
r   r   r   r   r   r'   r   r   r   RegisterOptionsr.   r/   r  rj   r2   r2   r3   test_registery  s   zTestPublisher.test_registerc                 c   r  )Nc                  _   r   r  r   rG   r2   r2   r3   r    r   z.TestPublisher.test_unregister.<locals>.on_callr8   )r   r   r   
unregisterr  r2   r2   r3   test_unregister  r  zTestPublisher.test_unregisterc                 C   sp   t jjdk rd S t }t|}| t}|t	dd W d    n1 s(w   Y  | 
dt|j d S )N   r   i  z3UNREGISTERED received for non-existant registration)twistedversionmajorr   r   assertRaisesr   rl   r   re   assertInstr	exception)r.   r/   	transportctxr2   r2   r3   $test_unregister_no_such_registration  s   
z2TestPublisher.test_unregister_no_such_registrationc                 #   sL    t  }t|} fdd d _| dV }||j |  j d S )Nc                     s
   d _ d S rn   )r   rG   r  r2   r3   r    s   
z2TestPublisher.test_unregister_log.<locals>.on_callFr8   )r   r   r   r   r7   r'   assertFalse)r.   r/   r"  rj   r2   r%  r3   test_unregister_log  s   z!TestPublisher.test_unregister_logc                    s\   g  G  fdddt }| }t| |d | t d | t d d t d S )Nc                       s"   e Zd Z fddZdddZdS )z7TestPublisher.test_on_disconnect_error.<locals>.AppSessc                    s     |j|f d S rs   r   r  )r.   r   r1   errorsr2   r3   r       zCTestPublisher.test_on_disconnect_error.<locals>.AppSess.onUserErrorsnarkc                 S   s   t d)NzThis shouldn't happen)r  )r.   rE   rB   quuxr2   r2   r3   onDisconnect  s   zDTestPublisher.test_on_disconnect_error.<locals>.AppSess.onDisconnectN)r,  )rv   rw   rx   r  r.  r2   r)  r2   r3   AppSess  s    r/  Fr>   r   )r   r   r{   r   rW   r   rN   	TypeError)r.   r/  sr2   r)  r3   test_on_disconnect_error  s   
z&TestPublisher.test_on_disconnect_errorN)rv   rw   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r$  r'  r2  r2   r2   r2   r3   r      sN    


(

	





*
4
/
!





r   c                   @   s   e Zd Zedd Zedd Zedd Zedd Zed	d
 Zedd Z	edd Z
edd Zedd Zedd ZdS )TestInvokerc                 c   sB    t  }t| dd }||dV  |dV }| |d d S )Nc                   S   rm   NrC   r2   r2   r2   r2   r3   myproc1  rq   z(TestInvoker.test_invoke.<locals>.myproc1com.myapp.myproc1rC   )r   r   r   r   r   )r.   r/   r5  r   r2   r2   r3   test_invoke  s   zTestInvoker.test_invokec                 c   s\    t  }t| dd }||dV  |d}|d}t||gV }| |ddg d S )Nc                   S   rm   r4  r2   r2   r2   r2   r3   r5    rq   z.TestInvoker.test_invoke_twice.<locals>.myproc1r6  TrC   )r   r   r   r   r	   r   )r.   r/   r5  d0d1r   r2   r2   r3   test_invoke_twice  s   

zTestInvoker.test_invoke_twicec           	      #   s    t  }t  }t|}t|}fdd|j |j fdd|_fdd|_dd }||dV  ||dV  |d}|d}t||gV }|d	d	g d
S )zW
            make sure each session independently generates sequential IDs
            c                    sD   t |tjr |jd | |S t |tjr |jd | |S )Nr>   r?   )rN   r   rc   r   rT   rZ   )origr1   ro   r2   r3   verify_seq_id  s   zCTestInvoker.test_invoke_request_id_sequences.<locals>.verify_seq_idc                    
    | S rs   r2   r   )orig0r=  r2   r3   r     r   z>TestInvoker.test_invoke_request_id_sequences.<locals>.<lambda>c                    r>  rs   r2   r   )orig1r=  r2   r3   r     r   c                   S   rm   r4  r2   r2   r2   r2   r3   r5    rq   z=TestInvoker.test_invoke_request_id_sequences.<locals>.myproc1r6  r8  N)r   r   rl   r   r   r	   r   )	r.   handler0handler1trans0trans1r5  r9  r:  r   r2   )r?  r@  r.   r=  r3    test_invoke_request_id_sequences  s"   

z,TestInvoker.test_invoke_request_id_sequencesc              
   #   s    t  }d|_t| g   fdd}||_tdfdd}||dV  z|dV  | d W n tyN } z| 	t
|t W Y d }~nd }~ww | d	t  |  d
 d
  d S )NTc                         | j|f d S rs   r(  r  r)  r2   r3   	log_error  r+  z6TestInvoker.test_invoke_user_raises.<locals>.log_errorrE   c                      r  rs   r2   r2   )
name_errorr2   r3   bing  rq   z1TestInvoker.test_invoke_user_raises.<locals>.bingzcom.myapp.myproc99zExpected an errorr>   r   )r   traceback_appr   r  	NameErrorr   r   r   r}   r   rN   r  r   rW   )r.   r/   rG  rI  r   r2   )r*  rH  r3   test_invoke_user_raises  s&   z#TestInvoker.test_invoke_user_raisesc                 #   s    t  }t| tdfdd	}ttdd td  fdd}||dtjd	d
V  |j	dtj
|ddV }d| tdD ]} | j | | j qDd S )Nc                 3   sN      | d u   | jd u tdD ]}| | t|V  qtd d S )N
   r   )r   rJ   ranger   r   )r   iro   r2   r3   rI  *  s   
z8TestInvoker.test_invoke_progressive_result.<locals>.bingc                 S   s   t  S rs   )r   )_r2   r2   r3   r   3  s    z<TestInvoker.test_invoke_progressive_result.<locals>.<lambda>rM  c                    s    |   |  d S rs   r   r   )progressiver2   r3   rJ   5  s   z<TestInvoker.test_invoke_progressive_result.<locals>.progresscom.myapp.myproc2r   r   on_progressr   r   rs   )r   r   r   listmaprN  r   r   r  r   r   r   r   r   r  )r.   r/   rI  rJ   r   rO  r2   )rQ  r.   r3   test_invoke_progressive_result%  s*   

z*TestInvoker.test_invoke_progressive_resultc                 #   s    t  }t| tdfdd	}t  tdg fdd}||_d fdd	}||dtjd	d
V  |j	ddtj
|dddV }d|  j d j dt d d  d S )Nc                 3   s\      |d u   |jd u  |d  d|  |jddd tdV  td d S )Nwordr   lifenothing)	somethingz
meaning ofr   )r   rJ   r   r   r   )r   r   keyro   r2   r3   rI  M  s   
z>TestInvoker.test_invoke_progressive_result_error.<locals>.bingrE   c                    rF  rs   r(  r  )logged_errorsr2   r3   	got_error[  r+  zCTestInvoker.test_invoke_progressive_result_error.<locals>.got_errorc                    s    d|  |  )NrZ  )r   r   )r   r[  )got_progressprogress_errorr.   r2   r3   rJ   _  s   
zBTestInvoker.test_invoke_progressive_result_error.<locals>.progressrR  r   r   r   rS  rX  )r   r\  r   rY  r>   r   )NNrs   )r   r   r   r   rK  r  r   r   r  r   r   r   r   r   r  rW   )r.   r/   rI  r^  rJ   r   r2   )r_  r]  r`  r.   r3   $test_invoke_progressive_result_errorH  s6   	

z0TestInvoker.test_invoke_progressive_result_errorc                 #   s    t  }t| tdfdd	}t   fdd}||dtjddV  |jdtj|dd	V }	d
| 
 j d S )Nc                 3   s>      | d u   | jd u |   tdV  td d S )NTr   r   rJ   r   r   r   ro   r2   r3   rI    s   
z@TestInvoker.test_invoke_progressive_result_no_args.<locals>.bingc                      s     d d S )Nzintentionally left blankr   r2   r_  r2   r3   rJ        zDTestInvoker.test_invoke_progressive_result_no_args.<locals>.progressrR  r   r   rS  r   r   rs   )r   r   r   r   r   r   r  r   r   r   r   r   r.   r/   rI  rJ   r   r2   r_  r.   r3   &test_invoke_progressive_result_no_args{  s$   

z2TestInvoker.test_invoke_progressive_result_no_argsc                 #   s    t  }t| tdfdd	}t  d fdd	}||dtjddV  |jdtj|dd	V }	d
| 
 j 	d j d S )Nc                 3   sB      | d u   | jd u | jdd tdV  td d S )NrX  r\  Tr   rb  rc  ro   r2   r3   rI    s   
zDTestInvoker.test_invoke_progressive_result_just_kwargs.<locals>.bingc                    s     |  d S rs   r   ri  rd  r2   r3   rJ     re  zHTestInvoker.test_invoke_progressive_result_just_kwargs.<locals>.progressrR  r   r   rS  r   r   rX  rs   )r   r   r   r   r   r   r  r   r   r   r   r   r  rf  r2   rg  r3   *test_invoke_progressive_result_just_kwargs  s&   

z6TestInvoker.test_invoke_progressive_result_just_kwargsc              
   #   s    t  }t| td  fdd}||dV }z=z|dV  |   W n  tyF } z| |t | 	|
 d W Y d }~nd }~ww W | V  d S W | V  d S | V  w )Nza simple errorc                      r  rs   r2   r2   r!  r2   r3   raiser  rq   z<TestInvoker.test_call_exception_runtimeerror.<locals>.raisercom.myapp.myproc_errorz(wamp.error.runtime_error: a simple error)r   r   r  r   r   r   r}   r   r   r   error_messager  r.   r/   rl  registration0r   r2   rk  r3    test_call_exception_runtimeerror  s$   z,TestInvoker.test_call_exception_runtimeerrorc              
   #   s    t  }t| t   fdd}||dV }z5z|dV  |   W n ty= } z| |t W Y d }~nd }~ww W | V  d S W | V  d S | V  w )Nc                      r  rs   r2   r2   rk  r2   r3   rl    rq   z4TestInvoker.test_call_exception_bare.<locals>.raiserrm  )	r   r   r}   r   r   r   r   r   r  ro  r2   rk  r3   test_call_exception_bare  s"   z$TestInvoker.test_call_exception_bareN)rv   rw   rx   r   r7  r;  rE  rL  rW  ra  rh  rj  rq  rr  r2   r2   r2   r3   r3    s*    


!
 
"
2

 
r3  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestAuthenticatorc                 C   s|   t t }tdddd}tdddd}|| | t}|| W d    n1 s.w   Y  dt|jv s<J d S )Nwampcraalicep4ssw0rd)authidsecretbob
password42authids)	r   r   r   r   add_authenticatorr  
ValueErrorr   r!  )r.   r   auth0auth1r#  r2   r2   r3   test_inconsistent_authids  s    
z+TestAuthenticator.test_inconsistent_authidsc                 C   sd   t t }G dd dt}| }ddd|_i |_| }ddd|_i |_|| || d S )Nc                   @       e Zd ZdZdd Zdd ZdS )zDTestAuthenticator.test_two_authenticators.<locals>.TestAuthenticatortestc                 S      t rs   NotImplementedErrorr.   r   	challenger2   r2   r3   on_challenge  rq   zQTestAuthenticator.test_two_authenticators.<locals>.TestAuthenticator.on_challengec                 S   r  rs   r  r.   	authextrar2   r2   r3   
on_welcome  rq   zOTestAuthenticator.test_two_authenticators.<locals>.TestAuthenticator.on_welcomeNrv   rw   rx   namer  r  r2   r2   r2   r3   rs        rs  value0value1r   what)rB   qux)r   r   r   r   r  _argsr|  )r.   r   rs  r~  r  r2   r2   r3   test_two_authenticators  s   

z)TestAuthenticator.test_two_authenticatorsc                 C   s   t t }G dd dt}| }ddd|_i |_| }ddi|_i |_|| | t}|| W d    n1 s?w   Y  | 	dt
|j d S )Nc                   @   r  )zHTestAuthenticator.test_inconsistent_authextra.<locals>.TestAuthenticatorr  c                 S   r  rs   r  r  r2   r2   r3   r  *  rq   zUTestAuthenticator.test_inconsistent_authextra.<locals>.TestAuthenticator.on_challengec                 S   r  rs   r  r  r2   r2   r3   r  -  rq   zSTestAuthenticator.test_inconsistent_authextra.<locals>.TestAuthenticator.on_welcomeNr  r2   r2   r2   r3   rs  &  r  rs  r  r  r   rE   zInconsistent authextra)r   r   r   r   r  r  r|  r  r}  r  r   r!  )r.   r   rs  r~  r  r#  r2   r2   r3   test_inconsistent_authextra#  s    

z-TestAuthenticator.test_inconsistent_authextraN)rv   rw   rx   r  r  r  r2   r2   r2   r3   rs    s    rs  )3
__future__r   osr   environgettwisted.internet.deferr   r   r   r   r   r	   twisted.trialr
   r  sixr   autobahnr   autobahn.twisted.wampr   r   autobahn.wampr   r   r   r   r   r   autobahn.wamp.requestr   autobahn.wamp.exceptionr   r   r   r   autobahn.wamp.authr   autobahn.wamp.interfacesr   r   r   objectr   TestCaserz   r   r   r3  rs  r2   r2   r2   r3   <module>   sN    w)   a  .       