
    afh                       d dl mZmZmZmZmZmZmZ d dlZd dl	Z	d dl
mZ d dlmZ d dlmZmZmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZmZmZmZ d dlmZmZm Z m!Z!m"Z" d dl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* d dl+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 d Z: G d de          Z;e G d de;                      Z< G d de<          Z= ej>        e<            G d de?          Z@dS )    )UnionOptionalDictAnyClassVarListCallableN)reduce)wamp)publicIdGeneratorObservableMixin)uri)message)types)role)	exception)ApplicationErrorProtocolErrorSerializationErrorTypeCheckError)ISessionIPayloadCodecIAuthenticator
ITransportIMessage)	ChallengeSessionDetailsCloseDetailsEncodedPayloadSubscribeOptions
CallResultRegisterOptions)PayloadExceededError)PublicationSubscriptionHandlerRegistrationEndpointPublishRequestSubscribeRequestUnsubscribeRequestCallRequestInvocationRequestRegisterRequestUnregisterRequestc                 R    t          j        |           pt          j        |           S N)inspectismethod
isfunction)fs    H/var/www/html/env/lib/python3.11/site-packages/autobahn/wamp/protocol.pyis_method_or_functionr8   ;   s#    A7'"4Q"7"77    c                      e Zd ZdZdZd Zedee         fd            Z	e
defd            Ze
defd            Zedee         fd            Zedee         fd	            Zedee         fd
            Zedee         fd            Zedee         fd            Zedee         fd            Zedee         fd            Zedeeeef                  fd            Zddedee         fdZddZd ZdS )BaseSessionzi
    WAMP session base class.

    This class implements :class:`autobahn.wamp.interfaces.ISession`.
    Nc                    t          j                    | _        |                     g d           d| _        i | _        t          j        t          t          j	        t          i| _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        t(          j        | _        d | _        d | _        t3                      | _        d S )N)joinleavereadyconnect
disconnect)valid_eventsF)txaiomake_loggerlogset_valid_eventstraceback_app_ecls_to_uri_patr   INVALID_PAYLOADr   PAYLOAD_SIZE_EXCEEDEDr$   _uri_to_ecls
_transport_realm_session_id_authid	_authrole_authmethod_authprovider
_authextrar   DEFAULT_CLIENT_ROLES_session_roles_session_details_payload_codecr   _request_id_genselfs    r7   __init__zBaseSession.__init__G   s    $&&   	 	
 	
 	
 # DF ,.@24H2
 15 &**.&*(,*.,048 =A<U ;? 8<  +}}r9   returnc                     | j         S )zY
        Implements :func:`autobahn.wamp.interfaces.ITransportHandler.transport`
        )rL   rY   s    r7   	transportzBaseSession.transportz   s     r9   c                 F    | j         duo| j                                         S )zS
        Implements :func:`autobahn.wamp.interfaces.ISession.is_connected`
        N)rL   isOpenrY   s    r7   is_connectedzBaseSession.is_connected   s$    
 d*Gt/E/E/G/GGr9   c                 <    | j         duo|                                 S )zR
        Implements :func:`autobahn.wamp.interfaces.ISession.is_attached`
        N)rN   ra   rY   s    r7   is_attachedzBaseSession.is_attached   s#    
 t+C0A0A0C0CCr9   c                     | j         S )zV
        Implements :func:`autobahn.wamp.interfaces.ISession.session_details`
        )rV   rY   s    r7   session_detailszBaseSession.session_details   s    
 $$r9   c                     | j         S r2   )rM   rY   s    r7   realmzBaseSession.realm   s
    {r9   c                     | j         S r2   )rN   rY   s    r7   
session_idzBaseSession.session_id       r9   c                     | j         S r2   )rO   rY   s    r7   authidzBaseSession.authid   
    |r9   c                     | j         S r2   )rP   rY   s    r7   authrolezBaseSession.authrole   s
    ~r9   c                     | j         S r2   )rQ   rY   s    r7   
authmethodzBaseSession.authmethod   rj   r9   c                     | j         S r2   )rR   rY   s    r7   authproviderzBaseSession.authprovider   s    !!r9   c                     | j         S r2   )rS   rY   s    r7   	authextrazBaseSession.authextra   s
    r9   r   errorc                 d   |Wt          |d          r8|j        | j        |<   || j        |j        d                                         <   dS t          d          t          |d          s9t	          j        |t          j        j                  g| j        |<   || j        |<   dS t          d          )zM
        Implements :func:`autobahn.wamp.interfaces.ISession.define`
        N	_wampurisr   zNcannot define WAMP exception from class with no decoration ("_wampuris" unset)z\cannot define WAMP exception: error URI is explicit, but class is decorated ("_wampuris" set)hasattrrx   rH   rK   r   RuntimeErrorPatternURI_TARGET_HANDLER)rZ   r   rv   s      r7   definezBaseSession.define   s     =y+.. u3<3F%i0BK!)"5a"8"<"<">">???"#sttt9k22 C47Ks{Ge4f4f3g%i0+4!%((("  $B  C  C  Cr9   c           	      h   d}t          |d          rt          |j                  }d}t          |d          r|j        }|r|r||d<   nd|i}t	          |t
          j                  r,t          |j                  t          k    r|j        n|j        }n.|j
        | j        v r| j        |j
                 d         j        }nd}d}	| j        r| j                            d|||          }	|	r0t          j        ||||	j        |	j        |	j        |	j                  }
nt          j        |||||          }
|
S )	a  
        Create a WAMP error message from an exception.

        :param request_type: The request type this WAMP error message is for.
        :type request_type: int

        :param request: The request ID this WAMP error message is for.
        :type request: int

        :param exc: The exception.
        :type exc: Instance of :class:`Exception` or subclass thereof.

        :param tb: Optional traceback. If present, it'll be included with the WAMP error message.
        :type tb: list or None
        Nargskwargs	tracebackr   zwamp.error.runtime_errorFpayloadenc_algoenc_keyenc_serializer)ry   listr   r   
isinstancer   r   typerv   str	__class__rH   _urirW   encoder   Errorr   r   r   r   )rZ   request_typerequestexctbr   r   r   rv   encoded_payloadmsgs              r7   _message_from_exceptionz#BaseSession._message_from_exception   si     3 	">>D3!! 	 ZF 	+ +&({##%r*c9566 	3!%ciC!7!7CIISYEE} 555-cm<Q?D2 	U"188tVTTO 	(- ' %(7(?)8)A(7(?/>/MO O OCC - ' % $ &	( (C 
r9   c                    d}d}|j         rk| j        s?d}| j                            |           t	          t          j        ||j                   }n%	 t          |j        |j         |j        |j	                  }| j        
                    d|j        |          \  }|_        |_        |j        |k    r\| j                            d||j                   t	          t          j        d                    ||j                  |j                   }ng# t           $ rZ}| j                            d|	           t	          t          j        d
                    |          |j                   }Y d}~nd}~ww xY w|r|S |j        | j        v r| j        |j                 }	 |j        r(|j        r ||j        i |j        }n* |di |j        }n|j        r ||j         }n
 |            }n@# t           $ r3 	 |                     t)          j                    d           n#  Y nxY wY nw xY w|s|j        rI|j        r%t-          j        |j        g|j        R i |j        }nZt-          j        |j        fi |j        }n=|j        rt-          j        |j        g|j        R  }nt-          j        |j                  }t/          |d          r|j         |_         t/          |d          r|j        |_        t/          |d          r|j        |_        t/          |d          r|j        |_        t/          |d          r|j        |_        |S )z
        Create a user (or generic) exception from a WAMP error message.

        :param msg: A WAMP error message.
        :type msg: instance of :class:`autobahn.wamp.message.Error`
        N5received encoded payload, but no payload codec activer   TzZURI within encrypted payload ('{decrypted_error}') does not match the envelope ('{error}'))decrypted_errorrv   FURI within encrypted payload ('{}') does not match the envelope ('{}').failed to decrypt application payload 1: {err}err+failed to decrypt application payload 1: {}zWhile re-constructing exceptionr   calleecallee_authidcallee_authroleforward_for )r   rW   rE   warnr   ENC_NO_PAYLOAD_CODECr    r   r   r   decoderv   r   r   ENC_TRUSTED_URI_MISMATCHformat	ExceptionENC_DECRYPT_ERRORrK   onUserErrorrC   create_failurer   ry   r   r   r   r   )	rZ   r   r   enc_errlog_msgr   r   eeclss	            r7   _exception_from_messagez#BaseSession._exception_from_message   s    < 	& Qg&&&*+;+PRYdgdpqqq&4S[#,PSPbdgdo&p&pO<@<O<V<VW[]`]fhw<x<x9OSXsz yO33x,;"%) &   
 #3,Edkkl{  ~A  ~G  H  H%(\# # # !   HMM"RXYMZZZ.(:ELLQOO!$  GGGGGG(  	N9)))$SY/D : 	%x 1"dCH;
