
    afJ                        d dl mZmZ d dlmZ d dlmZ d dlZ ej                     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mZmZ d dlmZ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' d dl(m)Z) d dl*m+Z+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1 dZ2d Z3d Z4d Z5d Z6 G d de)          Z7 G d de
j8        j'        j9                  Z:e G d de:e'j;                              Z;e G d d e:e'j<                              Z< G d! d"e=          Z>e G d# d$e>e'j?        e
j8        j'        j@                              Z?e G d% d&e>e'jA        e
j8        j'        jB                              ZA ee           G d' d(e=                      ZC G d) d*eCe;          ZD G d+ d,eCe<          ZE G d- d.e?          ZF G d/ d0eA          ZGed>d2            ZHed?d5            ZIe G d6 d7ejJ        e;                      ZJe G d8 d9ejK        e?                      ZKe G d: d;ejL        e<                      ZLe G d< d=ejM        eA                      ZMdS )@    )	b64encode	b64decode)Optional)implementerN)	endpoints)
ITransport)ConnectionDoneConnectionAbortedConnectionLost)Deferred)Failure)connectionDone)publichltypehlval)_is_tls_error_maybe_tls_reason)	websocket)TransportDetails)ConnectionRequestConnectionResponseConnectionDeny)protocol)IWebSocketClientAgent)create_transport_detailstransport_channel_id)PerMessageDeflateOfferPerMessageDeflateOfferAcceptPerMessageDeflateResponsePerMessageDeflateResponseAccept)create_client_agentWebSocketAdapterProtocolWebSocketServerProtocolWebSocketClientProtocolWebSocketAdapterFactoryWebSocketServerFactoryWebSocketClientFactoryWrappingWebSocketAdapterWrappingWebSocketServerProtocolWrappingWebSocketClientProtocolWrappingWebSocketServerFactoryWrappingWebSocketClientFactorylistenWS	connectWSWampWebSocketServerProtocolWampWebSocketServerFactoryWampWebSocketClientProtocolWampWebSocketClientFactoryc                      t          |           S )zB
    :returns: an instance implementing IWebSocketClientAgent
    )_TwistedWebSocketClientAgentreactors    L/var/www/html/env/lib/python3.11/site-packages/autobahn/twisted/websocket.pyr!   r!   V   s     (000    c                     t          | t                    s/t          d                    t	          |                               |                     d          s$|                     d          st          d          dS )z>
    raises a ValueError if `transport_config` is invalid
    z-'transport_config' must be a string, found {}zws://zwss://z6'transport_config' must start with 'ws://' or 'wss://'N)
isinstancestr
ValueErrorformattype
startswith)transport_configs    r7   check_transport_configrA   ]   s    
 &,, 
;BB4HXCYCYZZ
 
 	
 &&w// 
&&x00
D
 
 	
 4r8   c                     t          | t                    st          d          g d}|                                 D ](}||vr"t          d                    |                    )dS )z5
    raises a ValueError if `options` is invalid
    z'options' must be a dict)origin	protocols	useragentheadersproxyz'options' may not contain '{}'N)r:   dictr<   keysr=   )options
valid_keysactual_ks      r7   check_client_optionsrM   q   s    
 gt$$ 
