
    hh                       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@y)    )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                 Z    t        j                  |       xs t        j                  |       S N)inspectismethod
isfunction)fs    R/var/www/Befach/backend/env/lib/python3.12/site-packages/autobahn/wamp/protocol.pyis_method_or_functionr8   ;   s#    A7'"4"4Q"77    c                   r   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y)BaseSessionzi
    WAMP session base class.

    This class implements :class:`autobahn.wamp.interfaces.ISession`.
    Nc                    t        j                         | _        | 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               | _        y )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 ,,.@224H2
 15 &**.&*(,*.,048 =A<U<U ;? 8<  +}r9   returnc                     | j                   S )zY
        Implements :func:`autobahn.wamp.interfaces.ITransportHandler.transport`
        )rL   rY   s    r7   	transportzBaseSession.transportz   s     r9   c                 V    | j                   duxr | j                   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Gr9   c                 B    | j                   duxr | j                         S )zR
        Implements :func:`autobahn.wamp.interfaces.ISession.is_attached`
        N)rN   ra   rY   s    r7   is_attachedzBaseSession.is_attached   s#    
 t+C0A0A0C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                    |[t        |d      rD|j                  | j                  |<   || j                  |j                  d   j	                         <   yt        d      t        |d      sLt	        j                  |t        j                  j                        g| j                  |<   || j                  |<   y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+.3<3F3F%%i0BK!!)"5"5a"8"<"<">?"#stt9k247KKs{{GeGe4f3g%%i0+4!!%("  $B  C  Cr9   c           	         d}t        |d      rt        |j                        }d}t        |d      r|j                  }|r|r||d<   nd|i}t	        |t
        j                        r5t        |j                        t        k(  r|j                  n|j                  }nA|j                  | j                  v r'| j                  |j                     d   j                  }nd}d}	| j                  r| j                  j                  d|||      }	|	rFt        j                   ||||	j"                  |	j$                  |	j&                  |	j(                        }
|
S 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   sJ     3>D3!ZZF&({#%r*c9556!%ciiC!7CIISYYE}} 5 55--cmm<Q?DD2"1188tVTO-- ' %(7(?(?)8)A)A(7(?(?/>/M/MOC 
 -- ' % $ &	(C 
r9   c                    d}d}|j                   r4| j                  sDd}| j                  j                  |       t	        t        j
                  ||j                         }n	 t        |j                  |j                   |j                  |j                        }| j                  j                  d|j                  |      \  }|_        |_        |j                  |k7  ri| j                  j                  d||j                         t	        t        j                  dj                  ||j                        |j                         }	 |r|S |j                  | j$                  v r| j$                  |j                     }	 |j                  r<|j                  r ||j                  i |j                  }n6 |di |j                  }n#|j                  r ||j                   }n |       }|s|j                  ro|j                  r8t-        j                  |j                  g|j                  i |j                  }nt-        j                  |j                  fi |j                  }nV|j                  r+t-        j                  |j                  g|j                   }nt-        j                  |j                        }t/        |d      r|j                   |_         t/        |d      r|j0                  |_        t/        |d      r|j2                  |_        t/        |d      r|j4                  |_        t/        |d      r|j6                  |_        |S # t         $ r]}| j                  j                  d|	       t	        t        j"                  d
j                  |      |j                         }Y d}~hd}~ww xY w# t         $ r1 	 | j'                  t)        j*                         d       n#  Y nxY wY w xY w)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   s7    <<&&Qg&*+;+P+PRYdgdpdpq&4S[[#,,PSPbPbdgdodo&pO<@<O<O<V<VW[]`]f]fhw<x9OSXsz yyO3x,;"%)) & 
 #3,EEdkkl{  ~A  ~G  ~G  H%(\\# N99)))$$SYY/D ::xx"CHH;

;"0SZZ0xx"CHHo"f zz88#44SYYXXSZZXC#44SYYM#**MC88#44SYYJJC#44SYY?C 3
#<<CL3!CJ3( # 1 1C3)*"%"5"5C3&!ooCO
S ! HHMM"RXYMZ.(::ELLQO!$GN  $$,,.9sE   #A+M <A+N6 	N3AN..N36	O0 $O%$O0%O)'O0/O0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;   ?   s   
 C1-f 8J/   Hd H H DT D D %.!9 % % x}    HSM        (3-    HSM     "hsm " " 8DcN3  C	 C(3- C"9vbr9   r;   c                   H   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#jH                  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 Z8y);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         j                  |        |xs t        j                  d      | _        d| _        d| _        d| _        i | _        i | _	        i | _
        i | _        i | _        i | _        i | _        i | _        i | _        y)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.]8M8MT\8] $)+0" 8<  !!#  " ! ! r9   r\   c                     | j                   S r2   )r   rY   s    r7   r   zApplicationSession.config  rm   r9   payload_codecc                     || _         y)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                   j                  d j                  |       | _         j	                  d |      }t        j                  |d fd       t        j                  | fd fd       y)zV
        Implements :func:`autobahn.wamp.interfaces.ITransportHandler.onOpen`
        z{func}(transport={transport}))funcr^   r@   Nc                 (    j                  | d      S )NzWhile notifying 'connect'_swallow_errorfailrZ   s    r7   <lambda>z+ApplicationSession.onOpen.<locals>.<lambda>      ,,T3NOr9   c                 B    t        j                  j                        S r2   )rC   	as_future	onConnect_rZ   s    r7   r   z+ApplicationSession.onOpen.<locals>.<lambda>  s    eoodnn5r9   c                 (    j                  | 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  sm    
 	6T[[T]^ $ IIiy1tO	
 	5O	
r9   c                     | j                   j                  d| j                         | j                  | j                  j
                         y)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  s2    
 	z7		$++##$r9   rg   authmethodsrl   ro   ru   	resumableresume_sessionresume_tokenc	                    | j                   rt        d      | j                  st        d      || _        d| _        t        j                  || j                  |||||||	      }	| j                  j                  |	       y)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     455:;;  # mm%"&"5"5(3#)%-&/&/+9)57 	S!r9   c                 R    | j                   r| j                   j                          yy)zQ
        Implements :func:`autobahn.wamp.interfaces.ISession.disconnect`
        N)rL   closerY   s    r7   rA   zApplicationSession.disconnect  s     
 ??OO!!# r9   c                    t        |d      rot        |j                  t        j                        rK| j
                  j                  d| j                  j                  |j                  j                                y| j
                  j                  d| j                  j                  |t        j                  |             y)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=W&XHHMM: $ 7 7"jj668  : HHNN=nn--88>	  r9   c                     	 | j                  ||       y# t        $ rE | j                  j                  dt	        j
                  t	        j                                      Y yw xY w)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  sa    	T3'   	HHNN&11%2F2F2HI   	s    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| i |}g }j                  j                         D ]  \  }}||v st	        |dd       t
        k(  rv|j                  D cg c]  }|j                   }}t        ||   |j                        r\|j                  dj                  ||t        ||         j                               t        ||   |      r|j                  dj                  ||j                  t        ||         j                                |rt        dj                  |            t        j                  g| i | d {   S c c}w 7 	w)N
