
    tf                        d dl Z d dlmZ e j                            dd          rd dlmZmZmZ d dlm	Z	m
Z
mZ d dlmZ d dlZd dlmZ d dlmZ d d	lmZ d d
lmZ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j*                  Z+ G d dej*                  Z, G d dej*                  Z- G d dej*                  Z. G d dej*                  Z/dS dS )    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                   8    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dS )	MockTransportc                    d| _         || _        t          j                    | _        i | _        i | _        i | _        | j                            |            t          j
                    | _        t          j                    t          j                    d}t          j        | j        |          }| j                            |           t%                      | _        t)                      | _        d S )NF)brokerdealer)_log_handlerr   JsonSerializer_serializer_registrations_invocations_subscription_topicsonOpenr   id_my_session_idr   RoleBrokerFeaturesRoleDealerFeaturesr   Welcome	onMessager   _fake_router_sessionr   _transport_details)selfhandlerrolesmsgs       d/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/autobahn/wamp/test/test_wamp_protocol.py__init__zMockTransport.__init__2   s    DI#DM)8::D"$D "D(*D%M  &&&"&'))D#688DD[D]D]^^E/$"5u==CM##C((((:(<(<D%&6&8&8D###    c                     | j         S N)r0   r1   s    r5   transport_detailszMockTransport.transport_detailsG   s    **r7   c                 `    | j                             t          j        d|                     d S )Nr   )r"   r.   r   Unregistered)r1   reg_ids     r5   drop_registrationzMockTransport.drop_registrationJ   s6    M##$Q//    r7   c                 :
   | j         r?| j                            |          \  }}t          d                    |                     d }t          |t          j                  r|j        	                    d          r?|j
        r6t          j        |j        | j        j                                                  }nt!          |j                  dk    r,t          j        t          j        j        |j        d          }n|j        	                    d          rnt          j        t          j        j        |j        d          }not          |t          j                  rH|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        	                    d          r| j        |j                 }| j        j                                        }|| j        v rt1          d          |j        | j        |<   t          j        |||j        |j        |j                  }n8t          j        t          j        j        |j        d          }nt          |t          j                  rI|j        | j        v r9| j        |j                 }t          j        ||j        |j        |j                  }nt          |t          j                  rb|j        }|| j         v r| j         |         }n(| j        j                                        }|| j         |<   t          j!        |j        |          }n-t          |t          j"                  rt          j#        |j                  }nt          |t          j$                  rH| j        j                                        }|| j        |j        <   t          j%        |j        |          }nt          |t          j&                  rt          j'        |j                  }nct          |t          j                  rI| j        |j                 }t          j        t          j        j        ||j(        |j        |j                  }|rb| j         r?| j                            |          \  }}t          d                    |                     | j)        *                    |           d S d S )Nz	Send: {0}z	com.myappr   zwamp.error.invalid_uriznoreply.zwamp.error.not_authorizedcom.myapp.procedure1d   argscom.myapp.procedure2         com.myapp.procedure3bar   foobaz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   s   y 3$($4$>$>s$C$C!k((11222E#w// E9''44 r q ' 1#+t?X?h?m?m?o?o p p^^q((#M'/*FUmnnEEY))*55 r#M'/*FUpqqEEC.. :=$:::#N3;cUCCCEE]&<<<#N3;YYYGGGEE]&<<<#N3;YYYW\egOhOhiiiEE]--.@AA r#'#6s}#EL"7GLLNNG$"333+,BCCC14D%g.#. X"z),)=	  EE $M',*CS[RpqqEEC// #;$"333"/<G#N7#*_b_klllEC!233 	D555#8?HH#8HMMOOH7?D-e4*3;AAC!455 ,S[99C!122 #8HMMOO5A#CM2*3;EEC!344 ,S[99C// 
 +CK8L-I:    /9 :(,(8(B(B5(I(I%GX.//88999''.....	/ /r7   c                     dS NT r:   s    r5   isOpenzMockTransport.isOpen   s    4r7   c                     d S r9   rx   r:   s    r5   closezMockTransport.close       Dr7   c                     d S 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 	9 	9*	+ 	+ 	+	 	 	
R	/ R	/ R	/h	 	 		 	 		 	 	 	 	r7   r   c                       e Zd Zd Zd ZdS )	TestClosec                 j    t                      }t          |           |                    d           d S )NF)r   r   onClose)r1   r2   s     r5   test_server_abortzTestClose.test_server_abort   s5    (**G'""" OOE"""""r7   c                     t                      }t          |           t          t                                }t	          dd|i           |j        d<   |                    t                                 d S )NrG   rN   )r   r   r   	Exceptionr   
_call_reqsonLeaver   )r1   r2   deferreds      r5   test_reject_pendingzTestClose.test_reject_pending   se    (**G'""" IKK((H$/5(B$G$GGq!OOLNN+++++r7   N)r   r   r   r   r   rx   r7   r5   r   r      s2        	# 	# 	#	, 	, 	, 	, 	,r7   r   c                       e Zd Zd Zd ZdS )TestRegisterDecoratorc                     G d dt                     } |            }t          j                    |_        |                    |d           |                     dt          |j        j                             |j        j        d         }|                     d|d                    |                                d         d         d         }|                     d|j	                   d S )	Nc                   @    e Zd Z ej        d          d             ZdS )1TestRegisterDecorator.test_prefix.<locals>.Prefixmethod_namec                     d S r9   rx   r:   s    r5   some_methodz=TestRegisterDecorator.test_prefix.<locals>.Prefix.some_method       Dr7   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        +   
 fhhG!%GW-BCCC QG$6$A B BCCC%03DVT!W---..""1%a(+C=s}MMMMMr7   c                     G d dt                     } |            }t          j                    |_        |                    |d           |                     dt          |j        j                             |j        j        d         }|                     d|d                    |                                d         d         d         }|                     d|j	                   d S )	Nc                   @    e Zd Z ej        d          d             ZdS )3TestRegisterDecorator.test_auto_name.<locals>.MagicNc                     d S 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        *   
 eggG!%GW^<<< QG$6$A B BCCC%03DVT!W---..""1%a(+C6FFFFFr7   N)r   r   r   r   r   rx   r7   r5   r   r      s:        	N 	N 	N(	G 	G 	G 	G 	G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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dS )TestPublisherc              #     K   t                      }t          |           |                    d          V }|                     |d            |                    dddd          V }|                     |d            |                    dddddd          V }|                     |d            |                    dt	          j        d	          
          V }|                     |d            |                    ddddddt	          j        dg d                    V }|                     |d            |                    ddddddt	          j        dg dd                    V }|                     |d            d S )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   s	     (**G'""" '0B C CCCK[$/// '0BAq! L LLLK[$/// '0BAq!QSY` a aaaK[$/// '0BEL`lqLrLrLr s sssK[$/// '0BAq!QSY`joj~  KP  Zi  Zi  Zi  kj  kj  kj  !k  !k  k  kK[$/// '0BAq!QSY`joj~  KP  Zi  Zi  Zi  rv  kw  kw  kw  !x  !x  x  xK[$/////r7   c              #     K   t                      }t          |           |                    dt          j        d                    }t          j        dd          }|                    |          V  	 |V  d S # t          $ rA}|                     d|j	                   |                     d|j
                   Y d }~d S d }~ww xY 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 (	>RRRG//'*****<!!!!!!# < < <  AG444  ;;;;;;;;;<s   8A> >
C	6CC	c              #   ^  K   t                      }t          |           t                      |                    dt	          j        d                    }g fd}|                    |           t	          j        dd          }|                    |           | 	                    d	t                                                   d            	 |V  d S # t          $ rA}| 	                    d|j                   | 	                    d|j                   Y d }~d S d }~ww xY w)
Nr   Tr   r   c                 2                         |            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  sh     (**G'"""jjG
 $OO,>>> ,  M
 J      $$W--- (	>RRRGOOG$$$
 QJ000 T"""<####### < < <  AG444  ;;;;;;;;;<s   C! !
D,+6D''D,c              #      K   t                      }t          |           |                    dt          j        d                    V }|                     t          |j                  t          k               |                    ddddt          j        d                    V }|                     t          |j                  t          k               |                    dddddd	t          j        d          
          V }|                     t          |j                  t          k               |                    dt          j        dd                    V }|                     t          |j                  t          k               |                    dddddd	t          j        dg dd          
          V }|                     t          |j                  t          k               d S )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  s5     (**G'""" '0BEL`mqLrLrLr s sssKOOD00C7888 '0BAq!UZUivzU{U{U{ | |||KOOD00C7888 '0BAq!QSY`joj~  LP  kQ  kQ  kQ  !R  !R  R  RKOOD00C7888 '0BEL`lq  @D  ME  ME  ME  !F  !F  F  FKOOD00C7888 '0BAq!QSY`joj~  KP  Zi  Zi  Zi  w{  k|  k|  k|  !}  !}  }  }KOOD00C788888r7   c              #   6  K   t                      }t          |           t          j        d          }|                     |                    d|          t                    V  |                     |                    d|          t                    V  d S 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  s      (**G'"""*t<<<G$$W__5FPW_%X%XZjkkkkk$$W__Xw_%O%OQabbbbbbbr7   c              #     K   t                      }t          |           t          j        d          }|                    t
                     |                     |                    d|          t
                    V  |                    t                     |                     |                    d|          t
                    V  d S 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_%X%XZghhhhhNN:&&&$$W__Xw_%O%OQ^_______r7   c              #   v  K   t                      }t          |           |                    d          V }|                     |d           |                    dddd          V }|                     |d           |                    dddddd          V }|                     |d           |                    dt	          j        d	
                    V }|                     |d           |                    ddddddt	          j        d	
                    V }|                     |d           d S )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  sl     (**G'"""%;<<<<CS#&&&%;Q1EEEECS#&&&%;Q1"RYZZZZCS#&&&%;UEV_dEeEeEeffffCS#&&&%;Q1"RYchct  ~C  dD  dD  dD  E  E  E  ECS#&&&&&r7   c              #     K   t                      }t          |           |                    d          V }|                     |t          j                   |                     |j        d           |                     |j        i            |                    d          V }|                     |t          j                   |                     |j        d           |                     |j        ddd           d S )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888S[)444S]B///%;<<<<C!!#u'7888S[)444S]E",E,EFFFFFr7   c              #   P  K   t                      }t          |           d }|                    |d          V }|                     t	          |j                  t          k               |                    |dt          j        d                    V }|                     t	          |j                  t          k               |                    |dt          j        dd                    V }|                     t	          |j                  t          k               d S )Nc                  (    t          d| |           d S Nz	got eventrU   rP   s     r5   on_eventz.TestPublisher.test_subscribe.<locals>.on_event      k40000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  sV     (**G'"""1 1 1 ")!2!28=O!P!PPPLOOD11S8999!(!2!28=OY^Yo  wA  ZB  ZB  ZB!2  "C  "C  C  CLOOD11S8999!(!2!28=OY^Yo  wA  PT  ZU  ZU  ZU!2  "V  "V  V  VLOOD11S899999r7   c              #   \  K   t                      }t          |           t                      t                      |                    fdd          V }|                    fdd          V }|                     |j        |j        k               |                    dt          j        dd                    V }|	                    t          j        |j        |j                             |                     j        d           |                     j        d           d S )	Nc                  .                          d          S N*   r   event0s   r5   <lambda>z5TestPublisher.test_double_subscribe.<locals>.<lambda>      ++ r7   r   c                  .                          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  sM     (**G'"""ZZFZZF")"3"3++++-?#A #A A AM")"3"3....0B#D #D D DM OOM,0@@AAA
 $OO",%PPP ,    G gmM,<gjIIJJJ OOFM+=>>>OOFM+=>>>>>r7   c              #     K   t                      t                     fd}|_        t                      t                                          fdd          V }                    fdd          V }|                     |j        |j        k               |                                V                      dt          j
        dd                    V }                    t          j        |j        |j                             |                     j        d	           |                     j         d
           dS )z}
            Make sure we correctly deal with unsubscribing one of our handlers
            from the same topic.
            c                 f    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+?@@@@@)3GSAAAr7   c                  .                          d          S r   r   r  s   r5   r  zHTestPublisher.test_double_subscribe_single_unsubscribe.<locals>.<lambda>  r  r7   r   c                  .                          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 B B B B !*GZZFZZF")"3"3++++-?#A #A A AM")"3"3....0B#D #D D DM OOM,0@@AAA++-----
 $OO",%PPP ,    G gmM,<gjIIJJJ OOFM+=>>>OO-/GHHHHHr7   c              #   R  K   t                      t                     t                      fd}|_        t                      t                                          fdd          V }                    fdd          V }|                     |j        |j        k               |                                V  |                                V  j        sJ 	                    dt          j        dd                    V }	                     t          j        |j        |j                             |                     d	           n# t          $ r Y nw xY w|                     j         d
           |                     j         d           dS )z
            If we subscribe twice, and unsubscribe twice, we should then get
            an Unsubscribed message.
            c                     t          | t          j                  r                    |            t	          j        |           S r9   )rW   r   rk   r   r   r.   )r4   r2   unsubscribed_ds    r5   r.   zITestPublisher.test_double_subscribe_double_unsubscribe.<locals>.onMessage  s?    c7#788 1"++C000)3GSAAAr7   c                  .                          d          S r   r   r  s   r5   r  zHTestPublisher.test_double_subscribe_double_unsubscribe.<locals>.<lambda>  r  r7   r   c                  .                          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  s
      )**G'""" &ZZNB B B B B B !*GZZFZZF")"3"3++++-?#A #A A AM")"3"3....0B#D #D D DM OOM,0@@AAA++-----++----- "(((( $OO",%PPP ,    G!!'-0@'*"M"MNNN		23333    
 OO-/FGGGOO-/GHHHHHs   AE 