;;"d00SZ00x %"dCHo"dff   $$,..9   D  	@z 	@8 N#4SYXXXXSZXXCC#4SYMM#*MMCC8 @#4SYJJJJCC#4SY??C 3
## 	(<CL3!! 	$CJ3(( 	2 # 1C3)** 	6"%"5C3&& 	.!oCO
sE   AD 
E5AE00E5AG) )
H&4'HH&H H&%H&r2   NN)__name__
__module____qualname____doc__rE   r[   propertyr   r   r^   r   boolra   rc   r   re   r   rg   intri   rl   ro   rq   rs   r   r   ru   r   r}   r   r   r   r9   r7   r;   r;   ?   sv        
 C1- 1- 1-f 8J/    X Hd H H H VH DT D D D VD %.!9 % % % X% x}    X  HSM       X      X (3-    X  HSM       X  "hsm " " " X" 8DcN3    XC C	 C(3- C C C C"9 9 9 9vb b b b br9   r;   c                   R   e Zd ZdZd6deej                 fdZedej        fd            Z	e
dee         fd            Ze
dee         fd	            Ze
d
efd            Ze
d             Ze
	 	 	 	 	 	 	 d7dedeee                  dee         dee         deeeef                  dee         dee         dee         fd            Ze
d             Ze
d             Zd Zd ZdefdZe
d             Ze
dedefd            Z e
de!fd             Z"e
d!e#j$        dee         fd"            Z%d# Z&e
de'fd$            Z(e
d8d%ee         d&ee         fd'            Z)e
d(             Z*e
d)edee+         fd*            Z,e
	 	 d9d+e-e.ef         d)ee         d,ee/         d-ee         de-e0ee0         f         f
