o
    >h.                     @   sr  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  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d ZG dd de jZe
G dd deejZe
G dd deejZG dd deZe
G dd deejZe
G dd deejZe
G dd dejeZe
G dd dejeZe
G dd dejeZe
G d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                 C   s   t | tpt| S )z
    Returns ``True`` iff the value yields.

    .. seealso:: http://stackoverflow.com/questions/20730248/maybedeferred-analog-with-asyncio
    )
isinstancer   r   )value r   z/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/autobahn/asyncio/websocket.pyyields5   s   r   c                   @   s   e Zd ZU dZe ZdZee	 e
d< dZee e
d< dd Zdd Zd	d
 Zdd Zd*ddZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) ZdS )+WebSocketAdapterProtocolzP
    Adapter class for asyncio-based WebSocket client and server protocols.
    Npeer	is_serverc                 C   sT   | j jdt| j|d || _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   r   r   r   r    G   s   
z(WebSocketAdapterProtocol.connection_madec                 C   s&   |  | |d ur| j  d | _d S N)_connectionLostr   close)r%   excr   r   r   connection_lostZ   s   


z(WebSocketAdapterProtocol.connection_lostc                    s4   t  jjptjjd _ fdd} j| d S )N)loopc                    s2    j r j  } jr |  j s   d S r&   )r"   popleftr   _dataReceivedr#   )_datar%   r   r   processe   s   

z2WebSocketAdapterProtocol._consume.<locals>.process)r   factoryr+   txaioconfigwaiteradd_done_callback)r%   r1   r   r0   r   r#   b   s   z!WebSocketAdapterProtocol._consumec                 C   s*   | j | | j s| jd  d S d S r&   )r"   appendr5   done
set_result)r%   r/   r   r   r   data_receivedn   s   
z&WebSocketAdapterProtocol.data_receivedFc                 C   s,   |rt | jdr| j  d S | j  d S )Nabort)hasattrr   r;   r(   )r%   r;   r   r   r   _closeConnections   s   z)WebSocketAdapterProtocol._closeConnectionc                 C   sH   | j jrdt| j| j jdi}|| j _|  }t|r"t	| d S d S )Nz
tls-unique)
r!   	is_securer	   r   r   
channel_idonOpenr   asyncioensure_future)r%   r?   resr   r   r   _onOpeny   s   z WebSocketAdapterProtocol._onOpenc                 C   $   |  |}t|rt| d S d S r&   )onMessageBeginr   rA   rB   )r%   isBinaryrC   r   r   r   _onMessageBegin      
z(WebSocketAdapterProtocol._onMessageBeginc                 C   rE   r&   )onMessageFrameBeginr   rA   rB   )r%   lengthrC   r   r   r   _onMessageFrameBegin   rI   z-WebSocketAdapterProtocol._onMessageFrameBeginc                 C   rE   r&   )onMessageFrameDatar   rA   rB   r%   payloadrC   r   r   r   _onMessageFrameData   rI   z,WebSocketAdapterProtocol._onMessageFrameDatac                 C   "   |   }t|rt| d S d S r&   )onMessageFrameEndr   rA   rB   r%   rC   r   r   r   _onMessageFrameEnd      z+WebSocketAdapterProtocol._onMessageFrameEndc                 C   rE   r&   )onMessageFramer   rA   rB   rN   r   r   r   _onMessageFrame   rI   z(WebSocketAdapterProtocol._onMessageFramec                 C   rQ   r&   )onMessageEndr   rA   rB   rS   r   r   r   _onMessageEnd   rU   z&WebSocketAdapterProtocol._onMessageEndc                 C   s&   |  ||}t|rt| d S d S r&   )	onMessager   rA   rB   )r%   rO   rG   rC   r   r   r   
_onMessage   s   z#WebSocketAdapterProtocol._onMessagec                 C   rE   r&   )onPingr   rA   rB   rN   r   r   r   _onPing   rI   z WebSocketAdapterProtocol._onPingc                 C   rE   r&   )onPongr   rA   rB   rN   r   r   r   _onPong   rI   z WebSocketAdapterProtocol._onPongc                 C   s(   |  |||}t|rt| d S d S r&   )onCloser   rA   rB   )r%   wasCleancodereasonrC   r   r   r   _onClose   s   z!WebSocketAdapterProtocol._onClosec                 C      t d)Nznot implemented	Exception)r%   producer	streamingr   r   r   registerProducer      z)WebSocketAdapterProtocol.registerProducerc                 C   s   d S r&   r   r0   r   r   r   unregisterProducer   s   z+WebSocketAdapterProtocol.unregisterProducer)F)__name__
__module____qualname____doc__r3   make_loggerr   r   r   str__annotations__r   boolr    r*   r#   r:   r=   rD   rH   rL   rP   rT   rW   rY   r[   r]   r_   rd   rj   rl   r   r   r   r   r   >   s.   
 
