
    8'h`N                    |   d dl mZ d dl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 d dlmZmZmZ d dl 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,m-Z-m.Z. d Z/ G d de      Z0e
 G d de0             Z1 G d de1      Z2 G d de3      Z4y)    )absolute_importN)reduce)wamp)publicIdGeneratorObservableMixin)uri)message)types)role)	exception)ApplicationErrorProtocolErrorSessionNotReadySerializationError)ISessionIPayloadCodecIAuthenticator)SessionDetailsCloseDetailsEncodedPayload)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/html/trade_iq/venv/lib/python3.12/site-packages/autobahn/wamp/protocol.pyis_method_or_functionr,   <   s#    A7'"4"4Q"77    c                       e Zd ZdZdZd Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zdd
ZddZd Zy)BaseSessionzi
    WAMP session base class.

    This class implements :class:`autobahn.wamp.interfaces.ISession`.
    Nc                 X   t        j                         | _        | j                  g d       d| _        i | _        t        j                  t        t        j                  t        i| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        t'               | _        y)z


        )joinleavereadyconnect
disconnect)valid_eventsFN)txaiomake_loggerlogset_valid_eventstraceback_app_ecls_to_uri_patr   INVALID_PAYLOADr   PAYLOAD_SIZE_EXCEEDEDr   _uri_to_ecls_realm_session_id_authid	_authrole_authmethod_authprovider_payload_codecr   _request_id_genselfs    r+   __init__zBaseSession.__init__H   s     $$& 	 	
 # !# ,,.@224H
 ! #  +}r-   c                     | j                   S r&   )r@   rH   s    r+   realmzBaseSession.realmt   s    {{r-   c                     | j                   S r&   )rA   rH   s    r+   
session_idzBaseSession.session_idx       r-   c                     | j                   S r&   )rB   rH   s    r+   authidzBaseSession.authid|   s    ||r-   c                     | j                   S r&   )rC   rH   s    r+   authrolezBaseSession.authrole   s    ~~r-   c                     | j                   S r&   )rD   rH   s    r+   
authmethodzBaseSession.authmethod   rO   r-   c                     | j                   S r&   )rE   rH   s    r+   authproviderzBaseSession.authprovider   s    !!!r-   c                    |Rt        |d      sJ |j                  | j                  |<   || j                  |j                  d   j	                         <   yt        |d      rJ t	        j
                  t        j                  |      t        j
                  j                        g| j                  |<   || j                  t        j                  |      <   y)zM
        Implements :func:`autobahn.wamp.interfaces.ISession.define`
        N	_wampurisr   )	hasattrrY   r<   r?   r	   PatternsixuURI_TARGET_HANDLER)rI   r   errors      r+   definezBaseSession.define   s     =9k232/8/B/BD!!),>GDi11!488:;y+67603CEE%L#++JhJh0i/jD!!),.7DceeEl+r-   c           	         d}t        |d      rt        |j                        }d}t        |d      r|j                  }|rBt        j
                  r2|j                         D 	ci c]  \  }}	|j                  d      |	 }}}	|r|r||d<   nd|i}t        |t        j                        rRt        |j                        t        j                  k(  r|j                  nt	        j                  |j                        }