d.            Z1d/ Z2e
d0ede-ee3f         fd1            Z4e
	 	 	 d:d2e-e.ef         d0ee         d,ee5         d3ee         d-ee         de-e6ee6         f         fd4            Z7d5 Z8dS );ApplicationSessionz
    WAMP application session for applications (networking framework agnostic parts).

    Implements (partially):

        * :class:`autobahn.wamp.interfaces.ITransportHandler`
        * :class:`autobahn.wamp.interfaces.ISession`
    Nconfigc                    t                               |            |pt          j        d          | _        d| _        d| _        d| _        i | _        i | _	        i | _
        i | _        i | _        i | _        i | _        i | _        i | _        dS )zF
        Implements :func:`autobahn.wamp.interfaces.ISession`
        realm1rg   FN)r;   r[   r   ComponentConfig_config_goodbye_sent_transport_is_closingrW   _publish_reqs_subscribe_reqs_unsubscribe_reqs
_call_reqs_register_reqs_unregister_reqs_subscriptions_registrations_invocationsrZ   r   s     r7   r[   zApplicationSession.__init__p  s     	T""".4.]8MT\8]8]8] $)+0" 8<  !!#  " ! ! r9   r\   c                     | j         S r2   )r   rY   s    r7   r   zApplicationSession.config  rm   r9   payload_codecc                     || _         dS )zX
        Implements :func:`autobahn.wamp.interfaces.ISession.set_payload_codec`
        NrW   )rZ   r   s     r7   set_payload_codecz$ApplicationSession.set_payload_codec  s    
 ,r9   c                     | j         S )zX
        Implements :func:`autobahn.wamp.interfaces.ISession.get_payload_codec`
        r   rY   s    r7   get_payload_codecz$ApplicationSession.get_payload_codec  s    
 ""r9   r^   c                       j                             d j        |           | _                             d |          }t          j        |d fd           t          j        | fd fd           dS )zV
        Implements :func:`autobahn.wamp.interfaces.ITransportHandler.onOpen`
        z{func}(transport={transport}))funcr^   r@   Nc                 0                         | d          S )NzWhile notifying 'connect'_swallow_errorfailrZ   s    r7   <lambda>z+ApplicationSession.onOpen.<locals>.<lambda>      ,,T3NOO r9   c                 6    t          j        j                  S r2   )rC   	as_future	onConnect_rZ   s    r7   r   z+ApplicationSession.onOpen.<locals>.<lambda>  s    eodn55 r9   c                 0                         | d          S )NzWhile calling 'onConnect'r   r   s    r7   r   z+ApplicationSession.onOpen.<locals>.<lambda>  r   r9   )rE   debugonOpenrL   firerC   add_callbacks)rZ   r^   ds   `  r7   r   zApplicationSession.onOpen  s    
 	6T[T]^^^ $ IIiy11tOOOO	
 	
 	
 	5555OOOO	
 	
 	
 	
 	
r9   c                     | j                             d| j                   |                     | j        j                   dS )zP
        Implements :func:`autobahn.wamp.interfaces.ISession.onConnect`
        z{func}())r   N)rE   r   r   r=   r   rg   rY   s    r7   r   zApplicationSession.onConnect  s;    
 	z777		$+#$$$$$r9   rg   authmethodsrl   ro   ru   	resumableresume_sessionresume_tokenc	                     | j         rt          d          | j        st          d          || _        d| _        t          j        || j        |||||||	  	        }	| j                            |	           dS )zK
        Implements :func:`autobahn.wamp.interfaces.ISession.join`
        zsession already joinedzno transport set for sessionF)	rg   rolesr   rl   ro   ru   r   r   r   N)	rN   r   rL   rM   r   r   HellorU   send)
rZ   rg   r   rl   ro   ru   r   r   r   r   s
             r7   r=   zApplicationSession.join  s      	64555 	<:;;;  # m%"&"5(3#)%-&/&/+9)57 7 7 	S!!!!!r9   c                 J    | j         r| j                                          dS dS )zQ
        Implements :func:`autobahn.wamp.interfaces.ISession.disconnect`
        N)rL   closerY   s    r7   rA   zApplicationSession.disconnect  s2    
 ? 	$O!!#####	$ 	$r9   c                 X   t          |d          r_t          |j        t          j                  r@| j                            d| j        j        |j        	                                           dS | j        
                    d| j        j        |t          j        |                     dS )zR
        Implements :func:`autobahn.wamp.interfaces.ISession.onUserError`
        valuez{klass}.onUserError(): "{msg}")klassr   z*{klass}.onUserError(): "{msg}"
{traceback})r   r   r   N)ry   r   r   r   r   rE   r   r   r   error_messagerv   rC   failure_format_tracebackrZ   r   r   s      r7   r   zApplicationSession.onUserError  s    
 4!! 
	jY=W&X&X 
	HMM: $ 7"j6688  : : : : : HNN=n-8>>	      r9   c                     	 |                      ||           nO# t          $ rB | j                            dt	          j        t	          j                                         Y nw xY wdS )a  
        This is an internal generic error-handler for errors encountered
        when calling down to on*() handlers that can reasonably be
        expected to be overridden in user code.

        Note that it *cancels* the error, so use with care!

        Specifically, this should *never* be added to the errback
        chain for a Deferred/coroutine that will make it out to user
        code.
        zInternal error: {tb})r   N)r   r   rE   rv   rC   r   r   r   s      r7   r   z!ApplicationSession._swallow_error  s    	T3'''' 	 	 	HNN&1%2F2H2HII      	
 ts    A	A%$A%c                     fd}|S )z
        Does parameter type checking and validation against type hints
        and appropriately tells the user code and the caller (through router).
        c                    K   t          j        g| R i |}g }j                                        D ]\  }}||v rt	          |dd           t
          k    rod |j        D             }t          ||         |j                  sB|                    d	                    ||t          ||                   j                             t          ||         |          sG|                    d	                    ||j        t          ||                   j                             |r"t          d                    |                    t          j        g| R i | d {V S )N
__origin__c                     g | ]	}|j         
S r   )r   ).0args     r7   
<listcomp>zFApplicationSession.type_check.<locals>._type_check.<locals>.<listcomp>!  s    )P)P)P3#,)P)P)Pr9   z'{}' expected types={} got={}z'{}' expected type={} got={}z, )r3   getcallargs__annotations__itemsgetattrr   __args__r   appendr   r   r   r   r=   rC   r   )r   r   	argumentsresponsenamekindexpected_typesr   s          r7   _type_checkz2ApplicationSession.type_check.<locals>._type_check  s     +DB4BBB6BBIH"288:: x x
d9$$ t\488EAA)P)P$-)P)P)P))D/4=II h$OO ? F Ft^GKIVZOG\G\Ge!g !gh h h (	$>> x :AA$W[\efj\kWlWlWuvvx x x :$TYYx%8%8999?????????????r9   r   )rZ   r   r  s    ` r7   
type_checkzApplicationSession.type_check  s)    
	@ 	@ 	@ 	@ 	@* r9   r   c                 (   "#$%  j         it          t          j                  r=t	          j         j                  } fd} fd}t	          j        |||           dS t          t          j                  r\t          j
        j        j                  "t	          j         j        "          }" fd} fd}t	          j        |||           dS t          t          j                  r[t          j        j        j                  }t	          j         j        |          } fd} fd}t	          j        |||           dS t#          d                    j                            t          t          j                  r j        s-t          j                    } j                            |           d _         t          j
        j        j                  "t	          j         j        "          }" fd	} fd
}t	          j        |||           dS t          t          j                  r/j         j        v r j        j                 D ]}|j        #j        p|j        }	j        rۉ j        s$ j                             dj                    dS 	 tC          j"        j        j#        j$                  }
 j        %                    d|	|
          \  }_&        _'        |	|k    r j                             d            dS n;# tP          $ r.} j                             d|j                   Y d}~ dS d}~ww xY w#j)        r#j)        fntU                      }j&        r|tU          j&                  z   }j'        rj'        ntW                      }#j,        rNt          j-        |j.        j/        j0        j1        |	j2        j3        j        j4        
  
        |#j,        <    fd}# fd}t	          j        #j5        g|R i |}t	          j        |||           dS t#          d                    j                            t          t          j6                  rj7         j8        v r j8        9                    j7                  }t	          j:        |j;                  rt	          j<        |j;                  rdS t{          j.        |j>                  }t	          j?        |j;        |           dS t#          d                    j7                            t          t          j@                  rj7         jA        v r҉ jA        9                    j7                  }t	          j:        |j;                  rt	          j<        |j;                  rdS j         j        vrg  j        j        <   t          j        |j         |j                  } j        j                 C                    |           t	          j?        |j;        |           dS t#          d                    j7                            t          t          jD                  rۉj7         jE        v r jE        9                    j7                  }t	          j:        |j;                  rt	          j<        |j;                  rdS |jF         j        v r) j        |jF                 D ]	}d|_G        
 j        |jF        = t	          j?        |j;        d           dS t#          d                    j7                            t          t          jH                  r	j7         jI        v rӉ jI        j7                 }|jJ        $d}j        rB j        s8d} j                             |           t          t          jL        |          }n	 tC          j"        j        j#        j$                  }
 j        %                    d$|
          \  }_&        _'        $|k    rK j                             d|$           t          t          jM        d                    |$                    }n`# tP          $ rS} j                             d|            t          t          jN        d!                    |                    }Y d}~nd}~ww xY wjO        r|jP        jQ        r|r R                    |d"           dS j'        ptW                      }j&        ptU                      } fd#}|jP        r^|jP        jS        rRt	          j        |jP        jQ        t          jT        j&        jU        jV        jW        j4        d$j'                  }nt	          j        |jP        jQ        g|R i |}t	          j        |d|           dS dS  jI        j7        = |j;        }t	          j:        |          rt	          j<        |          rdS |rt	          jX        ||           dS j'        s|jP        r|jP        jS        rj'        pi }j&        r0t          jT        j&        jU        jV        jW        j4        d$|}n*t          jT        d<jU        jV        jW        j4        d$|}t	          j?        ||           dS j&        rdt          j&                  d%k    r*t          jT        j&         }t	          j?        ||           dS t	          j?        |j&        d                    dS t	          j?        |d           dS t#          d&                    j7                            t          t          jZ                  r6j7         j[        v r't#          d'                    j7                            j\         j]        vr't#          d(                    j\                             j]        j\                 %%j^        }jJ        p%jJ        $d}j        rB j        s8d)} j                             |           t          t          jL        |          }n	 tC          j"        j        j#        j$                  }
 j        %                    d$|
          \  }_&        _'        $|k    rK j                             d*|$           t          t          jM        d+                    |$                    }n`# tP          $ rS} j                             d,|            t          t          jN        d-                    |                    }Y d}~nd}~ww xY w|rG _                    t          jZ        j`        j7        |          } j                            |           dS |j)        	|j)        f}ntU                      }j&        r|tU          j&                  z   }j'        rj'        ntW                      }|j,        rNja        r$ fd.}nd}t          jb        %|jc        jd        je        $j2        j        /          ||j,        <   t	          j        |j5        g|R i |}$% fd0}% fd1}t          j7        |           j[        j7        <   t	          j        |||           dS t          t          jg                  r^j7         j[        vr# j        h                    d2j7        3           dS  j[        j7                 } t	          ji        | j;                   dS t          t          jj                  r
j7         jk        v rՉ jk        9                    j7                  }t	          j:        |j;                  rt	          j<        |j;                  rdS j\         j]        vr1t           j\        |jJ        |j^                  %% j]        j\        <   n't#          d4                    j\                            t	          j?        |j;        %           dS t#          d5                    j7                            t          t          jm                  rRj7        dk    rr	  j]        j\                 }!n5# t          $ r( t#          d6                    j\                            w xY w j        h                    d7|!jJ        j\        8           dS j7         jo        v r jo        9                    j7                  }t	          j:        |j;                  rt	          j<        |j;                  rdS |jp         j]        v r$d j]        |jp                 _G         j]        |jp        = t	          j?        |j;                   dS t#          d9                    j7                            t          t          jq                  r@d}jr        t          js        j`        k    r4j7         jI        v r& jI        9                    j7                  j;        }njr        t          jt        j`        k    r4j7         j8        v r& j8        9                    j7                  j;        }n3jr        t          ju        j`        k    r3j7         jA        v r% jA        9                    j7                  j;        }njr        t          jv        j`        k    r3j7         jE        v r% jE        9                    j7                  j;        }njr        t          jw        j`        k    r3j7         jk        v r% jk        9                    j7                  j;        }nLjr        t          jx        j`        k    r2j7         jo        v r$ jo        9                    j7                  j;        }|r@t	          j<        |          s*t	          jX        | y                                         dS dS t#          d:                    jr        j7                            t#          d;                    j                            )=zY
        Implements :func:`autobahn.wamp.interfaces.ITransportHandler.onMessage`
        Nc                    | `j                             d|            t          j        dd                    |                     }j                            |           d S j        rj        _        j	        _
        j        _        j        _        j        _        j        _        j        _        j        _        t/          j        j
        j        j        j        j        j        j        j        j        j        j        ddd           _                            dj                  }t;          j        |d fd           t;          j        |fd	d            t;          j        |d fd
           t;          j        |fdd            t;          j        |d fd           d S )Nz"Session denied by onWelcome: {res})reswamp.error.cannot_authenticate{0}F)rg   sessionrl   ro   rq   rs   ru   
serializerr^   resumedr   r   r=   c                 0                         | d          S )NzWhile notifying 'join'r   r   rZ   s    r7   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>n  s    $"5"5a9Q"R"R r9   c                 B    t          j        j        j                  S r2   )rC   r   onJoinrV   r   s    r7   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>s  s    %/$+t?T"U"U r9   c                 0                         | d          S )NzWhile firing onJoinr   r  s    r7   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>y  s    $"5"5a9N"O"O r9   c                 0                         d          S )Nr?   r   r   s    r7   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>~  s    $))GT":": r9   c                 0                         | d          S )NzWhile notifying 'ready'r   r  s    r7   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>  s    $"5"5a9R"S"S r9   )rE   r   r   Abortr   rL   r   rg   rM   r  rN   rl   rO   ro   rP   rq   rQ   rs   rR   ru   rS   r   _router_rolesr   _serializerSERIALIZER_IDtransport_detailsrV   r   rC   r   )r  replyr   r   rZ   s      r7   successz-ApplicationSession.onMessage.<locals>.successA  s   'KQTUUU '<ell3>O>O! ! ,,U333y 0&)i'*{D$#&:DL%(\DN'*~D$),)9D&&)mDO),D&,:"k $ 0#|!%#'#3%)%7"%-#'?#>#L"&/"C %"'%)- - -D)* 		&$0EFFA '4RRRR  
 'UUUU   '4OOOO  
 '::::   '4SSSS    r9   c                     t          j        dd          }j                            |                               | d          S )Nr  zError calling onWelcome handlerzWhile firing onWelcome)r   r  rL   r   r   )r   r$  rZ   s     r7   rv   z+ApplicationSession.onMessage.<locals>.error  sI    #M8:[ E O((///..q2JKKKr9   c                 x                          d          } fd}fd}t          j        |||           |S )Nr>   c                     S r2   r   )r   r   s    r7   
return_argzAApplicationSession.onMessage.<locals>.success.<locals>.return_arg  s    "
r9   c                 0                         | d          S )NzWhile firing 'leave' eventr   r  s    r7   _errorz=ApplicationSession.onMessage.<locals>.success.<locals>._error  s    #2216RSSSr9   )r   rC   r   )r   r   r)  r+  detailsrZ   s   `   r7   r%  z-ApplicationSession.onMessage.<locals>.success  sj    		'499A# # # # #T T T T T':v>>>Hr9   c                 0                         | d          S NzWhile firing onLeaver   r  s    r7   r+  z,ApplicationSession.onMessage.<locals>._error  s    ..q2HIIIr9   c                 n   | t          d          t          |           t          k    r|                     d          } t          |           t          k    r/t          d                    t          |                               t          j        |           }j        	                    |           d S )Nz4onChallenge user callback did not return a signatureutf8z"signature must be unicode (was {}))
r   r   bytesr   r   r   r   AuthenticaterL   r   )	signaturer$  rZ   s     r7   r%  z-ApplicationSession.onMessage.<locals>.success  s     ('(^___I%//$-$4$4V$<$<	I#--'(L(S(STXYbTcTc(d(deee#0;;EO((/////r9   c                 x                        | d           t          j        dd                    | j                            }j                            |           t          j        |j	        |j                  t          j        j                  }fd}fd}t          j        |||           |S )NzAuthentication failedr  r  c                 6                         d           | S Nr>   r  r   r,  rZ   s    r7   r%  z<ApplicationSession.onMessage.<locals>.error.<locals>.success  s    		'4999"
r9   c                 0                         | d          S r.  r   r  s    r7   r+  z;ApplicationSession.onMessage.<locals>.error.<locals>._error  s    #2216LMMMr9   )r   r   r  r   r   rL   r   r   r   reasonrC   r   onLeaver   )r   r$  r   r%  r+  r,  rZ   s        @r7   rv   z+ApplicationSession.onMessage.<locals>.error  s    $$S*ABBB#M*JELLY\YbLcLcddEO((///#0u}MMGg>>A# # # # # #
N N N N N'7F;;; Hr9   z8Received {0} message, and session is not yet establishedc                 6                         d           | S r6  r  r7  s    r7   r%  z-ApplicationSession.onMessage.<locals>.success  s    IIgtW555Jr9   c                 p    d                     j        j                  }                    | |          S )Nz7While firing onLeave for reason "{0}" and message "{1}")r   r9  r   r   )r   errmsgr   rZ   s     r7   r+  z,ApplicationSession.onMessage.<locals>._error  s6    V]]^a^hjmjuvvF..q&999r9   zjreceived encoded payload with enc_algo={enc_algo}, but no payload codec active - ignoring encoded payload!r   Fz-envelope topic URI does not match encoded onezNfailed to decode application payload encoded with enc_algo={enc_algo}: {error})rv   r   )	publisherpublisher_authidpublisher_authroletopictransaction_hashretainedr   r   c                     j         rjj        d         j        rZj        r5t	          j        j                  }j                            |           d S j        	                    d           d S d S d S )Nbrokerz}successfully processed event with acknowledged delivery, but could not send ACK, since the transport was lost in the meantime)
x_acknowledged_deliveryr   x_acknowledged_event_deliveryrL   r   EventReceivedpublicationr   rE   r   )r   r	  r   rZ   s     r7   _successz.ApplicationSession.onMessage.<locals>._success  s      #: st?QRZ?[?y s#'? !s/6/DS_/U/UH$(O$8$8$B$B$B$B$B$(HMM  3r  %s  %s  %s  %s  %ss s s sr9   c                 p    d                     j        j                  }                    | |          S )Nz&While firing {0} subscribed under {1}.)r   fnsubscriptionr   )r   r=  handlerr   rZ   s     r7   r+  z,ApplicationSession.onMessage.<locals>._error  s8    %M%T%T '
C,<&> &>F#'#6#6q&#A#AAr9   z5EVENT received for non-subscribed subscription ID {0}was_encryptedz1PUBLISHED received for non-pending request ID {0}z2SUBSCRIBED received for non-pending request ID {0}r   z4UNSUBSCRIBED received for non-pending request ID {0}r   TzXURI within encrypted payload ('{decrypted_proc}') does not match the envelope ('{proc}'))decrypted_procprocr   r   r   r   zLcould not deliver progressive call result, because payload decryption failedc                 4                         | d           d S )NzWhile firing on_progress)r   r   s    r7   r+  z,ApplicationSession.onMessage.<locals>._error  s     $($4$4T;U$V$V$V$V$Vr9   )r   r   r   r      z.RESULT received for non-pending request ID {0}z6INVOCATION received for request ID {0} already invokedz:INVOCATION received for non-registered registration ID {0}z<received encrypted INVOCATION payload, but no keyring activezcURI within encrypted INVOCATION payload ('{decrypted_proc}') does not match the envelope ('{proc}')zQURI within encrypted INVOCATION payload ('{}') does not match the envelope ('{}')z+failed to decrypt INVOCATION payload: {err}z(failed to decrypt INVOCATION payload: {}c                     | t          |           t          t          fv sJ |t          |          t          k    sJ d }j        r3j        st          d          j                            d| |          }|r4t          j	        j
        |j        d|j        |j        |j                  }nt          j	        j
        | |d          }j                            |           d S )N7trying to send encrypted payload, but no keyring activeFT)r   progressr   r   r   )r   r   rW  )r   r   tupledictr   rW   r   r   r   Yieldr   r   r   r   rL   r   )r   r   r   progress_msgr   rR  rZ   s       r7   rW  z.ApplicationSession.onMessage.<locals>.progress  s   /3|tDzzdTY]?Z?Z?Z/Z/5~fQUAUAUAU/U:>+.< )t373F -{6?@y6z6z0z>B>Q>X>XY^`dfjlr>s>sO+: )X;B=Q`QhRVRaRjQ`QhXgXv<x <x <xLL <C=NRPVRV<X <X <XL
 )-(<(<\(J(J(J(J(Jr9   )rW  callercaller_authidcaller_authrole	procedurerB  r   c                    	j         j        = d }j        r	j        sd}	j                            |           n	 t          | t          j                  r(	j        	                    d| j
        | j                  }n	j        	                    d| g          }n3# t          $ r&}	j                            d|           Y d }~nd }~ww xY w|rt          | t          j                  rKt          j        j        |j        |j        |j        |j        | j        | j        | j        | j        	  	        }nt          j        j        |j        |j        |j        |j                  }nut          | t          j                  r?t          j        j        | j
        | j        | j        | j        | j        | j                  }nt          j        j        | g          }	j        :	j                            d	                    j        j                             d S 	 	j                            |           d S # t6          $ r}t          j        t          j        j        j        t>          j         d
                    |j!        |j"        j        |          g          }	j                            |           Y d }~d S d }~wtF          $ r}t          j        t          j        j        j        t>          j$        d                    |j!        |j"        j        |          g          }	j                            |           Y d }~d S d }~ww xY w)NrV  Fz,failed to encrypt application payload: {err}r   )r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   zCSkipping result of "{}", request {} because transport disconnected.zasuccess return value (args={}, kwargs={}) from invoked procedure "{}" could not be serialized: {}zfsuccess return value (args={}, kwargs={}) from invoked procedure "{}" exceeds transport size limit: {})%r   r   r   rW   rE   r   r   r   r"   r   results	kwresultsr   r   rZ  r   r   r   r   r   r   r   rL   r   r   r_  r   r   r   
InvocationMESSAGE_TYPEr   rI   r   r   r$   rJ   )
r  r   r   r   r$  error_replyr   rR  registrationrZ   s
         r7   r%  z-ApplicationSession.onMessage.<locals>.success8  sZ   $($5ck$B26#&< !.+/+> %.2k(,g(>(>(>(>	)./9#u?O/P/P -qBFBUB\B\]bdhjmjuwz  xE  CF  CFBFBUB\B\]bdhknjoBpBp/8 ). ). ).,0HMM0^45 -: -. -. -. -. -. -. -. -.). $3 !J'1#u7G'H'H %m07ckFUF]GVG_FUF]M\MkEHZLOL]NQNaJM/1[ 1[ 1[ 18ckFUF]GVG_FUF]M\Mk	1m 1m 1m (2#u7G'H'H 
%J07ckCF;EH]EHZLOL]NQNaJM/1[ 1[ 1[ 18ckDG51J 1J 1J $(?#:$(HNN3x33  AM  AW  Y\  Yd  4e  4e  %f  %f  %f$*F!F$(O$8$8$?$?$?$?$?'9 !F !F !F29-@R@_adaln~  oO Gj  Gq  Gq  rw  r| rw  r~ r~  rH rsGt Gt Fu3v 3v 3vK
 %)O$8$8$E$E$E$E$E$E$E$E$E'; !F !F !F 3:-@R@_adaln~  oU Go  Gv  Gv  w|  wA w|  wC wC  wM wxGy Gy Fz3{ 3{ 3{K
 %)O$8$8$E$E$E$E$E$E$E$E$E!Fs>   AB 
C'CC!H= =
MA6KMA6MMc           
      b   j         j        = t          j        |           }	                     | |           n#  Y nxY wd }j        rt          j        |           }                    t          j	        j
        j        | j        |j                  }	 j                            |           n# t          $ rt}t          j        t          j	        j
        j        t"          j        d                    j        |          g          }j                            |           Y d }~nd }~wt*          $ rt}t          j        t          j	        j
        j        t"          j        d                    j        |          g          }j                            |           Y d }~nd }~ww xY wd S )NzLerror return value from invoked procedure "{0}" could not be serialized: {1}ra  zSsuccess return value from invoked procedure "{0}" exceeds transport size limit: {1})r   r   rC   failure_messager   rG   r   r   r   rd  re  r   r   rL   r   r   r   r   rI   r   r_  r$   rJ   )r   r=  formatted_tbr$  r   r   rg  rZ   s        r7   rv   z+ApplicationSession.onMessage.<locals>.error  s,   $($5ck$B).)>s)C)C!)$($4$4S&$A$A$A$A!)$(D/3#'#5 !W383QRU3V3VL(,(D(D$+$6$C$'K$'I$0$'L)" )"!@$(O$8$8$?$?$?$?'9 !@ !@ !@,3M':L:Y[^[fhx  iI AO  AV  AV  Wc  Wm  op  Aq  Aq  @r-s -s -sE$(O$8$8$?$?$?$?$?$?$?$?'; !@ !@ !@ -4M':L:Y[^[fhx  iO AV  A]  A]  ^j  ^t  vw  Ax  Ax  @y-z -z -zE$(O$8$8$?$?$?$?$?$?$?$?!@ (,ts.   ; ?B2 2
F,<A*D++F,8A*F''F,z7INTERRUPT received for non-pending invocation {request})r   z<REGISTERED received for already existing registration ID {0}z2REGISTERED received for non-pending request ID {0}z:UNREGISTERED received for non-existant registration ID {0}z3Router unregistered procedure '{proc}' with ID {id})rR  idz4UNREGISTERED received for non-pending request ID {0}z^WampAppSession.onMessage(): ERROR received for non-pending request_type {0} and request ID {1}zUnexpected message {0}r   )zrN   r   r   WelcomerC   r   	onWelcomer   r  r   r   r9  r:  r   methodextraonChallenger   r   r   Goodbyer   rL   r   EventrM  r   rN  rA  r   rW   rE   r   r    r   r   r   r   r   r   r   objrX  rY  details_argEventDetailsrI  r>  r?  r@  rB  rC  r   rL  	Publishedr   r   pop	is_futureon_reply	is_calledr%   rP  resolve
Subscribedr   r&   r  Unsubscribedr   subscription_idactiveResultr   r_  r   r   r   r   rW  optionson_progressr   r,  r"   r   r   r   rejectlenrd  r   rg  r   endpointr   re  receive_progressCallDetailsr\  r]  r^  r.   	Interruptr   cancel
Registeredr   r(   UnregisteredKeyErrorr   registration_idr   r   CallPublish	SubscribeUnsubscribeRegister
Unregisterr   )&rZ   r   r   r%  rv   r+  	challenger$  rM  rA  r   decoded_topicr   invoke_argsinvoke_kwargsrJ  futurepublish_requestrI  r   call_requestr   r   rQ  kwr   prog_dry  r   r  r  rW  invokedregr,  rN  rR  rg  s&   ``                                @@@@r7   	onMessagezApplicationSession.onMessage/  s   
 # #w// Sv ODNC88D D D D D DLL L L L L #Aw66666C// ;v,SZEEODL'::
 
 
 
 
 
J J J J J#Aw77777C!233 &v!OCJ	BB	OD$4i@@0 0 0 0 0    ( #Aw66666 $$^$e$efifs$t$tuuu #w// I	T) 0#O--EO((///#'   ,SZEEODL'::     
: : : : : : #Aw77777C// sT#t'::: )-(;C<L(M /F /F"."6 #	 ?\-?< /#'#6 / $  /[  fi  fr  !s  !s  !s &	!/6DS[RUR^`c`rtwt  7A  7AOJNJ]JdJdejlq  tC  KD  KD$GM38SZ
 (-'='=(,6e(f(f(f(. (>	 (1 !+ !+ !+$(HMM  3C  KL  WZ  WcM  %d  %d  %d$*FFFFFF!+ 9@&Pw{nn8 H*5ch*GK69j(L

dff". ]AFAST`bebq  ~A  ~K  ^a  ^r  GJ  G]  ej  }@  }Q  \_  \h  sv  s  MP  M\  B]  B]  B]M'*=>s s s s s sB B B B B B B
 "'![k![![![]![![+FHfEEEE_/F /Fd ((_(f(fgjgw(x(xyyyC!233 zT;$"444 '+&8&<&<S[&I&IO'?@@ U_UdUmEnEn  #.co_Mj"k"k"kK M/":KHHHHH'([(b(bcfcn(o(opppC!344 hT;$"666 #266s{CCGw'788 U_WM]=^=^  't/BBB@B+C,<=#/0@'-QUW^Wf#g#gL '(89@@NNN M'"2LAAAAA'(\(c(cdgdo(p(pqqqC!566 PT;$"888 #488EEGw'788 U_WM]=^=^  .$2EEE,0,?@W,X 8 8L27L// /0GH M'"2A66666'(^(e(efifq(r(rsssC00 {T;$/11#'?3;#?L'1D"G| &#2 &&]G HMM'222&67G7\^e&f&fGG&2@cl\_\npsp{2|2|GKGZGaGabfhln}G~G~ D#* $(>#9#9$(HMM )C7E-1 %2 %& %& %&
 /?(8(Q(p(w(w  yG  IM  )N  )N/& /&G! $- " " " $$T() !. !" !" !" +;$4$F$Q$X$XYZ$[$[+" +""* | DB (/; J& J $ 0 0  ;I  !J  !J  !J  !J  !J%(Z%9466'*x':577!W !W !W !W !W $0#7 !CL<P<X !C-2_\=Q=]=B=MsxUXU_\_\m^a^qZ]Zi	>\ >\
 QTPZ>\ >\.] .]FF .3_\=Q=] .C>B.C .C .C?A.C .CF !& 3FD& I I I I I/J J: !OCK8 $0#8 ?844 #9R9R #"F # B!L7;;;;;"z Bl.B B|G[Gc B),)9r#&8 !E*/*:CHBE*ILIZKNK^GJ	+E +E
 >D+E +ECC +0*: +E#*ILIZKNK^GJ+E +E >D	+E +EC
 !&h < < < < <#&8 !B'*38}}q'8'8.3.>.I(-h(D(D(D(D(D(-h(L(L(L(L(L$)M(D$A$A$A$A$A'(X(_(_`c`k(l(lmmmC!344 LT;$"333'(`(g(ghkhs(t(tuuu 't/BBB+,h,o,ops  qA  -B  -B  C  C  C (,':3;K'L#/#8"}F0F"&< *#'#6 **h $g 6 6 6*:;K;`bi*j*j!*6DS[RUR^`c`rtwt  7A  7AOKOK^KeKefkmq  tC  LD  LD$HNCHcj (,~'='=(,-U;I15	 )6 )* )* )* 3C,<,U,  -G  -G  HV  X\  -]  -]3* 3*# (1 !& !& !&$(HMM(U,- %2 %& %& %& /?(8(J(R(Y(YZ[(\(\/& /&GGGGGG!&, # oJ %)$@$@ASA`bebmov$w$wE O0077777  (|7/7|o.3gg"x L.9E#(OO.K:=*,PCJJ$&&M'3 &o#&#7 !4%K %K %K %K %K %K %K %K2 04HFKFWXdai_b_ififwhkh{bfili}adamGo Go Goh.B C (-x{'b['b'b'bTa'b'bHHF HF HF HF HF HF HF HFT%, %, %, %, %, %, %,N >Os{\d=e=eD-ck:!/'5IIIIIC!233 jT;d&777HNN#\fifqNrrrrr"/<G L!122222C!344 ^T;$"555 #155ckBBGw'788 U_WM]=^=^  't/BBB'3D#:JGL]_f_o'p'p@L+C,<==+,j,q,qru  sC  -D  -D  E  E  EM'"2LAAAAA'(\(c(cdgdo(p(pqqqC!566 IT;!##"1#2BC#   +&&,fS-=&>&>  
 HNNM ]+ #     
 [D$999 #377DDGw'788 U_WM]=^=^  .$2EEENS+G,CDK /0GH M'"233333'(^(e(efifq(r(rsssC// %T   #w|'@@@S[TXTcEcEc#223;??HHH %)EEE#+Y]YkJkJk#155ckBBKHH %):)GGGCK[_[oLoLo#377DDMHH %)<)IIIck]a]sNsNs#599#+FFOHH %)9)FFF3;Z^ZmKmKm#266s{CCLHH %);)HHHS[\`\qMqMq#488EENH p ?844 RXt/K/KC/P/PQQQQQR R (  )I  )P  )P  QT  Qa  cf  cn  )o  )o  p  p  p $$<$C$CCM$R$RSSSs]   1AL%%
M/"MM1Ab 
c0A	c++c0>At   
u=*A	u88u=BAB0 B02AC"c                     d _          j        rt          j        t          j        j        d                     j                            t          j         j                  } fd} fd}t          j	        |||           d _        t          j         j
                  } fd} fd}t          j	        |||           dS )zW
        Implements :func:`autobahn.wamp.interfaces.ITransportHandler.onClose`
        Nz=WAMP transport was lost without closing the session {} beforer9  r   c                 6                         d           | S r6  r  r7  s    r7   r%  z+ApplicationSession.onClose.<locals>.success(  s    		'4111
r9   c                 0                         | d          S r.  r   r  s    r7   r+  z*ApplicationSession.onClose.<locals>._error-  s    **1.DEEEr9   c                 4                         d          S )NrA   )	was_cleanr  )r   rZ   wasCleans    r7   r%  z+ApplicationSession.onClose.<locals>.success5  s    99\489DDDr9   c                 0                         | d          S )NzWhile firing onDisconnectr   r  s    r7   r+  z*ApplicationSession.onClose.<locals>._error9  s    &&q*EFFFr9   )rL   rN   r   r   REASON_TRANSPORT_LOSTr   rC   r   r:  r   onDisconnect)rZ   r  r   r%  r+  r,  s   ``   @r7   onClosezApplicationSession.onClose  s+   
  	$()?W^^_c_opp  G g66A     
F F F F F7F333#DOD-..	E 	E 	E 	E 	E 	E	G 	G 	G 	G 	GAw/////r9   r  c                      t          d          )zR
        Implements :func:`autobahn.wamp.interfaces.ISession.onChallenge`
        zBreceived authentication challenge, but onChallenge not implemented)rz   )rZ   r  s     r7   rp  zApplicationSession.onChallenge=  s     _```r9   r,  c                     dS )zM
        Implements :meth:`autobahn.wamp.interfaces.ISession.onJoin`
        Nr   rZ   r,  s     r7   r  zApplicationSession.onJoinH        r9   welcomec                     dS )zP
        Implements :meth:`autobahn.wamp.interfaces.ISession.onWelcome`
        Nr   )rZ   r  s     r7   rm  zApplicationSession.onWelcomeN  r  r9   c                 b   t          j        d          }| j        | j        | j        | j        | j        | j        g}g }|D ]=}|                    |	                                           |
                                 >|r)| j                            dt          |                     |D ]| j                            dj        j        j        j                   t          j        j                  st          j        j        |           t          j        |fdfd           |S )zB
        Errback any still outstanding requests with exc.
        Nz'Cancelling {count} outstanding requests)countzncleaning up outstanding {request_type} request {request_id}, firing errback on user handler {request_on_reply})request_on_reply
request_idr   c                     j         S r2   ry  r   r   s    r7   r   zBApplicationSession._errback_outstanding_requests.<locals>.<lambda>w  s
    W-= r9   c                     j         S r2   r  r  s    r7   r   zBApplicationSession._errback_outstanding_requests.<locals>.<lambda>w  s
    IY r9   )rC   create_future_successr   r   r   r   r   r   extendvaluesclearrE   infor  r   ry  r  r   r   rz  r  r   )rZ   r   r   all_requestsoutstandingrequestsr   s         @r7   _errback_outstanding_requestsz0ApplicationSession._errback_outstanding_requestsT  sc    '-- "O!
 $ 	 	Hx00111NN 	HMM9+&&     # 	[ 	[GHNND!(!1"-$.7     ?7#344 4W-s333 #=#=#=#=?Y?Y?Y?YZZZZr9   c                     |j         t          j        k    r' j                            d|j         |j                   t          |j         |j                  }                     |          } fd}t          j	        |||           |S )zN
        Implements :meth:`autobahn.wamp.interfaces.ISession.onLeave`
        z/session closed with reason {reason} [{message}]r  c                 B    j         r                                 d S d S r2   )rL   rA   r   s    r7   rA   z.ApplicationSession.onLeave.<locals>.disconnect  s-     "!!!!!" "r9   )
r9  r   REASON_DEFAULTrE   r   r   r   r  rC   r   )rZ   r,  r   r   rA   s   `    r7   r:  zApplicationSession.onLeavez  s    
 >\888HMMKT[Tblsl{M||| w~w??..s33	" 	" 	" 	" 	" 	Az:666r9   r9  r   c                 F   | j         s| j                            d           dS | j        sG|sd}t          j                            ||          }| j                            |           d| _        n| j                            d           | j        du p| j        j	        }|S )zL
        Implements :meth:`autobahn.wamp.interfaces.ISession.leave`
        z6session is not joined on a realm - no session to leaveNzwamp.close.normalr  TzBsession was already requested to leave - not sending GOODBYE again)
rN   rE   r   r   r   r   rq  rL   r   	is_closed)rZ   r9  r   r   r  s        r7   r>   zApplicationSession.leave  s    
  	HMMRSSSF! 	` -,,&&fg&FFCO  %%%!%DHMM^___Ot+Ht/H	r9   c                 V    t          j                    }|                     |           dS )zS
        Implements :meth:`autobahn.wamp.interfaces.ISession.onDisconnect`
        N)r   TransportLostr  )rZ   r   s     r7   r  zApplicationSession.onDisconnect  s,     %''**3/////r9   rA  c                 R   t          |          t          k    sJ |t          |          t          t          fv sJ |t          |          t          k    sJ t          j        |d                    | j        j	                  ddd           |
                    dd          }|r)t          |t          j                  st          d          | j        st!          j                    | j                                        }d}| j        r| j                            d|||          }|rp|r?t          j        ||f|j        |j        |j        |j        d|                                }nrt          j        |||j        |j        |j        |j                  }nC|r)t          j        ||f||d	|                                }nt          j        ||||	          }|rL|j        |j        |_        |j        |j        |_        |j        |j        |_        |j        |j        |_        |r7|j         r0tC          j"                    }tG          |||du
          | j$        |<   nd}	 | j        %                    |           n%# t          $ r}	|| j$        v r| j$        |= |	d}	~	ww xY w|S )zP
        Implements :meth:`autobahn.wamp.interfaces.IPublisher.publish`
        Nz{}.publish()Fr   strictallow_empty_components
allow_noner  z,options must be of type a.w.t.PublishOptionsTr   r   r   rO  )&r   r   r   rX  rY  r   check_or_raise_urir   r   r   rw  r   r   PublishOptionsr   rL   r   r  rX   nextrW   r   r  r   r   r   r   message_attrcorrelation_idcorrelation_uricorrelation_is_anchorcorrelation_is_lastacknowledgerC   create_futurer*   r   r   )
rZ   rA  r   r   r  r  r   r   ry  r   s
             r7   publishzApplicationSession.publish  sF   
 E{{c!!!!|tDzzdE]::::~f!5!5!55"5+9+@+@AX+Y+Y*/:?.3		5 	5 	5 	5 **Y-- 	L:gu/CDD 	LJKKK 	,)+++)..00
 	T"188udFSSO 	5 Uoj&+@.=.E/>/G.=.E5D5S@ @ )0(<(<(>(>@ @ oj&+.=.E/>/G.=.E5D5SU U U  
5oj&+@+/-3@ @ )0(<(<(>(>	@ @ oj&++/-35 5 5
  	F%1%,%;"&2&-&=#,8,3,I)*6*1*E' 	w* 	*,,H-;Japx|a|-~-~-~Dz**H	 O  %%%% 	 	 	T///&z2G	
 s   'J 
J$JJ$rN  r  check_typesc                 0    t          |          r|t          |d          r|rJ |t          |          t          k    sJ |t	          |t
          j                  sJ  j        st          j	                     fd}t          |          r |d||||          S g }t          j        |j        t                    D ]}|d         }d|j        v r|j        d         D ]}	|	                                r|	                                }
|	j        p|}|E|	j        t           j        j        k    rt          j        d          }nt          j        d          }|                     ||||
||	j                             t/          j        |d	
          S )zS
        Implements :meth:`autobahn.wamp.interfaces.ISubscriber.subscribe`
        Nr   c                    t          j        |d                    	j        j                  ddd           	j                                        }t          j                    }|r		                    |          }t          || |r|j        nd           }t          ||||          	j        |<   |r&t          j        ||fi |                                }nt          j        ||          }|rL|j        |j        |_        |j        |j        |_        |j        |j        |_        |j        |j        |_        	j                            |           |S )Nz{}.subscribe()FTr  )r   r  r   r   r   rX   r  rC   r  r  r'   rt  r+   r   r  r  r  r  r  r  rL   r   )
rs  rL  rA  r  r  r  ry  handler_objr   rZ   s
            r7   
_subscribez0ApplicationSession.subscribe.<locals>._subscribe  sl   &u/?/F/Ft~G^/_/_.3>B27	9 9 9 9 -2244J*,,H )__R((!"c'+S7+>+>tTTK/?
ES[]h/i/iD , ;'
ETTW=Q=Q=S=STT'
E:: J)5)0)?C&*6*1*AC'0<070MC-.:.5.IC+O  %%%Or9   rT  rx   wildcard)matchexactTconsume_exceptions)callablery   r   r   r   r   r!   rL   r   r  r3   
getmembersr   r8   __dict__
is_handlerr   r  uri_typer{   URI_TYPE_WILDCARDr  _check_typesrC   gather)rZ   rN  rA  r  r  r  
on_replieskrR  patr   suboptss   `           r7   	subscribezApplicationSession.subscribe  s    !!pe&7WWk=Z=Z&7cn&7&7o}Us 2 2 22*We6L"M"MM 	,)+++	 	 	 	 	@ G 	E:dGUG[III
 J'(9;PQQ j jt$-//#}[9 	j 	j>>++ j#&7799D&)k&<WG&#&<3;3P#P#P.3.D:.V.V.VGG.3.D7.S.S.SG&--jj$gWZWg.h.hiii<
tDDDDr9   c                    t          |t                    sJ |j        sJ |j        | j        v sJ || j        |j                 v sJ | j        st          j                    | j        |j                                     |           d|_        t          | j        |j                           }|dk    r| j
                                        }t          j                    }t          |||j                  | j        |<   t!          j        ||j                  }| j                            |           |S t          j        |          S )zU
        Called from :meth:`autobahn.wamp.protocol.Subscription.unsubscribe`
        Fr   )r   r&   r  rk  r   rL   r   r  remover  rX   r  rC   r  r,   r   r   r  r   r  )rZ   rM  scountr  ry  r   s         r7   _unsubscribezApplicationSession._unsubscribeQ  s?    ,55665""""$"55555t2<?CCCCC 	,)+++ 	LO,33LAAA# T(9::Q;;-2244J*,,H1CJPXZfZi1j1jD":.%j,/BBCO  %%%O .v666r9   r_  c                 p   	 t          |          t          k    sJ |t          |          t          t          fv sJ |t          |          t          k    sJ t          j        |d                     j        j	                  ddd           |
                    dd          }|r)t          |t          j                  st          d           j        st!          j                     j                                        	d} j        r>	  j                            d|||          }n#   j                                          xY w|rp|r?t          j        	|f|j        |j        |j        |j        d|                                }nrt          j        	||j        |j        |j        |j                  }nC|r)t          j        	|f||d	|                                }nt          j        	|||	          }|rL|j        |j        |_        |j        |j        |_        |j         |j         |_         |j!        |j!        |_!        	 fd
}tE          j#        |          }tI          	|||           j%        	<   	  j        &                    |           n#  	 j%        v r j%        	=  xY w|S )a{  
        Implements :meth:`autobahn.wamp.interfaces.ICaller.call`

        .. note::

            Regarding type hints for ``*args`` and ``**kwargs``, doesn't work as we
            can receive any Python types as list items or dict values, and because
            of what is discussed here
            https://adamj.eu/tech/2021/05/11/python-type-hints-args-and-kwargs/
        Nz	{}.call()Fr  r  z)options must be of type a.w.t.CallOptionsTr   r  c                 d    t          j                  }j                            |           d S r2   )r   CancelrL   r   )r   
