o
    èó·i®.  ã                   @   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
    N)Ú
isinstancer   r   )Úvalue© r   ú`C:\Users\psant\Downloads\PAF backend\school\venv\Lib\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Ú_consumeZ_connectionMade)Úselfr   r   r   r   r    G   s   ÿ
z(WebSocketAdapterProtocol.connection_madec                 C   s&   |   |¡ |d ur| j ¡  d | _d S ©N)Z_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   Z_dataReceivedr#   )Ú_Údata©r$   r   r   Úprocesse   s   

ýz2WebSocketAdapterProtocol._consume.<locals>.process)r   Úfactoryr)   ÚtxaioÚconfigÚwaiterÚadd_done_callback)r$   r.   r   r-   r   r#   b   s   z!WebSocketAdapterProtocol._consumec                 C   s*   | j  |¡ | j ¡ s| j d ¡ d S d S r%   )r"   Úappendr2   Ú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   r8   r&   )r$   r8   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!   Z	is_securer	   r   r   Ú
channel_idZonOpenr   ÚasyncioÚensure_future)r$   r;   Úresr   r   r   Ú_onOpeny   s   ÿÿz WebSocketAdapterProtocol._onOpenc                 C   ó$   |   |¡}t|ƒrt |¡ d S d S r%   )ZonMessageBeginr   r<   r=   )r$   ÚisBinaryr>   r   r   r   Ú_onMessageBegin†   ó   
ÿz(WebSocketAdapterProtocol._onMessageBeginc                 C   r@   r%   )ZonMessageFrameBeginr   r<   r=   )r$   Úlengthr>   r   r   r   Ú_onMessageFrameBegin‹   rC   z-WebSocketAdapterProtocol._onMessageFrameBeginc                 C   r@   r%   )ZonMessageFrameDatar   r<   r=   ©r$   Úpayloadr>   r   r   r   Ú_onMessageFrameData�   rC   z,WebSocketAdapterProtocol._onMessageFrameDatac                 C   ó"   |   ¡ }t|ƒrt |¡ d S d S r%   )ZonMessageFrameEndr   r<   r=   ©r$   r>   r   r   r   Ú_onMessageFrameEnd•   ó   ÿz+WebSocketAdapterProtocol._onMessageFrameEndc                 C   r@   r%   )ZonMessageFramer   r<   r=   rF   r   r   r   Ú_onMessageFrameš   rC   z(WebSocketAdapterProtocol._onMessageFramec                 C   rI   r%   )ZonMessageEndr   r<   r=   rJ   r   r   r   Ú_onMessageEndŸ   rL   z&WebSocketAdapterProtocol._onMessageEndc                 C   s&   |   ||¡}t|ƒrt |¡ d S d S r%   )Z	onMessager   r<   r=   )r$   rG   rA   r>   r   r   r   Ú
_onMessage¤   s   ÿz#WebSocketAdapterProtocol._onMessagec                 C   r@   r%   )ZonPingr   r<   r=   rF   r   r   r   Ú_onPing©   rC   z WebSocketAdapterProtocol._onPingc                 C   r@   r%   )ZonPongr   r<   r=   rF   r   r   r   Ú_onPong®   rC   z WebSocketAdapterProtocol._onPongc                 C   s(   |   |||¡}t|ƒrt |¡ d S d S r%   )ZonCloser   r<   r=   )r$   ZwasCleanÚcodeÚreasonr>   r   r   r   Ú_onClose³   s   ÿz!WebSocketAdapterProtocol._onClosec                 C   ó   t dƒ‚)Nznot implemented©Ú	Exception)r$   ZproducerZ	streamingr   r   r   ÚregisterProducer¸   ó   z)WebSocketAdapterProtocol.registerProducerc                 C   s   d S r%   r   r-   r   r   r   ÚunregisterProducer»   s   z+WebSocketAdapterProtocol.unregisterProducer)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r0   Úmake_loggerr   r   r   ÚstrÚ__annotations__r   Úboolr    r(   r#   r7   r:   r?   rB   rE   rH   rK   rM   rN   rO   rP   rQ   rT   rX   rZ   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©r[   r\   r]   r^   r0   r_   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   r>   )Z	onConnectr   r   r   Ú
_onConnectr   r<   r=   )r$   Úresponser>   r   r   r   rf   Ý   s
   
ÿz"WebSocketClientProtocol._onConnectc                 C   rU   )Nz)WSS over explicit proxies not implementedrV   r-   r   r   r   ÚstartTLSã   rY   z WebSocketClientProtocol.startTLSN)	r[   r\   r]   r^   r0   r_   r   rf   rh   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   r/   )r$   Úprotor   r   r   Ú__call__í   s   z WebSocketAdapterFactory.__call__N)r[   r\   r]   r^   r0   r_   r   rl   r   r   r   r   rj   ç   s    rj   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)Úpopr<   Úget_event_loopr)   r   r   Ú__init__©r$   ÚargsÚkwargsr)   r   r   r   rq     s   zWebSocketServerFactory.__init__N)
r[   r\   r]   r^   r0   r_   r   r   r   rq   r   r   r   r   r   ó   s
    r   c                   @   ri   )r   z 
    Base class for asyncio-based WebSocket client factories.

    Implements:

    * :class:`autobahn.websocket.interfaces.IWebSocketClientChannelFactory`
    c                 O   rn   )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)ro   r<   rp   r)   r   r   rq   rr   r   r   r   rq     s   	zWebSocketClientFactory.__init__N)r[   r\   r]   r^   r0   r_   r   rq   r   r   r   r   r     s    r   c                   @   rc   )r   z�
    asyncio-based WAMP-over-WebSocket server protocol.

    Implements:

    * :class:`autobahn.wamp.interfaces.ITransport`
    Nrd   r   r   r   r   r   *  re   r   c                   @   rm   )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)ro   r
   r   rq   Ú
_protocolsr   ©r$   r/   rs   rt   rv   r   r   r   rq   A  s   
z#WampWebSocketServerFactory.__init__N)
r[   r\   r]   r^   r0   r_   r   r   r   rq   r   r   r   r   r   7  ó
    r   c                   @   rc   )r   z‚
    asyncio-based WAMP-over-WebSocket client protocols.

    Implements:

    * :class:`autobahn.wamp.interfaces.ITransport`
    Nrd   r   r   r   r   r   X  re   r   c                   @   rm   )r   z;
    asyncio-based WAMP-over-WebSocket client factory.
    c                 O   ru   )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`
        rv   Nrw   )ro   r
   r   rq   rx   r   ry   r   r   r   rq   o  s   
z#WampWebSocketClientFactory.__init__N)
r[   r\   r]   r^   r0   r_   r   r   r   rq   r   r   r   r   r   e  rz   r   )!r<   r   r   Úcollectionsr   Útypingr   r0   Zuse_asyncioZautobahn.utilr   r   Zautobahn.asyncio.utilr   r	   Zautobahn.wampr
   Zautobahn.websocketr   Ú__all__r   ÚProtocolr   r   r   Úobjectrj   r   r   r   r   r   r   r   r   r   r   Ú<module>   s@   	  