nA|j                  | j                   v r'| j                   |j                     d   j"                  }
nd}
d}| j$                  r| j$                  j'                  d|
||      }|rFt)        j*                  |||
|j,                  |j.                  |j0                  |j2                  	      }|S t)        j*                  |||
||      }|S c c}	}w )
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utf8	tracebackr   zwamp.error.runtime_errorFpayloadenc_algoenc_keyenc_serializer)rZ   listrb   rc   r\   PY2	iteritemsdecode
isinstancer   r   typer_   	text_typer]   	__class__r<   _urirF   encoder
   Errorrg   rh   ri   rj   )rI   request_typerequestexctbrh   rb   rc   kvr_   encoded_payloadmsgs                r+   _message_from_exceptionz#BaseSession._message_from_exception   s     3>D3!ZZFcgg #,,.Aq  !#F 
 ')|$&+c9556!%ciiCMM!ACIIsuuSYYGWE}} 5 55--cmm<Q?DD3"1188tVTO-- ' %(7(?(?)8)A)A(7(?(?/>/M/MOC 
 -- ' % $ &	(C 
Ms   #G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rh   TzZURI within encrypted payload ('{decrypted_error}') does not match the envelope ('{error}'))decrypted_errorr_   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 exceptionrh   calleecallee_authidcallee_authroleforward_for )rh   rF   r9   warnr   ENC_NO_PAYLOAD_CODECr   rg   rj   ri   rn   r_   rb   rc   ENC_TRUSTED_URI_MISMATCHformat	ExceptionENC_DECRYPT_ERRORr?   onUserErrorr7   create_failurer   rZ   r   r   r   r   )	rI   r}   rx   enc_errlog_msgr|   r   eeclss	            r+   _exception_from_messagez#BaseSession._exception_from_message   s7    <<&&Rg&*+;+P+PRYdgdpdpq&4S[[#,,PSPbPbdgdodo&pO<@<O<O<V<VW[]`]f]fhw<x9OSXsz yyO3y,;"%)) & 
 #3,EEellm|  B  H  H  I%(\\# 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.(::FMMaP!$GN  $$,,.9sE   #A+M <A+N6 	N3AN..N36	O0 $O%$O0%O)'O0/O0r&   NN)__name__
__module____qualname____doc__r9   rJ   propertyrL   rN   rQ   rS   rU   rW   r`   r~   r   r   r-   r+   r/   r/   @   s    
 C*-X               " "8?Bbr-   r/   c                      e Zd ZdZddZed        Zed        Zed        Zed        Z	e	 	 	 	 	 	 	 dd       Z
ed	        Zed
        Zed        Zed        Zd Zd Zed        Zed        Zed        Zed        Zd Zed        Zedd       Zed        Zed        Zedd       Zd Zed        Zed d       Zd Zy)!ApplicationSessionz 
    WAMP endpoint session.
    Nc                 Z   t         j                  |        |xs t        j                  d      | _        t
        j                  | _        d| _        d| _	        d| _
        d| _        d| _        i | _        i | _        i | _        i | _        i | _        i | _        i | _        i | _        i | _        y)zF
        Implements :func:`autobahn.wamp.interfaces.ISession`
        realm1rL   NF)r/   rJ   r   ComponentConfigconfigr   DEFAULT_CLIENT_ROLES_session_roles
_transportrA   r@   _goodbye_sent_transport_is_closing_publish_reqs_subscribe_reqs_unsubscribe_reqs
_call_reqs_register_reqs_unregister_reqs_subscriptions_registrations_invocationsrI   r   s     r+   rJ   zApplicationSession.__init__E  s     	T"F 5 5I F #77"%*"  !!#  " ! ! r-   c                 :    |t        |t              sJ || _        y)zX
        Implements :func:`autobahn.wamp.interfaces.ISession.set_payload_codec`
        N)ro   r   rF   )rI   payload_codecs     r+   set_payload_codecz$ApplicationSession.set_payload_codecg  s!    
 $
=-(PQP+r-   c                     | j                   S )zX
        Implements :func:`autobahn.wamp.interfaces.ISession.get_payload_codec`
        )rF   rH   s    r+   get_payload_codecz$ApplicationSession.get_payload_codeco  s    
 """r-   c                      | _          j                  d |      }t        j                  |d fd       t        j                  | fd fd       y)zV
        Implements :func:`autobahn.wamp.interfaces.ITransportHandler.onOpen`
        r4   Nc                 (    j                  | d      S )NzWhile notifying 'connect'_swallow_errorfailrI   s    r+   <lambda>z+ApplicationSession.onOpen.<locals>.<lambda>      ,,T3NO r-   c                 B    t        j                  j                        S r&   )r7   	as_future	onConnect_rI   s    r+   r   z+ApplicationSession.onOpen.<locals>.<lambda>  s    eoodnn5 r-   c                 (    j                  | d      S )NzWhile calling 'onConnect'r   r   s    r+   r   z+ApplicationSession.onOpen.<locals>.<lambda>  r   r-   )r   firer7   add_callbacks)rI   	transportds   `  r+   onOpenzApplicationSession.onOpenv  sM    
 $IIiy1tO	
 	5O	
r-   c                 N    | j                  | j                  j                         y)zP
        Implements :func:`autobahn.wamp.interfaces.ISession.onConnect`
        Nr1   r   rL   rH   s    r+   r   zApplicationSession.onConnect  s    
 			$++##$r-   c	                 Z   |t        |      t        j                  k(  sJ |t        |      t        k(  sJ t        |      t        k(  r%|D ]   }	t        |	      t        j                  k(  r J  |t        |      t        j                  k(  sJ |t        |      t        j                  k(  sJ |t        |      t        k(  sJ | j
                  rt        d      || _        d| _        t        j                  || j                  |||||||	      }
| j                  j                  |
       y)zK
        Implements :func:`autobahn.wamp.interfaces.ISession.join`
        Nzalready joinedF)	rL   rolesauthmethodsrQ   rS   	authextra	resumableresume_sessionresume_token)rp   r\   rq   rk   dictrA   r   r@   r   r
   Hellor   r   send)rI   rL   r   rQ   rS   r   r   r   r   rU   r}   s              r+   r1   zApplicationSession.join  s!    }Us}} <=<"d;&74&?@?$) :