cancel_msgr  rZ   s     r7   	cancellerz*ApplicationSession.call.<locals>.canceller  s.     
33JO  ,,,,,r9   )r  )'r   r   r   rX  rY  r   r  r   r   r   rw  r   r   CallOptionsr   rL   r   r  rX   r  rW   r   rE   failurer  r   r   r   r   r  r  r  r  r  rC   r  r-   r   r   )
rZ   r_  r   r   r  r   r   r  ry  r  s
   `        @r7   callzApplicationSession.calls  sL    I#%%%%|tDzzdE]::::~f!5!5!55"9+6+=+=dn>U+V+V*/:?.3		5 	5 	5 	5 **Y-- 	I:gu/@AA 	IGHHH 	,)+++)..00
 	"&"5"<"<T9dTZ"["[  """ 	2 Rl:#,=+:+B,;,D+:+B2A2P= = &-%9%9%;%;= = l:#,+:+B,;,D+:+B2A2PR R R  
2l:#,=(,*0= = &-%9%9%;%;	= = l:#,(,*02 2 2
  	F%1%,%;"&2&-&=#,8,3,I)*6*1*E'	- 	- 	- 	- 	- 	- &;;;&1*iSZ&[&[
#	 O  %%%%	T_,,OJ/s   D, ,EJ J3r  prefixc                 2    t          |          r|t          |d          r|rJ  j        st          j                     fd}t          |          r |d||||          S g }t          j        |j        t                    D ]{}|d         }	d|	j	        v rh|	j	        d         D ]Z}
|

                                rD|
                                }|
j        p|}|                     |||	|||
j                             [|t          j        |d          S )zN
        Implements :meth:`autobahn.wamp.interfaces.ICallee.register`
        Nr   c                    t          j        |d                    
j        j                  ddd           
j                                        }t          j                    }|r
	                    |          }t          || |r|j        nd           }	d                    	|          }t          ||||          
j        |<   |r&t          j        ||fi |                                }nt          j        ||          }|rL|j        |j        |_        |j        |j        |_        |j        |j        |_        |j        |j        |_        
j                            |           |S )Nz{}.register()FTr  z{}{})r   r  r   r   r   rX   r  rC   r  r  r)   rt  r/   r   r  r  r  r  r  r  rL   r   )rs  rL  r_  r  r  r  ry  endpoint_objr   r  rZ   s            r7   	_registerz.ApplicationSession.register.<locals>._register  s   &y/>/E/EdnF]/^/^.3>B27	9 9 9 9 -2244J*,,H )__R((#BG-UW-@-@QUVVL!"MM&)<<	.=j(T]_k.l.lD
+ >&z9WW@T@T@V@VWW&z9== J)5)0)?C&*6*1*AC'0<070MC-.:.5.IC+O  %%%Or9   rT  rx   Tr  )r  ry   rL   r   r  r3   r  r   r8   r  is_endpointr   r  r  r  rC   r  )rZ   r  r_  r  r  r  r  r  r  rR  r  r   regoptss   `   `        r7   registerzApplicationSession.register  s^    ""vy'<'(T_B`B`'<it'<'<u 	,)+++ 	  	  	  	  	  	D H 	E 9T8YMMM
 J'(:<QRR j jt$-//#}[9 j j??,, j#&7799D&)k&<WG&--ii$gWZWg.h.hiii<
tDDDDr9   c                    t          |t                    sJ |j        sJ |j        | j        v sJ | j        st          j                    | j        	                                }t          j                    }t          |||j                  | j        |<   t          j        ||j                  }| j                            |           |S )zT
        Called from :meth:`autobahn.wamp.protocol.Registration.unregister`
        )r   r(   r  rk  r   rL   r   r  rX   r  rC   r  r0   r   r   r  r   )rZ   rg  r  ry  r   s        r7   _unregisterzApplicationSession._unregister  s     ,55665""""$"55555 	,)+++)..00
&((,=j(T`Tc,d,dj) \_==S!!!r9   r2   )NNNNNNNr   )NNN)NNNN)9r   r   r   r   r   r   r   r[   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r=   rA   r   r   r  r   r  r  r   rp  r   r  r   rl  rm  r  r   r:  r>   r  r%   r  r   r	   r!   r&   r  r  r"   r  r#   r(   r  r  r   r9   r7   r   r   e  s%         x(=>    > -    X ,x/F , , , V, #8M#: # # # V# 

 
 
 
 V
* % % V%  15%)'+37)--1+/#" #"#""49-#" c]#"  }	#"
 !c3h0#" !#" &c]#" $C=#" #" #" V#"J $ $ V$   V   *  8hTX hT hT hT hTT !0 !0 V!0F aY a3 a a a Va n    V
  Xc]    V