E,+E,c              #      K   t                      }t          |           t                      t                       fd}|                    fdd          V }|                    |dt	          j        d                    V }                     |j        |j        k               |                    dt	          j	        dd          	          V }|
                    t          j        |j        |j        d
g                                          j                                        j                                        j        d
                                j        d           dS )z
            Test various error-conditions when we try to add a second
            subscription-handler (its signature must match any
            existing handlers).
            c                                           d|v                                 t          |d         t          j                                                 |            d S )Nboom)r   rW   r   EventDetailsr   )rD   kwr  r1   s     r5   secondz:TestPublisher.test_double_subscribe_errors.<locals>.second)  sV     "---
2f:u7I J JKKK%%%%%r7   c                 .                         |           S r9   r   )argr  s    r5   r  z<TestPublisher.test_double_subscribe_errors.<locals>.<lambda>1  s    FOOC00 r7   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  s      )**G'"""ZZFZZF& & & & & & #*"3"300002D#F #F F FM")"3"3*&6:::# #  M
 OOM,0@@AAA $OO",%PPP ,    G m.
&JJJL L L
 OOFM***OOFM***V]F333V]I66666r7   c              #     K   t                      }t          |           t          d          t                      fd}||_        fd}|                    |d          V }|                    dt          j        dd                    V }t          j
        |j        |j                  }|                    |           |                     j                   d	S )