J'3==898:~f!>?>4>S]]#BCB DOt$;<;,--  # mm%"&"5"5(3#)%-&/&/+9)57 	S!r-   c                 R    | j                   r| j                   j                          yy)zQ
        Implements :func:`autobahn.wamp.interfaces.ISession.disconnect`
        N)r   closerH   s    r+   r5   zApplicationSession.disconnect  s     
 ??OO!!# r-   c                     | j                   duS )zS
        Implements :func:`autobahn.wamp.interfaces.ISession.is_connected`
        N)r   rH   s    r+   is_connectedzApplicationSession.is_connected  s    
 d**r-   c                 >    | j                   duxr | j                  duS )zR
        Implements :func:`autobahn.wamp.interfaces.ISession.is_attached`
        N)r   rA   rH   s    r+   is_attachedzApplicationSession.is_attached  s#    
 d*Kt/?/?t/KKr-   c                 n   t        |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`
        z{klass}.onUserError(): "{msg}")klassr}   z*{klass}.onUserError(): "{msg}"
{traceback})r   r}   re   N)ro   valuer   r   r9   r   rr   r   error_messager_   r7   failure_format_tracebackrI   r   r}   s      r+   r   zApplicationSession.onUserError  s    
 djj)"<"<=HHMM: $ 7 7"jj668  : HHNN=nn--88>	  r-   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})ry   N)r   r   r9   r_   r7   r   r   r   s      r+   r   z!ApplicationSession._swallow_error  sa    	T3'   	HHNN&11%2F2F2HI   	s    AA#"A#c                 .   "#$%  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                        rvj2                   j4                  v r9 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                  rqt        jZ                  |j\                  j^                  j`                  jb                  |	jd                  j:                  jf                  	      |#jX                  <    fd}# fd}t	        j
                  #jh                  g|i |}t	        j                  |||        yt#        dj%                  j2                              t        t        jj                        rjl                   jn                  v rg jn                  jq                  jl                        }ts        j\                  |jt                        }t	        jv                  |jx                  |       yt#        dj%                  jl                              t        t        jz                        rjl                   j|                  v rˉ j|                  jq                  jl                        }j2                   j4                  vrg  j4                  j2                  <   t        j2                  |j8                   |j6                        } j4                  j2                     j                  |       t	        jv                  |jx                  |       yt#        dj%                  jl                              t        t        j                        r։jl                   j                  v r j                  jq                  jl                        }|j                   j4                  v r< j4                  |j                     D ]	  }d|_D          j4                  |j                  = t	        jv                  |jx                  d       yt#        dj%                  jl                              t        t        j                        rwjl                   j                  v r9 j                  jl                     }|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                  jf                  d$jN                        }n-t	        j
                  |j                  j                  g|i |}t	        j                  |d|       y j                  jl                  = |jx                  }|rt	        j                  ||       yjN                  s"|j                  r|j                  j                  rjN                  xs i }jL                  rMt        j                  jL                  j                  j                  j                  jf                  d$|}nBt        j                  d<j                  j                  j                  jf                  d$|}t	        jv                  ||       yjL                  rot        jL                        d%kD  r3t        j                  jL                   }t	        jv                  ||       yt	        jv                  |jL                  d          yt	        jv                  |d       yt#        d&j%                  jl                              yt        t        j                        r`jl                   j                  v r$t#        d'j%                  jl                              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                  jl                  |      } j,                  j/                  |       y|jR                  |jR                  f}n
tU               }jL                  r|tU        jL                        z   }jN                  rjN                  n	tW               }|jX                  rgj                  r$ fd.}nd}t        j                  %|j                  j                  j                  $j:                  /      ||jX                  <   t	        j
                  |jh                  g|i |}$% fd0}% fd1}t        jl                  |       j                  jl                  <   t	        j                  |||       yt        t        j                        ryjl                   j                  vr( j>                  j                  d2jl                  3       y j                  jl                     } t	        j                  | jx                         yt        t        j                        rjl                   j                  v rȉ j                  jq                  jl                        }j                   j                  vrFt         j                  |j                  |j                        %% j                  j                  <   n$t#        d4j%                  j                              t	        jv                  |jx                  %       yt#        d5j%                  jl                              t        t        j                        r*jl                  dk(  rM	  j                  j                     }! j>                  j                  d7|!j                  j                  8       yjl                   j                  v r j                  jq                  jl                        }|j                   j                  v r5d j                  |j                     _D         j                  |j                  = t	        jv                  |jx                         yt#        d9j%                  jl                              t        t        j                        rd}j                  t        j                  j                  k(  rIjl                   j                  v r1 j                  jq                  jl                        jx                  }n,j                  t        j                  j                  k(  rIjl                   jn                  v r1 jn                  jq                  jl                        jx                  }nj                  t        j                  j                  k(  rIjl                   j|                  v r1 j|                  jq                  jl                        jx                  }nLj                  t        j                  j                  k(  rHjl                   j                  v r0 j                  jq                  jl                        jx                  }n݉j                  t        j                  j                  k(  rHjl                   j                  v r0 j                  jq                  jl                        jx                  }nnj                  t        j                  j                  k(  rGjl                   j                  v r/ j                  jq                  jl                        jx                  }|r;t	        j                  |      sUt	        j                  | j                               yt#        d:j%                  j                  jl                              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}~d}~ww xY w# t        $ r% t#        d6j%                  j                              w xY w)=zY
        Implements :func:`autobahn.wamp.interfaces.ITransportHandler.onMessage`
        Nc                 &   | \j                   j                  d       t        j                  ddj	                  |             }j
                  j                  |       y j                  rj                  _        j                  _
        j                  _        j                  _        j                  _        j"                  _        j&                  _        t+        j                  j                  j                  j                  j                   j$                  j,                  j
                  j.                  j0                  j2                  j4                  j6                        j9                  d      }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wamp.error.cannot_authenticate{0})rL   sessionrQ   rS   rU   rW   r   
serializerresumedr   r   r1   c                 (    j                  | d      S )NzWhile notifying 'join'r   r   rI   s    r+   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>1  s    $"5"5a9Q"R r-   c                 D    t        j                  j                        S r&   )r7   r   onJoin)r   detailsrI   s    r+   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>6  s    %//$++w"G r-   c                 (    j                  | d      S )NzWhile firing onJoinr   r   s    r+   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda><  s    $"5"5a9N"O r-   c                 (    j                  d      S )Nr3   r   r   s    r+   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>A  s    $))GT": r-   c                 (    j                  | d      S )NzWhile notifying 'ready'r   r   s    r+   r   z?ApplicationSession.onMessage.<locals>.success.<locals>.<lambda>G  s    $"5"5a9R"S r-   )r9   infor
   Abortr   r   r   rL   r@   r   rA   rQ   rB   rS   rC   rU   rD   rW   rE   r   _router_rolesr   r   _serializerSERIALIZER_IDr   r   r   r   r7   r   )resreplyr   r   r}   rI   s      @r+   successz-ApplicationSession.onMessage.<locals>.success  s   &CD '=v}}S?Q! ,,U3yy&)ii'*{{D$#&::DL%(\\DN'*~~D$),)9)9D&),D&,"kk $ 0 0#||!%#'#3#3%)%7%7"%--#'??#>#>#L#L #"%--%(%5%5G$ 		&$8A ''4R
 ''G ''4O
 '': ''4Sr-   c                     t        j                  dd      }j                  j                  |       j	                  | d      S )Nr   zError calling onWelcome handlerzWhile firing onWelcome)r
   r   r   r   r   )r   r   rI   s     r+   r_   z+ApplicationSession.onMessage.<locals>.errorJ  s?    #MM9;]E OO((/..q2JKKr-   c                 r     j                  d      } fd}fd}t        j                  |||       |S )Nr2   c                     S r&   r   )r   args    r+   