$ $ $L |    V"  HSM 8C=    V* 0 0 V0 XS Xh{6K X X X VXt NR\`CE CEx}!5 CEhsm CE#$45CEKSTX>CE,\ 223CE CE CE VCEJ 7  7  7D fc fuS*_7M f f f VfP RVTX/3?E ?Ex}!5 ?E(3- ?E"?3?EDLSM?E&tn?E8=lDQ]L^>^8_?E ?E ?E V?EB    r9   r   c                   ^    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd ZdS )_SessionShimar  
    shim that lets us present pep8 API for user-classes to override,
    but also backwards-compatible for existing code using
    ApplicationSession "directly".

    **NOTE:** this is not public or intended for use; you should import
    either autobahn.asyncio.wamp.Session or
    autobahn.twisted.wamp.Session depending on which async
    framework yo're using.
    Nc                 ,    |                      |          S r2   )on_joinr  s     r7   r  z_SessionShim.onJoinC  s    ||G$$$r9   c                    | j         rd | j                                         D             d         }d | j                                         D             d         }|                                 }|                     | j        j        t          | j                                                   |||           d S |                                  d S )Nc                 D    g | ]}|j                             d d          S )rl   N_argsgetr   xs     r7   r  z*_SessionShim.onConnect.<locals>.<listcomp>K  s(    YYYaagkk(D11YYYr9   c                 D    g | ]}|j                             d d          S )ro   Nr  r  s     r7   r  z*_SessionShim.onConnect.<locals>.<listcomp>L  s(    ]]]!J55]]]r9   )r   rl   ro   ru   )	_authenticatorsr  _merged_authextrar=   r   rg   r   keys
