
    8'h                        d dl mZ d dlZd dlZej                  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re)Z* G d de+      Z, G d dejZ                        Z. G d dejZ                        Z/ G d dejZ                        Z0 G d dejZ                        Z1 G d dejZ                        Z2yy)    )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                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)MockTransportc                    d| _         || _        t        j                         | _        i | _        i | _        i | _        | j                  j                  |        t        j                         | _        t        j                         t        j                         d}t        j                   | j                  |      }| j                  j#                  |       t%               | _        y )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msgs       \/var/www/html/trade_iq/venv/lib/python3.12/site-packages/autobahn/wamp/test/test_protocol.py__init__zMockTransport.__init__7   s    DI#DM)88:D"$D "D(*D%MM  &"&'')D $ 7 7 9dF]F]F_`E//$"5"5u=CMM##C((:(<D%    c                 b    | j                   j                  t        j                  d|             y )Nr   )r#   r/   r   Unregistered)r1   reg_ids     r5   drop_registrationzMockTransport.drop_registrationJ   s$    MM##$$Q/r7   c                 F   | j                   r8| j                  j                  |      \  }}t        dj	                  |             d }t        |t        j                        r|j                  j                  d      rQ|j                  r6t        j                  |j                  | j                  j                  j                               }nt!        |j                        dk(  r;t        j"                  t        j                  j$                  |j                  d      }n|j                  j                  d      rnt        j"                  t        j                  j$                  |j                  d      }nGt        |t        j&                        r|j(                  dk(  r$t        j*                  |j                  dg	      }n|j(                  d
k(  r%t        j*                  |j                  g d	      }n|j(                  dk(  r)t        j*                  |j                  g dddd      }n|j(                  j                  d      r| j,                  |j(                     }| j                  j                  j                         }|| j.                  v rt1        d      |j                  | j.                  |<   t        j2                  |||j4                  |j6                  |j8                        }nt        j"                  t        j&                  j$                  |j                  d      }nt        |t        j:                        rk|j                  | j.                  v r[| j.                  |j                     }t        j*                  ||j4                  |j6                  |j<                        }n	t        |t        j>                        r|j                  }|| j@                  v r| j@                  |   }n3| j                  j                  j                         }|| j@                  |<   t        jB                  |j                  |      }npt        |t        jD                        r!t        jF                  |j                        }n5t        |t        jH                        r^| j                  j                  j                         }|| j,                  |j(                  <   t        jJ                  |j                  |      }nt        |t        jL                        r t        jN                  |j                        }nt        |t        j"                        ri| j.                  |j                     }t        j"                  t        j&                  j$                  ||jP                  |j4                  |j6                        }|r`| j                   r8| j                  j                  |      \  }}t        dj	                  |             | jR                  jU                  |       y y )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@   rM   receive_progresszwamp.error.no_such_procedure)r@   rM   progresszReceive: {0})+r"   r%   	serializeprintformat
isinstancer   Publishtopic
startswithacknowledge	Publishedrequestr0   _request_id_gennextlenErrorMESSAGE_TYPECall	procedureResultr&   r'   r   
Invocationr@   rM   rN   YieldrO   	Subscriber(   
SubscribedUnsubscribeUnsubscribedRegister
Registered
Unregisterr9   errorr#   r/   )	r1   r4   payloadisbinaryreplyregistrationrY   rU   reply_ids	            r5   sendzMockTransport.sendO   sA   yy$($4$4$>$>s$C!k((12E#w/99''5 ' 1 1#++t?X?X?h?h?m?m?o p^q(#MM'//*F*FUnoEYY))+6#MM'//*F*FUqrEC.==$;;#NN3;;cUCE]]&==#NN3;;YGE]]&==#NN3;;YX^hjOklE]]--.AB#'#6#6s}}#EL"77GGLLNG$"3"33+,BCC14D%%g.#.. XX"zz),)=)=	E $MM',,*C*CS[[RqrEC/;;$"3"33"//<G#NN7#**_b_k_klEC!2!23		D555#88?H#88HHMMOH7?D--e4**3;;AC!4!45,,S[[9C!1!12#88HHMMO5A##CMM2**3;;EC!3!34,,S[[9C/ ++CKK8LL--II:: 99(,(8(8(B(B5(I%GX.//89''.	 r7   c                      yNT r1   s    r5   isOpenzMockTransport.isOpen   s    r7   c                      y Nrt   ru   s    r5   closezMockTransport.close       r7   c                      y rx   rt   ru   s    r5   abortzMockTransport.abort   rz   r7   N)	__name__
__module____qualname__r6   r;   rq   rv   ry   r|   rt   r7   r5   r   r   5   s"    	=&	
R	/h			r7   r   c                       e Zd Zd Zd Zy)	TestClosec                 P    t               }t        |       |j                  d       y )NF)r   r   onClose)r1   r2   s     r5   test_server_abortzTestClose.test_server_abort   s     (*G'" OOE"r7   c                     t               }t        |       t        t                     }t	        dd|i       |j
                  d<   |j                  t                      y )NrC   rJ   )r   r   r	   	Exceptionr   
