
    h.                        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j0                               Z G d de      Ze
 G d deej6                               Ze
 G d deej8                               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 y)     N)iscoroutine)Future)deque)Optional)publichltype)create_transport_detailstransport_channel_id)	websocket)protocol)WebSocketServerProtocolWebSocketClientProtocolWebSocketServerFactoryWebSocketClientFactoryWampWebSocketServerProtocolWampWebSocketClientProtocolWampWebSocketServerFactoryWampWebSocketClientFactoryc                 <    t        | t              xs t        |       S )z
    Returns ``True`` iff the value yields.

    .. seealso:: http://stackoverflow.com/questions/20730248/maybedeferred-analog-with-asyncio
    )
isinstancer   r   )values    V/var/www/Befach/backend/env/lib/python3.12/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y)WebSocketAdapterProtocolzP
    Adapter class for asyncio-based WebSocket client and server protocols.
    Npeer	is_serverc                 R   | j                   j                  dt        | j                        |       || _        t        | j                  | j                        | _        | j                  j                  | _        t               | _
        | j                          | j                          y )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     	6VDDXDX=Y!* 	 	, # #;4>>4>>"Z ++00	"Wr   c                 l    | j                  |       || j                  j                          d | _        y N)_connectionLostr!   close)r)   excs     r   connection_lostz(WebSocketAdapterProtocol.connection_lostZ   s.    S! ?NN  "r   c                      t         j                  j                  xs t        j                  j                         _         fd} j
                  j                  |       y )N)loopc                     j                   rDj                   j                         }j                  rj                  |       j                   rDj	                          y r+   )r&   popleftr!   _dataReceivedr'   )_datar)   s     r   processz2WebSocketAdapterProtocol._consume.<locals>.processe   sK    $$))113>>&&t, $$ MMOr   )r   factoryr1   txaioconfigwaiteradd_done_callback)r)   r7   s   ` r   r'   z!WebSocketAdapterProtocol._consumeb   sA    $,,"3"3"Hu||7H7HI	 	%%g.r   c                     | j                   j                  |       | j                  j                         s| j                  j	                  d        y y r+   )r&   appendr;   done
set_result)r)   r6   s     r   data_receivedz&WebSocketAdapterProtocol.data_receivedn   s=    !!$'{{!KK""4( "r   c                     |r1t        | j                  d      r| j                  j                          y | j                  j                          y )Nabort)hasattrr!   rC   r-   )r)   rC   s     r   _closeConnectionz)WebSocketAdapterProtocol._closeConnections   s2    WT^^W5NN  "NN  "r   c                    | j                   j                  r>dt        | j                  | j                   j                  d      i}|| j                   _        | j                         }t        |      rt        j                  |       y y )Nz
tls-unique)
r%   	is_securer
   r!   r   
channel_idonOpenr   asyncioensure_future)r)   rH   ress      r   _onOpenz WebSocketAdapterProtocol._onOpeny   so    "",, 24>>4CZCZCdCdfrsJ 2<D##.kkm#;!!#& r   c                 h    | j                  |      }t        |      rt        j                  |       y y r+   )onMessageBeginr   rJ   rK   )r)   isBinaryrL   s      r   _onMessageBeginz(WebSocketAdapterProtocol._onMessageBegin   s,    !!(+#;!!#& r   c                 h    | j                  |      }t        |      rt        j                  |       y y r+   )onMessageFrameBeginr   rJ   rK   )r)   lengthrL   s      r   _onMessageFrameBeginz-WebSocketAdapterProtocol._onMessageFrameBegin   s,    &&v.#;!!#& r   c                 h    | j                  |      }t        |      rt        j                  |       y y r+   )onMessageFrameDatar   rJ   rK   r)   payloadrL   s      r   _onMessageFrameDataz,WebSocketAdapterProtocol._onMessageFrameData   s,    %%g.#;!!#& r   c                 f    | j                         }t        |      rt        j                  |       y y r+   )onMessageFrameEndr   rJ   rK   r)   rL   s     r   _onMessageFrameEndz+WebSocketAdapterProtocol._onMessageFrameEnd   s*    $$&#;!!#& r   c                 h    | j                  |      }t        |      rt        j                  |       y y r+   )onMessageFramer   rJ   rK   rX   s      r   _onMessageFramez(WebSocketAdapterProtocol._onMessageFrame   s,    !!'*#;!!#& r   c                 f    | j                         }t        |      rt        j                  |       y y r+   )onMessageEndr   rJ   rK   r]   s     r   _onMessageEndz&WebSocketAdapterProtocol._onMessageEnd   s*    !#;!!#& r   c                 j    | j                  ||      }t        |      rt        j                  |       y y r+   )	onMessager   rJ   rK   )r)   rY   rP   rL   s       r   
_onMessagez#WebSocketAdapterProtocol._onMessage   s,    nnWh/#;!!#& r   c                 h    | j                  |      }t        |      rt        j                  |       y y r+   )onPingr   rJ   rK   rX   s      r   _onPingz WebSocketAdapterProtocol._onPing   *    kk'"#;!!#& r   c                 h    | j                  |      }t        |      rt        j                  |       y y r+   )onPongr   rJ   rK   rX   s      r   _onPongz WebSocketAdapterProtocol._onPong   rk   r   c                 l    | j                  |||      }t        |      rt        j                  |       y y r+   )onCloser   rJ   rK   )r)   wasCleancodereasonrL   s        r   _onClosez!WebSocketAdapterProtocol._onClose   s.    ll8T62#;!!#& r   c                     t        d      )Nznot implemented	Exception)r)   producer	streamings      r   registerProducerz)WebSocketAdapterProtocol.registerProducer   s    )**r   c                      y 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   >   s     %