on_connect)rZ   rl   ro   ru   s       r7   r   z_SessionShim.onConnectF  s     	 ZY4;O;V;V;X;XYYYZ\]F]]t?S?Z?Z?\?\]]]^`aH ..00III! !5!:!:!<!<==!#       OOr9   c                 $   	 | j         |j                 }ng# t          $ rZ t          d                    |j        t          t          | j                                                                                 w xY w|                    | |          S )NzBReceived challenge for unknown authmethod '{}' [authenticators={}])	r  rn  r  rz   r   r   sortedr  on_challenge)rZ   r  authenticators      r7   rp  z_SessionShim.onChallenge[  s    	 01ABMM 	 	 	T[[$t388::;;<<   	 ))$	:::s
    A$A9c                 N   |j         | j        d S 	 | j        |j                  }ng# t          $ rZ t          d                    |j         t          t          | j                                                                                w xY w|                    | |j	                  S )NzBReceived onWelcome for unknown authmethod '{}' [authenticators={}])
rq   r  r  rz   r   r   r  r  
on_welcomeru   )rZ   r   r  s      r7   rm  z_SessionShim.onWelcomeg  s    >!T%9%AF	 0@MM 	 	 	T[[Nt388::;;<<   	 ''cm<<<s
   % A$B	c                 ,    |                      |          S r2   )on_leaver  s     r7   r:  z_SessionShim.onLeavev  s    }}W%%%r9   c                 *    |                                  S r2   )on_disconnectrY   s    r7   r  z_SessionShim.onDisconnecty  s    !!###r9   c           	          t          t                    sJ  j        i  _         fd} |d            |d           j        }                                 }|                                D ]?\  }}||v r6||         |k    r*t          d                    ||||                             @ j        j        <   d S )Nc                 "    t           fdt          j                                                  gz   D                       }t	          |          dk    r6t          d                     d                    |                              d S )Nc                 <    g | ]}|j         v |j                  S r   )r  )r   ar
  s     r7   r  zG_SessionShim.add_authenticator.<locals>.at_most_one.<locals>.<listcomp>  s2       17?? "??r9   rT  zInconsistent {}s: {} )setr   r  r  r  
ValueErrorr   r=   )r
  unir  rZ   s   ` r7   at_most_onez3_SessionShim.add_authenticator.<locals>.at_most_one  s        d299;;<<N    C
 3xx!|| *11    |r9   rl   ro   z4Inconsistent authextra values for '{}': '{}' vs '{}')	r   r   r  ru   r  r  r(  r   r
  )rZ   r  r*  ru   mergedr  vs   ``     r7   add_authenticatorz_SessionShim.add_authenticator~  s   -88888'#%D 	 	 	 	 	 	 	H 	J "+	''))LLNN 	 	DAqI~~)A,!"3"3 JQQ1il    4A]/000r9   c                     d | j                                         D             d }t          |t                                }fdfd|D             S )a:  
        internal helper

        :returns: a single 'authextra' dict, consisting of all keys
            from any authenticator's authextra.

        Note that when the authenticator was added, we already checked
        that any keys it does contain has the same value as any
        existing authextra.
        c                     g | ]	}|j         