__origin__z'{}' expected types={} got={}z'{}' expected type={} got={}z, )r3   getcallargs__annotations__itemsgetattrr   __args__r   r   appendr   r   r   r=   rC   r   )	r   r   	argumentsresponsenamekindargexpected_typesr   s	           r7   _type_checkz2ApplicationSession.type_check.<locals>._type_check  sE    ++DB4B6BIH"2288:
d9$ t\48EABF--)P3#,,)P)P))D/4==I$OO ? F Ft^GKIVZOG\GeGe!gh (	$> :AA$W[\efj\kWlWuWuvx ; $TYYx%899????? *Q @s2   A E&"E&&E9E&AE&A<E&E$
E&r   )rZ   r   r
  s    ` r7   
type_checkzApplicationSession.type_check  s    
	@* r9   r   c                 1   "#$%  j                   t        t        j                        rCt	        j
                   j                        } fd} fd}t	        j                  |||       yt        t        j                        rmt        j                  j                  j                        "t	        j
                   j                  "      }" fd} fd}t	        j                  |||       yt        t        j                        rlt        j                  j                  j                        }t	        j
                   j                   |      } fd} fd}t	        j                  |||       yt#        dj%                  j&                              t        t        j(                        r j*                  s/t        j(                         } j,                  j/                  |       d _         t        j                  j                  j                        "t	        j
                   j                  "      }" fd	} fd
}t	        j                  |||       yt        t        j0                        rj2                   j4                  v rD j4                  j2                     D ]&  }|j6                  #j8                  xs |j8                  }	j:                  r j<                  s) j>                  jA                  dj:                          y	 tC        jD                  j:                  jF                  jH                        }
 j<                  jK                  d|	|
      \  }_&        _'        |	|k7  r j>                  jA                  d        y#jR                  r#jR                  fn	tU               }jL                  r|tU        jL                        z   }jN                  rjN                  n	tW               }#jX                  r|t        jZ                  |j\                  j^                  j`                  jb                  |	jd                  jf                  j:                  jh                  
      |#jX                  <    fd}# fd}t	        j
                  #jj                  g|i |}t	        j                  |||       ) yt#        dj%                  j2                              t        t        jl                        rjn                   jp                  v r jp                  js                  jn                        }t	        jt                  |jv                        r t	        jx                  |jv                        ryt{        j\                  |j|                        }t	        j~                  |jv                  |       yt#        dj%                  jn                              t        t        j                        rGjn                   j                  v r
 j                  js                  jn                        }t	        jt                  |jv                        r t	        jx                  |jv                        ryj2                   j4                  vrg  j4                  j2                  <   t        j2                  |j8                   |j6                        } j4                  j2                     j                  |       t	        j~                  |jv                  |       yt#        dj%                  jn                              t        t        j                        rjn                   j                  v rى j                  js                  jn                        }t	        jt                  |jv                        r t	        jx                  |jv                        ry|j                   j4                  v r< j4                  |j                     D ]	  }d|_G          j4                  |j                  = t	        j~                  |jv                  d       yt#        dj%                  jn                              t        t        j                        rjn                   j                  v rd j                  jn                     }|j                  $d}j:                  r j<                  s8d} j>                  jA                  |       t        t        j                  |      }n	 tC        jD                  j:                  jF                  jH                        }
 j<                  jK                  d$|
      \  }_&        _'        $|k7  rI j>                  jA                  d|$       t        t        j                  dj%                  |$            }	 j                  rG|j                  j                  r=|r j                  |d"       yjN                  xs
 tW               }jL                  xs
 tU               } fd#}|j                  r|j                  j                  rt	        j
                  |j                  j                  t        j                  jL                  j                  j                  j                  jh                  d$jN                        }n-t	        j
                  |j                  j                  g|i |}t	        j                  |d|       y j                  jn                  = |jv                  }t	        jt                  |      rt	        jx                  |      ry|rt	        j                  ||       yjN                  s"|j                  r|j                  j                  rjN                  xs i }jL                  rMt        j                  jL                  j                  j                  j                  jh                  d$|}nBt        j                  d<j                  j                  j                  jh                  d$|}t	        j~                  ||       yjL                  rot        jL                        d%kD  r3t        j                  jL                   }t	        j~                  ||       yt	        j~                  |jL                  d          yt	        j~                  |d       yt#        d&j%                  jn                              yt        t        j                        rkjn                   j                  v r$t#        d'j%                  jn                              j                   j                  vr$t#        d(j%                  j                               j                  j                     %%j                  }j                  xs %j                  $d}j:                  r j<                  s8d)} j>                  jA                  |       t        t        j                  |      }n	 tC        jD                  j:                  jF                  jH                        }
 j<                  jK                  d$|
      \  }_&        _'        $|k7  rI j>                  jA                  d*|$       t        t        j                  d+j%                  |$            }	 |rQ j                  t        j                  j                  jn                  |      } j,                  j/                  |       y|jR                  |jR                  f}n
