
    af                        d dl Z d dlZd dlZd dlmZmZmZmZmZ d dl	Z	d dl
mZ  e	j                     d dlmZmZmZ d dlmZ d dlmZmZ 	 d dlmZ n# e$ r eZY nw xY w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' d dl(m)Z)m*Z* d dl+m,Z,m-Z-m.Z.m/Z/ d dl0m1Z1 g dZ2e G d de)j3                              Z3 e,j4        e3            e-j5        e3            G d de)j6                  Z6e G d de7                      Z8 G d de3          Z9 G d de7          Z: G d dej;                  Z< G d de)j=                  Z> G d d e7          Z? e.j4        e?            G d! d"e7          Z@ e.j4        e@           dS )#    N)OptionalDictAnyListUnion)WebSocketProtocol)inlineCallbackssucceedDeferred)service)IReactorCoreIStreamClientEndpoint)CertificateOptions)public)	parse_url)WampWebSocketClientFactory)WampRawSocketClientFactory)PerMessageDeflateOfferPerMessageDeflateResponsePerMessageDeflateResponseAccept)protocolauth)ITransportHandlerISessionIAuthenticatorISerializer)ComponentConfig)ApplicationSessionApplicationSessionFactoryApplicationRunnerApplicationServiceSessionc                   0    e Zd ZdZ ej                    ZdS )r   z
    WAMP application session for Twisted-based applications.

    Implements:

        * :class:`autobahn.wamp.interfaces.ITransportHandler`
        * :class:`autobahn.wamp.interfaces.ISession`
    N)__name__
__module____qualname____doc__txaiomake_loggerlog     G/var/www/html/env/lib/python3.11/site-packages/autobahn/twisted/wamp.pyr   r   K   s*          %


CCCr-   r   c                   B    e Zd ZU dZeZeed<   	  ej                    Z	dS )r   zJ
    WAMP application session factory for Twisted-based applications.
    sessionN)
r%   r&   r'   r(   r   r0   __annotations__r)   r*   r+   r,   r-   r.   r   r   _   sD           #5G444 %


CCCr-   r   c                      e Zd ZdZ ej                    Z	 	 	 	 	 	 	 	 	 	 	 	 ddedee         dee	ee
f                  deee                  dee         dee	ee
f                  d	ee	ee
f                  d
ee	ee
f                  dee         dee         dee         dee         dee         fdZed             Ze	 	 	 ddedededee         dee         de ed          ef         fd            ZdS )r    z
    This class is a convenience tool mainly for development and quick hosting
    of WAMP application components.

    It can host a WAMP application component in a WAMP-over-WebSocket client
    connecting to a WAMP router.
    Nurlrealmextraserializerssslproxyheaderswebsocket_optionsmax_retriesinitial_retry_delaymax_retry_delayretry_delay_growthretry_delay_jitterc                 ,   |t          |          t          k    sJ || _        || _        |pt                      | _        || _        || _        || _        || _        || _	        |	| _
        |