_call_reqsonLeaver   )r1   r2   deferreds      r5   test_reject_pendingzTestClose.test_reject_pending   sI    (*G'" IK(H$/5(B$GGq!OOLN+r7   N)r}   r~   r   r   r   rt   r7   r5   r   r      s    	#	,r7   r   c                       e Zd Zd Zd Zy)TestRegisterDecoratorc                     G d dt               } |       }t        j                         |_        |j	                  |d       | j                  dt        |j                  j                               |j                  j                  d   }| j                  d|d          |j                         d   d   d   }| j                  d|j                         y )	Nc                   <    e Zd Z ej                  d      d        Zy)1TestRegisterDecorator.test_prefix.<locals>.Prefixmethod_namec                      y rx   rt   ru   s    r5   some_methodz=TestRegisterDecorator.test_prefix.<locals>.Prefix.some_method       r7   Nr}   r~   r   r   registerr   rt   r7   r5   Prefixr      s    n- .r7   r   zcom.example.prefix.prefixrC   r   rq   zcom.example.prefix.method_name
r   mockMock
_transportr   assertEqualr\   
mock_calls	call_listr`   )r1   r   sessioncallregs        r5   test_prefixz!TestRegisterDecorator.test_prefix   s    + 
 hG!%GW-CD QG$6$6$A$A BC%%003DVT!W-.."1%a(+C>Nr7   c                     G d dt               } |       }t        j                         |_        |j	                  |d       | j                  dt        |j                  j                               |j                  j                  d   }| j                  d|d          |j                         d   d   d   }| j                  d|j                         y )	Nc                   <    e Zd Z ej                  d      d        Zy)3TestRegisterDecorator.test_auto_name.<locals>.MagicNc                      y rx   rt   ru   s    r5   r   z?TestRegisterDecorator.test_auto_name.<locals>.Magic.some_method   r   r7   r   rt   r7   r5   Magicr      s    d# $r7   r   zcom.example.r   rC   r   rq   zcom.example.some_methodr   )r1   r   r   r   r   s        r5   test_auto_namez$TestRegisterDecorator.test_auto_name   s    * 
 gG!%GW_= QG$6$6$A$A BC%%003DVT!W-.."1%a(+C7Gr7   N)r}   r~   r   r   r   rt   r7   r5   r   r      s    	O(	Hr7   r   c                   8   e Zd Zed        Zed        Zed        Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zed
        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zd Zed        Zd Zy)TestPublisherc              #     K   t               }t        |       |j                  d      }| j                  |d        |j                  dddd      }| j                  |d        |j                  dddddd      }| j                  |d        |j                  dt	        j
                  d	      
      }| j                  |d        |j                  ddddddt	        j
                  dg d            }| j                  |d        |j                  ddddddt	        j
                  dg dd            }| j                  |d        y w)Ncom.myapp.topic1rC   rD   rE   rH   hellorJ   rG   F)
exclude_meoptionsr>      i,  )r   excluderJ   rG   r   T)r   r   retain)r   r   publishr   r   PublishOptionsr1   r2   publications      r5   test_publishzTestPublisher.test_publish   sq    (*G'" '0C DDK[$/ '0CQ1 MMK[$/ '0CQ1RTZa bbK[$/ '0CUMaMamrMs ttK[$/ '0CQ1RTZakpkk  LQ  [j  lk  !l  lK[$/ '0CQ1RTZakpkk  LQ  [j  sw  lx  !y  yK[$/s   EEc              #   ~  K   t               }t        |       |j                  dt        j                  d            }t        j
                  dd      }|j                  |       	 | y # t        $ rB}| j                  d|j                         | j                  d|j                         Y d }~y d }~ww xY ww)Nnoreply.fooTrW   r   testinghow are you?reasonr   )r   r   r   r   r   r   r   r   r   rk   r   )r1   r2   r   detailses        r5   test_publish_outstanding_errorsz-TestPublisher.test_publish_outstanding_errors   s     (*G'"
 "//,,> * K ((
OTG//'**=!!# =  QWW5  !))<<=s0   A'B=*A/ .B=/	B:88B50B=5B::B=c              #     K   t               }t        |       t               |j                  dt	        j
                  d            }g fd}|j                  |       t	        j                  dd      }|j                  |       | j                  d	t                     j                  d        	 | y # t        $ rB}| j                  d|j                         | j                  d|j                         Y d }~y d }~ww xY ww)
Nr   Tr   r   c                 *    j                  |        S rx   )append)r	   error_d
got_errorss    r5   errbackzLTestPublisher.test_publish_outstanding_errors_async_errback.<locals>.errback(  s    !!$'r7   r   r   r   rC   )r   r   r   r   r   r   
addErrbackr   r   r   r\   callbackr   rk   r   )r1   r2   publication_dr   r   r   r   r   s         @@r5   -test_publish_outstanding_errors_async_errbackz;TestPublisher.test_publish_outstanding_errors_async_errback  s     (*G'"jG
 $OO,,> , M
 J $$W- ((
OTGOOG$
 QJ0 T"=### =  QWW5  !))<<=s0   B4D9B> =D>	D	8D?DD		Dc              #     K   t               }t        |       |j                  dt        j                  d            }| j                  t        |j                        t        t        fv        |j                  ddddt        j                  d            }| j                  t        |j                        t        t        fv        |j                  dddddd	t        j                  d      
      }| j                  t        |j                        t        t        fv        |j                  dt        j                  dd            }| j                  t        |j                        t        t        fv        |j                  dddddd	t        j                  dg dd      
      }| j                  t        |j                        t        t        fv        y w)Nr   Tr   r   rC   rD   rE   rH   r   r   F)r   rW   r   )r   r   rW   )
r   r   r   r   r   
assertTruetyper*   intlongr   s      r5   test_publish_acknowledgedz'TestPublisher.test_publish_acknowledgedA  s    (*G'" '0CUMaManrMs ttKOOD0S$K?@ '0CQ1V[VjVjw{V| }}KOOD0S$K?@ '0CQ1RTZakpkk  MQ  lR  !S  SKOOD0S$K?@ '0CUMaMamr  AE  NF  !G  GKOOD0S$K?@ '0CQ1RTZakpkk  LQ  [j  x|  l}  !~  ~KOOD0S$K?@s   G&G(c              #     K   t               }t        |       t        j                  d      }| j	                  |j                  d|      t               | j	                  |j                  d|      t               y wNTr   zde.myapp.topic1r   foobar)r   r   r   r   assertFailurer   r   r1   r2   r   s      r5    test_publish_undefined_exceptionz.TestPublisher.test_publish_undefined_exceptionU  sj     (*G'"**t<G$$W__5GQX_%Y[kll$$W__Y_%PRbccs   A?Bc              #   Z  K   t               }t        |       t        j                  d      }|j	                  t
               | j                  |j                  d|      t
               |j	                  t               | j                  |j                  d|      t
               y wr   )	r   r   r   r   definer   r   r   r   r   s      r5   test_publish_defined_exceptionz,TestPublisher.test_publish_defined_exception_  s     (*G'"**t<GNN=)$$W__5GQX_%Y[hiiNN:&$$W__Y_%PR_``s   B)B+c              #     K   t               }t        |       |j                  d      }| j                  |d       |j                  dddd      }| j                  |d       |j                  dddddd      }| j                  |d       |j                  dt	        j
                  d	
            }| j                  |d       |j                  ddddddt	        j
                  d	
            }| j                  |d       y w)Nr=   r>   rC   rD   rE   rH   r   r   i'  )timeoutr   r   )r   r   r   r   r   CallOptionsr1   r2   ress      r5   	test_callzTestPublisher.test_calll  s    (*G'"%<==CS#&%<aAFFCS#&%<aA2SZ[[CS#&%<eFWFW`eFfggCS#&%<aA2SZdidudu  D  eE  F  FCS#&s   D
Dc              #     K   t               }t        |       |j                  d      }| j                  |t        j
                         | j                  |j                  d       | j                  |j                  i        |j                  d      }| j                  |t        j
                         | j                  |j                  d       | j                  |j                  ddd       y w)NrA   rB   rF   rG   rH   rI   )	r   r   r   assertIsInstancer   