return_argzAApplicationSession.onMessage.<locals>.success.<locals>.return_arg[  s    "
r-   c                 (    j                  | d      S )NzWhile firing 'leave' eventr   r   s    r+   _errorz=ApplicationSession.onMessage.<locals>.success.<locals>._error^  s    #2216RSSr-   )r   r7   r   )r  r   r  r  r   rI   s   `   r+   r   z-ApplicationSession.onMessage.<locals>.successW  s7    		'49A#T'':v>Hr-   c                 (    j                  | d      S NzWhile firing onLeaver   r   s    r+   r  z,ApplicationSession.onMessage.<locals>._errorc  s    ..q2HIIr-   c                 X   | t        d      t        |       t        j                  k(  r| j	                  d      } t        |       t        j
                  k7  r#t        dj                  t        |                   t        j                  |       }j                  j                  |       y )Nz4onChallenge user callback did not return a signaturerd   z"signature must be unicode (was {}))r   rp   r\   binary_typern   rq   r   r
   Authenticater   r   )	signaturer   rI   s     r+   r   z-ApplicationSession.onMessage.<locals>.successl  s     ('(^__I#//9$-$4$4V$<	I#--7'(L(S(STXYbTc(dee#00;EOO((/r-   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 Nr2   r   r  r   rI   s    r+   r   z<ApplicationSession.onMessage.<locals>.error.<locals>.success~  s    		'49"
r-   c                 (    j                  | d      S r  r   r   s    r+   r  z;ApplicationSession.onMessage.<locals>.error.<locals>._error  s    #2216LMMr-   )r   r
   r   r   r   r   r   r   r   reasonr7   r   onLeaver   )r   r   r   r   r  r   rI   s        @r+   r_   z+ApplicationSession.onMessage.<locals>.errorv  s    $$S*AB#MM*KV]][^[d[dMefEOO((/#00u}}MGg>A#
N''7F; Hr-   z8Received {0} message, and session is not yet establishedc                 .    j                  d       | S r  r   r  s    r+   r   z-ApplicationSession.onMessage.<locals>.success  s    IIgtW5Jr-   c                 t    dj                  j                  j                        }j                  | |      S )Nz7While firing onLeave for reason "{0}" and message "{1}")r   r  r
   r   )r   errmsgr}   rI   s     r+   r  z,ApplicationSession.onMessage.<locals>._error  s6    V]]^a^h^hjmjujuvF..q&99r-   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})r_   rh   )	publisherpublisher_authidpublisher_authroletopicretainedrh   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_deliveryr   r
   EventReceivedpublicationr   r9   r   )r   responser}   rI   s     r+   _successz.ApplicationSession.onMessage.<locals>._success  sp      #::t?Q?QRZ?[?y?y#'??/6/D/DS__/UH$(OO$8$8$B$(HHMM  3r  %s @z:r-   c                 t    dj                  j                  j                        }j                  | |      S )Nz&While firing {0} subscribed under {1}.)r   fnsubscriptionr   )r   r  handlerr}   rI   s     r+   r  z,ApplicationSession.onMessage.<locals>._error  s5    %M%T%T '