&
 
 	

  J LLNN  :%%077AA   & r8   c                 h   |j         r ddlm} |                    |j                  }|j        4||_        t          j        | |j        d         |j        d                   }nO|j         r(ddlm} t          j	        | |j        |j
        |          }n t          j        | |j        |j
                  }|S )Nr   sslhostport)isSecuretwisted.internetrP   optionsForClientTLSrQ   rG   contextFactoryr   HostnameEndpointSSL4ClientEndpointrR   )r6   factoryr@   rJ   rP   context_factoryendpoints          r7   _endpoint_from_configr\      s      @((((((11',??} !0-M&!M&!
 
  	,,,,,, 3	 HH !1 H Or8   c                        e Zd ZdZd ZddZdS )r4   z6
    This agent creates connections using Twisted
    c                     || _         d S N)_reactor)selfr6   s     r7   __init__z%_TwistedWebSocketClientAgent.__init__   s    r8   Nc                 D  	 t          |           t          |           t          d|| j        d|}|t          n||_        t          | j        |||          }t                      	|                    |          }	fd	fd}|	                    |           	S )a-  
        Open a new connection.

        :param dict transport_config: valid transport configuration

        :param dict options: additional options for the factory

        :param protocol_class: a callable that returns an instance of
            the protocol (WebSocketClientProtocol if the default None
            is passed in)

        :returns: a Deferred that fires with an instance of
            `protocol_class` (or WebSocketClientProtocol by default)
            that has successfully shaken hands (completed the
            handshake).
        )urlr6   Nc                 2                         |            d S r_   )errback)frtn_ds    r7   failedz1_TwistedWebSocketClientAgent.open.<locals>.failed   s    MM!r8   c                 L      fd} j                             |            S )Nc                 2                                    | S r_   )callback)argprotorh   s    r7   handshake_completedzQ_TwistedWebSocketClientAgent.open.<locals>.got_proto.<locals>.handshake_completed   s    u%%%
r8   )is_openaddCallbacks)rn   ro   ri   rh   s   ` r7   	got_protoz4_TwistedWebSocketClientAgent.open.<locals>.got_proto   sB          M&&':FCCCLr8    )
rA   rM   r'   r`   r$   r   r\   r   connectrq   )
ra   r@   rJ   protocol_classrY   r[   proto_drr   ri   rh   s
           @@r7   openz!_TwistedWebSocketClientAgent.open   s    " 	/000W%%%( 
 M
 
 
 

 7E6L22R` )AQSZ[[

""7++	 	 	 	 		 	 	 	 	 	 	Y///r8   r_   )__name__
__module____qualname____doc__rb   rw   rs   r8   r7   r4   r4      sA              , , , , , ,r8   r4   c                       e Zd ZU dZ ej                    ZdZee	         e
d<   dZee         e
d<   d ZefdefdZdefd	ZddZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z dS )r"   a  
    Adapter class for Twisted WebSocket client and server protocols.

    Called from Twisted:

    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol.connectionMade`
    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol.connectionLost`
    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol.dataReceived`

    Called from Network-independent Code (WebSocket implementation):

    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onOpen`
    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onMessageBegin`
    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onMessageFrameData`
    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onMessageFrameEnd`
    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onMessageEnd`
    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onMessage`
    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onPing`
    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onPong`
    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._onClose`

    FIXME:

    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._closeConnection`
    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol._create_transport_details`
    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol.registerProducer`
    * :meth:`autobahn.twisted.websocket.WebSocketAdapterProtocol.unregisterProducer`
    Npeer	is_serverc                    t          | j        | j                  | _        t          j        | j        _        | j        j        | _        	 | j                            | j	                   n#  Y nxY w| 
                                 | j                            dt          | j                  t          | j                             d S )Nz/{func} connection established for peer="{peer}"funcr}   )r   	transportr~   _transport_detailsr   CHANNEL_FRAMING_WEBSOCKETchannel_framingr}   setTcpNoDelay
tcpNoDelay_connectionMadelogdebugr   connectionMader   ra   s    r7   r   z'WebSocketAdapterProtocol.connectionMade  s    
 #;4>4>"Z"Z2B2\/ +0		N((9999	D 	 	H"4#677!$),, 	 	. 	. 	. 	. 	.s   A( (A,reasonc                    d}t          |j        t                    r%| j                            d| j                   d}n)t          |j                  r-| j                            t          |j                             nt          |j        t                    r"| j                            d| j                   nt          |j        t                    rXt          |j                  }t          |j        d          r|j        j        }| j                            d| j        |           n:| j                            d	| j        t          |j                  |j        
           |                     |           |rC| j                            dt!          | j                  t%          | j                             d S | j                            dt!          | j                  t%          | j                  |           d S )NFz,Connection to/from {peer} was closed cleanly)r}   Tz-Connection to/from {peer} was aborted locallymessagezDConnection to/from {peer} was lost in a non-clean fashion: {message})r}   r   z7Connection to/from {peer} lost ({error_type}): {error}))r}   