tU               }jL                  r|tU        jL                        z   }jN                  rjN                  n	tW               }|jX                  rrj                  r$ fd.}nd}t        j                  %|j                  j                  j                  $jd                  j:                  /      ||jX                  <   t	        j
                  |jj                  g|i |}$% fd0}% fd1}t        jn                  |       j                  jn                  <   t	        j                  |||       yt        t        j                        ryjn                   j                  vr( j>                  j                  d2jn                  3       y j                  jn                     } t	        j                  | jv                         yt        t        j                        rDjn                   j                  v r j                  js                  jn                        }t	        jt                  |jv                        r t	        jx                  |jv                        ryj                   j                  vrFt         j                  |j                  |j                        %% j                  j                  <   n$t#        d4j%                  j                              t	        j~                  |jv                  %       yt#        d5j%                  jn                              t        t        j                        rijn                  dk(  rM	  j                  j                     }! j>                  j                  d7|!j                  j                  8       yjn                   j                  v rщ j                  js                  jn                        }t	        jt                  |jv                        r t	        jx                  |jv                        ry|j                   j                  v r5d j                  |j                     _G         j                  |j                  = t	        j~                  |jv                         yt#        d9j%                  jn                              t        t        j                        rd}j                  t        j                  j                  k(  rIjn                   j                  v r1 j                  js                  jn                        jv                  }n,j                  t        j                  j                  k(  rIjn                   jp                  v r1 jp                  js                  jn                        jv                  }nj                  t        j                  j                  k(  rIjn                   j                  v r1 j                  js                  jn                        jv                  }nLj                  t        j                  j                  k(  rHjn                   j                  v r0 j                  js                  jn                        jv                  }n݉j                  t        j                  j                  k(  rHjn                   j                  v r0 j                  js                  jn                        jv                  }nnj                  t        j                  j                  k(  rGjn                   j                  v r/ j                  js                  jn                        jv                  }|r;t	        jx                  |      sUt	        j                  | j                               yt#        d:j%                  j                  jn                              yt#        d;j%                  j&                              # tP        $ r3} j>                  jA                  d|j:                         Y d}~ yd}~ww xY w# tP        $ rQ} j>                  jA                  d|        t        t        j                  d!j%                  |            }Y d}~<d}~ww xY w# tP        $ rQ} j>                  jA                  d,|        t        t        j                  d-j%                  |            }Y d}~	cd}~ww xY w# t        $ r% t#        d6j%                  j                              w xY w)=zY
        Implements :func:`autobahn.wamp.interfaces.ITransportHandler.onMessage`
        Nc                 T   | ^j                   j                  d|        t        j                  ddj	                  |             }j
                  j                  |       y j                  rj                  _        j                  _
        j                  _        j                  _        j                  _        j"                  _        j&                  _        j*                  _        t/        j                  j                  j                  j                  j                   j$                  j&                  j
                  j0                  j2                  j
                  j4                  ddd       _        j9                  dj6                        }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       y )Nz"Session denied by onWelcome: {res})reswamp.error.cannot_authenticate{0}F)rg   sessionrl   ro   rq   rs   ru   
serializerr^   resumedr   r   r=   c                 (    j                  | d      S )NzWhile notifying 'join'r   r   rZ   s    r7   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>n  s    $"5"5a9Q"Rr9   c                 X    t        j                  j                  j                        S r2   )rC   r   onJoinrV   r   s    r7   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>s  s    %//$++t?T?T"Ur9   c                 (    j                  | d      S )NzWhile firing onJoinr   r  s    r7   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>y  s    $"5"5a9N"Or9   c                 (    j                  d      S )Nr?   r   r   s    r7   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>~  s    $))GT":r9   c                 (    j                  | d      S )NzWhile notifying 'ready'r   r  s    r7   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>  s    $"5"5a9R"Sr9   )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 '<ell3>O! ,,U3yy&)ii'*{{D$#&::DL%(\\DN'*~~D$),)9)9D&&)mmDO),D&,:"kk $ 0 0#||!%#'#3#3%)%7%7"%--#'??#>#>#L#L"&//"C"C %"'%)-D)* 		&$0E0EFA ''4R
 ''U ''4O
 '': ''4Sr9   c                     t        j                  dd      }j                  j                  |       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  s?    #MM8:[E OO((/..q2JKKr9   c                 r     j                  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                 (    j                  | d      S )NzWhile firing 'leave' eventr   r  s    r7   _errorz=ApplicationSession.onMessage.<locals>.success.<locals>._error  s    #2216RSSr9   )r   rC   r   )r  r   r&  r(  detailsrZ   s   `   r7   r"  z-ApplicationSession.onMessage.<locals>.success  s7    		'49A#T'':v>Hr9   c                 (    j                  | d      S NzWhile firing onLeaver   r  s    r7   r(  z,ApplicationSession.onMessage.<locals>._error  s    ..q2HIIr9   c                 0   | t        d      t        |       t        k(  r| j                  d      } t        |       t        k7  r#t        dj                  t        |                   t        j                  |       }j                  j                  |       y )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(STXYbTc(dee#00;EOO((/r9   c                    j                  | d       t        j                  ddj                  | j                              }j
                  j                  |       t        j                  |j                  |j                        t        j                  j                        }fd}fd}t        j                  |||       |S )NzAuthentication failedr  r  c                 .    j                  d       | S Nr>   r  r  r)  rZ   s    r7   r"  z<ApplicationSession.onMessage.<locals>.error.<locals>.success  s    		'49"
r9   c                 (    j                  | d      S r+  r   r  s    r7   r(  z;ApplicationSession.onMessage.<locals>.error.<locals>._error  s    #2216L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#MM*JELLY\YbYbLcdEOO((/#00u}}MGg>A#
N''7F; Hr9   z8Received {0} message, and session is not yet establishedc                 .    j                  d       | S r3  r  r4  s    r7   r"  z-ApplicationSession.onMessage.<locals>.success  s    IIgtW5Jr9   c                 t    dj                  j                  j                        }j                  | |      S )Nz7While firing onLeave for reason "{0}" and message "{1}")r   r6  r   r   )r   errmsgr   rZ   s     r7   r(  z,ApplicationSession.onMessage.<locals>._error  s6    V]]^a^h^hjmjujuvF..q&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                   r}j                  d   j                  rcj                  r;t	        j
                  j                        }j                  j                  |       y j                  j                  d       y y y )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  sp      #::t?Q?QRZ?[?y?y#'??/6/D/DS__/UH$(OO$8$8$B$(HHMM  3r  %s @z:r9   c                 t    dj                  j                  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  s5    %M%T%T '