| _        || _        || _        || _        d| _        d| _        dS )af  

        :param url: The WebSocket URL of the WAMP router to connect to (e.g. `ws://example.com:8080/mypath`)
        :param realm: The WAMP realm to join the application session to.
        :param extra: Optional extra configuration to forward to the application component.
        :param serializers: A list of WAMP serializers to use (or None for default serializers).
           Serializers must implement :class:`autobahn.wamp.interfaces.ISerializer`.
        :type serializers: list
        :param ssl: (Optional). If specified this should be an
            instance suitable to pass as ``sslContextFactory`` to
            :class:`twisted.internet.endpoints.SSL4ClientEndpoint`` such
            as :class:`twisted.internet.ssl.CertificateOptions`. Leaving
            it as ``None`` will use the result of calling Twisted
            :meth:`twisted.internet.ssl.platformTrust` which tries to use
            your distribution's CA certificates.
        :param proxy: Explicit proxy server to use; a dict with ``host`` and ``port`` keys.
        :param headers: Additional headers to send (only applies to WAMP-over-WebSocket).
        :param websocket_options: Specific WebSocket options to set (only applies to WAMP-over-WebSocket).
            If not provided, conservative and practical default are chosen.
        :param max_retries: Maximum number of reconnection attempts. Unlimited if set to -1.
        :param initial_retry_delay: Initial delay for reconnection attempt in seconds (Default: 1.0s).
        :param max_retry_delay: Maximum delay for reconnection attempts in seconds (Default: 60s).
        :param retry_delay_growth: The growth factor applied to the retry delay between reconnection
            attempts (Default 1.5).
        :param retry_delay_jitter: A 0-argument callable that introduces noise into the
            delay (Default ``random.random``).
        Nr   )typedictr3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   _client_service_connect_successes)selfr3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   s                 r.   __init__zApplicationRunner.__init__x   s    V e!4!4!44
_dff
&
!2&#6 ."4"4  $"#r-   c                     | j                             d| j        j                   | j        r| j                                        S t          d          S )zF
        Stop reconnecting, if auto-reconnecting was enabled.
        z{klass}.stop()klassN)r+   debug	__class__r%   rC   stopServicer
   rE   s    r.   stopzApplicationRunner.stop   sN    
 	't~/FGGG 	!'335554== r-   TFinfostart_reactorauto_reconnect	log_levelendpointreactorreturnc                 V   #$%  j                             d j        j                   r?ddlm t          j                     t          j        _	        t          j
        |           t                    r	 fd}n} j                            d          r@t           j                  \  }}	}
 j        r j        d         nd}t!          ||	          }nt#           j                  \  }}	}
}}}t%          | j         j         j         j        
          }t+                      g}d }i dt,          j        ddddddddddddddddddddddddddd |d!|d"d#d$d%dd&} j        r|                     j                    |j        d>i | d|_        |r|}nd} j        &|st;          d' j        j        z             j        }n|rdd(lm}  ||	          }ddlm  j        1dd)l m!}  | j        d*          j        d+                   }||_"        n.|rdd,l m#} |J  ||	|
|          }ndd)l m!}  ||	|
          }d- $$ fd.}d}|r"	 dd/l$m%} dd0l$m&# d}n# tN          $ r d}Y nw xY w|rՉ j                             d1            j(         j)         j*         j+         j,        H j*        dk    r9i % fd2}d3 j)        fd4 j*        fd5 j+        fd6|ffD ]\  }}||%|<   #% fd7}nd8 }n
 #            } ||||9           _-         j-        .                                  j-        /                                }n/ j                             d:           |0                    |          }|1                    |           rw G fd;d<td                    }  |             }!|3                    |!           4                                  j5        6                    d=d          }"|!j7        r|!j7        |"r|"dS |S )?a  
        Run the application component.

        :param make: A factory that produces instances of :class:`autobahn.twisted.wamp.ApplicationSession`
           when called with an instance of :class:`autobahn.wamp.types.ComponentConfig`.
        :param start_reactor: When ``True`` (the default) this method starts
           the Twisted reactor and doesn't return until the reactor
           stops. If there are any problems starting the reactor or
           connect()-ing, we stop the reactor and raise the exception
           back to the caller.
        :param auto_reconnect:
        :param log_level:
        :param endpoint:
        :param reactor:
        :return: None is returned, unless you specify
            ``start_reactor=False`` in which case the Deferred that
            connect() returns is returned; this will callback() with
            an IProtocol instance, which will actually be an instance
            of :class:`WampWebSocketClientProtocol`
        z{klass}.run()rH   r   rT   )levelc                      t          j        j                  } 	  |           }|S # t          $ r9 j                            d           rj        r                                  w xY w)N)runnerzAApplicationSession could not be instantiated: {log_failure.value})r   r4   r5   	Exceptionr+   failurerunningrN   )cfgr0   makerT   rE   rP   s     r.   createz%ApplicationRunner.run.<locals>.create   s    %dj$*TJJJ#"d3iiG #N !   H$$%hiii$ ' '	s
   , AA/rsN)
serializer)r3   r6   r8   r9   c                 N    t          | t                    rt          |           S d S N)
isinstancer   r   )responses    r.   acceptz%ApplicationRunner.run.<locals>.accept  s0    h(ABB E:8DDDE Er-   versionutf8validateIncomingTacceptMaskedServerFramesFmaskClientFrames	applyMaskmaxFramePayloadSizei   maxMessagePayloadSizeautoFragmentSizei   
failByDropechoCloseCodeReasonserverConnectionDropTimeoutg      ?openHandshakeTimeoutg      @closeHandshakeTimeout
tcpNoDelayperMessageCompressionOffersperMessageCompressionAcceptautoPingIntervalg      $@g      @   )autoPingTimeoutautoPingSizeautoPingRestartOnAnyTrafficzqssl= argument value passed to %s conflicts with the "ws:" prefix of the url argument. Did you mean to use "wss:"?optionsForClientTLS)TCP4ClientEndpointhostport)SSL4ClientEndpointc                    t          | d          rk| j        f| j                                        r| j                                        S | j                                        r| j                                        S d S d S d S )N_session)hasattrr   is_attachedleaveis_connected
disconnect)protos    r.   cleanupz&ApplicationRunner.run.<locals>.cleanup[  s    uj)) 7en.H>--// 7 >//111^0022 7 >44666	7 7.H.H7 7r-   c                 X    xj         dz  c_                             dd|            | S )N   beforeshutdown)rD   addSystemEventTrigger)r   r   rT   rE   s    r.   
init_protoz)ApplicationRunner.run.<locals>.init_protod  s6    ##q(##))(JOOOLr-   )ClientService)backoffPolicyzusing t.a.i.ClientServicec                  P    j         dnj         } t          j                    | z  S )Nr   )r?   random)jrE   s    r.   _jitterz&ApplicationRunner.run.<locals>._jitter|  s(    !%!8!@AAdF]%}22r-   initialDelaymaxDelayfactorjitterc                     j         dk    r'j        dk    s| j        k     r  di |           S t          d                                            dS )Nr   zhit stopl    @ k r,   )rD   r;   printrN   )failed_attemptsr   kwargsrE   s    r.   retryz$ApplicationRunner.run.<locals>.retry  sn    2Q66D<LPR<R<RVehlhxVxVx#:==#:#:6#:#:?#K#KK!*--- IIKKK#2?r-   c                     dS )Nr   r,   )_s    r.   r   z$ApplicationRunner.run.<locals>.retry  s     qr-   )retryPolicyzusing t.i.e.connect()c                       e Zd ZdZ fdZdS )-ApplicationRunner.run.<locals>.ErrorCollectorNc                 H    |j         | _                                         d S rd   )value	exceptionrN   )rE   r\   rT   s     r.   __call__z6ApplicationRunner.run.<locals>.ErrorCollector.__call__  s    %,]DNLLNNNNNr-   )r%   r&   r'   r   r   rW   s   r.   ErrorCollectorr     s3         	# # # # # # #r-   r   errorr,   )8r+   rJ   rK   r%   twisted.internetrT   r)   use_twistedconfigloopstart_loggingcallabler3   
startswithparse_rs_urlr6   r   parse_ws_urlr   r8   r9   r   r   DEFAULT_SPEC_VERSIONr:   updatesetProtocolOptionsnoisyr7   RuntimeErrortwisted.internet.sslr~   twisted.internet.endpointsr   contextFactoryr   twisted.application.internetr   r   ImportErrorr;   r<   r=   r>   r?   rC   startServicewhenConnectedconnectaddCallbackobject
addErrbackrunr5   getr   )&rE   r_   rP   rQ   rR   rS   rT   r`   isSecurer   r   rb   transport_factoryresourcepathparamsoffersrg   protocol_optionsclientcontext_factoryr~   r   r   r   use_servicer   r   keyvalr   dr   connect_error	app_errorr   r   r   s&   ```   `                            @@@r.   r   zApplicationRunner.run   s   0 	dn.EFFF 	1 100000 'ELi0000D>> 	
# 
# 
# 
# 
# 
# 
# 
# 
# F8t$$ >	E#/#9#9 HdD 150@J)!,,dJ !;6j Y Y Y <H;Q;Q8HdD(D& !;6tx]a]muyu  JN  JV  !W  !W  !W -../FE E E
 ,A &  +E  #D	 
 T  &w  (  #E  d  &u  .r  '  (  d  .v   .v! " #C# $ $& " 04/     6 % @ ''(>??? 10DD3CDDD #( 	AFF #Ox# 1&R/01 1 1 #'( <DDDDDD"5"5d";";000000z%IIIIII++GTZ5GTZI[\\3B!00 AIIIIII&222++GT4QQIIIIII++GT4@@
	7 	7 	7	 	 	 	 	 	 	
  	$$FFFFFFFFFFFF" $ $ $#$  .	2HNN6777 ,0H0TX\XlXx  }A  }T  }`  dh  d{  dG'!++F3 3 3 3 3 '5d6N%O&0$2F%G&.0G%H&.%8%: . .S ?*-F3K3 3 3 3 3 3 3 3! ! ! ! & $1=9JX]#^#^#^D  --///$2244AA HNN2333011A 	
j!!!  	
# # # # # # # # # # +N,,MLL''' KKMMM
 
w55I &  #--     
 Hs   4J JJ)NNNNNNNNNNNN)TFrO   NN)r%   r&   r'   r(   r)   r*   r+   strr   r   r   r   r   r   intfloatrF   r   rN   boolr   r   r   rA   r   r   r,   r-   r.   r    r    l   s         %