error_typeerrorz8{func} connection lost for peer="{peer}", closed cleanlyr   zD{func} connection lost for peer="{peer}", closed with error {reason})r   r}   r   )r:   valuer	   r   r   r}   r   r   r   r
   r   r;   hasattrr   r>   _connectionLostr   connectionLostr   )ra   r   	was_cleanr   s       r7   r   z'WebSocketAdapterProtocol.connectionLost'  s    	flN33 	^HNNI $	  + + +II6<(( 	^HNN,V\::;;;;&788 	^HNNJ $	  + + + + n55 	^&,''Gv|Y// / ,.HNNVY      HNNT $	d6<6H6HPVP\  ^ ^ ^ 	V$$$  	*HNNU &t': ; ; %di 0 0  2 2 2 2 2 HNNa &t': ; ; %di 0 0"(  * * * * *r8   datac           
          | j                             dt          | j                  t	          | j                  t	          t          |                               |                     |           d S )Nz2{func} received {data_len} bytes for peer="{peer}")r   r}   data_len)r   r   r   dataReceivedr   r}   len_dataReceivedra   r   s     r7   r   z%WebSocketAdapterProtocol.dataReceivedU  sj    K"4#455!$),, %c$ii 0 0 	 	2 	2 	2 	4     r8   Fc                     |r0t          | j        d          r| j                                         d S | j                                         d S )NabortConnection)r   r   r   loseConnection)ra   aborts     r7   _closeConnectionz)WebSocketAdapterProtocol._closeConnection^  sT     	,WT^->?? 	,N**,,,,, N))+++++r8   c                     | j         j        r.dt          | j        | j         j        d          i}|| j         _        |                                  d S )Nz
tls-unique)r   	is_securer   r   r~   
channel_idonOpen)ra   r   s     r7   _onOpenz WebSocketAdapterProtocol._onOpene  sR    ", 	< 24>4CZCdfrssJ 2<D#.r8   c                 0    |                      |           d S r_   )onMessageBegin)ra   isBinarys     r7   _onMessageBeginz(WebSocketAdapterProtocol._onMessageBeginp  s    H%%%%%r8   c                 0    |                      |           d S r_   )onMessageFrameBegin)ra   lengths     r7   _onMessageFrameBeginz-WebSocketAdapterProtocol._onMessageFrameBegins  s      (((((r8   c                 0    |                      |           d S r_   )onMessageFrameDatara   payloads     r7   _onMessageFrameDataz,WebSocketAdapterProtocol._onMessageFrameDatav  s    (((((r8   c                 .    |                                   d S r_   )onMessageFrameEndr   s    r7   _onMessageFrameEndz+WebSocketAdapterProtocol._onMessageFrameEndy  s         r8   c                 0    |                      |           d S r_   )onMessageFramer   s     r7   _onMessageFramez(WebSocketAdapterProtocol._onMessageFrame|  s    G$$$$$r8   c                 .    |                                   d S r_   )onMessageEndr   s    r7   _onMessageEndz&WebSocketAdapterProtocol._onMessageEnd  s    r8   c                 2    |                      ||           d S r_   )	onMessage)ra   r   r   s      r7   
_onMessagez#WebSocketAdapterProtocol._onMessage  s    w)))))r8   c                 0    |                      |           d S r_   )onPingr   s     r7   _onPingz WebSocketAdapterProtocol._onPing      Gr8   c                 0    |                      |           d S r_   )onPongr   s     r7   _onPongz WebSocketAdapterProtocol._onPong  r   r8   c                 4    |                      |||           d S r_   )onClosera   wasCleancoder   s       r7   _onClosez!WebSocketAdapterProtocol._onClose  s    XtV,,,,,r8   c                 <    | j                             ||           dS )z
        Register a Twisted producer with this protocol.

        :param producer: A Twisted push or pull producer.
        :type producer: object
        :param streaming: Producer type.
        :type streaming: bool
        N)r   registerProducer)ra   producer	streamings      r7   r   z)WebSocketAdapterProtocol.registerProducer  s"     	'')<<<<<r8   c                 8    | j                                          dS )zA
        Unregister Twisted producer with this protocol.
        N)r   unregisterProducerr   s    r7   r   z+WebSocketAdapterProtocol.unregisterProducer  s     	))+++++r8   )F)!rx   ry   rz   r{   txaiomake_loggerr   r}   r   r;   __annotations__r~   boolr   r   r   r   bytesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rs   r8   r7   r"   r"      s         : %