C,<,<&>F#'#6#6q&#AAr-   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    r+   r  z,ApplicationSession.onMessage.<locals>._errorG  s    $($4$4T;U$Vr-   )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 |rBt        j
                  r2|j                         D ci c]  \  }}|j                  d      | }}}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 c c}}w )Nrd   7trying to send encrypted payload, but no keyring activeFT)rg   progressrh   ri   rj   )rb   rc   r/  )rp   rk   tupler   r\   rl   rm   rn   rh   rF   r   rt   r
   Yieldrw   rg   ri   rj   r   r   )	rb   rc   rz   r{   r|   progress_msgr}   r*  rI   s	         r+   r/  z.ApplicationSession.onMessage.<locals>.progress  s5   /3|tDzdTY]?Z([/Z/5~fQUAU(V/U+1cgg =C<L<L<N6.48Aq 120@!0C6.F 6.
 ;?+.<<373F3F6?@z6{0{>B>Q>Q>X>XY^`dfjlr>sO+:;B==Q`QhQhRVRaRjRjQ`QhQhXgXvXv<xL <C==NRPVRV<XL
 )-(<(<\(J16.s   E	)r/  callercaller_authidcaller_authrole	procedurerh   c                     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                  j2                  |      g      }j,                  j5                  |       Y d }~y d }~wtB        $ r}t        j8                  t        j:                  j<                  j                  t>        jD                  dj1                  j2                  |      g      }j,                  j5                  |       Y d }~y d }~ww xY w)Nr.  Fz,failed to encrypt application payload: {err}r   )rg   rh   ri   rj   r   r   r   r   rf   )rb   rc   r   r   r   r   rb   zCSkipping result of "{}", request {} because transport disconnected.zNsuccess return value from invoked procedure "{0}" could not be serialized: {1}Ssuccess return value from invoked procedure "{0}" exceeds transport size limit: {1})#r   rw   rh   rF   r9   r   ro   r   
CallResultrt   results	kwresultsr   r
   r1  rg   ri   rj   r   r   r   r   r   debugr   r6  r   r   ru   
InvocationMESSAGE_TYPEr   r=   r   r>   )	r   r|   r   r   r   r}   r*  registrationrI   s	        r+   r   z-ApplicationSession.onMessage.<locals>.success  s   $($5$5ckk$B26#&<<+/+>+>2l(,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$*!@$(OO$8$8$?S 09 ).,0HHMM0^45 -: -. -.).T (: !@,3MM':L:L:Y:Y[^[f[fhx  iI  iI AR  AY  AY  Zf  Zp  Zp  rs  At  @u-vE$(OO$8$8$?$?'; !@ -4MM':L:L:Y:Y[^[f[fhx  iO  iO AW  A^  A^  _k  _u  _u  wx  Ay  @z-{E$(OO$8$8$?$?!@s?   A+J' K '	K0KK	O=$A?M((O=4A?O88O=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}r8  r9  )r   rw   r7   failure_messager   r;   r   r~   r
   r>  r?  r   rh   r   r   r   ru   r   r=   r   r6  r   r>   )r   r  formatted_tbr   r   r}   r@  rI   s        r+   r_   z+ApplicationSession.onMessage.<locals>.error8  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P  AW  AW  Xd  Xn  Xn  pq  Ar  @s-tE$(OO$8$8$?$? (, (< !@ -4MM':L:L:Y:Y[^[f[fhx  iO  iO AW  A^  A^  _k  _u  _u  wx  A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})rw   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})r*  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   )yrA   ro   r
   Welcomer7   r   	onWelcomer   r   r   r   r  r  	ChallengemethodextraonChallenger   r   rr   Goodbyer   r   r   Eventr%  r   r&  r  rh   rF   r9   r   r   rg   rj   ri   rn   rb   rc   r   objr0  r   details_argEventDetailsr   r  r  r  r  r   r$  	Publishedrw   r   popr   r(  resolveon_reply
Subscribedr   r   appendUnsubscribedr   subscription_idactiveResultr   r6  r   r   r   r   r/  optionson_progressr   r   r:  r   r   r   rejectlenr>  r   r@  r   endpointr~   r?  receive_progressCallDetailsr3  r4  r5  r"   	Interruptr=  cancel
Registeredr   r   UnregisteredKeyErrorr   r   registration_idru   rv   CallPublish	SubscribeUnsubscribeRegister
Unregister	is_calledr   )&rI   r}   r   r   r_   r  	challenger   r%  r  r|   decoded_topicr   invoke_argsinvoke_kwargsr"  futurepublish_requestr   rw   call_requestr   r   r)  kwrb   prog_drS  rc   r   r^  r/  invokedregr   r&  r*  r@  s&   ``                                @@@@r+   	onMessagezApplicationSession.onMessage  s=   
 # #w/ OODNNC8@D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 /F"."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  ux  uA  uA  LO  LX  LX  fi  fu  fu  BvM'*=*=>sB
 "'![k![]![++FHfE_/Fd ((_(f(fgjgwgw(xyyC!2!23;;$"4"44 '+&8&8&<&<S[[&IO #.coo_MjMj"kK MM/":":KH'([(b(bcfcncn(oppC!3!34;;$"6"66 #2266s{{CG ''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 ..$2E2EE,0,?,?@W@W,X 8L27L/8 //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(q(x(x  zH  JN  )O/&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 #!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mA <D 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*i $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 -A  -H  -H  IW  Y]  -^3*
 # %)$@$@ASASA`A`bebmbmov$wE OO007  (||7/7||o.3g"xx.9E#((O.K:=**CJJ$&M'33#&#7#7%K> 04HFKFWFWXdai_b_i_ififwfwhkh{h{bfadamamGoh.B.B C (-x{{'b['bTa'bHB@H%,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 ''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 HHMMN ]]++ " 
 [[D$9$99 #3377DG ..$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S[ (1 !+$(HHMM  3C  KL  WZ  Wc  WcM  %d$*!+\ $- " $$T() !. !" +;$4$F$F$R$Y$YZ[$\+""j (1 !&$(HHMM(U,- %2 %& /?(8(J(J(R(Y(YZ[(\/&G!&X $ +&&,fS-=-=&> sr   %A!AX8A!AY A!AZ6 F6A\ X	AYX#(AYYAYY	AZ3Y"AAZ.Z.AZ3Z6	A\Z?AA\\A\\.A]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r  r
   c                 .    j                  d       | S r  r   r  s    r+   r   z+ApplicationSession.onClose.<locals>.success  s    		'41
r-   c                 (    j                  | d      S r  r   r   s    r+   r  z*ApplicationSession.onClose.<locals>._error  s    **1.DEEr-   c                 ,    j                  d      S )Nr5   )	was_cleanr   )r  rI   wasCleans    r+   r   z+ApplicationSession.onClose.<locals>.success  s    99\489DDr-   c                 (    j                  | d      S )NzWhile firing onDisconnectr   r   s    r+   r  z*ApplicationSession.onClose.<locals>._error  s    &&q*EFFr-   )r   rA   r   r   REASON_TRANSPORT_LOSTr   r7   r   r  r   onDisconnect)rI   r  r   r   r  r   s   ``   @r+   onClosezApplicationSession.onClose  s    
 (())??X__`d`p`pqG g6A
F7F3#DOOD--.	E	GAw/r-   c                     t        d      )zR
        Implements :func:`autobahn.wamp.interfaces.ISession.onChallenge`
        zBreceived authentication challenge, but onChallenge not implemented)r   )rI   rn  s     r+   rJ  zApplicationSession.onChallenge  s    
 \]]r-   c                      y)zM
        Implements :func:`autobahn.wamp.interfaces.ISession.onJoin`
        Nr   rI   r   s     r+   r   zApplicationSession.onJoin      r-   c                      y)zP
        Implements :func:`autobahn.wamp.interfaces.ISession.onWelcome`
        Nr   )rI   r}   s     r+   rF  zApplicationSession.onWelcome  r  r-   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_idrv   c                     j                   S r&   rS  r   rw   s    r+   r   zBApplicationSession._errback_outstanding_requests.<locals>.<lambda>#  s    W-=-= r-   c                     j                   S r&   r  r  s    r+   r   zBApplicationSession._errback_outstanding_requests.<locals>.<lambda>#  s    IYIY r-   )r7   create_future_successr   r   r   r   r   r   extendvaluesclearr9   r   r]  r=  rS  r  rr   r   rm  r\  r   )rI   rx   r   all_requestsoutstandingrequestsrw   s         @r+   _errback_outstanding_requestsz0ApplicationSession._errback_outstanding_requests   s>    ''-  ""OO!!
 $ 	Hx01NN	 HHMM9+&   # 	[GHHNND!(!1!1"--$..77   ??7#3#34W--s3 #=?YZ	[ r-   c                 @    |j                   t        j                  k7  r2 j                  j	                  d|j                   |j
                         t        |j                   |j
                        } j                  |      } fd}t        j                  |||       |S )zN
        Implements :func:`autobahn.wamp.interfaces.ISession.onLeave`
        z/session closed with reason {reason} [{message}]r{  c                 @    j                   rj                          y y r&   )r   r5   r   s    r+   r5   z.ApplicationSession.onLeave.<locals>.disconnect2  s    ! r-   )