C,<,<&>F#'#6#6q&#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                 *    j                  | d       y )NzWhile firing on_progress)r   r   s    r7   r(  z,ApplicationSession.onMessage.<locals>._error  s    $($4$4T;U$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                  r5j
                  st        d      j
                  j                  d| |      }|rNt        j                  j                  |j                  d|j                  |j                  |j                        }n#t        j                  j                  | |d      }j                  j                  |       y )N7trying to send encrypted payload, but no keyring activeFT)r   progressr   r   r   )r   r   rT  )r   r   tupledictr   rW   r   r   r   Yieldr   r   r   r   rL   r   )r   r   r   progress_msgr   rO  rZ   s       r7   rT  z.ApplicationSession.onMessage.<locals>.progress  s    /3|tDzdTY]?Z([/Z/5~fQUAU(V/U:>+.<<373F3F6?@y6z0z>B>Q>Q>X>XY^`dfjlr>sO+:;B==Q`QhQhRVRaRjRjQ`QhQhXgXvXv<xL <C==NRPVRV<XL
 )-(<(<\(Jr9   )rT  callercaller_authidcaller_authrole	procedurer?  r   c                 X   	j                   j                  = d }j                  r	j                  sd}	j                  j                  |       nl	 t        | t        j                        r3	j                  j                  d| j                  | j                        }n	j                  j                  d| g      }|rt        | t        j                        ryt        j                  j                  |j                  |j                  |j                   |j"                  | j$                  | j&                  | j(                  | j*                  	      }nt        j                  j                  |j                  |j                  |j                   |j"                        }nt        | t        j                        rct        j                  j                  | j                  | j                  | j$                  | j&                  | j(                  | j*                        }n"t        j                  j                  | g      }	j,                  @	j                  j/                  d	j1                  j2                  j                               y 	 	j,                  j5                  |       y # t        $ r(}	j                  j                  d|       Y d }~d }~ww xY w# t6        $ r}t        j8                  t        j:                  j<                  j                  t>        j@                  d
j1                  |jB                  |jD                  j2                  |      g      }	j,                  j5                  |       Y d }~y d }~wtF        $ r}t        j8                  t        j:                  j<                  j                  t>        jH                  dj1                  |jB                  |jD                  j2                  |      g      }	j,                  j5                  |       Y d }~y d }~ww xY w)NrS  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   rW  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   rO  registrationrZ   s
         r7   r"  z-ApplicationSession.onMessage.<locals>.success8  s   $($5$5ckk$B26#&<<+/+>+>2k(,g(>	)./9#u?O?O/PBFBUBUB\B\]bdhjmjujuwz  xE  xE  CFBFBUBUB\B\]bdhknjoBp $3'1#u7G7G'H07ckkFUF]F]GVG_G_FUF]F]M\MkMkEHZZLOL]L]NQNaNaJM//1[ 18ckkFUF]F]GVG_G_FUF]F]M\MkMk	1m (2#u7G7G'H07ckkCF;;EH]]EHZZLOL]L]NQNaNaJM//1[ 18ckkDG51J $(??#:$(HHNN3x33  AM  AW  AW  Y\  Yd  Yd  4e  %f$*!F$(OO$8$8$?S 09 ).,0HHMM0^45 -: -. -.).T (: !F29--@R@R@_@_adalaln~  oO  oO Gj  Gq  Gq  rw  r|  r| rw  r~  r~ r~  rH  rH rsGt Fu3vK
 %)OO$8$8$E$E'; !F 3:--@R@R@_@_adalaln~  oU  oU Go  Gv  Gv  w|  wA  wA w|  wC  wC wC  wM  wM wxGy Fz3{K
 %)OO$8$8$E$E!Fs?   A+J' K '	K0KK	P)$BM>>P)
BP$$P)c           
         j                   j                  = t        j                  |       }	 j	                  | |       d }j
                  rt        j                  |       }j                  t        j                  j                  j                  | j                  |j                        }	 j                  j                  |       y #  Y xY w# t        $ r}t        j                   t        j                  j                  j                  t"        j$                  dj'                  j(                  |      g      }j                  j                  |       Y d }~y d }~wt*        $ r}t        j                   t        j                  j                  j                  t"        j,                  dj'                  j(                  |      g      }j                  j                  |       Y d }~y d }~ww xY w)NzLerror return value from invoked procedure "{0}" could not be serialized: {1}r^  zSsuccess return value from invoked procedure "{0}" exceeds transport size limit: {1})r   r   rC   failure_messager   rG   r   r   r   ra  rb  r   r   rL   r   r   r   r   rI   r   r\  r$   rJ   )r   r:  formatted_tbr!  r   r   rd  rZ   s        r7   rv   z+ApplicationSession.onMessage.<locals>.error  s   $($5$5ckk$B).)>)>s)C!)$($4$4S&$A 04#'#5#5383Q3QRU3VL(,(D(D$+$6$6$C$C$'KK$'II$0$'LL)"!@$(OO$8$8$? (,=!)$(  (: !@,3MM':L:L:Y:Y[^[f[fhx  iI  iI AO  AV  AV  Wc  Wm  Wm  op  Aq  @r-sE$(OO$8$8$?$? (, (< !@ -4MM':L:L:Y:Y[^[f[fhx  iO  iO AV  A]  A]  ^j  ^t  ^t  vw  Ax  @y-zE$(OO$8$8$?$? (,!@s1   C 0C C	G5A?E  G5,A?G00G5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})rO  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   r6  r7  r   methodextraonChallenger   r   r   Goodbyer   rL   r   EventrJ  r   rK  r>  r   rW   rE   r   r    r   r   r   r   r   r   r   objrU  rV  details_argEventDetailsrF  r;  r<  r=  r?  r@  r   rI  	Publishedr   r   pop	is_futureon_reply	is_calledr%   rM  resolve
