
    8'hf/                        d dl mZ d dlmZ d dlZ ej
                          d dlmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZ 	 d dlZd d	lmZ d d
lmZ  eed      rej.                  Zn	 eed      ZdZd Z G d dej6                        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jB                               Z!e G d de ejD                               Z"e G d dejF                  e             Z#e G d dejH                  e!             Z$e G d d ejJ                  e             Z%e G d! d"ejL                  e"             Z&y# e$ r d dlZd d	lmZ d d
lmZ Y 5w xY w)#    )absolute_import)dequeN)public)transport_channel_idpeer2str)	websocket)protocol)TransportDetails)iscoroutine)Futureensure_futureasync)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/html/trade_iq/venv/lib/python3.12/site-packages/autobahn/asyncio/websocket.pyyieldsr   D   s     eV$:E(::    c                   ~    e Zd ZdZ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.
    c                     || _         t               | _        | j                          	 t	        |j                  d            | _        | j                          y #  d| _        Y xY w)Npeername?)	transportr   receive_queue_consumer   get_extra_infopeer_connectionMade)selfr"   s     r   connection_madez(WebSocketAdapterProtocol.connection_madeR   sT    ""W	 !9!9*!EFDI 		DIs   A 	A#c                 l    | j                  |       || j                  j                          d | _        y N)_connectionLostr"   close)r(   excs     r   connection_lostz(WebSocketAdapterProtocol.connection_lost_   s.    S! ?NN  "r   c                      t         j                  j                  xs t        j                  j                         _         fd} j
                  j                  |       y )N)loopc                     t        j                        rMj                  j                         }j                  rj	                  |       t        j                        rMj                          y r+   )lenr#   popleftr"   _dataReceivedr$   )_datar(   s     r   processz2WebSocketAdapterProtocol._consume.<locals>.processj   sU    d(()))113>>&&t, d(() MMOr   )r   factoryr1   txaioconfigwaiteradd_done_callback)r(   r8   s   ` r   r$   z!WebSocketAdapterProtocol._consumeg   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(   r7   s     r   data_receivedz&WebSocketAdapterProtocol.data_receiveds   s=    !!$'{{!KK""4( "r   c                     |r1t        | j                  d      r| j                  j                          y | j                  j                          y )Nabort)hasattrr"   rD   r-   )r(   rD   s     r   _closeConnectionz)WebSocketAdapterProtocol._closeConnectionx   s2    WT^^W5NN  "NN  "r   c                 R    | j                         }t        |      rt        |       y y r+   )onOpenr   r   r(   ress     r   _onOpenz WebSocketAdapterProtocol._onOpen~   s!    kkm#;# r   c                 T    | j                  |      }t        |      rt        |       y y r+   )onMessageBeginr   r   )r(   isBinaryrJ   s      r   _onMessageBeginz(WebSocketAdapterProtocol._onMessageBegin   s&    !!(+#;# r   c                 T    | j                  |      }t        |      rt        |       y y r+   )onMessageFrameBeginr   r   )r(   lengthrJ   s      r   _onMessageFrameBeginz-WebSocketAdapterProtocol._onMessageFrameBegin   s&    &&v.#;# r   c                 T    | j                  |      }t        |      rt        |       y y r+   )onMessageFrameDatar   r   r(   payloadrJ   s      r   _onMessageFrameDataz,WebSocketAdapterProtocol._onMessageFrameData   s&    %%g.#;# r   c                 R    | j                         }t        |      rt        |       y y r+   )onMessageFrameEndr   r   rI   s     r   _onMessageFrameEndz+WebSocketAdapterProtocol._onMessageFrameEnd   s$    $$&#;# r   c                 T    | j                  |      }t        |      rt        |       y y r+   )onMessageFramer   r   rV   s      r   _onMessageFramez(WebSocketAdapterProtocol._onMessageFrame   s&    !!'*#;# r   c                 R    | j                         }t        |      rt        |       y y r+   )onMessageEndr   r   rI   s     r   _onMessageEndz&WebSocketAdapterProtocol._onMessageEnd   s$    !#;# r   c                 V    | j                  ||      }t        |      rt        |       y y r+   )	onMessager   r   )r(   rW   rN   rJ   s       r   
