
    h                     
   d dl Z d dlm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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% d dl&m'Z'  G d de(      Z) G d dejT                        Z+ G d dejT                        Z, G d dejT                        Z- G d dejT                        Z. G d dejT                        Z/yy)    NUSE_TWISTEDF)inlineCallbacksDeferredreturnValue)succeedfailDeferredList)unittest)util)ApplicationSession)Session)messagerole
serializertypesuriCloseDetails)CallRequest)ApplicationErrorNotAuthorized)
InvalidUriProtocolError)create_authenticator)IAuthenticator)TransportDetailsc                   6    e Zd 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%               | _        t)               | _        y )NF)brokerdealer)_log_handlerr   JsonSerializer_serializer_registrations_invocations_subscription_topicsonOpenr   id_my_session_idr   RoleBrokerFeaturesRoleDealerFeaturesr   Welcome	onMessager   _fake_router_sessionr   _transport_details)selfhandlerrolesmsgs       a/var/www/Befach/backend/env/lib/python3.12/site-packages/autobahn/wamp/test/test_wamp_protocol.py__init__zMockTransport.__init__2   s    DI#DM)88:D"$D "D(*D%MM  &"&'')D#668DD[D[D]^E//$"5"5u=CMM##C((:(<D%&6&8D#    c                     | j                   S N)r0   r1   s    r5   transport_detailszMockTransport.transport_detailsG   s    ***r7   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rD   kwargszcom.myapp.myproczduplicate invocation)rD   rQ   receive_progresszwamp.error.no_such_procedure)rD   rQ   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   
InvocationrD   rQ   rR   YieldrS   	Subscriber'   
SubscribedUnsubscribeUnsubscribedRegister
Registered
Unregisterr=   errorr"   r.   )	r1   r4   payloadisbinaryreplyregistrationr]   rY   reply_ids	            r5   sendzMockTransport.sendO   sA   yy$($4$4$>$>s$C!k((12E#w/99''4 ' 1 1#++t?X?X?h?h?m?m?o p^q(#MM'//*F*FUmnEYY))*5#MM'//*F*FUpqEC.==$::#NN3;;cUCE]]&<<#NN3;;YGE]]&<<#NN3;;YW\egOhiE]]--.@A#'#6#6s}}#EL"77GGLLNG$"3"33+,BCC14D%%g.#.. XX"zz),)=)=	E $MM',,*C*CS[[RpqE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 r:   s    r5   isOpenzMockTransport.isOpen   s    r7   c                      y r9   rx   r:   s    r5   closezMockTransport.close       r7   c                      y r9   rx   r:   s    r5   abortzMockTransport.abort   r|   r7   N)
__name__
__module____qualname__r6   r;   r?   ru   ry   r{   r~   rx   r7   r5   r   r   0   s'    	9*	+	
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 )NrG   rN   )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   rx   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 r9   rx   r:   s    r5   some_methodz=TestRegisterDecorator.test_prefix.<locals>.Prefix.some_method       r7   Nr   r   r   r   registerr   rx   r7   r5   Prefixr      s    m, -r7   r   zcom.example.prefix.prefixrG   r   ru   zcom.example.prefix.method_name
r   mockMock
_transportr   assertEqualr`   
mock_calls	call_listrd   )r1   r   sessioncallregs        r5   test_prefixz!TestRegisterDecorator.test_prefix   s    + 
 hG!%GW-BC QG$6$6$A$A BC%%003DVT!W-.."1%a(+C=s}}Mr7   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 r9   rx   r:   s    r5   r   z?TestRegisterDecorator.test_auto_name.<locals>.Magic.some_method   r   r7   r   rx   r7   r5   Magicr      s    d# $r7   r   zcom.example.r   rG   r   ru   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6Fr7   N)r   r   r   r   r   rx   r7   r5   r   r      s    	N(	G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.topic1rG   rH   rI   rL   hellorN   rK   F)
exclude_meoptionsrB      i,  )r   excluderN   rK   r   T)r   r   retain)r   r   publishr   r   PublishOptionsr1   r2   publications      r5   test_publishzTestPublisher.test_publish   sq    (*G'" '0B CCK[$/ '0BAq! LLK[$/ '0BAq!QSY` aaK[$/ '0BEL`L`lqLr ssK[$/ '0BAq!QSY`joj~j~  KP  Zi  kj  !k  kK[$/ '0BAq!QSY`joj~j~  KP  Zi  rv  kw  !x  x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r[   r   testinghow are you?reasonr   )r   r   r   r   r   r   r   r   r   ro   r   )r1   r2   r   detailses        r5   test_publish_outstanding_errorsz-TestPublisher.test_publish_outstanding_errors   s     (*G'"
 "//,,> * K ((	>RG//'**<!!# <  AGG4  ;;<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 r9   )append)r   error_d
got_errorss    r5   errbackzLTestPublisher.test_publish_outstanding_errors_async_errback.<locals>.errback(  s    !!$'r7   r   r   r   rG   )r   r   r   r   r   r   
addErrbackr   r   r   r`   callbackr   ro   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- ((	>RGOOG$
 QJ0 T"<### <  AGG4  ;;<s0   B4D9B> =D>	D	8D?DD		Dc              #     K   t               }t        |       |j                  dt        j                  d            }| j                  t        |j                        t        k(         |j                  ddddt        j                  d            }| j                  t        |j                        t        k(         |j                  dddddd	t        j                  d      
      }| j                  t        |j                        t        k(         |j                  dt        j                  dd            }| j                  t        |j                        t        k(         |j                  dddddd	t        j                  dg dd      
      }| j                  t        |j                        t        k(         y w)Nr   Tr   r   rG   rH   rI   rL   r   r   F)r   r[   r   )r   r   r[   )	r   r   r   r   r   
assertTruetyper)   intr   s      r5   test_publish_acknowledgedz'TestPublisher.test_publish_acknowledgedA  s    (*G'" '0BEL`L`mqLr ssKOOD0C78 '0BAq!UZUiUivzU{ ||KOOD0C78 '0BAq!QSY`joj~j~  LP  kQ  !R  RKOOD0C78 '0BEL`L`lq  @D  ME  !F  FKOOD0C78 '0BAq!QSY`joj~j~  KP  Zi  w{  k|  !}  }KOOD0C78s   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__5FPW_%XZjkk$$W__Xw_%OQabbs   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__5FPW_%XZghhNN:&$$W__Xw_%OQ^__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)NrA   rB   rG   rH   rI   rL   r   r   i'  )timeoutr   r   )r   r   r   r   r   CallOptionsr1   r2   ress      r5   	test_callzTestPublisher.test_calll  s    (*G'"%;<<CS#&%;Q1EECS#&%;Q1"RYZZCS#&%;UEVEV_dEeffCS#&%;Q1"RYchctct  ~C  dD  E  E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)NrE   rF   rJ   rK   rL   rM   )	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        k(         |j                  |dt        j                  d            }| j                  t	        |j
                        t        k(         |j                  |dt        j                  dd            }| j                  t	        |j
                        t        k(         y w)Nc                      t        d| |       y Nz	got eventrU   rP   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   SubscribeOptionsr1   r2   r   subscriptions       r5   test_subscribezTestPublisher.test_subscribe  s     (*G'"1 ")!2!28=O!PPLOOD1S89!(!2!28=OY^YoYo  wA  ZB!2  "C  CLOOD1S89!(!2!28=OY^YoYo  wA  PT  ZU!2  "V  VLOOD1S89s   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 NrN   r   event1s   r5   r  z5TestPublisher.test_double_subscribe.<locals>.<lambda>      .r7   TFr[   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+-?#A AM")"3"3.0B#D D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 r9   )rW   r   rk   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+-?#A AM")"3"3.0B#D D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 r9   )rW   r   rk   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+-?#A AM")"3"3.0B#D D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   rW   r   EventDetailsr   )rD   kwr  r1   s     r5   secondz:TestPublisher.test_double_subscribe_errors.<locals>.second)  s>     "-
2f:u7I7I JK%r7   c                 &    j                  |       S r9   r   )argr  s    r5   r  z<TestPublisher.test_double_subscribe_errors.<locals>.<lambda>1  s    FOOC0r7   r   r   details_argTFr
  r   arg0rC   )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02D#F F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 rw   )valuer   )r   r4   error_instance	got_err_ds     r5   observerz?TestPublisher.test_publish_callback_exception.<locals>.observerW  s"    !QWW,&&t, -r7   c                       r9   rx   )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   r0  r   subr   r4   r.  r/  s	          @@r5   test_publish_callback_exceptionz-TestPublisher.test_publish_callback_exceptionL  s     
 )*G'")*=>N 
I- #+G%  ))$0BCCC $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   rP   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=O!PPL**,,   A Ac              #   d  K   t               }t        |       d }|j                  |d      }| j                  t	        |j
                        t        k(         |j                  |dt        j                  d            }| j                  t	        |j
                        t        k(         y w)Nc                      t        d| |       y Nzgot callr   rP   s     r5   on_callz,TestPublisher.test_register.<locals>.on_call~      j$/r7   rA   r   r   r   )	r   r   r   r   r   r)   r   r   RegisterOptionsr1   r2   r=  rs   s       r5   test_registerzTestPublisher.test_registery  s     (*G'"0 ")!1!1';Q!RRLOOD1S89!(!1!1';Q[`[p[pw  \A!1  "B  BLOOD1S89s   B.B0c              #      K   t               }t        |       d }|j                  |d      }|j                          y w)Nc                      t        d| |       y r<  r   rP   s     r5   r=  z.TestPublisher.test_unregister.<locals>.on_call  r>  r7   rA   )r   r   r   
unregisterr@  s       r5   test_unregisterzTestPublisher.test_unregister  sB     (*G'"0 ")!1!1';Q!RRL))++r9  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   ru   r   rn   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 rw   )r  )rD   rQ   r=  s     r5   r=  z2TestPublisher.test_unregister_log.<locals>.on_call  s
    !%r7   FrA   )r   r   r  r   r?   r)   assertFalse)r1   r2   rO  rs   r=  s       @r5   test_unregister_logz!TestPublisher.test_unregister_log  s_     (*G%g.I&"GN!(!1!1';Q!RRL''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 r9   r   r-  )r1   r   r4   errorss      r5   r3  zCTestPublisher.test_on_disconnect_error.<locals>.AppSess.onUserError  s    MM177C.1r7   c                     t        d      )NzThis shouldn't happen)r2  )r1   rN   rK   quuxs       r5   onDisconnectzDTestPublisher.test_on_disconnect_error.<locals>.AppSess.onDisconnect  s    &'>??r7   N)snark)r   r   r   r3  r^  )r[  s   r5   AppSessrX    s    2@r7   r`  FrG   r   )r   r   r   r   r`   r   rW   	TypeError)r1   r`  sr[  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*  r5  r8  rA  rE  rQ  rU  rc  rx   r7   r5   r   r      s   		0 
	0, 
	< 
	<. 
&	< 
&	<P 
	9 
	9& 
	c 
	c 

	` 

	` 
	' 
	'& 
	G 
	G 
	: 
	:  
	? 
	?6 
(	I 
(	IT 
2	I 
2	Ih 
-	7 
-	7^ 
	. 
	.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NrL   rx   rx   r7   r5   myproc1z(TestInvoker.test_invoke.<locals>.myproc1      r7   com.myapp.myproc1rL   )r   r   r   r   r   )r1   r2   ri  r   s       r5   test_invokezTestInvoker.test_invoke  sS     (*G'" ""7,?@@%899C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rh  rx   rx   r7   r5   ri  z.TestInvoker.test_invoke_twice.<locals>.myproc1  rj  r7   rk  TrL   )r   r   r   r   r	   r   )r1   r2   ri  d0d1r   s         r5   test_invoke_twicezTestInvoker.test_invoke_twice  su     (*G'" ""7,?@@12B12B$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 )NrG   rH   )rW   r   rl   r   r]   rc   )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 r9   rx   )r4   orig0rv  s    r5   r  z>TestInvoker.test_invoke_request_id_sequences.<locals>.<lambda>      mE3&?r7   c                      |       S r9   rx   )r4   orig1rv  s    r5   r  z>TestInvoker.test_invoke_request_id_sequences.<locals>.<lambda>  ry  r7   c                       yrh  rx   rx   r7   r5   ri  z=TestInvoker.test_invoke_request_id_sequences.<locals>.myproc1  rj  r7   rk  ro  N)r   r   ru   r   r   r	   r   )r1   handler0handler1trans0trans1ri  rp  rq  r   rx  r{  rv  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A##G-@AA23B23B$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 r9   rZ  )r   r4   r[  s     r5   	log_errorz6TestInvoker.test_invoke_user_raises.<locals>.log_error  s    qwwn-r7   rN   c                       r9   rx   )
name_errors   r5   bingz1TestInvoker.test_invoke_user_raises.<locals>.bing  s	      r7   zcom.myapp.myproc99zExpected an errorrG   r   )r   traceback_appr   r3  	NameErrorr   r   r   r   r   rW   r2  r   r`   )r1   r2   r  r  r   r[  r  s        @@r5   test_invoke_user_raisesz#TestInvoker.test_invoke_user_raises  s     (*G$(G!'"F."+G"5)J! ""4)=>>=ll#788		-. 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   rS   ranger   r   )r   ir1   s     r5   r  z8TestInvoker.test_invoke_progressive_result.<locals>.bing*  s^     t 34 0 0 <=rA$$Q'!!*$ # Bs   A+A.c                     t               S r9   )r   )_s    r5   r  z<TestInvoker.test_invoke_progressive_result.<locals>.<lambda>3  s    XZr7   r  c                 .    |    j                  |        y r9   r   )r%  progressives    r5   rS   z<TestInvoker.test_invoke_progressive_result.<locals>.progress5  s    C ))#.r7   com.myapp.myproc2r   r&  on_progressr   r   r9   )r   r   r   listmapr  r   r   r?  r   r   r   r   r  r)  )r1   r2   r  rS   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   rS   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rN   c                 @    j                  | j                  |f       y r9   rZ  )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   rS   zBTestInvoker.test_invoke_progressive_result_error.<locals>.progress_  s'      I6%%c*$$r7   r  r   r&  r%  r  r  )r   r  r   r  rG   r   )NNr9   )r   r   r   r   r  r3  r   r   r?  r   r   r   r   r  r)  r`   )	r1   r2   r  r  rS   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   rS   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   rS   zDTestInvoker.test_invoke_progressive_result_no_args.<locals>.progress  s    %%&@Ar7   r  r   r&  r  r   r   r9   )r   r   r   r   r   r   r?  r   r   r   r   r  r1   r2   r  rS   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 r9   r   )r  r  s    r5   rS   zHTestInvoker.test_invoke_progressive_result_just_kwargs.<locals>.progress  s    %%c*r7   r  r   r&  r  r   r   r  r9   )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                       r9   rx   rN  s   r5   raiserz<TestInvoker.test_call_exception_runtimeerror.<locals>.raiser      r7   com.myapp.myproc_errorz(wamp.error.runtime_error: a simple error)r   r   r2  r   r   r   r   r   r   r   error_messagerD  r1   r2   r  registration0r   rN  s        @r5    test_call_exception_runtimeerrorz,TestInvoker.test_call_exception_runtimeerror  s     (*G'"$%56I  #*"2"26;S"TTM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                       r9   rx   r  s   r5   r  z4TestInvoker.test_call_exception_bare.<locals>.raiser  r  r7   r  )	r   r   r   r   r   r   r   r   rD  r  s        @r5   test_call_exception_barez$TestInvoker.test_call_exception_bare  s     (*G'"!I  #*"2"26;S"TTM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   rl  rr  r  r  r  r  r  r  r  r  rx   r7   r5   re  re    s    	
	& 

	& 
	< 
	< 
	< 
	<B 
	7 
	7@ 
 	; 
 	;D 
0	B 
0	Bd 
	1 
	1> 
	: 
	:@ 
	1 
	1$ 
	1 
	1r7   re  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_authenticatorrK  
ValueErrorrM  rN  )r1   r   auth0auth1rP  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         r9   NotImplementedErrorr1   r   	challenges      r5   on_challengezQTestAuthenticator.test_two_authenticators.<locals>.TestAuthenticator.on_challenge      --r7   c                     t         r9   r  r1   	authextras     r5   
on_welcomezOTestAuthenticator.test_two_authenticators.<locals>.TestAuthenticator.on_welcome  r  r7   Nr   r   r   namer  r  rx   r7   r5   r  r        ..r7   r  value0value1r   what)rK   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         r9   r  r  s      r5   r  zUTestAuthenticator.test_inconsistent_authextra.<locals>.TestAuthenticator.on_challenge*  r  r7   c                     t         r9   r  r  s     r5   r  zSTestAuthenticator.test_inconsistent_authextra.<locals>.TestAuthenticator.on_welcome-  r  r7   Nr  rx   r7   r5   r  r  &  r  r7   r  r  r  r   rN   zInconsistent authextra)r   r   r   r   r  r  r  rK  r  rL  rM  rN  )r1   r   r  r  r  rP  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  rx   r7   r5   r  r    s    	3$	-<	Hr7   r  )0osunittest.mockr   environgettwisted.internet.deferr   r   r   r   r   r	   twisted.trialr
   rH  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   autobahn.wamp.typesr   objectr   TestCaser   r   r   re  r  rx   r7   r5   <module>r     s   6 
 ::>>-'MMBB&8-QQ1GA774z zx,H%% ,$'G 1 1 'GR\A)) \A|Z1h'' Z1X	OHH-- OHg (r7   