
    %i؂                       d dl Z d dlmZ d dlmZmZmZmZmZm	Z	m
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mZmZmZ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,m-Z-m.Z.m/Z/m0Z0m1Z1 d dl2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 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)    N)reduce)AnyCallableClassVarDictListOptionalUnion)wamp)PayloadExceededError)IdGeneratorObservableMixinpublic)	exceptionmessageroletypesuri)ApplicationErrorProtocolErrorSerializationErrorTypeCheckError)IAuthenticatorIMessageIPayloadCodecISession
ITransport)CallRequestEndpointHandlerInvocationRequestPublicationPublishRequestRegisterRequestRegistrationSubscribeRequestSubscriptionUnregisterRequestUnsubscribeRequest)
CallResult	ChallengeCloseDetailsEncodedPayloadRegisterOptionsSessionDetailsSubscribeOptionsc                 Z    t        j                  |       xs t        j                  |       S N)inspectismethod
isfunction)fs    p/var/www/html/navyabakers_fullstack/navyabakers_prod/venv/lib/python3.12/site-packages/autobahn/wamp/protocol.pyis_method_or_functionr8   J   s#    A7'"4"4Q"77    c                   t   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__W   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.transport   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"<"<">?"d  9k2KKs{{'E'EF4%%i0 ,5!!%("r 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   sB   $ 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--'//(11'//.==C 
 --gudFKC
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  s/    <<&&Qg&*$99 \\&4S\\33E3Es{{'O =A<O<O<V<Vcii=9OSXsz yyO3x,;"%)) & 
 #3,EEdkk / &)\\# 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
[ ! HHMMHa "  /(::ELLQO!$G	V  $$,,.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;   N   s    C1-f 8J/   Hd H H DT D D %.!9 % % x}    HSM        (3-    HSM     "hsm " " 8DcN3  	 (3- 0 =A9vmr9   r;   c                   L   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__  s     	T".4 /
8M8M9

 $)+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>  s    $"5"5d<W"X r9   c                 B    t        j                  j                        S r2   )rC   	as_future	onConnect_rZ   s    r7   r   z+ApplicationSession.onOpen.<locals>.<lambda>  s    eoodnn5 r9   c                 (    j                  | d      S )NzWhile calling 'onConnect'r   r   s    r7   r   z+ApplicationSession.onOpen.<locals>.<lambda>  s    ,,T3NO r9   )rE   debugonOpenrL   firerC   add_callbacks)rZ   r^   ds   `  r7   r   zApplicationSession.onOpen  sq    
 	+$++ 	 	

 $ IIiy1tX	
 	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%%#)%

 	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JJ	22'
 HHMM0nn--JJ,,.   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_checkE  sE    ++DB4B6BIH"2288: 
d9$ t\48EABF--)P3#,,)P)P))D/4==I$OO ? F F$(.$y:O:X:X!"
 (	$> :AA $dmmT)D/5J5S5S$ $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    	@4 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>  s    $"5"5a9Q"R r9   c                 X    t        j                  j                  j                        S r2   )rC   r   onJoinrV   r   s    r7   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>  s    %//$++t?T?T"U r9   c                 (    j                  | d      S )NzWhile firing onJoinr   r  s    r7   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>  s    4+>+>qBW+X r9   c                 (    j                  d      S )Nr?   r   r   s    r7   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>  s    TYYw5M r9   c                 (    j                  | d      S )NzWhile notifying 'ready'r   r  s    r7   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>  s    $"5"5a9R"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>.successq  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 ''R ''U ''4!X ''+MtT''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9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  s9    		'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     ('R  I%/$-$4$4V$<	I#-'@GGYX  $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8%,,syy:QE OO((/#00u}}MGg>A#
N ''7F; Hr9   z8Received {0} message, and session is not yet establishedc                 .    j                  d       | S r2  r  r3  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   r5  r   r   )r   errmsgr   rZ   s     r7   r'  z,ApplicationSession.onMessage.<locals>._error  s5    V]]

CKKF  ..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`  s{     !$ ; ;$($6$6$,%""?"?%@ $(??/6/D/DS__/UH$(OO$8$8$B$(HHMM )h%&%@ !<r9   c                 t    dj                  j                  j                        }j                  | |      S )Nz&While firing {0} subscribed under {1}.)r   fnsubscriptionr   )r   r9  handlerr   rZ   s     r7   r'  z,ApplicationSession.onMessage.<locals>._errorq  s7    %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   rS  )r   r   tupledictr   rW   r   r   r   Yieldr   r   r   r   rL   r   )r   r   r   progress_msgr   rN  rZ   s       r7   rS  z.ApplicationSession.onMessage.<locals>.progress  s   /3|tDz,0,1N* @* )* 0* 06~fQUAU(U/U:>+.<<373F3F6?4m72 12 150C0C0J0J494v12 -< ,;;B==038G8O8O9=9H9Q9Q8G8O8O?N?]?]<.L <C==03597=9=	<.L )-(<(<\(Jr9   )rS  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)NrR  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   rV  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   rN  registrationrZ   s
         r7   r!  z-ApplicationSession.onMessage.<locals>.success  sZ   $($5$5ckk$B26#&<<+/+>+>2k(,g(>)./9#u?O?O/P484G4G4N4N8=8<8;8;	56 1@ 594G4G4N4N8=tcU56 1@ $3'1#u7G7G'H07,/KK4C4K4K5D5M5M4C4K4K;J;Y;Y36:::=:K:K<?<O<O8;
1* 18,/KK4C4K4K5D5M5M4C4K4K;J;Y;Y1* (2#u7G7G'H07,/KK1436==36:::=:K:K<?<O<O8;1* 18ckkQTPU0V#'??#:$(HHNN(m(t(t,8,B,BCKK)*%&
 %+"!F$(OO$8$8$?e 09 ).,0HHMM0^45 -: -. -.).f (: !F29--(/(:(:(G(G(+(8(H(H -P  -W  -W05

050<0F0F01	-..*	3&K %)OO$8$8$E$E'; !F 3:--(/(:(:(G(G(+(8(N(N -U  -\  -\05

050<0F0F01	-..*	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   r`  ra  r   r   rL   r   r   r   r   rI   r   r[  r   rJ   )r   r9  formatted_tbr   r   r   rc  rZ   s        r7   rv   z+ApplicationSession.onMessage.<locals>.errore  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(/(:(:(G(G(+(8(H(H,z  -B  -B0<0F0F-..*		-&E %)OO$8$8$?$?" (,! (< !@ -4MM(/(:(:(G(G(+(8(N(N -B  -I  -I0<0F0F-..*		-&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})rN  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,   r5  r6  r+   methodextraonChallenger   r   r   Goodbyer   rL   r   EventrI  r   rJ  r=  r   rW   rE   r   r-   r   r   r   r   r   r   r   objrT  rU  details_argEventDetailsrE  r:  r;  r<  r>  r?  r   rH  	Publishedr   r   pop	is_futureon_reply	is_calledr"   rL  resolve
Subscribedr   r'   r  Unsubscribedr   subscription_idactiveResultr   r[  r   r   r   r   rS  optionson_progressr   r(  r*   r   r   r   rejectlenr`  r   rc  r   endpointr   ra  receive_progressCallDetailsrX  rY  rZ  r!   	Interruptr   cancel
Registeredr   r%   UnregisteredKeyErrorr   registration_idr   r   CallPublish	SubscribeUnsubscribeRegister
Unregisterr   )&rZ   r   r   r!  rv   r'  	challenger   rI  r=  r   decoded_topicr   invoke_argsinvoke_kwargsrF  futurepublish_requestrE  r   call_requestr   r   rM  kwr   prog_dru  r   r  r  rS  invokedregr(  rJ  rN  rc  s&   ``                                @@@@r7   	onMessagezApplicationSession.onMessagea  s   
 ##w/ OODNNC8AFL ##Aw6C/,,SZZEOODLL':J ##Aw7C!2!23!OOCJJ		B	OOD$4$4i@0. ##Aw6 $NUU  #w/))#OO-EOO((/#'   ,,SZZEOODLL':
: ##Aw7C/##t':'::(,(;(;C<L<L(M UF"."6"6 #		 ?\-?-?<<#'#6#6 $ %Q-0\\ !. !" !'!/6D(+(+(+(:(:(+	7&O )-(;(;(B(B,15/)* %HM38SZ (-'=(,,[)* )/8?w{{n88*5chh*GK69jj

df"..AFASAS , #*---141E1E363I3I&+141E1E),),,/OOBM'*=*=>&"B "'#JJ")4"8E" ++FHfEkUFp (OVV,,  C!2!23;;$"4"44&*&8&8&<&<S[[&IO'?'?@U__'00F  #.7T7T#K
 MM/":":KH'KRRKK  C!3!34;;$"6"66"2266s{{CGw'7'78U__((>  ''t/B/BB@B++C,<,<=#/(('--w$L
 ''(8(89@@N MM'"2"2LA'LSSKK  C!5!56;;$"8"88"4488EGw'7'78U__((>  ..$2E2EE,0,?,?#33- 8L 38L/8 !//0G0GH MM'"2"2A6'NUUKK  C0;;$//1#'??3;;#?L'11D"G||#22 W $ !HHMM'2&6 0 E Ew'G#&2@$'KK$'LL$'$6$6$'KK	3" %)$7$7$>$>(,dO%& !E#*" $(>#9$(HHMM )C7E-1 %2 %&
 /?(8(Q(Q(p(w(w,:D)*/&G || (//;;& $ 0 0$+$r!"
 &)ZZ%946'*xx':57!W %1$8$8(4(<(<(D(D-2__(4(<(<(H(H(-(8(8-0XX36:::=:K:K<?<O<O8;)* /2jj)*
.&F .3__(4(<(<(H(H.&KO.&SU.&F !& 3 3FD& I !OOCKK8 $0#8#8 ??849R" #!LL7;"zz , 4 49M9M9U9U),)9r#&88*/*:*:),/2zz696G6G8;8K8K47OO+& +1+&C +0*:*: +&/2zz696G6G8;8K8K47OO	+&
 +1+&C !&h <#&88'*388}q'8.3.>.>.I(-h(D(-h(L$)MM(D$A'HOOKK g <r C!3!34;;$"3"33'PWWKK  ''t/B/BB+X__ # 0 0  (,':':3;K;K'L#/#8#8"}}F0F0F"&<<#'#6#6*h $g 6*:$4$I$I7+"$!*6D(+(+(+(:(:(+	7&O )-(;(;(B(B,14)* %INCHcj" (,~'=(,-U;I15	 )6 )* 3C,<,U,U,  -G  -G0>-.3* # %)$@$@ ' 2 2 ? ?g%E !OO007  (||7/7||o.3g"xx.9E#((O.K:=**CJJ$&M'33#&#7#7$%KN 04HFKFWFW$0-5+.::252C2C474G4G.2585I5I-0\\	G"h.B.B C (- ((.9(=J(HlF\5,n >O #X>D--ckk: "//'5IC!2!23;;d&7&77HHNNQ # # 
 #//<G LL!1!12C!3!34;;$"5"55"1155ckkBGw'7'78U__((>  ''t/B/BB'3 #"2"2G4E4EwGWGW( AM++C,<,<=+Zaa # 0 0  MM'"2"2LA'LSSKK  C!5!56;;!#"11#2B2BC HHNNM ]]++ # 
 [[D$9$99"3377DGw'7'78U__((>  ..$2E2EENS++G,C,CDK //0G0GH MM'"2"23'NUUKK  C/ $$(A(AAt6#223;;?HHH $$(D(DDt'9'99#1155ckkBKKH $$(9(9(F(FFt';';;#3377DMMH $$(;(;(H(HHt'='==#5599#++FOOH $$(8(8(E(EEt':'::#2266s{{CLLH $$(:(:(G(GGt'<'<<#4488ENNH ??84Xt/K/KC/PQ'x,,ckk  5 $$<$C$CCMM$RSSe (1 !+$(HHMM(x./14 %2 %&
 %+!+d $- 
" $$T() !. !" +;$4$F$F$Q$X$X()%&+"
"~ (1 
!&$(HHMM(U,- %2 %& /?(8(J(J(R(Y(Y,-)*/&G
!&N
 $ +&&,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r5  r   c                 .    j                  d       | S r2  r  r3  s    r7   r!  z+ApplicationSession.onClose.<locals>.successC  s    		'41
r9   c                 (    j                  | d      S r*  r   r  s    r7   r'  z*ApplicationSession.onClose.<locals>._errorH  s    **1.DEEr9   c                 ,    j                  d      S )NrA   )	was_cleanr  )r  rZ   wasCleans    r7   r!  z+ApplicationSession.onClose.<locals>.successQ  s    99\489DDr9   c                 (    j                  | d      S )NzWhile firing onDisconnectr   r  s    r7   r'  z*ApplicationSession.onClose.<locals>._errorU  s    &&q*EFFr9   )rL   rN   r   r,   REASON_TRANSPORT_LOSTr   rC   r   r6  r   onDisconnect)rZ   r  r   r!  r'  r(  s   ``   @r7   onClosezApplicationSession.onClose2  s    
 (())??W^^$$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   rl  zApplicationSession.onChallengeZ  s     P
 	
r9   r(  c                      y)zM
        Implements :meth:`autobahn.wamp.interfaces.ISession.onJoin`
        Nr   rZ   r(  s     r7   r  zApplicationSession.onJoing      r9   welcomec                      y)zP
        Implements :meth:`autobahn.wamp.interfaces.ISession.onWelcome`
        Nr   )rZ   r  s     r7   ri  zApplicationSession.onWelcomem  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   ru  r   r   s    r7   r   zBApplicationSession._errback_outstanding_requests.<locals>.<lambda>  s    W-- r9   c                     j                   S r2   r  r  s    r7   r   zBApplicationSession._errback_outstanding_requests.<locals>.<lambda>  s    9I9I r9   )rC   create_future_successr   r   r   r   r   r   extendvaluesclearrE   infor  r   ru  r  r   r   rv  r  r   )rZ   r   r   all_requestsoutstandingrequestsr   s         @r7   _errback_outstanding_requestsz0ApplicationSession._errback_outstanding_requestss  s?    ''-  ""OO!!
 $ 	Hx01NN	 HHMM9+&   # 	GHHNND!(!1!1"--$..77   ??7#3#34W--s3 -/I	 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   )
r5  r,   REASON_DEFAULTrE   r   r   r   r  rC   r   )rZ   r(  r   r   rA   s   `    r7   r6  zApplicationSession.onLeave  s    
 >>\888HHMMA~~   w~~w?..s3	" 	Az:6r9   r5  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   rm  rL   r   	is_closed)rZ   r5  r   r   r  s        r7   r>   zApplicationSession.leave  s    
 HHMMRS!!,,,&&fg&FCOO  %!%DHHMMT 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   rK  )&r   r   r   rT  rU  r   check_or_raise_urir   r   r   rs  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   ru  r   s
             r7   publishzApplicationSession.publish  s   
 E{c!!!|tDzdE]:::~f!555"""))$..*A*AB#(	
 **Y-:gu/C/CDJKK))++))..0
"1188udFSOoo ,33,55+33#2#A#A **, oo+33,55+33#2#A#A oo !	
 **, ooj%d6R%%1%,%;%;"&&2&-&=&=#,,8,3,I,I)**6*1*E*E'w****,H-;H_D5P.Dz* H	 OO  %   	T///&&z2G	s   :K 	L K==LrJ  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    rp  r&   r   r  r  r  r  r  r  rL   r   )
ro  rH  r=  r}  r  r  ru  handler_objr   rZ   s
            r7   
_subscribez0ApplicationSession.subscribe.<locals>._subscribeN  sY   &&(//0G0GH'+  --224J**,H__R(!"c'7+>+>tTK/?E8[0D  , ''
ETW=Q=Q=ST''
E:))5)0)?)?C&**6*1*A*AC'00<070M0MC-..:.5.I.IC+OO  %Or9   rP  rx   wildcard)matchexactTconsume_exceptions)callablery   r   r   r   r   r0   rL   r   r  r3   
getmembersr   r8   __dict__
is_handlerr   r}  uri_typer{   URI_TYPE_WILDCARDr  _check_typesrC   gather)rZ   rJ  r=  r}  r  r  
on_replieskrN  patr   suboptss   `           r7   	subscribezApplicationSession.subscribe:  s    !e&7G[)+	
 
 }Us 222*We6L6L"MMM))++"	H 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&-- *$+T4#BRBR!"$ <<
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{  rg  r   rL   r   r  remover  rX   r  rC   r  r)   r   r   r  r   r  )rZ   rI  scountr  ru  r   s         r7   _unsubscribezApplicationSession._unsubscribe  s;    ,555""""$"5"5555t22<??CCCC))++ 	LOO,33LA# T((9:Q;--224J**,H1CHloo2D"":. %%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   rT  rU  r   r  r   r   r   rs  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  ru  r  s
   `        @r7   callzApplicationSession.call  s    I#%%%|tDzdE]:::~f!555""&&t~~'>'>?#(	
 **Y-:gu/@/@AGHH))++))..0
"&"5"5"<"<)T6# ll ,33,55+33#2#A#A **, ll+33,55+33#2#A#A ll !	
 **, ll:ytFS%%1%,%;%;"&&2&-&=&=#,,8,3,I,I)**6*1*E*E'	- &&;&1	8W'

#	 OO  % S  "D	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   rp  r$   r   r  r  r  r  r  r  rL   r   )ro  rH  r[  r}  r  r  ru  endpoint_objr   r  rZ   s            r7   	_registerz.ApplicationSession.register.<locals>._register6  sp   &&'..t~~/F/FG'+  --224J**,H__R(#BGW-@-@QUVL!"MM&)<	.=Hi/D
+ &&z9W@T@T@VW&&z9=))5)0)?)?C&**6*1*A*AC'00<070M0MC-..:.5.I.IC+OO  %Or9   rP  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  rN  r  r   regoptss   `   `        r7   registerzApplicationSession.register#  s    "y'<Hk*;	
 
 ))++$	L HT8YMM J''(:(:<QR t$--/#}}[9 ??,#&779D&)kk&<WG&-- )$,dD'3CSCS!"	 <<
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{  rg  r   rL   r   r  rX   r  rC   r  r(   r   r   r  r   )rZ   rc  r  ru  r   s        r7   _unregisterzApplicationSession._unregisterr  s     ,555""""$"5"5555))++))..0
&&(,=,//-
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+   rl  r/   r  r   rh  ri  r  r,   r6  r>   r  r"   r  r
   r   r0   r'   r  r  r*   r  r.   r%   r   r  r   r9   r7   r   r     s   x(=(=> B --   ,x/F , , #8M#: # # 

 
 
, % %  ,0 $"&.2$((,&*'"'" d3i('" 	'"
 3-'" DcN+'" D>'" !'" sm'" '"R $ $  (* DOTX OTb %0 %0N 

Y 

3 

 

 n  
  Xc]  
&P |  , HSM 8C=  . 0 0 _S _h{6K _ _B   $.2&*PEx}%PE }PE *+	PE
 d^PE 
|T,//	0PE PEd"7H oc ouS*_7M o ob  $(-1 $&*LE#&LE C=LE /*	LE
 LE d^LE 
|T,//	0LE LE\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.onJoin  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.onConnect  s    
 6:5I5I5P5P5R01Hd+F 8<7K7K7R7R7T23J-H ..0III!! !5!5!:!:!<=!#   OO%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	  rj  r  rz   r   r   sortedr  on_challenge)rZ   r  authenticators      r7   rl  z_SessionShim.onChallenge  s    	 001A1ABM ))$	::  	T[[$$c&1E1E1J1J1L*M&N 	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   ri  z_SessionShim.onWelcome  s    >>!T%9%9%A	 00@M ''cmm<<  	T[[NNCt/C/C/H/H/J(K$L 	s   A AB)c                 $    | j                  |      S r2   )on_leaver  s     r7   r6  z_SessionShim.onLeave  s    }}W%%r9   c                 "    | j                         S r2   )on_disconnectrY   s    r7   r  z_SessionShim.onDisconnect  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 )NrP  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     "$"6"6"="="?@M?Rqww GGDM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 "++	'')LLN 	DAqI~)A,!"3 JQQ!! 	 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<'( 188;<<r9   )r	  r  ru   r   r  )rZ   r  r(  unique_keysr+  r  r*  s         @r7   r  z_SessionShim._merged_authextra	  sl     ,0+?+?+F+F+HIaakkI
	% \:su=
	= 0;;!?1%%;;' 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_connect0	  s    		$++##$r9   c                      y r2   r   rY   s    r7   r  z_SessionShim.on_disconnect3	  r.  r9   )r   r   r   r   r	  r  r   rl  ri  r6  r  r$  r  r  r  r  r  r   r9   r7   r  r    sM    	 O%2	;=&$
/Ab<F%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__E	  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__M	  s"     ,,t{{+r9   r2   )r   r   r   r   r   r  r[   r7  r   r9   r7   r3  r3  ;	  s     !GF	r9   r3  )Ar3   	functoolsr   typingr   r   r   r   r   r	   r
   rC   autobahnr   autobahn.exceptionr   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.requestr   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   autobahn.wamp.typesr*   r+   r,   r-   r.   r/   r0   r8   r;   r   r  abc_registerobjectr3  r   r9   r7   <module>rD     s   4   G G G   3 > > > >       8u/ up	 @ @ @F8j% j\   ( ) r9   