CD(3- $Ix~$$$. . .4 0> ,* ,*W ,* ,* ,* ,*\! ! ! ! !, , , ,	 	 	& & &) ) )) ) )! ! !% % %  * * *    - - -	= 	= 	=, , , , ,r8   r"   c                   4    e Zd ZdZ ej                    ZdZdS )r#   z
    Base class for Twisted-based WebSocket server protocols.

    Implements :class:`autobahn.websocket.interfaces.IWebSocketChannel`.
    TN)rx   ry   rz   r{   r   r   r   r~   rs   r8   r7   r#   r#     s/          %


CIIIr8   r#   c                   F    e Zd ZdZ ej                    ZdZdefdZ	d Z
dS )r$   z
    Base class for Twisted-based WebSocket client protocols.

    Implements :class:`autobahn.websocket.interfaces.IWebSocketChannel`.
    Fresponsec                     | j                             dt          | j                  |           |                     |          S )Nz{meth}(response={response}))methr   )r   r   r   
_onConnect	onConnect)ra   r   s     r7   r   z"WebSocketClientProtocol._onConnect  s:    46$/;R;R]efff~~h'''r8   c                     | j                             d           | j                            | j        j                   d S )NzStarting TLS upgrade)r   r   r   startTLSrY   rV   r   s    r7   r   z WebSocketClientProtocol.startTLS  s8    -... ;<<<<<r8   N)rx   ry   rz   r{   r   r   r   r~   r   r   r   rs   r8   r7   r$   r$     s`          %


CI(#5 ( ( ( (= = = = =r8   r$   c                       e Zd ZdZdS )r%   zP
    Adapter class for Twisted-based WebSocket client and server factories.
    Nrx   ry   rz   r{   rs   r8   r7   r%   r%                r8   r%   c                   6    e Zd ZdZ ej                    Zd ZdS )r&   z
    Base class for Twisted-based WebSocket server factories.

    Implements :class:`autobahn.websocket.interfaces.IWebSocketServerChannelFactory`
    c                     |                     dd          }|ddlm} || _        t          j        j        | g|R i | dS )a  

        .. note::
            In addition to all arguments to the constructor of
            :meth:`autobahn.websocket.interfaces.IWebSocketServerChannelFactory`,
            you can supply a ``reactor`` keyword argument to specify the
            Twisted reactor to be used.
        r6   Nr   r5   )poprT   r6   r   r&   rb   )ra   argskwargsr6   s       r7   rb   zWebSocketServerFactory.__init__  s_     **Y--?000000'0GGGGGGGGGr8   Nrx   ry   rz   r{   r   r   r   rb   rs   r8   r7   r&   r&     sD          %


CH H H H Hr8   r&   c                   6    e Zd ZdZ ej                    Zd ZdS )r'   z
    Base class for Twisted-based WebSocket client factories.

    Implements :class:`autobahn.websocket.interfaces.IWebSocketClientChannelFactory`
    c                     |                     dd          }|ddlm} || _        t          j        j        | g|R i | | j        r.| j        )ddlm} |	                    | j
                  | _        dS dS dS )a  

        .. note::
            In addition to all arguments to the constructor of
            :func:`autobahn.websocket.interfaces.IWebSocketClientChannelFactory`,
            you can supply a ``reactor`` keyword argument to specify the
            Twisted reactor to be used.
        r6   Nr   r5   rO   )r   rT   r6   r   r'   rb   rS   rG   rP   rU   rQ   rV   )ra   r   r   r6   rP   s        r7   rb   zWebSocketClientFactory.__init__  s     **Y--?000000'0GGGGGGG = 	ETZ3 -,,,,,"%"9"9$)"D"DD	E 	E33r8   Nr   rs   r8   r7   r'   r'     sD          %