CallResultr   results	kwresultsr   s      r5   test_call_with_complex_resultz+TestPublisher.test_call_with_complex_result  s     (*G'"%<==C!!#u'7'78S[[)4S]]B/%<==C!!#u'7'78S[[)4S]]E",EFs   C0C2c              #   .  K   t               }t        |       d }|j                  |d      }| j                  t	        |j
                        t        t        fv        |j                  |dt        j                  d            }| j                  t	        |j
                        t        t        fv        |j                  |dt        j                  dd            }| j                  t	        |j
                        t        t        fv        y w)Nc                      t        d| |       y Nz	got eventrQ   rL   s     r5   on_eventz.TestPublisher.test_subscribe.<locals>.on_event      k40r7   r   wildcardmatchr   T)r   get_retained)
r   r   	subscriber   r   r*   r   r   r   SubscribeOptionsr1   r2   r   subscriptions       r5   test_subscribezTestPublisher.test_subscribe  s     (*G'"1 ")!2!28=P!QQLOOD1c4[@A!(!2!28=PZ_ZpZp  xC  [D!2  "E  ELOOD1c4[@A!(!2!28=PZ_ZpZp  xC  RV  [W!2  "X  XLOOD1c4[@As   DDc              #   D  K   t               }t        |       t               t               |j                  fdd      }|j                  fdd      }| j	                  |j
                  |j
                  k(         |j                  dt        j                  dd            }|j                  t        j                  |j
                  |j
                               | j	                  j                  d       | j	                  j                  d       y w)	Nc                  &     j                  d      S N*   r   event0s   r5   <lambda>z5TestPublisher.test_double_subscribe.<locals>.<lambda>      + r7   r   c                  &     j                  d      S NrJ   r   event1s   r5   r  z5TestPublisher.test_double_subscribe.<locals>.<lambda>      . r7   TFrW   r   r   Missing callback)r   r   r   r   r   r*   r   r   r   r/   r   Eventcalled)r1   r2   subscription0subscription1r   r  r  s        @@r5   test_double_subscribez#TestPublisher.test_double_subscribe  s     (*G'"ZFZF")"3"3+-@#B BM")"3"3.0C#E EM OOM,,0@0@@A
 $OO#,,%P ,  G gmmM,<,<gjjIJ OOFMM+=>OOFMM+=>s   DD c              #     K   t               t               fd}|_        t               t               j	                  fdd      }j	                  fdd      }| j                  |j                  |j                  k(         |j                          j                  dt        j                  dd            }j                  t        j                  |j                  |j                               | j                  j                  d	       | j                  j                   d
       yw)z}
            Make sure we correctly deal with unsubscribing one of our handlers
            from the same topic.
            c                 h    t        | t        j                        rJ t        j                  |       S rx   )rS   r   rg   r   r/   )r4   r2   s    r5   r/   zITestPublisher.test_double_subscribe_single_unsubscribe.<locals>.onMessage  s,    %c7+?+?@@@)33GSAAr7   c                  &     j                  d      S r   r   r   s   r5   r  zHTestPublisher.test_double_subscribe_single_unsubscribe.<locals>.<lambda>  r  r7   r   c                  &     j                  d      S r  r   r  s   r5   r  zHTestPublisher.test_double_subscribe_single_unsubscribe.<locals>.<lambda>  r  r7   TFr	  r   r
  Second callback fired.N)r   r   r/   r   r   r   r*   unsubscriber   r   r   r   r  r  )r1   r/   r  r  r   r  r  r2   s        @@@r5   (test_double_subscribe_single_unsubscribez6TestPublisher.test_double_subscribe_single_unsubscribe  s     )*G'"