Subscribedr   r&   r  Unsubscribedr   subscription_idactiveResultr   r\  r   r   r   r   rT  optionson_progressr   r)  r"   r   r   r   rejectlenra  r   rd  r   endpointr   rb  receive_progressCallDetailsrY  rZ  r[  r.   	Interruptr   cancel
Registeredr   r(   UnregisteredKeyErrorr   registration_idr   r   CallPublish	SubscribeUnsubscribeRegister
Unregisterr   )&rZ   r   r   r"  rv   r(  	challenger!  rJ  r>  r   decoded_topicr   invoke_argsinvoke_kwargsrG  futurepublish_requestrF  r   call_requestr   r   rN  kwr   prog_drv  r   r  r  rT  invokedregr)  rK  rO  rd  s&   ``                                @@@@r7   	onMessagezApplicationSession.onMessage/  s'   
 # #w/ OODNNC8DLL ##Aw6C/,,SZZEOODLL':
J##Aw7C!2!23!OOCJJ		B	OOD$4$4i@0( ##Aw6 $$^$e$efifsfs$tuu #w/))#OO-EOO((/#'   ,,SZZEOODLL':
: ##Aw7C/##t':':: )-(;(;C<L<L(M"."6"6 #		 ?\-?-?<<#'#6#6 $  /[  fi  fr  fr  !s &	!/6DS[[RUR^R^`c`r`rtwtt  7AOJNJ]J]JdJdejlq  tC  KD$GM38SZ
 (-'=(,6e(f(.8?w{{n88*5chh*GK69jj

df"..AFASAST`bebqbq  ~A  ~K  ~K  ^a  ^r  ^r  GJ  G]  G]  ej  }@  }Q  }Q  \_  \h  \h  sv  s  s  MP  M\  M\  B]M'*=*=>sB
 "'![k![]![++FHfE_ )Nd ((_(f(fgjgwgw(xyyC!2!23;;$"4"44 '+&8&8&<&<S[[&IO'?'?@U__UdUmUmEn #.coo_MjMj"kK MM/":":KH'([(b(bcfcncn(oppC!3!34;;$"6"66 #2266s{{CGw'7'78U__WM]M]=^ ''t/B/BB@B++C,<,<=#/0@0@'--QUW^WfWf#gL ''(8(89@@N MM'"2"2LA'(\(c(cdgdodo(pqqC!5!56;;$"8"88 #4488EGw'7'78U__WM]M]=^ ..$2E2EE,0,?,?@W@W,XL27L/ -Y //0G0GH MM'"2"2A6'(^(e(efifqfq(rssC0;;$//1#'??3;;#?L'11D"G||#22&]G HHMM'2&67G7\7\^e&fG&2@cll\_\n\npsp{p{2|GKGZGZGaGabfhln}G~ D#* $(>#9$(HHMM )C7E-1 %2 %&
 /?(8(Q(Q(p(w(w  yG  IM  )N/&G
 || (//;;& $ 0 0  ;I  !J%(ZZ%946'*xx':57!W $0#7#7L<P<P<X<X-2__\=Q=Q=]=]=B=M=MsxxUXU_U_\_\m\m^a^q^qZ]ZiZi	>\
 QTPZPZ>\.]F .3__\=Q=Q=]=] .C>B.C?A.CF !& 3 3FD& I !OOCKK8 $0#8#8 ??849R" #!LL7;"zzl.B.B|G[G[GcGc),)9r#&88*/*:*:CHHBE**ILIZIZKNK^K^GJ	+E
 >D+EC +0*:*: +E#**ILIZIZKNK^K^GJ+E >D	+EC
 !&h <#&88'*388}q'8.3.>.>.I(-h(D(-h(L$)MM(D$A'(X(_(_`c`k`k(lmmG <J C!3!34;;$"3"33'(`(g(ghkhshs(tuu ''t/B/BB+,h,o,ops  qA  qA  -B  C  C (,':':3;K;K'L#/#8#8"}}F0F0F"&<<#'#6#6*h $g 6*:;K;`;`bi*j!*6DS[[RUR^R^`c`r`rtwtt  7AOKOK^K^KeKefkmq  tC  LD$HNCHcj (,~'=(,-U;I15	 )6 )* 3C,<,U,U,  -G  -G  HV  X\  -]3*
 # %)$@$@ASASA`A`bebmbmov$wE OO007  (||7/7||o.3g"xx.9E#((O.K:=**CJJ$&M'33#&#7#7%K2 04HFKFWFWXdai_b_i_ififwfwhkh{h{bfili}i}adamamGoh.B.B C (-x{{'b['bTa'bHHFT%,N >Os{{\d=eD--ckk:!//'5IC!2!23;;d&7&77HHNN#\fifqfqNr"//<G LL!1!12C!3!34;;$"5"55 #1155ckkBGw'7'78U__WM]M]=^ ''t/B/BB'3D#:J:JGL]L]_f_o_o'p@L++C,<,<=+,j,q,qru  sC  sC  -D  E  EMM'"2"2LA'(\(c(cdgdodo(pqqC!5!56;;!#"11#2B2BC HHNNM ]]++ # 
 [[D$9$99 #3377DGw'7'78U__WM]M]=^ ..$2E2EENS++G,C,CDK //0G0GH MM'"2"23'(^(e(efifqfq(rssC/   ##w||'@'@@S[[TXTcTcEc#223;;?HHH %%)E)EE#++Y]YkYkJk#1155ckkBKKH %%):):)G)GGCKK[_[o[oLo#3377DMMH %%)<)<)I)IIckk]a]s]sNs#5599#++FOOH %%)9)9)F)FF3;;Z^ZmZmKm#2266s{{CLLH %%););)H)HHS[[\`\q\qMq#4488ENNH ??84Xt/K/KC/PQ'  )I  )P  )P  QT  Qa  Qa  cf  cn  cn  )o  p  p 5 $$<$C$CCMM$RSSA (1 !+$(HHMM  3C  KL  WZ  Wc  WcM  %d$*!+n $- " $$T() !. !" +;$4$F$F$Q$X$XYZ$[+""p (1 !&$(HHMM(U,- %2 %& /?(8(J(J(R(Y(YZ[(\/&G!&` $ +&&,fS-=-=&> sr   %A!A^A!A_ 8A!A`5 K6Ab ^	A_^"(A__A__	A`2_!AA`-`-A`2`5	Ab`>AAb
b
Abb.Ac c                     d _          j                  rt        j                  t        j                  j                  dj                   j                              t        j                   j                        } fd} fd}t        j                  |||       d _        t        j                   j                        } fd} fd}t        j                  |||       y)zW
        Implements :func:`autobahn.wamp.interfaces.ITransportHandler.onClose`
        Nz=WAMP transport was lost without closing the session {} beforer6  r   c                 .    j                  d       | S r3  r  r4  s    r7   r"  z+ApplicationSession.onClose.<locals>.success(  s    		'41