C )-37<@593759?C.28<487;7;>$ >$>$ >$ !c3h0>$ 'tK'89	>$
 12>$ !c3h0>$ #4S>2>$ %-T#s(^$<>$ 'sm>$ '/uo>$ #+5/>$ &.e_>$ &.e_>$ >$ >$ >$@ 	! 	! V	! KPQU.2A At AD AA/78M/NAl+A7<TT$ZZ=Q7RA A A VA A Ar-   r    c                   p    e Zd ZdZd Zed             Zed             Zed             Zed             Z	dS )_ApplicationSessionzh
    WAMP application session class used internally with :class:`autobahn.twisted.app.Application`.
    c                 J    t                               | |           || _        dS )a  

        :param config: The component configuration.
        :type config: Instance of :class:`autobahn.wamp.types.ComponentConfig`
        :param app: The application this session is for.
        :type app: Instance of :class:`autobahn.twisted.wamp.Application`.
        N)r   rF   app)rE   r   r   s      r.   rF   z_ApplicationSession.__init__  s%     	##D&111r-   c              #      K   | j                             d          V  |                     | j        j                   dS )zP
        Implements :meth:`autobahn.wamp.interfaces.ISession.onConnect`
        	onconnectN)r   _fire_signaljoinr   r4   rM   s    r.   	onConnectz_ApplicationSession.onConnect  sA      
 h##K00000		$+#$$$$$r-   c              #      K   | j         j        D ]\  }}|                     ||          V  | j         j        D ]\  }}|                     ||          V  | j                             d          V  dS )zM
        Implements :meth:`autobahn.wamp.interfaces.ISession.onJoin`
        onjoinedN)r   _procsregister	_handlers	subscriber   )rE   detailsuriprochandlers        r.   onJoinz_ApplicationSession.onJoin  s      
  	+ 	+IC--c****** H. 	/ 	/LC..#......h##J///////r-   c              #   j   K   | j                             d          V  |                                  dS )zN
        Implements :meth:`autobahn.wamp.interfaces.ISession.onLeave`
        onleaveN)r   r   r   rE   r   s     r.   onLeavez_ApplicationSession.onLeave  s:      
 h##I.....r-   c              #   B   K   | j                             d          V  dS )zS
        Implements :meth:`autobahn.wamp.interfaces.ISession.onDisconnect`
        ondisconnectN)r   r   rM   s    r.   onDisconnectz _ApplicationSession.onDisconnect  s*      
 h##N3333333r-   N)