r  r   REASON_DEFAULTr9   r   r
   r   r  r7   r   )rI   r   rx   r   r5   s   `    r+   r  zApplicationSession.onLeave&  s    
 >>\888HHMMKT[TbTblsl{l{M| w~~w?..s3	" 	Az:6r-   c                 ^   | j                   st        d      | j                  sH|sd}t        j                  j                  ||      }| j                  j                  |       d| _        n| j                  j                  d       | j                  du xs | j                  j                  }|S )zL
        Implements :func:`autobahn.wamp.interfaces.ISession.leave`
        zsession hasn't joined a realmzwamp.close.normalr{  TzBsession was already requested to leave - not sending GOODBYE againN)rA   r   r   r   r
   rK  r   r   r9   r   	is_closed)rI   r  r
   r}   r  s        r+   r2   zApplicationSession.leave8  s    
 !"BCC!!-,,&&fg&FCOO  %!%DHHMM^_OOt+Ht/H/H	r-   c                 N    t        j                         }| j                  |       y)zS
        Implements :func:`autobahn.wamp.interfaces.ISession.onDisconnect`
        N)r   TransportLostr  )rI   rx   s     r+   r  zApplicationSession.onDisconnectM  s      %%'**3/r-   c                    t        |      t        j                  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      |rBt        j                   r2|j#                         D ci c]  \  }}|j%                  d      | }}}| j&                  st)        j*                         | j,                  j/                         }d}| j0                  r| j0                  j3                  d|||      }|r|rSt        j4                  ||f|j6                  |j8                  |j:                  |j<                  d	|j?                         }	nt        j4                  |||j6                  |j8                  |j:                  |j<                  	      }	nD|r)t        j4                  ||f||d
|j?                         }	nt        j4                  ||||
      }	|rt|j@                  |j@                  |	_         |jB                  |jB                  |	_!        |jD                  |jD                  |	_"        |jF                  |jF                  |	_#        |r>|jH                  r2tK        jL                         }
tO        ||
|du      | jP                  |<   nd}
	 | j&                  jS                  |	       |
S c c}}w # t        $ r"}|| jP                  v r| jP                  |= |d}~ww xY w)zP
        Implements :func:`autobahn.wamp.interfaces.IPublisher.publish`
        Nz{}.publish()Fr
   strictallow_empty_components
allow_nonerZ  z,options must be of type a.w.t.PublishOptionsrd   Trf   rb   rc   r'  )*rp   r\   rq   rk   r0  r   r
   check_or_raise_urir   rr   r   rQ  ro   r   PublishOptionsr   rl   rm   rn   r   r   r  rG   nextrF   rt   rh  rg   rh   ri   rj   message_attrcorrelation_idcorrelation_uricorrelation_is_anchorcorrelation_is_lastacknowledger7   create_futurer   r   r   )rI   r  rb   rc   rZ  rz   r{   r  r|   r}   rS  r   s               r+   publishzApplicationSession.publishX  s/   
 E{cmm+,+|tDzdE]:;:~f!565""5+9+@+@AXAX+Y*/:?.3		5 **Y-:gu/C/CDJKKcgg #,,.Aq  !#F 
 ))++))..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  % WL  	T///&&z2G	s   +L%L+ +	M4MMc           
      B    t        |      r|t        |d      sJ |t        |      t        j                  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-                   ||||	|
               t/        j0                  |d	
      S )zS
        Implements :func:`autobahn.wamp.interfaces.ISubscriber.subscribe`
        Nrr   c                    t        j                  |dj                  j                  j                        ddd       j
                  j                         }t        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   rr   r   rG   r  r7   r  r   rN  r   r   ri  r  r  r  r  r  r   r   )	rM  r$  r  rZ  r  rS  handler_objr}   rI   s	           r+   
_subscribez0ApplicationSession.subscribe.<locals>._subscribe  sD   &&u/?/F/Ft~~G^G^/_.3>B27	9 --224J**,H!"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  %Or-   r,  rY   wildcard)matchexactTconsume_exceptions)callablerZ   rp   r\   rq   ro   r   SubscribeOptionsr   r   r  r'   
getmembersrr   r,   __dict__
is_handlerr	   rZ  uri_typer[   URI_TYPE_WILDCARDrU  r7   gather)rI   r&  r  rZ  r  
on_repliesrz   r*  patrs   suboptss   `          r+   	subscribezApplicationSession.subscribe  sp   
 !e&7GG[<YZY}Us}} <=<*We6L6L"MNM))++	< GdGUG<<
 J''(9(9;PQ Xt$--/#}}[9 	X>>+#&779D&)kk&<WG&#&<<3;;3P3P#P.3.D.D;.WG.3.D.D8.TG&--j$g.VW	XX <<
tDDr-   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   )ro   r   rX  rD  r   r   r   r  remover]  rG   r  r7   r  r    r   r
   rj  r   r  )rI   r%  scountr  rS  r}   s         r+   _unsubscribezApplicationSession._unsubscribe  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6r-   c                     t        |      t        j                  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      |rBt        j                   r2|j#                         D ci c]  \  }}|j%                  d      | }}} j&                  st)        j*                          j,                  j/                         d} j0                  r	  j0                  j3                  d|||      }|r|rSt        j8                  |f|j:                  |j<                  |j>                  |j@                  d	|jC                         }nt        j8                  ||j:                  |j<                  |j>                  |j@                  	      }nD|r)t        j8                  |f||d