S r   )ru   )r   r%  s     r7   r  z2_SessionShim._merged_authextra.<locals>.<listcomp>  s    IIIaakIIIr9   c                 J    | t          |                                          z  S r2   )r'  r  )r  ys     r7   extract_keysz4_SessionShim._merged_authextra.<locals>.extract_keys  s    s16688}}$$r9   c                 n    D ]}| |v r
||          c S t          d                    |                     )z
            for anything already in self._authenticators, we checked
            that it has the same value for any keys in its authextra --
            so here we just extract the first one
            zNo values for '{}')r(  r   )r  ru   
authextrass     r7   first_value_forz7_SessionShim._merged_authextra.<locals>.first_value_for  sW     ( ( (		>>$Q<''' " $++A..  r9   c                 (    i | ]}| |          S r   r   )r   r  r5  s     r7   
<dictcomp>z2_SessionShim._merged_authextra.<locals>.<dictcomp>  s5     
 
 
 q!!
 
 
r9   )r  r  r
   r'  )rZ   r2  unique_keysr4  r5  s      @@r7   r  z_SessionShim._merged_authextra  s     JI4+?+F+F+H+HIII
	% 	% 	% \:suu==	 	 	 	 	
 
 
 
 
 
 
 	
r9   c                     d S r2   r   r  s     r7   r
  z_SessionShim.on_join      r9   c                 .    |                                   d S r2   )rA   r  s     r7   r  z_SessionShim.on_leave  s    r9   c                 D    |                      | j        j                   d S r2   )r=   r   rg   rY   s    r7   r  z_SessionShim.on_connect  s    		$+#$$$$$r9   c                     d S r2   r   rY   s    r7   r!  z_SessionShim.on_disconnect  r:  r9   )r   r   r   r   r  r  r   rp  rm  r:  r  r-  r  r
  r  r  r!  r   r9   r7   r  r  4  s        	 	 O% % %  *
; 
; 
;= = =& & &$ $ $
+A +A +AZ#
 #
 #
P    % % %    r9   r  c                   &    e Zd ZdZeZ	 ddZd ZdS )ApplicationSessionFactoryz(
    WAMP endpoint session factory.
    Nc                 >    |pt          j        d          | _        dS )z

        :param config: The default component configuration.
        :type config: instance of :class:`autobahn.wamp.types.ComponentConfig`
        r   r   N)r   r   r   r   s     r7   r[   z"ApplicationSessionFactory.__init__  s"     E 5H E E Er9   c                 H    |                      | j                  }| |_        |S )z
        Creates a new WAMP application session.

        :returns: -- An instance of the WAMP application session class as
                     given by `self.session`.
        )r  r   factory)rZ   r  s     r7   __call__z"ApplicationSessionFactory.__call__  s#     ,,t{++r9   r2   )r   r   r   r   r   r  r[   rC  r   r9   r7   r?  r?    sQ          !GF F F F	 	 	 	 	r9   r?  )Atypingr   r   r   r   r   r   r	   rC   r3   	functoolsr
   autobahnr   autobahn.utilr   r   r   autobahn.wampr   r   r   r   r   autobahn.wamp.exceptionr   r   r   r   autobahn.wamp.interfacesr   r   r   r   r   autobahn.wamp.typesr   r   r   r    r!   r"   r#   autobahn.exceptionr$   autobahn.wamp.requestr%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r8   r;   r   r  abc_registerobjectr?  r   r9   r7   <module>rP     s1  4 H G G G G G G G G G G G G G G G G G               > > > > > > > > > >       ! ! ! ! ! !             # # # # # # g g g g g g g g g g g g b b b b b b b b b b b b b b                                    3 3 3 3 3 3                           8 8 8c c c c c/ c c cL	 K K K K K K K K\.i i i i i% i i iZ  ( ) ) )         r9   