_onMessagez#WebSocketAdapterProtocol._onMessage   s&    nnWh/#;# r   c                 T    | j                  |      }t        |      rt        |       y y r+   )onPingr   r   rV   s      r   _onPingz WebSocketAdapterProtocol._onPing   $    kk'"#;# r   c                 T    | j                  |      }t        |      rt        |       y y r+   )onPongr   r   rV   s      r   _onPongz WebSocketAdapterProtocol._onPong   rh   r   c                 X    | j                  |||      }t        |      rt        |       y y r+   )onCloser   r   )r(   wasCleancodereasonrJ   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   N)F)__name__
__module____qualname____doc__r)   r/   r$   rB   rF   rK   rO   rS   rX   r[   r^   ra   rd   rg   rk   rq   rw   r{   ry   r   r   r   r   M   sa    
/)
#










+r   r   c                   :    e Zd ZdZ ej
                         ZddZy)r   z
    Base class for asyncio-based WebSocket server protocols.

    Implements:

    * :class:`autobahn.websocket.interfaces.IWebSocketChannel`
    c                 0    t        | j                  d|      S )W
        Implements :func:`autobahn.wamp.interfaces.ITransport.get_channel_id`
        Tr   r"   r(   channel_id_types     r   get_channel_idz&WebSocketServerProtocol.get_channel_id   s     $DNND/JJr   N
tls-unique)r|   r}   r~   r   r:   make_loggerlogr   ry   r   r   r   r      s     %


CKr   r   c                   L    e Zd ZdZ ej
                         Zd Zd ZddZ	d Z
y)r   z
    Base class for asyncio-based WebSocket client protocols.

    Implements:

    * :class:`autobahn.websocket.interfaces.IWebSocketChannel`
    c                 T    | j                  |      }t        |      rt        |       y y r+   )	onConnectr   r   )r(   responserJ   s      r   
_onConnectz"WebSocketClientProtocol._onConnect   s$    nnX&#;# r   c                     t        d      )Nz)WSS over explicit proxies not implementedrs   rz   s    r   startTLSz WebSocketClientProtocol.startTLS   s    CDDr   c                 0    t        | j                  d|      S )r   Fr   r   s     r   r   z&WebSocketClientProtocol.get_channel_id   s     $DNNE?KKr   c                     | j                   j                  dd      du}|rdt        | j                   dd      i}ni }t        | j                  ||      S )z]
        Internal helper.
        Base class calls this to create a TransportDetails
        peercertNr   F)r&   	is_securesecure_channel_id)r"   r%   r   r
   r&   )r(   r   r   s      r   _create_transport_detailsz1WebSocketClientProtocol._create_transport_details   sY    
 NN11*dC4O	3DNNE<X! !#TYY)Whiir   Nr   )r|   r}   r~   r   r:   r   r   r   r   r   r   ry   r   r   r   r      s0     %


C
ELj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	   r9   )r(   protos     r   __call__z WebSocketAdapterFactory.__call__  s    r   N)r|   r}   r~   r   r:   r   r   r   ry   r   r   r   r      s     %


Cr   r   c                       e Zd Zd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)popasyncio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   r   r	   r   ry   r   r   r   r   	  s     'HHr   r   c                       e Zd Zd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   r   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   r   ry   r   r   r   r   #  s    Hr   r   c                       e Zd ZdZy)r   z
    asyncio-based WAMP-over-WebSocket server protocol.

    Implements:

    * :class:`autobahn.wamp.interfaces.ITransport`
    Nr|   r}   r~   r   ry   r   r   r   r   <      r   r   c                       e Zd Zd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(   r9   r   r   r   s        r   r   z#WampWebSocketServerFactory.__init__O  sT     jj5,,55dG[Q"oo{ 	''>t>v>r   N)r|   r}   r~   r   r   r	   r   ry   r   r   r   r   G  s     +H?r   r   c                       e Zd ZdZy)r   z
    asyncio-based WAMP-over-WebSocket client protocols.

    Implements:

    * :class:`autobahn.wamp.interfaces.ITransport`
    Nr   ry   r   r   r   r   f  r   r   r   c                       e Zd Zd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__y  sR     jj5,,55dG[Q"oo{''>t>v>r   N)r|   r}   r~   r   r   r	   r   ry   r   r   r   r   q  s     +H?r   r   )'
__future__r   collectionsr   r:   use_asyncioautobahn.utilr   autobahn.asyncio.utilr   r   autobahn.wampr   autobahn.websocketr	   autobahn.websocket.typesr
   r   r   r   ImportErrortrolliusrE   r   getattr__all__r   Protocolr   r   r   objectr   r   r   r   r   r   r   ry   r   r   <module>r      s  6 '         @ # ' 5	 # 7O$))MGW-M	;qw// qh K68X8X K K$ %j68X8X %j %jP	f 	 H4h6U6U H H2 H4h6U6U H H0 )"G"GI`   ?!E!EG] ? ?< )"G"GI`   ?!E!EG] ? ?M
    $ s   E0 0F	F	