B !*GZFZF")"3"3+-@#B BM")"3"3.0C#E EM OOM,,0@0@@A++--
 $OO#,,%P ,  G gmmM,<,<gjjIJ OOFMM+=>OO-/GHs   D;E c              #      K   t               t               t               fd}|_        t               t               j	                  fdd      }j	                  fdd      }| j                  |j                  |j                  k(         |j                          |j                          j                  sJ j                  dt        j                  dd            }	 j                  t        j                  |j                  |j                               | j                  d	       | j                  j                   d
       | j                  j                   d       y# t        $ r Y Fw xY ww)z
            If we subscribe twice, and unsubscribe twice, we should then get
            an Unsubscribed message.
            c                     t        | t        j                        rj                  |        t	        j
                  |       S rx   )rS   r   rg   r   r   r/   )r4   r2   unsubscribed_ds    r5   r/   zITestPublisher.test_double_subscribe_double_unsubscribe.<locals>.onMessage  s4    c7#7#78"++C0)33GSAAr7   c                  &     j                  d      S r   r   r   s   r5   r  zHTestPublisher.test_double_subscribe_double_unsubscribe.<locals>.<lambda>  r  r7   r   c                  &     j                  d      S r  r   r  s   r5   r  zHTestPublisher.test_double_subscribe_double_unsubscribe.<locals>.<lambda>  r  r7   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   )	r1   r/   r  r  r   r  r  r2   r  s	        @@@@r5   (test_double_subscribe_double_unsubscribez6TestPublisher.test_double_subscribe_double_unsubscribe  sk     )*G'" &ZNB !*GZFZF")"3"3+-@#B BM")"3"3.0C#E EM OOM,,0@0@@A++--++-- "(((( $OO#,,%P ,  G!!'--0@0@'**"MN		23 OO-/FGOO-/GH ! s+   C3F:A
E? ;F?	FF
FFc              #      K   t               }t        |       t               t                fd}|j                  fdd      }|j                  |dt	        j
                  d            } j                  |j                  |j                  k(         |j                  dt	        j                  dd      	      }|j                  t        j                  |j                  |j                  d
g              j                  j                          j                  j                          j                  j                  d
        j                  j                  d       yw)z
            Test various error-conditions when we try to add a second
            subscription-handler (its signature must match any
            existing handlers).
            c                      j                  d|v        j                  t        |d   t        j                               j	                  |        y )Nboom)r   rS   r   EventDetailsr   )r@   kwr  r1   s     r5   secondz:TestPublisher.test_double_subscribe_errors.<locals>.second)  s>     "-
2f:u7I7I JK%r7   c                 &    j                  |       S rx   r   )argr  s    r5   r  z<TestPublisher.test_double_subscribe_errors.<locals>.<lambda>1  s    FOOC0 r7   r   r  details_argTFr	  r   arg0r?   )r'  N)r   r   r   r   r   r   r   r*   r   r   r/   r   r  r  r   result)r1   r2   r"  r  r  r   r  r  s   `     @@r5   test_double_subscribe_errorsz*TestPublisher.test_double_subscribe_errors  s7     )*G'"ZFZF& #*"3"302E#G GM")"3"3+&&6:# M
 OOM,,0@0@@A $OO#,,%P ,  G m..