CD(3- $Ix~$&
/)
#''
'
'
'
'
'
'
'
'
'
+r   r   c                   2    e Zd ZdZ ej
                         Zy)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           %


Cr   r   c                   >    e Zd ZdZ ej
                         Zd Zd Zy)r   z
    Base class for asyncio-based WebSocket client protocols.

    Implements:

    * :class:`autobahn.websocket.interfaces.IWebSocketChannel`
    c                     | j                  |      }| j                  j                  dt        | j                        |       t        |      rt        j                  |       y y )Nz{func}: {res})r    rL   )	onConnectr"   r#   r   
_onConnectr   rJ   rK   )r)   responserL   s      r   r   z"WebSocketClientProtocol._onConnect   sI    nnX&VDOO-D#N#;!!#& r   c                     t        d      )Nz)WSS over explicit proxies not implementedrv   r}   s    r   startTLSz WebSocketClientProtocol.startTLS   s    CDDr   N)	r   r   r   r   r9   r   r"   r   r   r|   r   r   r   r      s$     %


C'Er   r   c                   8    e Zd ZdZ ej
                         Zd Zy)WebSocketAdapterFactoryzP
    Adapter class for asyncio-based WebSocket client and server factories.
    c                 4    | j                         }| |_        |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	y)r   z
    Base class for asyncio-based WebSocket server factories.

    Implements:

    * :class:`autobahn.websocket.interfaces.IWebSocketServerChannelFactory`
    c                     |j                  dd      }|xs t        j                         | _        t	        j
                  j                  | g|i | y)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__  sG     zz&$'4G224	''00GGGr   N)
r   r   r   r   r9   r   r"   r   r   r   r|   r   r   r   r      s$     %


C&HHr   r   c                   8    e Zd ZdZ ej
                         Zd Zy)r   z
    Base class for asyncio-based WebSocket client factories.

    Implements:

    * :class:`autobahn.websocket.interfaces.IWebSocketClientChannelFactory`
    c                     |j                  dd      }|xs t        j                         | _        t	        j
                  j                  | g|i | y)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__  sG     zz&$'4G224	''00GGGr   N)r   r   r   r   r9   r   r"   r   r|   r   r   r   r     s     %


CHr   r   c                   2    e Zd ZdZ ej
                         Zy)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	y)r   z;
    asyncio-based WAMP-over-WebSocket server factory.
    c                     |j                  dd      }t        j                  j                  | ||       | j                  |d<   t        j                  | g|i | y)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  sT     jj5,,55dG[Q"oo{ 	''>t>v>r   N)
r   r   r   r   r9   r   r"   r   r   r   r|   r   r   r   r   7  s#     %


C*H?r   r   c                   2    e Zd ZdZ ej
                         Zy)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	y)r   z;
    asyncio-based WAMP-over-WebSocket client factory.
    c                     |j                  dd      }t        j                  j                  | ||       | j                  |d<   t        j                  | g|i | y)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  sR     jj5,,55dG[Q"oo{''>t>v>r   N)
r   r   r   r   r9   r   r"   r   r   r   r|   r   r   r   r   e  s#     %


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 # '	;Cw// CL 	68X8X 	 	 E68X8X E E*	f 	 H4h6U6U H H6 H4h6U6U H H4 	)"G"GI` 	 	 ?!E!EG] ? ?@ 	)"G"GI` 	 	 ?!E!EG] ? ?r   