r9   c                 (    j                  | d      S r+  r   r  s    r7   r(  z*ApplicationSession.onClose.<locals>._error-  s    **1.DEEr9   c                 ,    j                  d      S )NrA   )	was_cleanr  )r  rZ   wasCleans    r7   r"  z+ApplicationSession.onClose.<locals>.success5  s    99\489DDr9   c                 (    j                  | d      S )NzWhile firing onDisconnectr   r  s    r7   r(  z*ApplicationSession.onClose.<locals>._error9  s    &&q*EFFr9   )rL   rN   r   r   REASON_TRANSPORT_LOSTr   rC   r   r7  r   onDisconnect)rZ   r  r   r"  r(  r)  s   ``   @r7   onClosezApplicationSession.onClose  s    
 (())??W^^_c_o_opG g6A
F7F3#DOOD--.	E	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   rm  zApplicationSession.onChallenge=  s     _``r9   r)  c                      y)zM
        Implements :meth:`autobahn.wamp.interfaces.ISession.onJoin`
        Nr   rZ   r)  s     r7   r  zApplicationSession.onJoinH      r9   welcomec                      y)zP
        Implements :meth:`autobahn.wamp.interfaces.ISession.onWelcome`
        Nr   )rZ   r  s     r7   rj  zApplicationSession.onWelcomeN  r  r9   c                    t        j                  d      }| j                  | j                  | j                  | j
                  | j                  | j                  g}g }|D ]1  }|j                  |j                                |j                          3 |r&| j                  j                  dt        |             |D ]  | j                  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   rv  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    IYIYr9   )rC   create_future_successr   r   r   r   r   r   extendvaluesclearrE   infor  r   rv  r  r   r   rw  r  r   )rZ   r   r   all_requestsoutstandingrequestsr   s         @r7   _errback_outstanding_requestsz0ApplicationSession._errback_outstanding_requestsT  s2    ''-  ""OO!!
 $Hx01NN % HHMM9+&   #GHHNND!(!1!1"--$..77   ??7#3#34W--s3 #=?YZ # r9   c                 @    |j                   t        j                  k7  r2 j                  j	                  d|j                   |j
                         t        |j                   |j
                        } j                  |      } fd}t        j                  |||       |S )zN
        Implements :meth:`autobahn.wamp.interfaces.ISession.onLeave`
        z/session closed with reason {reason} [{message}]r  c                 @    j                   rj                          y y r2   )rL   rA   r   s    r7   rA   z.ApplicationSession.onLeave.<locals>.disconnect  s    ! r9   )