r   c                   @      e Zd ZdZe ZdS )r   z
    Base class for asyncio-based WebSocket server protocols.

    Implements:

    * :class:`autobahn.websocket.interfaces.IWebSocketChannel`
    Nrm   rn   ro   rp   r3   rq   r   r   r   r   r   r          r   c                   @   s(   e Zd ZdZe Zdd Zdd ZdS )r   z
    Base class for asyncio-based WebSocket client protocols.

    Implements:

    * :class:`autobahn.websocket.interfaces.IWebSocketChannel`
    c                 C   s<   |  |}| jjdt| j|d t|rt| d S d S )Nz{func}: {res})r   rC   )	onConnectr   r   r   
_onConnectr   rA   rB   )r%   responserC   r   r   r   ry      s
   
z"WebSocketClientProtocol._onConnectc                 C   re   )Nz)WSS over explicit proxies not implementedrf   r0   r   r   r   startTLS   rk   z WebSocketClientProtocol.startTLSN)	rm   rn   ro   rp   r3   rq   r   ry   r{   r   r   r   r   r      s
    r   c                   @       e Zd ZdZe Zdd ZdS )WebSocketAdapterFactoryzP
    Adapter class for asyncio-based WebSocket client and server factories.
    c                 C   s   |   }| |_|S r&   )r   r2   )r%   protor   r   r   __call__   s   z WebSocketAdapterFactory.__call__N)rm   rn   ro   rp   r3   rq   r   r   r   r   r   r   r}      s    r}   c                   @   $   e Zd ZdZe ZeZdd Z	dS )r   z
    Base class for asyncio-based WebSocket server factories.

    Implements:

    * :class:`autobahn.websocket.interfaces.IWebSocketServerChannelFactory`
    c                 O   8   | dd}|pt | _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.
        r+   N)poprA   get_event_loopr+   r   r   __init__r%   argskwargsr+   r   r   r   r     s   zWebSocketServerFactory.__init__N)
rm   rn   ro   rp   r3   rq   r   r   r   r   r   r   r   r   r      s
    r   c                   @   r|   )r   z
    Base class for asyncio-based WebSocket client factories.

    Implements:

    * :class:`autobahn.websocket.interfaces.IWebSocketClientChannelFactory`
    c                 O   r   )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.
        r+   N)r   rA   r   r+   r   r   r   r   r   r   r   r     s   	zWebSocketClientFactory.__init__N)rm   rn   ro   rp   r3   rq   r   r   r   r   r   r   r     s    r   c                   @   ru   )r   z
    asyncio-based WAMP-over-WebSocket server protocol.

    Implements:

    * :class:`autobahn.wamp.interfaces.ITransport`
    Nrv   r   r   r   r   r   *  rw   r   c                   @   r   )r   z;
    asyncio-based WAMP-over-WebSocket server factory.
    c                 O   B   | 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%   r2   r   r   r   r   r   r   r   A  s   
z#WampWebSocketServerFactory.__init__N)
rm   rn   ro   rp   r3   rq   r   r   r   r   r   r   r   r   r   7  
    r   c                   @   ru   )r   z
    asyncio-based WAMP-over-WebSocket client protocols.

    Implements:

    * :class:`autobahn.wamp.interfaces.ITransport`
    Nrv   r   r   r   r   r   X  rw   r   c                   @   r   )r   z;
    asyncio-based WAMP-over-WebSocket client factory.
    c                 O   r   )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   r   r   r   r   o  s   
z#WampWebSocketClientFactory.__init__N)
rm   rn   ro   rp   r3   rq   r   r   r   r   r   r   r   r   r   e  r   r   )!rA   r   r   collectionsr   typingr   r3   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   r   <module>   s@   	  