zK
            Ensure we handle an exception from the user code.
            zwe have a problemc                 L    | j         k    r                    d           d S d S rw   )valuer   )r   r4   error_instance	got_err_ds     r5   observerz?TestPublisher.test_publish_callback_exception.<locals>.observerW  s2    !QW,,&&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CCCC $OO",%PPP ,    G -
33Cc""" OOI,-----r7   c              #      K   t                      }t          |           d }|                    |d          V }|                                V  d S )Nc                  (    t          d| |           d S 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  sj      (**G'"""1 1 1 ")!2!28=O!P!PPPL**,,,,,,,r7   c              #     K   t                      }t          |           d }|                    |d          V }|                     t	          |j                  t          k               |                    |dt          j        d                    V }|                     t	          |j                  t          k               d S )Nc                  (    t          d| |           d S 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 0 0 ")!1!1';Q!R!RRRLOOD11S8999!(!1!1';Q[`[pw  \A  \A  \A!1  "B  "B  B  BLOOD11S899999r7   c              #      K   t                      }t          |           d }|                    |d          V }|                                V  d S )Nc                  (    t          d| |           d S 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  sj      (**G'"""0 0 0 ")!1!1';Q!R!RRRL))+++++++r7   c                 r   t           j        j        dk     rd S t                      }t	          |          }|                     t                    5 }|                    t          j	        dd                     d d d            n# 1 swxY w Y   | 
                    dt          |j                             d S )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1 S&q$//                 MMECM""    s   )BBBc              #      K   t                      }t          |          }fdd_        |                    d          V }|                    |j                   |                     j                   d S )Nc                      d_         d S 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   rN  rs   r<  s       @r5   test_unregister_logz!TestPublisher.test_unregister_log  s      (**G%g..I& & & & &"GN!(!1!1';Q!R!RRRL''888W^,,,,,r7   c                 @   g  G fddt                     } |            }t          |           |                    d           |                     t	                    d           |                     t          d         d         t                               d S )Nc                   "    e Zd Z fdZddZdS )7TestPublisher.test_on_disconnect_error.<locals>.AppSessc                 @                         |j        |f           d S r9   r   r-  )r1   r   r4   errorss      r5   r3  zCTestPublisher.test_on_disconnect_error.<locals>.AppSess.onUserError  s!    MM17C.11111r7   snarkc                      t          d          )NzThis shouldn't happen)r2  )r1   rN   rK   quuxs       r5   onDisconnectzDTestPublisher.test_on_disconnect_error.<locals>.AppSess.onDisconnect  s    &'>???r7   N)r[  )r   r   r   r3  r^  )rZ  s   r5   AppSessrW    sH        2 2 2 2 2@ @ @ @ @ @r7   r_  FrG   r   )r   r   r   r   r`   r   rW   	TypeError)r1   r_  srZ  s      @r5   test_on_disconnect_errorz&TestPublisher.test_on_disconnect_error  s    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  r@  rD  rP  rT  rb  rx   r7   r5   r   r      s/       		0 	0 
	0, 
	< 	< 
	<. 