CE E E E Er8   r'   c                   H    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S )r(   a  
    An adapter for stream-based transport over WebSocket.

    This follows `websockify <https://github.com/kanaka/websockify>`_
    and should be compatible with that.

    It uses WebSocket subprotocol negotiation and supports the
    following WebSocket subprotocols:

      - ``binary`` (or a compatible subprotocol)
      - ``base64``

    Octets are either transmitted as the payload of WebSocket binary
    messages when using the ``binary`` subprotocol (or an alternative
    binary compatible subprotocol), or encoded with Base64 and then
    transmitted as the payload of WebSocket text messages when using
    the ``base64`` subprotocol.
    c                    t          |t                    r`|}|j        D ]}|| j        j        v r|dk    | _        |c S  t          t          j        d                    | j        j                            t          |t                    ri|}|j
        | j        j        vrB|                     t          j        j        d                    | j        j                             |j
        dk    | _        d S t          d          )Nbase64z2this server only speaks {0} WebSocket subprotocolsz2this client only speaks {0} WebSocket subprotocolszlogic error)r:   r   rD   rY   _subprotocols_binaryModer   NOT_ACCEPTABLEr=   r   r   _fail_connectionWebSocketProtocol CLOSE_STATUS_CODE_PROTOCOL_ERROR	Exception)ra   requestOrResponserequestpr   s        r7   r   z"WrappingWebSocketAdapter.onConnect$  sL   '):;; 	+'G&  222()XD$HHH 3 !!>@t@{@{  }A  }I  }W  AX  AX  Y  Y  Y)+=>> 	+(H (BBB%%h&@&a  dX  d_  d_  `d  `l  `z  d{  d{  |  |  | ( 1X =D M***r8   c                 8    | j                                          d S r_   )_protor   r   s    r7   r   zWrappingWebSocketAdapter.onOpen6  s    ""$$$$$r8   c                 b   || j         k    r'|                     t          j        j        d           d S |s`	 t          |          }nO# t          $ rB}|                     t          j        j        d                    |                     Y d }~nd }~ww xY w| j	        
                    |           d S )Nz>message payload type does not match the negotiated subprotocolz*message payload base64 decoding error: {0})r   r   r   r   "CLOSE_STATUS_CODE_UNSUPPORTED_DATAr   r   !CLOSE_STATUS_CODE_INVALID_PAYLOADr=   r   r   )ra   r   r   es       r7   r   z"WrappingWebSocketAdapter.onMessage9  s   t'''!!("<"_  bb  c  c  c  c  c ``'00GG  ` ` `))(*D*f  iU  i\  i\  ]^  i_  i_  `  `  `  `  `  `  `  ``K$$W-----s   A 
B8BBc                 :    | j                             d            d S r_   )r   r   r   s       r7   r   z WrappingWebSocketAdapter.onCloseE  s    ""4(((((r8   c                     t          |          t          k    sJ | j        r|                     |d           d S t	          |          }|                     |d           d S )NT)r   F)r>   r   r   sendMessager   r   s     r7   writezWrappingWebSocketAdapter.writeH  sm    DzzU"""" 	3TD11111T??DTE22222r8   c                 :    |D ]}|                      |           d S r_   )r  )ra   r   ds      r7   writeSequencez&WrappingWebSocketAdapter.writeSequenceQ  s,     	 	AJJqMMMM	 	r8   c                 .    |                                   d S r_   )	sendCloser   s    r7   r   z'WrappingWebSocketAdapter.loseConnectionV  s    r8   c                 4    | j                                         S r_   )r   getPeerr   s    r7   r
  z WrappingWebSocketAdapter.getPeerZ      ~%%'''r8   c                 4    | j                                         S r_   )r   getHostr   s    r7   r  z WrappingWebSocketAdapter.getHost^  r  r8   N)rx   ry   rz   r{   r   r   r   r   r  r  r   r
  r  rs   r8   r7   r(   r(     s         &+ + +$% % %	. 	. 	.) ) )3 3 3  
  ( ( (( ( ( ( (r8   r(   c                       e Zd ZdZdS )r)   zD
    Server protocol for stream-based transport over WebSocket.
    Nr   rs   r8   r7   r)   r)   c  r   r8   r)   c                       e Zd ZdZdS )r*   zD
    Client protocol for stream-based transport over WebSocket.
    Nr   rs   r8   r7   r*   r*   i  r   r8   r*   c                   4    e Zd ZdZ	 	 	 	 d	dZd Zd Zd ZdS )
r+   zL
    Wrapping server factory for stream-based transport over WebSocket.
    NTr   c                 6   || _         ddg| _        |r| j                            |           t                              | ||| j                   |                     |           |                     d           |rd }|                     |           d	S d	S )