r%   r&   r'   r(   rF   r	   r   r   r   r   r,   r-   r.   r   r     s         
 
 
 % % _% 
0 
0 _
0   _ 4 4 _4 4 4r-   r   c                   r    e Zd ZdZ ej                    ZddZd ZddZ	dd	Z
dd
Zd Zed             ZdS )r!   z
    A WAMP application. The application object provides a simple way of
    creating, debugging and running WAMP application components.
    Nc                 L    || _         g | _        g | _        i | _        d| _        dS )z

        :param prefix: The application URI prefix to use for procedures and topics,
           e.g. ``"com.example.myapp"``.
        :type prefix: unicode
        N)_prefixr   r   _signalsr0   )rE   prefixs     r.   rF   zApplication.__init__  s3         r-   c                 L    | j         J t          ||           | _         | j         S )aC  
        Factory creating a WAMP application session for the application.

        :param config: Component configuration.
        :type config: Instance of :class:`autobahn.wamp.types.ComponentConfig`

        :returns: obj -- An object that derives of
           :class:`autobahn.twisted.wamp.ApplicationSession`
        )r0   r   )rE   r   s     r.   r   zApplication.__call__  s+     |###*6488|r-   ws://localhost:8080/wsrealm1Tc                 X    t          ||          }|                    | j        |          S )z
        Run the application.

        :param url: The URL of the WAMP router to connect to.
        :type url: unicode
        :param realm: The realm on the WAMP router to join.
        :type realm: unicode
        )r    r   r   )rE   r3   r4   rP   rZ   s        r.   r   zApplication.run*  s)     #3..zz$-777r-   c                       fd}|S )ab  
        Decorator exposing a function as a remote callable procedure.

        The first argument of the decorator should be the URI of the procedure
        to register under.

        :Example:

        .. code-block:: python

           @app.register('com.myapp.add2')
           def add2(a, b):
              return a + b

        Above function can then be called remotely over WAMP using the URI `com.myapp.add2`
        the function was registered under.

        If no URI is given, the URI is constructed from the application URI prefix
        and the Python function name.

        :Example:

        .. code-block:: python

           app = Application('com.myapp')

           # implicit URI will be 'com.myapp.add2'
           @app.register()
           def add2(a, b):
              return a + b

        If the function `yields` (is a co-routine), the `@inlineCallbacks` decorator
        will be applied automatically to it. In that case, if you wish to return something,
        you should use `returnValue`:

        :Example:

        .. code-block:: python

           from twisted.internet.defer import returnValue

           @app.register('com.myapp.add2')
           def add2(a, b):
              res = yield stuff(a, b)
              returnValue(res)

        :param uri: The URI of the procedure to register under.
        :type uri: unicode
        c                     r}n)j         J d                    j         | j                  }t          j        |           rt          |           } j                            || f           | S Nz{0}.{1})r   formatr%   inspectisgeneratorfunctionr	   r   appendfunc_urirE   r   s     r.   	decoratorz'Application.register.<locals>.decoratorh  sy     E|/// ''dmDD*400 -&t,,Kd|,,,Kr-   r,   rE   r   r	  s   `` r.   r   zApplication.register6  s+    d	 	 	 	 	 	 r-   c                       fd}|S )a  
        Decorator attaching a function as an event handler.

        The first argument of the decorator should be the URI of the topic
        to subscribe to. If no URI is given, the URI is constructed from
        the application URI prefix and the Python function name.

        If the function yield, it will be assumed that it's an asynchronous
        process and inlineCallbacks will be applied to it.

        :Example:

        .. code-block:: python

           @app.subscribe('com.myapp.topic1')
           def onevent1(x, y):
              print("got event on topic1", x, y)

        :param uri: The URI of the topic to subscribe to.
        :type uri: unicode
        c                     r}n)j         J d                    j         | j                  }t          j        |           rt          |           } j                            || f           | S r  )r   r  r%   r  r  r	   r   r  r  s     r.   r	  z(Application.subscribe.<locals>.decorator  sy     E|/// ''dmDD*400 -&t,,N!!4,///Kr-   r,   r
  s   `` r.   r   zApplication.subscribev  s*    ,	 	 	 	 	 	 r-   c                       fd}|S )a  
        Decorator attaching a function as handler for application signals.

        Signals are local events triggered internally and exposed to the
        developer to be able to react to the application lifecycle.

        If the function yield, it will be assumed that it's an asynchronous
        coroutine and inlineCallbacks will be applied to it.

        Current signals :

           - `onjoined`: Triggered after the application session has joined the
              realm on the router and registered/subscribed all procedures
              and event handlers that were setup via decorators.
           - `onleave`: Triggered when the application session leaves the realm.

        .. code-block:: python

           @app.signal('onjoined')
           def _():
              # do after the app has join a realm

        :param name: The name of the signal to watch.
        :type name: unicode
        c                     t          j        |           rt          |           } j                            g                               |            | S rd   )r  r  r	   r   