&JL
 OOFMM*OOFMM*V]]F3V]]I6s   E-E2c              #     K   t               }t        |       t        d      t               fd}||_        fd}|j                  |d      }|j                  dt        j                  dd            }t        j                  |j                  |j                        }|j                  |       | j                  j                         y	w)
zK
            Ensure we handle an exception from the user code.
            zwe have a problemc                 H    | j                   k(  rj                  d       y y rs   )valuer   )r   r4   error_instance	got_err_ds     r5   observerz?TestPublisher.test_publish_callback_exception.<locals>.observerW  s"    !QWW,&&t, -r7   c                       rx   rt   )r-  s   r5   r  z;TestPublisher.test_publish_callback_exception.<locals>.boom\  s	    $$r7   r   TFr	  r   N)r   r   RuntimeErrorr   onUserErrorr   r   r   r   r   r  r*   r/   r   r  )	r1   r2   r/  r  subr   r4   r-  r.  s	          @@r5   test_publish_callback_exceptionz-TestPublisher.test_publish_callback_exceptionL  s     
 )*G'")*=>N 
I- #+G%  ))$0CDDC $OO#,,%P ,  G --

3Cc" OOI,,-s   CCc              #      K   t               }t        |       d }|j                  |d      }|j                          y w)Nc                      t        d| |       y r   r   rL   s     r5   r   z0TestPublisher.test_unsubscribe.<locals>.on_events  r   r7   r   )r   r   r   r  r   s       r5   test_unsubscribezTestPublisher.test_unsubscriben  sB     (*G'"1 ")!2!28=P!QQL**,,   A Ac              #   x  K   t               }t        |       d }|j                  |d      }| j                  t	        |j
                        t        t        fv        |j                  |dt        j                  d            }| j                  t	        |j
                        t        t        fv        y w)Nc                      t        d| |       y Nzgot callr   rL   s     r5   on_callz,TestPublisher.test_register.<locals>.on_call~      j$/r7   r=   r   r   r   )
r   r   r   r   r   r*   r   r   r   RegisterOptionsr1   r2   r<  ro   s       r5   test_registerzTestPublisher.test_registery  s     (*G'"0 ")!1!1';R!SSLOOD1c4[@A!(!1!1';R\a\q\q  yB  ]C!1  "D  DLOOD1c4[@As   B8B:c              #      K   t               }t        |       d }|j                  |d      }|j                          y w)Nc                      t        d| |       y r;  r   rL   s     r5   r<  z.TestPublisher.test_unregister.<locals>.on_call  r=  r7   r=   )r   r   r   
unregisterr?  s       r5   test_unregisterzTestPublisher.test_unregister  sB     (*G'"0 ")!1!1';R!SSL))++r8  c                 R   t         j                  j                  dk  ry t               }t	        |      }| j                  t              5 }|j                  t        j                  dd             d d d        | j                  dt        j                               y # 1 sw Y   /xY w)N   r   i  z3UNREGISTERED received for non-existant registration)twistedversionmajorr   r   assertRaisesr   rq   r   rj   assertInstr	exception)r1   r2   	transportctxs       r5   $test_unregister_no_such_registrationz2TestPublisher.test_unregister_no_such_registration  s    $$r)(*G%g.I""=1 S&&q$/ MMECMM"	 s   	&BB&c              #      K   t               }t        |      }fdd_        |j                  d      }|j	                  |j
                         | j                  j                         y w)Nc                      d_         y rs   )r  )r@   rM   r<  s     r5   r<  z2TestPublisher.test_unregister_log.<locals>.on_call  s
    !%r7   Fr=   )r   r   r  r   r;   r*   assertFalse)r1   r2   rN  ro   r<  s       @r5   test_unregister_logz!TestPublisher.test_unregister_log  s_     (*G%g.I&"GN!(!1!1';R!SSL''8W^^,s   A-A0c                     g  G fddt               } |       }t        |       |j                  d       | j                  t	              d       | j                  t        d   d   t                     y )Nc                        e Zd Z fdZddZy)7TestPublisher.test_on_disconnect_error.<locals>.AppSessc                 @    j                  |j                  |f       y rx   r   r,  )r1   r   r4   errorss      r5   r2  zCTestPublisher.test_on_disconnect_error.<locals>.AppSess.onUserError  s    MM177C.1r7   c                     t        d      )NzThis shouldn't happen)r1  )r1   rJ   rG   quuxs       r5   onDisconnectzDTestPublisher.test_on_disconnect_error.<locals>.AppSess.onDisconnect  s    &'>??r7   N)snark)r}   r~   r   r2  r]  )rZ  s   r5   AppSessrW    s    2@r7   r_  FrC   r   )r   r   r   r   r\   r   rS   	TypeError)r1   r_  srZ  s      @r5   test_on_disconnect_errorz&TestPublisher.test_on_disconnect_error  sg    F@, @ 	A! IIe S[!,OOJvay|Y?@r7   N)r}   r~   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r)  r4  r7  r@  rD  rP  rT  rb  rt   r7   r5   r   r      s   		0 
	0, 
	= 
	=. 
&	= 
&	=P 
	A 
	A& 
	d 
	d 

	a 

	a 
	' 
	'& 
	G 
	G 
	B 
	B  
	? 
	?6 
(	I 
(	IT 
2	I 
2	Ih 
-	7 
-	7^ 
	. 
	.B 
	- 
	- 
	B 
	B 
	, 
	,	 

	- 

	-	Ar7   r   c                       e Zd Zed        Zed        Zed        Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zed
        Zy)TestInvokerc              #      K   t               }t        |       d }|j                  |d       |j                  d      }| j	                  |d       y w)Nc                       yNrH   rt   rt   r7   r5   myproc1z(TestInvoker.test_invoke.<locals>.myproc1      r7   com.myapp.myproc1rH   )r   r   r   r   r   )r1   r2   rh  r   s       r5   test_invokezTestInvoker.test_invoke  sS     (*G'" ""7,@AA%9::CS"%s   AAc              #      K   t               }t        |       d }|j                  |d       |j                  d      }|j                  d      }t	        ||g      }| j                  |ddg       y w)Nc                       yrg  rt   rt   r7   r5   rh  z.TestInvoker.test_invoke_twice.<locals>.myproc1  ri  r7   rj  TrH   )r   r   r   r   r
   r   )r1   r2   rh  d0d1r   s         r5   test_invoke_twicezTestInvoker.test_invoke_twice  su     (*G'" ""7,@AA23B23B$b"X..CS:z":;s   A3A5c              #      	
K   t               }t               }t        |      }t        |      } fd|j                  	|j                  
	fd|_        