|jC                         }nt        j8                  |||
      }|rt|jD                  |jD                  |_"        |jF                  |jF                  |_#        |jH                  |jH                  |_$        |jJ                  |jJ                  |_%         fd}	tM        jN                  |	      }
tQ        ||
|       jR                  <   	  j&                  jU                  |       |
S c c}}w #   j4                  j7                           xY w#   jR                  v r jR                  =  xY w)zJ
        Implements :func:`autobahn.wamp.interfaces.ICaller.call`
        Nz	{}.call()Fr  rZ  z)options must be of type a.w.t.CallOptionsrd   Trf   r  c                 f    t        j                        }j                  j                  |       y r&   )r
   Cancelr   r   )r   
cancel_msgr  rI   s     r+   	cancellerz*ApplicationSession.call.<locals>.cancellerk  s#     
3JOO  ,r-   )r  )+rp   r\   rq   rk   r0  r   r
   r  r   rr   r   rQ  ro   r   CallOptionsr   rl   rm   rn   r   r   r  rG   r  rF   rt   r9   failurerg  rg   rh   ri   rj   r  r  r  r  r  r7   r  r!   r   r   )rI   r6  rb   rc   rZ  rz   r{   r|   r}   r  rS  r  s   `          @r+   callzApplicationSession.call  s-   
 I#--/0/|tDzdE]:;:~f!565""9+6+=+=dnn>U>U+V*/:?.3		5 **Y-:gu/@/@AGHHcgg #,,.Aq  !#F 
 ))++))..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  % e  "z	T__,OOJ/s   -LL#  M #M M!c           
          t        |      r|t        |d      sJ |t        |      t        j                  k(  sJ |t        |t        j                        sJ t        t        j                        sJ  j                  st        j                          fd}t        |      r |d|||      S g }t        j                  |j                  t              D ]u  }|d   }d|j                  v s|j                  d   D ]M  }	|	j!                         s|	j#                         }
|	j$                  xs |}|j'                   ||||
|             O w t)        j*                  |d      S )zN
        Implements :func:`autobahn.wamp.interfaces.ICallee.register`
        Nrr   c                    t        j                  |dj                  	j                  j                        ddd       	j
                  j                         }t        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   rr   r   rG   r  r7   r  r   rN  r#   r   rk  r  r  r  r  r  r   r   )
rM  r$  r6  rZ  r  rS  endpoint_objr}   prefixrI   s
           r+   	_registerz.ApplicationSession.register.<locals>._register  s[   &&y/>/E/EdnnF]F]/^.3>B27	9 --224J**,H#BGW-@-@QUVL!#NN69=	.=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  %Or-   r,  rY   Tr  )r  rZ   rp   r\   rq   ro   r   RegisterOptionsr   r   r  r'   r  rr   r,   r  is_endpointr	   rZ  rU  r7   r  )rI   r^  r6  rZ  r  r  r  rz   r*  r  rs   regoptss   `   `       r+   registerzApplicationSession.register  sR   
 "y'<S^A_`_ DOs}}$DED*We6K6K"LML~FCMM!BBB))++	@ H T8Y@@
 J''(:(:<QR Xt$--/#}}[9 X??,#&779D&)kk&<WG&--i$g.VW	XX <<
tDDr-   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`
        )ro   r   rX  rD  r   r   r   r  rG   r  r7   r  r$   r   r
   rl  r   )rI   r@  r  rS  r}   s        r+   _unregisterzApplicationSession._unregister  s     ,565""""$"5"5565))++))..0
&&(,=j(T`TcTc,dj)  \__=S!r-   r&   )NNNNNNNr   )NNN)r   r   r   r   rJ   r   r   r   r   r   r1   r5   r   r   r   r   ry  r  rJ  r   rF  r  r  r2   r  r  r  r  r  r  r  r   r-   r+   r   r   ?  s    D , , # # 
 
  % %   )" )"V $ $ + + L L   *QTf !0 !0F ^ ^  
  