z

        :param factory: Stream-based factory to be wrapped.
        :type factory: A subclass of ``twisted.internet.protocol.Factory``
        :param url: WebSocket URL of the server this server factory will work for.
        :type url: unicode
        binaryr   rd   r6   rD   autoFragmentSizeF
failByDropc                 \    | D ](}t          |t                    rt          |          c S )d S r_   )r:   r   r   )offersoffers     r7   acceptz7WrappingWebSocketServerFactory.__init__.<locals>.accept  sM    # C CE!%)?@@ C;EBBBBBCC Cr8   perMessageCompressionAcceptN)_factoryr   appendr&   rb   setProtocolOptions)ra   rY   rd   r6   enableCompressionr  subprotocolr  s           r7   rb   z'WrappingWebSocketServerFactory.__init__t  s      &1 	3%%k222'',/07262D 	( 	F 	F 	F 	1ABBB 	5111 		HC C C
 ###GGGGG		H 		Hr8   c                     t                      }| |_        | j                            |          |_        ||j        _        |S r_   )r)   rY   r  buildProtocolr   r   ra   addrrn   s      r7   r$  z,WrappingWebSocketServerFactory.buildProtocol  :    /11}22488!&r8   c                 l    | j                                          t                              |            d S r_   )r  startFactoryr&   r   s    r7   r)  z+WrappingWebSocketServerFactory.startFactory  s0    ""$$$++D11111r8   c                 l    | j                                          t                              |            d S r_   )r  stopFactoryr&   r   s    r7   r+  z*WrappingWebSocketServerFactory.stopFactory  s0    !!###**400000r8   NTr   N)rx   ry   rz   r{   rb   r$  r)  r+  rs   r8   r7   r+   r+   o  sr          #'"#!(H (H (H (HT  2 2 21 1 1 1 1r8   r+   c                   (    e Zd ZdZ	 	 	 	 ddZd ZdS )r,   zL
    Wrapping client factory for stream-based transport over WebSocket.
    NTr   c                    || _         ddg| _        |r| j                            |           t                              | ||| j                   |                     |           |                     d           |r@t                      g}|                     |           d }|                     |	           d