setdefaultr  )r  namerE   s    r.   r	  z%Application.signal.<locals>.decorator  sN    *400 -&t,,M$$T2..55d;;;Kr-   r,   )rE   r  r	  s   `` r.   signalzApplication.signal  s*    4	 	 	 	 	 	
 r-   c              /      K   | j                             |g           D ]@}	  ||i |V  # t          $ r&}| j                            d|           Y d}~9d}~ww xY wdS )z
        Utility method to call all signal handlers for a given signal.

        :param name: The signal name.
        :type name: str
        z5Warning: exception in signal handler swallowed: {err})errN)r   r   r[   r+   rO   )rE   r  argsr   r   es         r.   r   zApplication._fire_signal  s       }((r22 	^ 	^G^ gt.v...... ^ ^ ^U[\]]]]]]]]^	^ 	^s   
,
AAArd   )r   r   T)r%   r&   r'   r(   r)   r*   r+   rF   r   r   r   r   r  r	   r   r,   r-   r.   r!   r!     s         
 %


C   *  
8 
8 
8 
8> > > >@" " " "H  B ^ ^ _^ ^ ^r-   r!   c                   $    e Zd ZdZeZddZd ZdS )r"   a  
    A WAMP application as a twisted service.
    The application object provides a simple way of creating, debugging and running WAMP application
    components inside a traditional twisted application

    This manages application lifecycle of the wamp connection using startService and stopService
    Using services also allows to create integration tests that properly terminates their connections

    It can host a WAMP application component in a WAMP-over-WebSocket client
    connecting to a WAMP router.
    Nc                     || _         || _        |pt                      | _        || _        || _        t          j                            |            | 	                                 dS )a[  

        :param url: The WebSocket URL of the WAMP router to connect to (e.g. `ws://somehost.com:8090/somepath`)
        :type url: unicode

        :param realm: The WAMP realm to join the application session to.
        :type realm: unicode

        :param make: A factory that produces instances of :class:`autobahn.asyncio.wamp.ApplicationSession`
           when called with an instance of :class:`autobahn.wamp.types.ComponentConfig`.
        :type make: callable

        :param extra: Optional extra configuration to forward to the application component.
        :type extra: dict

        :param context_factory: optional, only for secure connections. Passed as contextFactory to
            the ``listenSSL()`` call; see https://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IReactorSSL.connectSSL.html
        :type context_factory: twisted.internet.ssl.ClientContextFactory or None

        You can replace the attribute factory in order to change connectionLost or connectionFailed behaviour.
        The factory attribute must return a WampWebSocketClientFactory object
        N)