fd|_        d }|j                  |d       |j                  |d       |j	                  d      }|j	                  d      }t        ||g      } j                  |ddg       yw)zW
            make sure each session independently generates sequential IDs
            c                     t        |t        j                        rj                  |j                  d       n6t        |t        j
                        rj                  |j                  d        | |      S )NrC   rD   )rS   r   rh   r   rY   r_   )origr4   r1   s     r5   verify_seq_idzCTestInvoker.test_invoke_request_id_sequences.<locals>.verify_seq_id  sS    c7#3#34$$S[[!4W\\2$$S[[!4Cy r7   c                      |       S rx   rt   )r4   orig0ru  s    r5   r  z>TestInvoker.test_invoke_request_id_sequences.<locals>.<lambda>      mE3&? r7   c                      |       S rx   rt   )r4   orig1ru  s    r5   r  z>TestInvoker.test_invoke_request_id_sequences.<locals>.<lambda>  rx  r7   c                       yrg  rt   rt   r7   r5   rh  z=TestInvoker.test_invoke_request_id_sequences.<locals>.myproc1  ri  r7   rj  rn  N)r   r   rq   r   r   r
   r   )r1   handler0handler1trans0trans1rh  ro  rp  r   rw  rz  ru  s   `        @@@r5    test_invoke_request_id_sequencesz,TestInvoker.test_invoke_request_id_sequences  s     
 *+H)+H"8,F"8,F! KKEKKE?FK?FK ##G-ABB##G-ABB34B34B$b"X..CS:z":;s   CCc              #     K   t               }d|_        t        |       g fd}||_        t	        d      fd}|j                  |d       	 |j                  d       | j                  d       | j                  dt                     | j                  d   d          y # t        $ r)}| j                  t        |t                     Y d }~ad }~ww xY ww)	NTc                 @    j                  | j                  |f       y rx   rY  )r   r4   rZ  s     r5   	log_errorz6TestInvoker.test_invoke_user_raises.<locals>.log_error  s    qwwn-r7   rJ   c                       rx   rt   )
name_errors   r5   bingz1TestInvoker.test_invoke_user_raises.<locals>.bing  s	      r7   zcom.myapp.myproc99zExpected an errorrC   r   )r   traceback_appr   r2  	NameErrorr   r   r	   r   r   rS   r1  r   r\   )r1   r2   r  r  r   rZ  r  s        @@r5   test_invoke_user_raisesz#TestInvoker.test_invoke_user_raises  s     (*G$(G!'"F."+G"5)J! ""4)>??=ll#899		-. QF,Z16  = 
1l ;<<	=s0   AC!$B, 84C!,	C5CC!CC!c              #      K   t               }t        |       t        d fd	       }t        t	        d t        d                  fd}|j                  |dt        j                  d             |j                  dt        j                  |      	      } j                  d
|       t        d      D ]?  } j                  |   j                          j                  ||   j                         A y w)Nc              3      K   j                  | d u       j                  | j                  d u       t        d      D ]   }| j                  |       t        |       " t	        d       y w)N
   r   )r   rO   ranger   r   )r   ir1   s     r5   r  z8TestInvoker.test_invoke_progressive_result.<locals>.bing*  sc     t 34 0 0 <=r %A$$Q'!!*$% Bs   A+A.c                     t               S rx   )r   )_s    r5   r  z<TestInvoker.test_invoke_progressive_result.<locals>.<lambda>3  s    XZ r7   r  c                 .    |    j                  |        y rx   r   )r$  progressives    r5   rO   z<TestInvoker.test_invoke_progressive_result.<locals>.progress5  s    C ))#.r7   com.myapp.myproc2r   r%  on_progressr   r   rx   )r   r   r   listmapr  r   r   r>  r   r   r   r   r  r(  )r1   r2   r  rO   r   r  r  s   `     @r5   test_invoke_progressive_resultz*TestInvoker.test_invoke_progressive_result%  s     (*G'"    s#7rCDK/ ""$%%)< 
  $))h? %  C R%2Y ;A 5 56  KN$9$9:;s   C;C?c              #   R   K   t               }t        |       t        d fd	       }t               t	        d      g fd}||_        d fd	}|j                  |dt        j                  d             |j                  ddt        j                  |	      d
      } j                  d|        j                  j                          j                  dj                          j                  dt                      j                  d   d          y w)Nc              3     K   j                  |d u       j                  |j                  d u       j                  |d       j                  d|        |j                  dd       t        d       t	        d       y w)Nwordr$  lifenothing)	somethingz