&	< &	< 
&	<P 
	9 	9 
	9& 
	c 	c 
	c 

	` 
	` 

	` 
	' 	' 
	'& 
	G 	G 
	G 
	: 	: 
	:  
	? 	? 
	?6 
(	I (	I 
(	IT 
2	I 2	I 
2	Ih 
-	7 -	7 
-	7^ 
	. 	. 
	.B 
	- 	- 
	- 
	: 	: 
	: 
	, 	, 
	,	 	 	 

	- 
	- 

	-	A 	A 	A 	A 	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dS )TestInvokerc              #      K   t                      }t          |           d }|                    |d          V  |                    d          V }|                     |d           d S )Nc                      dS NrL   rx   rx   r7   r5   myproc1z(TestInvoker.test_invoke.<locals>.myproc1      rr7   com.myapp.myproc1rL   )r   r   r   r   r   )r1   r2   rh  r   s       r5   test_invokezTestInvoker.test_invoke  s      (**G'"""   ""7,?@@@@@%89999CS"%%%%%r7   c              #   $  K   t                      }t          |           d }|                    |d          V  |                    d          }|                    d          }t	          ||g          V }|                     |ddg           d S )Nc                      dS rg  rx   rx   r7   r5   rh  z.TestInvoker.test_invoke_twice.<locals>.myproc1  ri  r7   rj  TrL   )r   r   r   r   r	   r   )r1   r2   rh  d0d1r   s         r5   test_invoke_twicezTestInvoker.test_invoke_twice  s      (**G'"""   ""7,?@@@@@122B122B$b"X....CS:z":;;;;;r7   c              #      	
K   t                      }t                      }t          |          }t          |          } fd|j        	|j        
	fd|_        
fd|_        d }|                    |d          V  |                    |d          V  |                    d          }|                    d          }t          ||g          V }                     |ddg           dS )zW
            make sure each session independently generates sequential IDs
            c                     t          |t          j                  r                    |j        d           n5t          |t          j                  r                    |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  sm    c7#344 5$$S[!4444W\22 5$$S[!444tCyy r7   c                      |           S r9   rx   )r4   orig0ru  s    r5   r  z>TestInvoker.test_invoke_request_id_sequences.<locals>.<lambda>      mmE3&?&? r7   c                      |           S r9   rx   )r4   orig1ru  s    r5   r  z>TestInvoker.test_invoke_request_id_sequences.<locals>.<lambda>  rx  r7   c                      dS rg  rx   rx   r7   r5   rh  z=TestInvoker.test_invoke_request_id_sequences.<locals>.myproc1  ri  r7   rj  rn  N)r   r   ru   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  s2     
 *++H)++H"8,,F"8,,F! ! ! ! ! KEKE?????FK?????FK   ##G-@AAAAA##G-@AAAAA233B233B$b"X....CS:z":;;;;;r7   c              #   .  K   t                      }d|_        t          |           g fd}||_        t	          d          fd}|                    |d          V  	 |                    d          V  |                     d           n?# t          $ r2}| 	                    t          |t                               Y d }~nd }~ww xY w|                     dt                               |                     d         d                    d S )	NTc                 @                         | j        |f           d S r9   rY  )r   r4   rZ  s     r5   	log_errorz6TestInvoker.test_invoke_user_raises.<locals>.log_error  s!    qw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   rZ  r  s        @@r5   test_invoke_user_raisesz#TestInvoker.test_invoke_user_raises  sV     (**G$(G!'"""F. . . . ."+G"5))J! ! ! ! ! ""4)=>>>>>=ll#788888		-.... = = = 
1l ; ;<<<<<<<<	= QF,,,Z166666s   $,B 
C(CCc              #   P   K   t                      }t          |           t          d fd	            }t          t	          d t          d                              fd}|                    |dt          j        d                    V  |	                    dt          j
        |          	          V }                     d
|           t          d          D ]C}                     |         j                                        ||         j                   Dd S )Nc              3      K                        | d u                                | j        d u           t          d          D ](}|                     |           t          |          V  )t	          d           d S )N
   r   )r   rS   ranger   r   )r   ir1   s     r5   r  z8TestInvoker.test_invoke_progressive_result.<locals>.bing*  s      t 3444 0 <===r % %A$$Q'''!!**$$$$Br7   c                     t                      S r9   )r   )_s    r5   r  z<TestInvoker.test_invoke_progressive_result.<locals>.<lambda>3  s
    XZZ r7   r  c                 >    |                               |            d S 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%  sh     (**G'"""          _  s#7#7rCCDDK/ / / / / ""#%)<<<    
  #)h??? %    C R%%%2YY ; ;A 5666  KN$9::::; ;r7   c              #      K   t                      }t          |           t          d fd	            }t                      t	          d          g fd}||_        d fd	}|                    |dt          j        d                    V  |	                    ddt          j
        |	          d
          V }                     d|                                j                                        dj                                        dt                                                    d         d                    d S )Nc              3   8  K                        |d u                                |j        d u                               |d                               d|            |                    dd           t          d          V  t	          d           d S )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  s      t 3444 0 <===  f---  ,,,  9 ===l+++++Br7   rN   c                 @                         | j        |f           d S r9   rY  )r   r4   logged_errorss     r5   	got_errorzCTestInvoker.test_invoke_progressive_result_error.<locals>.got_error[  s#    $$ags^44444r7   c                 ^                         d|                               |            )Nr  )r   r   )r%  r  got_progressprogress_errorr1   s     r5   rS   zBTestInvoker.test_invoke_progressive_result_error.<locals>.progress_  s3      I66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 5 5 5 5"+G% % % % % % % % ""#%)<<<      #)h???	 %    C R%%% OOL/000V\%8999QM 2 2333^]1-=a-@AAAAAr7   c              #      K   t                      }t          |           t          d	 fd	            }t                      fd}|                    |dt          j        d                    V  |                    dt          j        |                    V } 	                    d|            
                    j                   d S )
Nc              3      K                        | d u                                | j        d u           |                                  t          d          V  t          d           d S )NTr   r   rS   r   r   r   r1   s    r5   r  z@TestInvoker.test_invoke_progressive_result_no_args.<locals>.bing  sk      t 3444 0 <===  """dmm###Br7   c                  2                          d           d S )Nzintentionally left blankr   )r  s   r5   rS   zDTestInvoker.test_invoke_progressive_result_no_args.<locals>.progress  s    %%&@AAAA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 B B B B ""#%)<<<      #)h??? %    C R%%%OOL/00000r7   c              #      K   t                      }t          |           t          d
 fd	            }t                      d
fd	}|                    |dt          j        d                    V  |                    dt          j        |                    V } 	                    d|            
                    j                    	                    d	j                   d S )Nc              3      K                        | d u                                | j        d u           |                     d           t          d          V  t          d           d S )Nr  )r  Tr   r  r  s    r5   r  zDTestInvoker.test_invoke_progressive_result_just_kwargs.<locals>.bing  sp      t 3444 0 <===  V ,,,dmm###Br7   c                 2                         |            d S 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  s1     (**G'"""          _  $::L+ + + + + + ""#%)<<<      #)h??? %    C R%%%OOL/000V\%899999r7   c              #     K   t                      }t          |           t          d          fd}|                    |d          V }	 |                    d          V  |                                  nZ# t          $ rM}|                     |t                     | 	                    |
                                d           Y d }~nd }~ww xY w|                                V  d S # |                                V  w xY w)Nza simple errorc                       r9   rx   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   r2  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66I          #*"2"26;S"T"TTTM1ll#;<<<<<		 ` ` `%%a)9:::  !2!24^________` $..0000000m..000000s1   +A: 9C, :
CACC, CC, ,Dc              #     K   t                      }t          |           t                      fd}|                    |d          V }	 |                    d          V  |                                  n2# t          $ r%}|                     |t                     Y d }~nd }~ww xY w|                                V  d S # |                                V  w xY 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   rC  r  s        @r5   test_call_exception_barez$TestInvoker.test_call_exception_bare  s     (**G'"""!I          #*"2"26;S"T"TTTM1ll#;<<<<<		 ; ; ;%%a)9::::::::; $..0000000m..000000s0   +A9 8C 9
B(B#C #B((C CN)r   r   r   r   rk  rq  r  r  r  r  r  r  r  r  rx   r7   r5   rd  rd    s(       	
	& 
	& 

	& 
	< 	< 
	< 
	< 	< 
	<B 
	7 	7 
	7@ 
 	;  	; 
 	;D 
0	B 0	B 
0	Bd 
	1 	1 
	1> 
	: 	: 
	:@ 
	1 	1 
	1$ 
	1 	1 
	1 	1 	1r7   rd  c                        e Zd Zd Zd Zd ZdS )TestAuthenticatorc                 v   t          t          j                              }t          ddd          }t          ddd          }|                    |           |                     t                    5 }|                    |           d d d            n# 1 swxY w Y   dt          |j                  v sJ d S )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   dikk**G(!  E
 )#  E %%e,,,"":.. 1#))%0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1CM 2 2222222s   4BBBc                 ,   t          t          j                              } G d dt                    } |            }ddd|_        i |_         |            }ddd|_        i |_        |                    |           |                    |           d S )Nc                       e Zd ZdZd Zd ZdS )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    7        . . .. . . . .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    dikk**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 |_        |                    |           |                     t                    5 }|                    |           d d d            n# 1 swxY w Y   | 	                    dt          |j                             d S )Nc                       e Zd ZdZd Zd ZdS )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  rJ  r  rK  rL  rM  )r1   r   r  r  r  rO  s         r5   test_inconsistent_authextraz-TestAuthenticator.test_inconsistent_authextra#  sD   dikk**G. . . . .N . . . &%''E EO EK%%''ExEO EK%%e,,,"":.. 1#))%0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1MM2C4F4FGGGGGs   B::B>B>N)r   r   r   r  r  r  rx   r7   r5   r  r    sF        	3 	3 	3$	- 	- 	-<	H 	H 	H 	H 	Hr7   r  )0osunittest.mockr   environgettwisted.internet.deferr   r   r   r   r   r	   twisted.trialr
   rG  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   rd  r  rx   r7   r5   <module>r     s  6 
			      :>>-'' bHMMMMMMMMMMBBBBBBBBBB&&&&&&NNN888888------QQQQQQQQQQQQQQQQ111111GGGGGGGGAAAAAAAA777777777777444444z z z z z z z zx, , , , ,H% , , ,$'G 'G 'G 'G 'G 1 'G 'G 'GR\A \A \A \A \A) \A \A \A|Z1 Z1 Z1 Z1 Z1h' Z1 Z1 Z1X	OH OH OH OH OHH- OH OH OH OH OHgbH bHr7   