r3   r4   rB   r5   r_   r   r   MultiServicerF   setupService)rE   r3   r4   r_   r5   r   s         r.   rF   zService.__init__  s_    . 
_dff
	.%%d+++r-   c                 `    t           j                  \  }}}}}} fd}                     | j                  }|r0ddlm}	  j        }
|
ddlm}  ||          }
 |	||||
          }n) j        t          d          dd	lm	}  ||||          }|
                                dS )
z2
        Setup the application component.
        c                  f    t          j        j                  }                     |           }|S rd   )r   r4   r5   r_   )r^   r0   rE   s     r.   r`   z$Service.setupService.<locals>.create  s*    !$*dj99CiinnGNr-   )r3   r   )	SSLClientNr}   )r   z+context_factory specified on non-secure URI)	TCPClient)r   r3   factoryr   r  r   r   r~   r[   r  setServiceParent)rE   	is_securer   r   r   r   r   r`   r   r  ctxr~   r   r  s   `             r.   r  zService.setupService  s    9ETX8N8N5	4xv	 	 	 	 	 !LLTXL>>  	>>>>>>>&C{DDDDDD))$//YtT+<SQQQFF#/ MNNN>>>>>>YtT+<==F%%%%%r-   )NN)r%   r&   r'   r(   r   r  rF   r  r,   r-   r.   r"   r"     sH        
 
 )G   >& & & & &r-   r"   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )r#   c                     d S rd   r,   )rE   welcome_msgs     r.   
on_welcomezSession.on_welcome       r-   c                     d S rd   r,   r   s     r.   on_joinzSession.on_join#  r&  r-   c                 .    |                                   d S rd   )r   r   s     r.   on_leavezSession.on_leave&  s    r-   c                 D    |                      | j        j                   d S rd   )r   r   r4   rM   s    r.   
on_connectzSession.on_connect)  s    		$+#$$$$$r-   c                     d S rd   r,   rM   s    r.   on_disconnectzSession.on_disconnect,  r&  r-   N)r%   r&   r'   r%  r(  r*  r,  r.  r,   r-   r.   r#   r#     s_              % % %    r-   r#   c                       e Zd Zd Zd ZdS )AuthCryptoSignc                 L   |                                 D ]3}|dvr-t          d                    || j        j                            4dD ](}||vr"t          d                    |                    )|                    dt                                D ](}|dvr"t          d                    |                    )dd	lm} |	                    t          j        |d
                             | _        d|                    dt                                v r;|d         d         }|| j                                        k    rt          d          nG|                    dt                                |d<   | j                                        |d         d<   || _        d S )N)	authextraauthidauthroleprivkeyUnexpected key '{}' for {})r5  z Must provide '{}' for cryptosignr2  )pubkeychannel_binding	trustroot	challengez"Unexpected key '{}' in 'authextra'r   )CryptosignKeyr5  r7  z,Public key doesn't correspond to private key)keys
