
    tf.                        d dl Z d dl mZ d dl mZ d dlmZ d dlmZ d dlZ ej                     d dl	m
Z
mZ d dlmZmZ d dlmZ d d	lmZ d
Zd Z G d de j                  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                              Ze
 G d deej                              Ze
 G d dej        e                      Ze
 G d dej        e                      Ze
 G d dej        e                      Ze
 G d dej         e                      Z dS )     N)iscoroutine)Future)deque)Optional)publichltype)create_transport_detailstransport_channel_id)	websocket)protocol)WebSocketServerProtocolWebSocketClientProtocolWebSocketServerFactoryWebSocketClientFactoryWampWebSocketServerProtocolWampWebSocketClientProtocolWampWebSocketServerFactoryWampWebSocketClientFactoryc                 J    t          | t                    pt          |           S )z
    Returns ``True`` iff the value yields.

    .. seealso:: http://stackoverflow.com/questions/20730248/maybedeferred-analog-with-asyncio
    )
isinstancer   r   )values    Y/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/autobahn/asyncio/websocket.pyyieldsr   5   s!     eV$$:E(:(::    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d Zd Z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 )WebSocketAdapterProtocolzP
    Adapter class for asyncio-based WebSocket client and server protocols.
    Npeer	is_serverc                 H   | j                             dt          | j                  |           || _        t          | j        | j                  | _        | j        j        | _        t                      | _
        |                                  |                                  d S )Nz{func}(transport={transport}))func	transport)logdebugr   connection_mader!   r	   r   _transport_detailsr   r   receive_queue_consume_connectionMade)selfr!   s     r   r$   z(WebSocketAdapterProtocol.connection_madeG   s     	6VDDX=Y=Y!* 	 	, 	, 	, # #;4>4>"Z"Z +0	"WWr   c                 t    |                      |           || j                                         d | _        d S N)_connectionLostr!   close)r)   excs     r   connection_lostz(WebSocketAdapterProtocol.connection_lostZ   s<    S!!! ?N  """r   c                      t           j        j        pt          j        j                   _         fd} j                            |           d S )N)loopc                     j         r<j                                         }j        r                    |           j         <                                 d S r+   )r&   popleftr!   _dataReceivedr'   )_datar)   s     r   processz2WebSocketAdapterProtocol._consume.<locals>.processe   s`    $ -)1133> -&&t,,, $ - MMOOOOOr   )r   factoryr1   txaioconfigwaiteradd_done_callback)r)   r7   s   ` r   r'   z!WebSocketAdapterProtocol._consumeb   s[    $,"3"Hu|7HIII	 	 	 	 	 	%%g.....r   c                     | j                             |           | j                                        s| j                            d            d S d S r+   )r&   appendr;   done
set_result)r)   r6   s     r   data_receivedz&WebSocketAdapterProtocol.data_receivedn   sU    !!$'''{!! 	)K""4(((((	) 	)r   Fc                     |r0t          | j        d          r| j                                         d S | j                                         d S )Nabort)hasattrr!   rC   r-   )r)   rC   s     r   _closeConnectionz)WebSocketAdapterProtocol._closeConnections   sQ     	#WT^W55 	#N  """""N  """""r   c                     | j         j        r.dt          | j        | j         j        d          i}|| j         _        |                                 }t          |          rt          j	        |           d S d S )Nz
tls-unique)
r%   	is_securer
   r!   r   
channel_idonOpenr   asyncioensure_future)r)   rH   ress      r   _onOpenz WebSocketAdapterProtocol._onOpeny   s}    ", 	< 24>4CZCdfrssJ 2<D#.kkmm#;; 	'!#&&&&&	' 	'r   c                 z    |                      |          }t          |          rt          j        |           d S d S r+   )onMessageBeginr   rJ   rK   )r)   isBinaryrL   s      r   _onMessageBeginz(WebSocketAdapterProtocol._onMessageBegin   sD    !!(++#;; 	'!#&&&&&	' 	'r   c                 z    |                      |          }t          |          rt          j        |           d S d S r+   )onMessageFrameBeginr   rJ   rK   )r)   lengthrL   s      r   _onMessageFrameBeginz-WebSocketAdapterProtocol._onMessageFrameBegin   sD    &&v..#;; 	'!#&&&&&	' 	'r   c                 z    |                      |          }t          |          rt          j        |           d S d S r+   )onMessageFrameDatar   rJ   rK   r)   payloadrL   s      r   _onMessageFrameDataz,WebSocketAdapterProtocol._onMessageFrameData   sD    %%g..#;; 	'!#&&&&&	' 	'r   c                 x    |                                  }t          |          rt          j        |           d S d S r+   )onMessageFrameEndr   rJ   rK   r)   rL   s     r   _onMessageFrameEndz+WebSocketAdapterProtocol._onMessageFrameEnd   sB    $$&&#;; 	'!#&&&&&	' 	'r   c                 z    |                      |          }t          |          rt          j        |           d S d S r+   )onMessageFramer   rJ   rK   rX   s      r   _onMessageFramez(WebSocketAdapterProtocol._onMessageFrame   sD    !!'**#;; 	'!#&&&&&	' 	'r   c                 x    |                                  }t          |          rt          j        |           d S d S r+   )onMessageEndr   rJ   rK   r]   s     r   _onMessageEndz&WebSocketAdapterProtocol._onMessageEnd   sB    !!#;; 	'!#&&&&&	' 	'r   c                 |    |                      ||          }t          |          rt          j        |           d S d S r+   )	onMessager   rJ   rK   )r)   rY   rP   rL   s       r   
_onMessagez#WebSocketAdapterProtocol._onMessage   sD    nnWh//#;; 	'!#&&&&&	' 	'r   c                 z    |                      |          }t          |          rt          j        |           d S d S r+   )onPingr   rJ   rK   rX   s      r   _onPingz WebSocketAdapterProtocol._onPing   B    kk'""#;; 	'!#&&&&&	' 	'r   c                 z    |                      |          }t          |          rt          j        |           d S d S r+   )onPongr   rJ   rK   rX   s      r   _onPongz WebSocketAdapterProtocol._onPong   rk   r   c                 ~    |                      |||          }t          |          rt          j        |           d S d S r+   )onCloser   rJ   rK   )r)   wasCleancodereasonrL   s        r   _onClosez!WebSocketAdapterProtocol._onClose   sF    ll8T622#;; 	'!#&&&&&	' 	'r   c                      t          d          )Nznot implemented	Exception)r)   producer	streamings      r   registerProducerz)WebSocketAdapterProtocol.registerProducer   s    )***r   c                     d S r+    r)   s    r   unregisterProducerz+WebSocketAdapterProtocol.unregisterProducer   s	     	r   )F)__name__
__module____qualname____doc__r9   make_loggerr"   r   r   str__annotations__r   boolr$   r/   r'   rA   rE   rM   rQ   rU   rZ   r^   ra   rd   rg   rj   rn   rt   rz   r~   r|   r   r   r   r   >   sm          %


CD(3- $Ix~$$$  &  
/ 
/ 
/) ) )
# # # #' ' '' ' '
' ' '
' ' '
' ' '
' ' '
' ' '
' ' '
' ' '
' ' '
' ' '
+ + +    r   r   c                   0    e Zd ZdZ ej                    ZdS )r   z
    Base class for asyncio-based WebSocket server protocols.

    Implements:

    * :class:`autobahn.websocket.interfaces.IWebSocketChannel`
    Nr   r   r   r   r9   r   r"   r|   r   r   r   r      *          %


CCCr   r   c                   <    e Zd ZdZ ej                    Zd Zd ZdS )r   z
    Base class for asyncio-based WebSocket client protocols.

    Implements:

    * :class:`autobahn.websocket.interfaces.IWebSocketChannel`
    c                     |                      |          }| j                            dt          | j                  |           t          |          rt          j        |           d S d S )Nz{func}: {res})r    rL   )	onConnectr"   r#   r   
_onConnectr   rJ   rK   )r)   responserL   s      r   r   z"WebSocketClientProtocol._onConnect   sf    nnX&&VDO-D-D#NNN#;; 	'!#&&&&&	' 	'r   c                      t          d          )Nz)WSS over explicit proxies not implementedrv   r}   s    r   startTLSz WebSocketClientProtocol.startTLS   s    CDDDr   N)	r   r   r   r   r9   r   r"   r   r   r|   r   r   r   r      sS          %


C' ' 'E E E E Er   r   c                   6    e Zd ZdZ ej                    Zd ZdS )WebSocketAdapterFactoryzP
    Adapter class for asyncio-based WebSocket client and server factories.
    c                 <    |                                  }| |_        |S r+   )r   r8   )r)   protos     r   __call__z WebSocketAdapterFactory.__call__   s    r   N)r   r   r   r   r9   r   r"   r   r|   r   r   r   r      s?          %


C    r   r   c                   :    e Zd ZdZ ej                    ZeZd Z	dS )r   z
    Base class for asyncio-based WebSocket server factories.

    Implements:

    * :class:`autobahn.websocket.interfaces.IWebSocketServerChannelFactory`
    c                     |                     dd          }|pt          j                    | _        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 ``loop`` keyword argument to specify the
            asyncio event loop to be used.
        r1   N)poprJ   get_event_loopr1   r   r   __init__r)   argskwargsr1   s       r   r   zWebSocketServerFactory.__init__  sV     zz&$''4G244	'0GGGGGGGGGr   N)
r   r   r   r   r9   r   r"   r   r   r   r|   r   r   r   r      sI          %


C&HH H H H Hr   r   c                   6    e Zd ZdZ ej                    Zd ZdS )r   z
    Base class for asyncio-based WebSocket client factories.

    Implements:

    * :class:`autobahn.websocket.interfaces.IWebSocketClientChannelFactory`
    c                     |                     dd          }|pt          j                    | _        t	          j        j        | g|R i | dS )a  

        .. note::
            In addition to all arguments to the constructor of
            :meth:`autobahn.websocket.interfaces.IWebSocketClientChannelFactory`,
            you can supply a ``loop`` keyword argument to specify the
            asyncio event loop to be used.
        r1   N)r   rJ   r   r1   r   r   r   r   s       r   r   zWebSocketClientFactory.__init__  sV     zz&$''4G244	'0GGGGGGGGGr   N)r   r   r   r   r9   r   r"   r   r|   r   r   r   r     sD          %


CH H H H Hr   r   c                   0    e Zd ZdZ ej                    ZdS )r   z
    asyncio-based WAMP-over-WebSocket server protocol.

    Implements:

    * :class:`autobahn.wamp.interfaces.ITransport`
    Nr   r|   r   r   r   r   *  r   r   r   c                   :    e Zd ZdZ ej                    ZeZd Z	dS )r   z;
    asyncio-based WAMP-over-WebSocket server 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`
        serializersN	protocols)r   r   r   r   
_protocolsr   r)   r8   r   r   r   s        r   r   z#WampWebSocketServerFactory.__init__A  sg     jj55,55dG[QQQ"o{ 	'>t>>>v>>>>>r   N)
r   r   r   r   r9   r   r"   r   r   r   r|   r   r   r   r   7  sD          %


C*H? ? ? ? ?r   r   c                   0    e Zd ZdZ ej                    ZdS )r   z
    asyncio-based WAMP-over-WebSocket client protocols.

    Implements:

    * :class:`autobahn.wamp.interfaces.ITransport`
    Nr   r|   r   r   r   r   X  r   r   r   c                   :    e Zd ZdZ ej                    ZeZd Z	dS )r   z;
    asyncio-based WAMP-over-WebSocket client 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 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`
        r   Nr   )r   r   r   r   r   r   r   s        r   r   z#WampWebSocketClientFactory.__init__o  se     jj55,55dG[QQQ"o{'>t>>>v>>>>>r   N)
r   r   r   r   r9   r   r"   r   r   r   r|   r   r   r   r   e  sD          %


C*H? ? ? ? ?r   r   )!rJ   r   r   collectionsr   typingr   r9   use_asyncioautobahn.utilr   r   autobahn.asyncio.utilr	   r
   autobahn.wampr   autobahn.websocketr   __all__r   Protocolr   r   r   objectr   r   r   r   r   r   r   r|   r   r   <module>r      s?  6                                ( ( ( ( ( ( ( ( P P P P P P P P # # # # # # ' ' ' ' ' '	; ; ;C C C C Cw/ C C CL 	 	 	 	 	68X 	 	 	 E E E E E68X E E E*	 	 	 	 	f 	 	 	 H H H H H4h6U H H H6 H H H H H4h6U H H H4 	 	 	 	 	)"GI` 	 	 	 ? ? ? ? ?!EG] ? ? ?@ 	 	 	 	 	)"GI` 	 	 	 ? ? ? ? ?!EG] ? ? ? ? ?r   