meaning ofr   )r   rO   r   r   r   )r$  r   keyr1   s      r5   r  z>TestInvoker.test_invoke_progressive_result_error.<locals>.bingM  st     t 34 0 0 <=  f-  ,  9 =l++Bs   BBrJ   c                 @    j                  | j                  |f       y rx   rY  )r   r4   logged_errorss     r5   	got_errorzCTestInvoker.test_invoke_progressive_result_error.<locals>.got_error[  s    $$aggs^4r7   c                 N    j                  d|       j                  |        )Nr  )r   r   )r$  r  got_progressprogress_errorr1   s     r5   rO   zBTestInvoker.test_invoke_progressive_result_error.<locals>.progress_  s'      I6%%c*$$r7   r  r   r%  r$  r  r  )r   r  r   r  rC   r   )NNrx   )r   r   r   r   r  r2  r   r   r>  r   r   r   r   r  r(  r\   )	r1   r2   r  r  rO   r   r  r  r  s	   `     @@@r5   $test_invoke_progressive_result_errorz0TestInvoker.test_invoke_progressive_result_errorH  s    (*G'"    $:L&u-NM5"+G% ""$%%)<   $))h?	 %  C R% OOL//0V\%8%89QM 23^]1-=a-@As   D!D'c              #   t   K   t               }t        |       t        d	 fd	       }t               fd}|j	                  |dt        j                  d             |j                  dt        j                  |            } j                  d|        j                  j                         y w)
Nc              3      K   j                  | d u       j                  | j                  d u       | j                          t        d       t        d       y w)NTr   r   rO   r   r   r   r1   s    r5   r  z@TestInvoker.test_invoke_progressive_result_no_args.<locals>.bing  sL     t 34 0 0 <=  "dm#Bs   AAc                  (     j                  d       y )Nzintentionally left blankr   )r  s   r5   rO   zDTestInvoker.test_invoke_progressive_result_no_args.<locals>.progress  s    %%&@Ar7   r  r   r%  r  r   r   rx   )r   r   r   r   r   r   r>  r   r   r   r   r  r1   r2   r  rO   r   r  s   `    @r5   &test_invoke_progressive_result_no_argsz2TestInvoker.test_invoke_progressive_result_no_args{  s     (*G'"    $:LB ""$%%)<   $))h? %  C R%OOL//0s   B4B8c              #      K   t               }t        |       t        d
 fd	       }t               d