$L  "  ( 0 0 ^ ^@ @E @ED 7D e eN ?E ?EBr-   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)_SessionShima  
    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 :class:`autobahn.asyncio.wamp.Session` or
    :class:`autobahn.twisted.wamp.Session` depending on which async
    framework you're using.
    Nc                 $    | j                  |      S r&   )on_joinr  s     r+   r   z_SessionShim.onJoin  s    ||G$$r-   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                               |xs d|xs d|       y | j                          y c c}w c c}w )NrQ   rS   r   default)r   rQ   rS   r   )_authenticatorsr  _argsget_merged_authextrar1   r   rL   rk   keys
on_connect)rI   xrQ   rS   r   s        r+   r   z_SessionShim.onConnect  s     <@;O;O;V;V;XYaaggkk(D1YZ\]F?C?S?S?Z?Z?\]!J5]^`aH ..0III!! !5!5!:!:!<=*!/Z#   OO Z]s   #D.#Dc                     	 | j                   |j                     }|j                  | |      S # t        $ r% t        dj	                  |j                              w xY w)Nz.Received challenge for unknown authmethod '{}')r  rH  re  RuntimeErrorr   on_challenge)rI   rn  authenticators      r+   rJ  z_SessionShim.onChallenge  sg    	 001A1ABM ))$	::  	@GG$$ 	s	   - .Ac                    |j                   | j                  y 	 | j                  |j                      }|j                  | |j                        S # t        $ r% t        dj	                  |j                               w xY w)Nz.Received onWelcome for unknown authmethod '{}')rU   r  re  r  r   
on_welcomer   )rI   r}   r  s      r+   rF  z_SessionShim.onWelcome  s    >>!T%9%9%A	 00@M ''cmm<<  	@GGNN 	s   A .A>c                 $    | j                  |      S r&   )on_leaver  s     r+   r  z_SessionShim.onLeave  s    }}W%%r-   c                 "    | j                         S r&   )on_disconnectrH   s    r+   r  z_SessionShim.onDisconnect!  s    !!##r-   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 )Nr,  zInconsistent {}s: {} )	setrk   r  r  r  r]  
ValueErrorr   r1   )nameaunir  rI   s      r+   at_most_onez3_SessionShim.add_authenticator.<locals>.at_most_one0  s    d2299;<N177?  C
 3x!| *11  s   $BrQ   rS   z4Inconsistent authextra values for '{}': '{}' vs '{}')	ro   r   r  r   r  itemsr  r   r  )rI   r  r  r   mergedrz   r{   s   ``     r+   add_authenticatorz_SessionShim.add_authenticator&  s    -888'#%D 	 	H 	J "++	'')LLN 	DAqI~)A,!"3 JQQ1il 	 4A]//0r-   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 r&   )r  r  )r  ys     r+   extract_keysz4_SessionShim._merged_authextra.<locals>.extract_keys`  s    s1668}$$r-   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   )rz   r   
authextrass     r+   first_value_forz7_SessionShim._merged_authextra.<locals>.first_value_fore  sB     ( (		>$Q<'( $++A. r-   )r  r  r   r   r  )rI   r  r  unique_keysr  rz   r  s         @r+   r  z_SessionShim._merged_authextraS  sv     ,0+?+?+F+F+HIaakkI
	% \:su=	  !
 q!!
 	
+ J*
s   A(A-c                      y r&   r   r  s     r+   r  z_SessionShim.on_join{      r-   c                 $    | j                          y r&   )r5   r  s     r+   r  z_SessionShim.on_leave~  s    r-   c                 N    | j                  | j                  j                         y r&   r   rH   s    r+   r  z_SessionShim.on_connect  s    		$++##$r-   c                      y r&   r   rH   s    r+   r  z_SessionShim.on_disconnect  r  r-   )r   r   r   r   r  r   r   rJ  rF  r  r  r  r  r  r  r  r  r   r-   r+   r  r    sM    	 O%*	;=&$
+AZ#
P%r-   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     r+   rJ   z"ApplicationSessionFactory.__init__  s     F 5 5I Fr-   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)rI   r   s     r+   __call__z"ApplicationSessionFactory.__call__  s"     ,,t{{+r-   r&   )r   r   r   r   r   r   rJ   r  r   r-   r+   r  r    s     !GG	r-   r  )5
__future__r   r\   r7   r'   	functoolsr   autobahnr   autobahn.utilr   r   r   autobahn.wampr	   r
   r   r   r   autobahn.wamp.exceptionr   r   r   r   autobahn.wamp.interfacesr   r   r   autobahn.wamp.typesr   r   r   autobahn.exceptionr   autobahn.wamp.requestr   r   r   r   r   r   r   r    r!   r"   r#   r$   r,   r/   r   r  objectr  r   r-   r+   <module>r      s   6 ' 
     > >  !   # h h L L L L 3   8|/ |~ [ [ [|,g% g\ r-   