r6  r   REASON_DEFAULTrE   r   r   r   r  rC   r   )rZ   r)  r   r   rA   s   `    r7   r7  zApplicationSession.onLeavez  s    
 >>\888HHMMKT[TbTblsl{l{M| w~~w?..s3	" 	Az:6r9   r6  r   c                    | j                   s| j                  j                  d       y| j                  sH|sd}t        j
                  j                  ||      }| j                  j                  |       d| _        n| j                  j                  d       | j                  du xs | 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   rn  rL   r   	is_closed)rZ   r6  r   r   r  s        r7   r>   zApplicationSession.leave  s    
 HHMMRS!!,,,&&fg&FCOO  %!%DHHMM^_OOt+Ht/H/H	r9   c                 N    t        j                         }| j                  |       y)zS
        Implements :meth:`autobahn.wamp.interfaces.ISession.onDisconnect`
        N)r   TransportLostr  )rZ   r   s     r7   r  zApplicationSession.onDisconnect  s      %%'**3/r9   r>  c                 
   t        |      t        k(  sJ |t        |      t        t        fv sJ |t        |      t        k(  sJ t        j                  |dj                  | j                  j                        ddd       |j                  dd      }|r%t        |t        j                        st        d      | j                  st!        j"                         | j$                  j'                         }d}| j(                  r| j(                  j+                  d|||      }|r|rSt        j,                  ||f|j.                  |j0                  |j2                  |j4                  d|j7                         }nt        j,                  |||j.                  |j0                  |j2                  |j4                        }nD|r)t        j,                  ||f||d	|j7                         }nt        j,                  ||||	      }|rt|j8                  |j8                  |_        |j:                  |j:                  |_        |j<                  |j<                  |_        |j>                  |j>                  |_        |r>|j@                  r2tC        jD                         }tG        |||du
      | jH                  |<   nd}	 | j                  jK                  |       |S # t        $ r"}	|| jH                  v r| jH                  |= |	d}	~	ww xY w)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   rL  )&r   r   r   rU  rV  r   check_or_raise_urir   r   r   rt  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   r>  r   r   r~  r  r   r   rv  r   s
             r7   publishzApplicationSession.publish  s   
 E{c!"!|tDzdE]:;:~f!565""5+9+@+@AXAX+Y*/:?.3		5 **Y-:gu/C/CDJKK))++))..0
"1188udFSOooj&+@.=.E.E/>/G/G.=.E.E5D5S5S@ )0(<(<(>@ ooj&+.=.E.E/>/G/G.=.E.E5D5S5SU ooj&+@+/-3@ )0(<(<(>	@ ooj&++/-35
 %%1%,%;%;"&&2&-&=&=#,,8,3,I,I)**6*1*E*E'w****,H-;Japx|a|-~Dz*H	 OO  %   	T///&&z2G	s   :K 	L K==LrK  r~  check_typesc                 J    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 s|j                  d   D ]  }	|	j                         s|	j!                         }
|	j"                  xs |}|T|	j$                  t         j&                  j(                  k(  rt        j                  d      }nt        j                  d      }|j+                   ||||
||	j,                                 t/        j0                  |d	
      S )zS
        Implements :meth:`autobahn.wamp.interfaces.ISubscriber.subscribe`
        Nr   c                    t        j                  |dj                  	j                  j                        ddd       	j
                  j                         }t        j                         }|r	j                  |      }t        || |r|j                  nd       }t        ||||      	j                  |<   |r&t        j                  ||fi |j                         }nt        j                  ||      }|rt|j                   |j                   |_        |j"                  |j"                  |_        |j$                  |j$                  |_        |j&                  |j&                  |_        	j(                  j+                  |       |S )Nz{}.subscribe()FTr  )r   r  r   r   r   rX   r  rC   r  r  r'   rq  r+   r   r  r  r  r  r  r  rL   r   )
rp  rI  r>  r~  r  r  rv  handler_objr   rZ   s
            r7   
_subscribez0ApplicationSession.subscribe.<locals>._subscribe  sU   &&u/?/F/Ft~~G^G^/_.3>B27	9 --224J**,H__R(!"c'7+>+>tTK/?
ES[]h/iD  ,''
ETW=Q=Q=ST''
E:))5)0)?)?C&**6*1*A*AC'00<070M0MC-..:.5.I.IC+OO  %Or9   rQ  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   rK  r>  r~  r  r  
on_replieskrO  patr   suboptss   `           r7   	subscribezApplicationSession.subscribe  sn    !e&7WWk=Zcnpo}Us 232*We6L6L"MNM))++	@ GdGUG[II
 J''(9(9;PQt$--/#}}[9>>+#&779D&)kk&<WG&#&<<3;;3P3P#P.3.D.D:.VG.3.D.D7.SG&--j$gWZWgWg.hi  : R <<
t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                     j                  |       d|_        t        | j                  |j                           }|dk(  r| j                  j                         }t        j                         }t        |||j                        | j                  |<   t!        j"                  ||j                        }| j
                  j%                  |       |S t        j&                  |      S )zU
        Called from :meth:`autobahn.wamp.protocol.Subscription.unsubscribe`
        Fr   )r   r&   r|  rh  r   rL   r   r  remover  rX   r  rC   r  r,   r   r   r  r   r  )rZ   rJ  scountr  rv  r   s         r7   _unsubscribezApplicationSession._unsubscribeQ  s:    ,565""""$"5"5565t22<??CCDC))++ 	LOO,33LA# T((9:Q;--224J**,H1CJPXZfZiZi1jD"":.%%j,//BCOO  %O ..v66r9   r\  c                     	 t        |      t        k(  sJ |t        |      t        t        fv sJ |t        |      t        k(  sJ t        j                  |dj                   j                  j                        ddd       |j                  dd      }|r%t        |t        j                        st        d       j                  st!        j"                          j$                  j'                         	d} j(                  r	  j(                  j+                  d|||      }|r|rSt        j0                  	|f|j2                  |j4                  |j6                  |j8                  d|j;                         }nt        j0                  	||j2                  |j4                  |j6                  |j8                        }nD|r)t        j0                  	|f||d	|j;                         }nt        j0                  	|||	      }|rt|j<                  |j<                  |_        |j>                  |j>                  |_        |j@                  |j@                  |_         |jB                  |jB                  |_!        	 fd
}tE        jF                  |      }tI        	|||       jJ                  	<   	  j                  jM                  |       |S #   j,                  j/                           xY w#  	 jJ                  v r jJ                  	=  xY w)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                 f    t        j                        }j                  j                  |       y r2   )r   CancelrL   r   )r   
cancel_msgr  rZ   s     r7   	cancellerz*ApplicationSession.call.<locals>.canceller  s#     
3JOO  ,r9   )r  )'r   r   r   rU  rV  r   r  r   r   r   rt  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  rv  r  s
   `        @r7   callzApplicationSession.calls  s    I#%&%|tDzdE]:;:~f!565""9+6+=+=dnn>U>U+V*/:?.3		5 **Y-:gu/@/@AGHH))++))..0
"&"5"5"<"<T9dTZ"[
 ll:#,=+:+B+B,;,D,D+:+B+B2A2P2P= &-%9%9%;= ll:#,+:+B+B,;,D,D+:+B+B2A2P2PR ll:#,=(,*0= &-%9%9%;	= ll:#,(,*02
 %%1%,%;%;"&&2&-&=&=#,,8,3,I,I)**6*1*E*E'	- &&;&1*iSZ&[
#	 OO  % I  "z	T__,OOJ/s   K 2K/ K,/Lr  prefixc                 :    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 s|	j                  d   D ]X  }
|
j                         s|
j                         }|
j                  xs |}|j                   |||	|||
j                               Z  t        j                   |d      S )zN
        Implements :meth:`autobahn.wamp.interfaces.ICallee.register`
        Nr   c                 6   t        j                  |dj                  
j                  j                        ddd       
j
                  j                         }t        j                         }|r
j                  |      }t        || |r|j                  nd       }	dj                  	|      }t        ||||      
j                  |<   |r&t        j                  ||fi |j                         }nt        j                  ||      }|rt|j                   |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)   rq  r/   r   r  r  r  r  r  r  rL   r   )rp  rI  r\  r~  r  r  rv  endpoint_objr   r  rZ   s            r7   	_registerz.ApplicationSession.register.<locals>._register  sl   &&y/>/E/EdnnF]F]/^.3>B27	9 --224J**,H__R(#BGW-@-@QUVL!"MM&)<	.=j(T]_k.lD
+&&z9W@T@T@VW&&z9=))5)0)?)?C&**6*1*A*AC'00<070M0MC-..:.5.I.IC+OO  %Or9   rQ  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  rO  r  r   regoptss   `   `        r7   registerzApplicationSession.register  s    "y'<'(T_B`itvu))++ 	D H T8YMM
 J''(:(:<QRt$--/#}}[9??,#&779D&)kk&<WG&--i$gWZWgWg.hi	  : S <<
tDDr9   c                    t        |t              sJ |j                  sJ |j                  | j                  v sJ | j
                  st        j                         | j                  j                         }t        j                         }t        |||j                        | j                  |<   t        j                  ||j                        }| j
                  j!                  |       |S )zT
        Called from :meth:`autobahn.wamp.protocol.Registration.unregister`
        )r   r(   r|  rh  r   rL   r   r  rX   r  rC   r  r0   r   r   r  r   )rZ   rd  r  rv  r   s        r7   _unregisterzApplicationSession._unregister  s     ,565""""$"5"5565))++))..0