S d
S )a  

        :param factory: Stream-based factory to be wrapped.
        :type factory: A subclass of ``twisted.internet.protocol.Factory``
        :param url: WebSocket URL of the server this client factory will connect to.
        :type url: unicode
        r  r   r  r  Fr  )perMessageCompressionOffersc                 N    t          | t                    rt          |           S d S r_   )r:   r   r    )r   s    r7   r  z7WrappingWebSocketClientFactory.__init__.<locals>.accept  s0    h(ABB E:8DDDE Er8   r  N)r  r   r  r'   rb   r   r   )	ra   rY   rd   r6   r!  r  r"  r  r  s	            r7   rb   z'WrappingWebSocketClientFactory.__init__  s     &1 	3%%k222'',/07262D 	( 	F 	F 	F 	1ABBB 	5111 	H -../F###GGGE E E ###GGGGG	H 	Hr8   c                     t                      }| |_        | j                            |          |_        ||j        _        |S r_   )r*   rY   r  r$  r   r   r%  s      r7   r$  z,WrappingWebSocketClientFactory.buildProtocol  r'  r8   r,  )rx   ry   rz   r{   rb   r$  rs   r8   r7   r,   r,     sT          #'"#!+H +H +H +HZ    r8   r,      c                    t          | d          r| j        }nddlm} | j        r|ddlm} |                                }| j        7|| _        |                    | j        d         | j        d         | ||          }nO| j        r%|	                    | j
        | j        | |||          }n#|                    | j
        | j        | ||          }|S )a  
    Establish WebSocket connection to a server. The connection parameters like target
    host, port, resource and others are provided via the factory.

    :param factory: The WebSocket protocol factory to be used for creating client protocol instances.
    :type factory: An :class:`autobahn.websocket.WebSocketClientFactory` instance.

    :param contextFactory: SSL context factory, required for secure WebSocket connections ("wss").
    :type contextFactory: A `twisted.internet.ssl.ClientContextFactory <http://twistedmatrix.com/documents/current/api/twisted.internet.ssl.ClientContextFactory.html>`_ instance.

    :param timeout: Number of seconds to wait before assuming the connection has failed.
    :type timeout: int

    :param bindAddress: A (host, port) tuple of local address to bind to, or None.
    :type bindAddress: tuple

    :returns: The connector.
    :rtype: An object which implements `twisted.interface.IConnector <http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IConnector.html>`_.
    r6   r   r5   NrO   rQ   rR   )r   r6   rT   rS   rP   ClientContextFactoryrG   rV   
connectTCP
connectSSLrQ   rR   )rY   rV   timeoutbindAddressr6   rP   conns          r7   r.   r.     s    , w	"" -/,,,,,, 8!,,,,,, 5577N} !/!!'-"7v9NPWY`bmnn 	a%%glGL'>[bdoppDD%%glGL'7T_``DKr8   2    c                     t          | d          r| j        }nddlm} | j        r0|t	          d          |                    | j        | |||          }n|                    | j        | ||          }|S )a  
    Listen for incoming WebSocket connections from clients. The connection parameters like
    listening port and others are provided via the factory.

    :param factory: The WebSocket protocol factory to be used for creating server protocol instances.
    :type factory: An :class:`autobahn.websocket.WebSocketServerFactory` instance.

    :param contextFactory: SSL context factory, required for secure WebSocket connections ("wss").
    :type contextFactory: A twisted.internet.ssl.ContextFactory.

    :param backlog: Size of the listen queue.
    :type backlog: int

    :param interface: The interface (derived from hostname given) to bind to, defaults to '' (all).
    :type interface: str

    :returns: The listening port.
    :rtype: An object that implements `twisted.interface.IListeningPort <http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IListeningPort.html>`_.
    r6   r   r5   NzCSecure WebSocket listen requested, but no SSL context factory given)r   r6   rT   rS   r   	listenSSLrR   	listenTCP)rY   rV   backlog	interfacer6   listeners         r7   r-   r-     s    , w	"" -/,,,,,, P!abbb$$W\7NGU^__$$W\7GYOOOr8   c                       e Zd ZdZdS )r/   z
    Twisted-based WAMP-over-WebSocket server protocol.

    Implements:

    * :class:`autobahn.wamp.interfaces.ITransport`
    Nr   rs   r8   r7   r/   r/   8             r8   r/   c                       e Zd ZdZeZd ZdS )r0   zD
    Twisted-based WAMP-over-WebSocket server protocol factory.
    c                     |                     dd          }t          j                            | ||           | j        |d<   t          j        | g|R i | dS )a  

        :param factory: A callable that produces instances that implement
            :class:`autobahn.wamp.interfaces.ITransportHandler`
        :type factory: callable

        :param serializers: A list of WAMP serializers to use (or ``None``
            for all available serializers).
        :type serializers: list of objects implementing
            :class:`autobahn.wamp.interfaces.ISerializer`
        serializersNrD   )r   r   r0   rb   