fd	}|j	                  |dt        j                  d             |j                  dt        j                  |            } j                  d|        j                  j                          j                  d	j                         y w)Nc              3      K   j                  | d u       j                  | j                  d u       | j                  d       t        d       t        d       y w)Nr  )r  Tr   r  r  s    r5   r  zDTestInvoker.test_invoke_progressive_result_just_kwargs.<locals>.bing  sQ     t 34 0 0 <=  V ,dm#Bs   AAc                 (    j                  |        y rx   r   )r  r  s    r5   rO   zHTestInvoker.test_invoke_progressive_result_just_kwargs.<locals>.progress  s    %%c*r7   r  r   r%  r  r   r   r  rx   )r   r   r   r   r   r   r>  r   r   r   r   r  r(  r  s   `    @r5   *test_invoke_progressive_result_just_kwargsz6TestInvoker.test_invoke_progressive_result_just_kwargs  s     (*G'"    $:L+ ""$%%)<   $))h? %  C R%OOL//0V\%8%89s   CCc              #     K   t               }t        |       t        d      fd}|j                  |d      }	 |j	                  d       | j                          |j                          y # t        $ r@}| j                  |t               | j                  |j                         d       Y d }~Wd }~ww xY w# |j                          w xY ww)Nza simple errorc                       rx   rt   rM  s   r5   raiserz<TestInvoker.test_call_exception_runtimeerror.<locals>.raiser      r7   com.myapp.myproc_errorz(wamp.error.runtime_error: a simple error)r   r   r1  r   r   r	   r   r   r   r   error_messagerC  r1   r2   r  registration0r   rM  s        @r5    test_call_exception_runtimeerrorz,TestInvoker.test_call_exception_runtimeerror  s     (*G'"$%56I  #*"2"26;T"UUM1ll#<==		
 $..00	  `%%a)9:  !24^__` $..00s:   :C#A4 !C4	B==6B83C  8B==C   CCc              #   p  K   t               }t        |       t               fd}|j                  |d      }	 |j	                  d       | j                          |j                          y # t        $ r }| j                  |t               Y d }~7d }~ww xY w# |j                          w xY ww)Nc                       rx   rt   r  s   r5   r  z4TestInvoker.test_call_exception_bare.<locals>.raiser  r  r7   r  )	r   r   r   r   r   r	   r   r   rC  r  s        @r5   test_call_exception_barez$TestInvoker.test_call_exception_bare  s     (*G'"!I  #*"2"26;T"UUM1ll#<==		 $..00  ;%%a)9::; $..00s:   9B6#A3  B63	B<BB BB B33B6N)r}   r~   r   r   rk  rq  r  r  r  r  r  r  r  r  rt   r7   r5   rd  rd    s    	
	& 

	& 
	< 
	< 
	< 
	<B 
	7 
	7@ 
 	; 
 	;D 
0	B 
0	Bd 
	1 
	1> 
	: 
	:@ 
	1 
	1$ 
	1 
	1r7   rd  c                       e Zd Zd Zd Zd Zy)TestAuthenticatorc                 @   t        t        j                               }t        ddd      }t        ddd      }|j	                  |       | j                  t              5 }|j	                  |       d d d        dt        j                        v sJ y # 1 sw Y   #xY w)Nwampcraalicep4ssw0rd)authidsecretbob
password42authids)	r   r   r   r   add_authenticatorrJ  
ValueErrorrL  rM  )r1   r   auth0auth1rO  s        r5   test_inconsistent_authidsz+TestAuthenticator.test_inconsistent_authids  s    diik*G("E
 )$E %%e,"":. 1#))%01CMM 22221 1s    BBc                     t        t        j                               } G d dt              } |       }ddd|_        i |_         |       }ddd|_        i |_        |j                  |       |j                  |       y )Nc                       e Zd ZdZd Zd Zy)DTestAuthenticator.test_two_authenticators.<locals>.TestAuthenticatortestc                     t         rx   NotImplementedErrorr1   r   	challenges      r5   on_challengezQTestAuthenticator.test_two_authenticators.<locals>.TestAuthenticator.on_challenge      --r7   c                     t         rx   r  r1   	authextras     r5   
on_welcomezOTestAuthenticator.test_two_authenticators.<locals>.TestAuthenticator.on_welcome  r  r7   Nr}   r~   r   namer  r  rt   r7   r5   r  r        ..r7   r  value0value1r   what)rG   qux)r   r   r   r   r  _argsr  )r1   r   r  r  r  s        r5   test_two_authenticatorsz)TestAuthenticator.test_two_authenticators  s|    diik*G.N . &'EEO EK%'EEO EK%%e,%%e,r7   c                    t        t        j                               } G d dt              } |       }ddd|_        i |_         |       }ddi|_        i |_        |j                  |       | j                  t              5 }|j                  |       d d d        | j                  dt        j                               y # 1 sw Y   /xY w)Nc                       e Zd ZdZd Zd Zy)HTestAuthenticator.test_inconsistent_authextra.<locals>.TestAuthenticatorr  c                     t         rx   r  r  s      r5   r  zUTestAuthenticator.test_inconsistent_authextra.<locals>.TestAuthenticator.on_challenge*  r  r7   c                     t         rx   r  r  s     r5   r  zSTestAuthenticator.test_inconsistent_authextra.<locals>.TestAuthenticator.on_welcome-  r  r7   Nr  rt   r7   r5   r  r  &  r  r7   r  r  r  r   rJ   zInconsistent authextra)r   r   r   r   r  r  r  rJ  r  rK  rL  rM  )r1   r   r  r  r  rO  s         r5   test_inconsistent_authextraz-TestAuthenticator.test_inconsistent_authextra#  s    diik*G.N . &'EEO EK%'ExEO EK%%e,"":. 1#))%01MM2C4FG1 1s   CCN)r}   r~   r   r  r  r  rt   r7   r5   r  r    s    	3$	-<	Hr7   r  )3
__future__r   osr   environgettwisted.internet.deferr   r   r   r   r	   r
   twisted.trialr   rG  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   TestCaser   r   r   rd  r  rt   r7   r5   <module>r     s   6 ' 	 ::>>-'MMBB&8-QQ1GA77
u un,H%% ,$'H 1 1 'HR\A)) \A|Z1h'' Z1X	OHH-- OHc (r7   