&&(,=j(T`TcTc,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   rm  r   r  r   ri  rj  r  r   r7  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/F , , #8M#: # # 

 
 
* % %  15%)'+37)--1+/#"#""49-#" c]#"  }	#"
 !c3h0#" !#" &c]#" $C=#" #"J $ $   *8hTX hTT !0 !0F aY a3 a a n  
  Xc]  
$L |  " HSM 8C=  * 0 0 XS Xh{6K X Xt NR\`CEx}!5 CEhsm CE#$45CEKSTX>CE,\ 223CE CEJ 7D fc fuS*_7M f fP RVTX/3?Ex}!5 ?E(3- ?E"?3?EDLSM?E&tn?E8=lDQ]L^>^8_?E ?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y)_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                 $    | j                  |      S r2   )on_joinr  s     r7   r  z_SessionShim.onJoinC  s    ||G$$r9   c                    | j                   r| j                   j                         D cg c]  }|j                  j                  dd         c}d   }| j                   j                         D cg c]  }|j                  j                  dd         c}d   }| j	                         }| j                  | j                  j                  t        | j                   j                               |||       y | j                          y c c}w c c}w )Nrl   ro   )r   rl   ro   ru   )_authenticatorsr  _argsget_merged_authextrar=   r   rg   r   keys
on_connect)rZ   xrl   ro   ru   s        r7   r   z_SessionShim.onConnectF  s     <@;O;O;V;V;XYaaggkk(D1YZ\]F?C?S?S?Z?Z?\]!J5]^`aH ..0III!! !5!5!:!:!<=!#   OO Z]s   #D.#D	c                    	 | j                   |j                     }|j                  | |      S # t        $ rP t        dj	                  |j                  t        t        | j                   j                                                 w xY w)NzBReceived challenge for unknown authmethod '{}' [authenticators={}])	r
  rk  r  rz   r   r   sortedr  on_challenge)rZ   r  authenticators      r7   rm  z_SessionShim.onChallenge[  s    	 001A1ABM ))$	::  	T[[$$t3388:;< 	s
   - ABc                 X   |j                   | j                  y 	 | j                  |j                      }|j                  | |j                        S # t        $ rP t        dj	                  |j                   t        t        | j                  j                                                 w xY w)NzBReceived onWelcome for unknown authmethod '{}' [authenticators={}])
rq   r
  r  rz   r   r   r  r  
on_welcomeru   )rZ   r   r  s      r7   rj  z_SessionShim.onWelcomeg  s    >>!T%9%9%A	 00@M ''cmm<<  	T[[NNt3388:;< 	s   A AB)c                 $    | j                  |      S r2   )on_leaver  s     r7   r7  z_SessionShim.onLeavev  s    }}W%%r9   c                 "    | j                         S r2   )on_disconnectrY   s    r7   r  z_SessionShim.onDisconnecty  s    !!##r9   c           	      p    t        t              sJ  j                  i  _         fd} |d        |d       j                  } j	                         }|j                         D ]1  \  }}||v s||   |k7  st        dj                  ||||                 j                  j                  <   y )Nc                 2   t        t        j                  j                               gz   D cg c]  }| |j                  v r|j                  |    ! c}      }t        |      dkD  r*t        dj                  | dj                  |                  y c c}w )NrQ  zInconsistent {}s: {} )	setr   r
  r  r  r  
ValueErrorr   r=   )r  aunir  rZ   s      r7   at_most_onez3_SessionShim.add_authenticator.<locals>.at_most_one  s    d2299;<N177?  C
 3x!| *11  s   $B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'#%D 	 	H 	J "++	'')LLNDAqI~)A,!"3 JQQ1il  # 4A]//0r9   c                     | j                   j                         D cg c]  }|j                   c}d }t        |t	                     }fd}|D ci c]  }| ||       c}S c c}w c c}w )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                 :    | t        |j                               z  S r2   )r  r  )r  ys     r7   extract_keysz4_SessionShim._merged_authextra.<locals>.extract_keys  s    s1668}$$r9   c                 \    D ]  }| |v s||    c S  t        dj                  |             )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  s=     (		>$Q<' ( $++A. r9   )r
  r  ru   r
   r  )rZ   r   r)  unique_keysr,  r  r+  s         @r7   r  z_SessionShim._merged_authextra  sv     ,0+?+?+F+F+HIaakkI
	% \:su=	  !
 q!!
 	
+ J*
s   A(A-c                      y r2   r   r  s     r7   r  z_SessionShim.on_join      r9   c                 $    | j                          y r2   )rA   r  s     r7   r  z_SessionShim.on_leave  s    r9   c                 N    | j                  | j                  j                         y r2   )r=   r   rg   rY   s    r7   r  z_SessionShim.on_connect  s    		$++##$r9   c                      y r2   r   rY   s    r7   r  z_SessionShim.on_disconnect  r/  r9   )r   r   r   r   r
  r  r   rm  rj  r7  r  r%  r  r  r  r  r  r   r9   r7   r  r  4  sM    	 O%*
;=&$
+AZ#
P%r9   r  c                   $    e Zd ZdZeZ	 ddZd Zy)ApplicationSessionFactoryz(
    WAMP endpoint session factory.
    Nc                 B    |xs t        j                  d      | _        y)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 5 5H Er9   c                 J    | j                  | 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[   r8  r   r9   r7   r4  r4    s     !GF	r9   r4  )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objectr4  r   r9   r7   <module>rE     s   4 H G G     > >  !   # g g b b      3   8c/ cL	 K K K\.i% iZ   ( ) r9   