_protocolsr&   ra   rY   r   r   rF  s        r7   rb   z#WampWebSocketServerFactory.__init__K  sg     jj55,55dG[QQQ"o{ 	'>t>>>v>>>>>r8   N)rx   ry   rz   r{   r/   r   rb   rs   r8   r7   r0   r0   C  s4          +H? ? ? ? ?r8   r0   c                       e Zd ZdZdS )r1   z
    Twisted-based WAMP-over-WebSocket client protocol.

    Implements:

    * :class:`autobahn.wamp.interfaces.ITransport`
    Nr   rs   r8   r7   r1   r1   b  rC  r8   r1   c                       e Zd ZdZeZd ZdS )r2   zD
    Twisted-based WAMP-over-WebSocket client protocol factory.
    c                     |                     dd          }t          j                            | ||           | j        |d<   t          j        | g|R i | d| _        dS )a  

        :param factory: A callable that produces instances that implement
            :class:`autobahn.wamp.interfaces.ITransportHandler`
        :type factory: callable

        :param serializer: The WAMP serializer to use (or ``None`` for
           "best" serializer, chosen as the first serializer available from
           this list: CBOR, MessagePack, UBJSON, JSON).
        :type serializer: object implementing :class:`autobahn.wamp.interfaces.ISerializer`
        rF  NrD   F)r   r   r2   rb   rG  r'   noisyrH  s        r7   rb   z#WampWebSocketClientFactory.__init__u  sl     jj55,55dG[QQQ"o{'>t>>>v>>> 


r8   N)rx   ry   rz   r{   r1   r   rb   rs   r8   r7   r2   r2   m  s4          +H    r8   r2   )Nr2  N)Nr:  r;  )Nr   r   r   typingr   zope.interfacer   r   use_twistedtwisted.internet.protocoltwistedrT   r   twisted.internet.interfacesr   twisted.internet.errorr	   r
   r   twisted.internet.deferr   twisted.python.failurer   r   autobahn.utilr   r   r   r   r   autobahn.wampr   autobahn.wamp.typesr   autobahn.websocket.typesr   r   r   autobahn.websocketr   autobahn.websocket.interfacesr   autobahn.twisted.utilr   r   autobahn.websocket.compressr   r   r   r    __all__r!   rA   rM   r\   r4   internetProtocolr"   r#   r$   objectr%   r&   ServerFactoryr'   ClientFactoryr(   r)   r*   r+   r,   r.   r-   r/   r0   r1   r2   rs   r8   r7   <module>rd     s  6 ( ' ' ' ' ' ' '       & & & & & &               & & & & & & 2 2 2 2 2 2          + + + + + + * * * * * * 4 4 4 4 4 4 / / / / / / / / / / : : : : : : : : # # # # # # 0 0 0 0 0 0 Z Z Z Z Z Z Z Z Z Z ' ' ' ' ' ' ? ? ? ? ? ? P P P P P P P P$ $ $ $ $ $ $ $ $ $ $ $41 1 1  (  2& & &R4 4 4 4 4#8 4 4 4ns, s, s, s, s,w/8A s, s, s,l     68X    = = = = =68X = = =&    f    H H H H H4h6UW^WgWpW~ H H H6  E  E  E  E  E4h6UW^WgWpW~  E  E  ER ZP( P( P( P( P(v P( P( P(f    &>@W       &>@W   <1 <1 <1 <1 <1%; <1 <1 <1~7 7 7 7 7%; 7 7 7t ( ( ( (V        F     )"GI`    ? ? ? ? ?!EG] ? ? ?<     )"GI`        !EG]     r8   