ValueErrorr  rK   r%   r   rB   autobahn.wamp.cryptosignr;  
from_bytesbinasciia2b_hex_privkey
public_key_args)rE   kwr   r;  r7  s        r.   rF   zAuthCryptoSign.__init__3  s   7799 	 	CHHH 077T^=TUU   I  	 	C"}} 6==cBB    66+tvv.. 	 	CQQQ 8??DD   R
 	;:::::%00R	]++
 
 rvvk4662222_X.F113333 B   4
 !ff[$&&99B{O(,(@(@(B(BB{OH%


r-   c                     | j         d                             dd           }| j        j        j                            |d           }| j                            |||          }|S )Nr2  r8  )
channel_idchannel_id_type)rD  r   	transporttransport_detailsrG  rB  sign_challenge)rE   r0   r:  rH  rG  signed_challenges         r.   on_challengezAuthCryptoSign.on_challengeU  si    *[1556GNN^5@DD_VZ[[
=77	jHW 8 Y Yr-   Nr%   r&   r'   rF   rM  r,   r-   r.   r0  r0  1  s3             D         r-   r0  c                       e Zd Zd Zd ZdS )AuthWampCrac                    |                                 D ]3}|dvr-t          d                    || j        j                            4dD ](}||vr"t          d                    |                    )|| _        |                    d          | _        t          | j        t                    s!| j        
                    d          | _        d S d S )N)r2  r3  r4  secretr6  )rR  r3  zMust provide '{}' for wampcrarR  utf8)r<  r=  r  rK   r%   rD  pop_secretre   r   decode)rE   rE  r   s      r.   rF   zAuthWampCra.__init__c  s    7799 	 	CGGG 077T^=TUU   H ( 	 	C"}} 3::3??   
 
vvh''$,,, 	7<..v66DLLL	7 	7r-   c                 H   | j                             d          }d|j        v r8t          j        ||j        d         |j        d         |j        d                   }t          j        ||j        d                             d                    }|                    d          S )NrS  salt
iterationskeylenr:  ascii)rU  encoder5   r   
derive_keycompute_wcsrV  )rE   r0   r:  r   	signatures        r.   rM  zAuthWampCra.on_challengeu  s    l!!&))Y_$$/'-)	 C $OK(//77
 
	 (((r-   NrN  r,   r-   r.   rP  rP  a  s2        7 7 7$) ) ) ) )r-   rP  )Ar  r@  r   typingr   r   r   r   r   r)   autobahn.websocket.protocolr   r   twisted.internet.deferr	   r
   r   twisted.applicationr   twisted.internet.interfacesr   r   r   r   r   autobahn.utilr   autobahn.websocket.utilr   r   autobahn.rawsocket.utilr   autobahn.twisted.websocketr   autobahn.twisted.rawsocketr   autobahn.websocket.compressr   r   r   autobahn.wampr   r   autobahn.wamp.interfacesr   r   r   r   autobahn.wamp.typesr   __all__r   r   abc_registerr   r   r    r   r!   r  r"   _SessionShimr#   r0  rP  r,   r-   r.   <module>rq     s  6    3 3 3 3 3 3 3 3 3 3 3 3 3 3  9 9 9 9 9 9      E E E E E E E E E E ' ' ' ' ' ' K K K K K K K K7777777    !           = = = = = = = = = = = = A A A A A A A A A A A A? ? ? ? ? ? ? ? ? ? ) ( ( ( ( ( ( ( ] ] ] ] ] ] ] ] ] ] ] ] / / / / / /
 
 
 
 
 
 
 
4 
 
 
   - . . .  ( ) ) )
 
 
 
 
 B 
 
 
 Y Y Y Y Y Y Y Yx
34 34 34 34 34, 34 34 34lK^ K^ K^ K^ K^& K^ K^ K^\K& K& K& K& K&g" K& K& K&^    h#   **  *  *  *  * V *  *  * Z   ' ' '") ") ") ") ")& ") ") ")J   $ $ $ $ $s   A AA