U
    •uÄc[,  ã                   @   s  d dl Z d dlZd dlZe ¡  d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ d dlmZmZmZ d d	lmZmZ d
ZeG dd„ dejƒƒZe e¡ e e¡ G dd„ dejƒZeG dd„ deƒƒZ G dd„ dej!ƒZ"dS )é    N)Úpublic)Úprotocol)ÚComponentConfig)Ú	parse_url)ÚWampWebSocketClientFactory)ÚWampRawSocketClientFactory)ÚPerMessageDeflateOfferÚPerMessageDeflateResponseÚPerMessageDeflateResponseAccept)ÚITransportHandlerÚISession)ÚApplicationSessionÚApplicationSessionFactoryÚApplicationRunnerc                   @   s   e Zd ZdZe ¡ ZdS )r   z½
    WAMP application session for asyncio-based applications.

    Implements:

        * ``autobahn.wamp.interfaces.ITransportHandler``
        * ``autobahn.wamp.interfaces.ISession``
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚtxaioÚmake_loggerÚlog© r   r   úY/var/www/html/CISBACKEND/school/venv/lib/python3.8/site-packages/autobahn/asyncio/wamp.pyr   7   s   	r   c                   @   s&   e Zd ZU dZeZeed< e ¡ Z	dS )r   zJ
    WAMP application session factory for asyncio-based applications.
    ÚsessionN)
r   r   r   r   r   r   Ú__annotations__r   r   r   r   r   r   r   r   K   s   
r   c                   @   s<   e Zd ZdZe ¡ Zddd„Zedd„ ƒZ	edd	d
„ƒZ
dS )r   zæ
    This class is a convenience tool mainly for development and quick hosting
    of WAMP application components.

    It can host a WAMP application component in a WAMP-over-WebSocket client
    connecting to a WAMP router.
    Nc                 C   s¤   t |ƒtkst‚|dks(t |ƒtks(t‚|dks@t |ƒtks@t‚|dksXt |ƒtksXt‚|dkspt |ƒtkspt‚|| _|| _|p„tƒ | _|| _|| _|| _	|| _
dS )aU  

        :param url: The WebSocket URL of the WAMP router to connect to (e.g. `ws://somehost.com:8090/somepath`)
        :type url: str

        :param realm: The WAMP realm to join the application session to.
        :type realm: str

        :param extra: Optional extra configuration to forward to the application component.
        :type extra: dict

        :param serializers: A list of WAMP serializers to use (or None for default serializers).
           Serializers must implement :class:`autobahn.wamp.interfaces.ISerializer`.
        :type serializers: list

        :param ssl: An (optional) SSL context instance or a bool. See
           the documentation for the `loop.create_connection` asyncio
           method, to which this value is passed as the ``ssl``
           keyword parameter.
        :type ssl: :class:`ssl.SSLContext` or bool

        :param proxy: Explicit proxy server to use; a dict with ``host`` and ``port`` keys
        :type proxy: dict or None

        :param headers: Additional headers to send (only applies to WAMP-over-WebSocket).
        :type headers: dict
        N)ÚtypeÚstrÚAssertionErrorÚdictÚurlÚrealmÚextraÚserializersÚsslÚproxyÚheaders)Úselfr   r    r!   r"   r#   r$   r%   r   r   r   Ú__init__e   s    #zApplicationRunner.__init__c                 C   s
   t ƒ ‚dS )zF
        Stop reconnecting, if auto-reconnecting was enabled.
        N)ÚNotImplementedError©r&   r   r   r   Ústop•   s    zApplicationRunner.stopTÚinfoc                    sî  t ˆ ƒr‡ ‡fdd„}nˆ }ˆj d¡rZtˆjƒ\}}}ˆjrHˆjd nd}t||d�}	nbtˆjƒ\}}}}
}}t|ˆjˆjˆjˆj	d�}	t
ƒ g}dd	„ }|	jd
d
dddddddd||d� ˆjdkrÌ|}n ˆjræ|sætdˆjj ƒ‚ˆj}t ¡ }| ¡ �r,|�r,t t ¡ ¡ t ¡ }t|	dƒ�r,||	_tjdk�s<t‚|tj_|j|	|||d�}|�s`|S | |¡\}}tj|d� z| tj |j!¡ W n t"k
�r¤   Y nX z| #¡  W n t$k
�rÈ   Y nX |j%�râ| |j% &¡ ¡ | '¡  dS )a  
        Run the application component. Under the hood, this runs the event
        loop (unless `start_loop=False` is passed) so won't return
        until the program is done.

        :param make: A factory that produces instances of :class:`autobahn.asyncio.wamp.ApplicationSession`
           when called with an instance of :class:`autobahn.wamp.types.ComponentConfig`.
        :type make: callable

        :param start_loop: When ``True`` (the default) this method
            start a new asyncio loop.
        :type start_loop: bool

        :returns: None is returned, unless you specify
            `start_loop=False` in which case the coroutine from calling
            `loop.create_connection()` is returned. This will yield the
            (transport, protocol) pair.
        c               
      sr   t ˆjˆjƒ} zˆ | ƒ}W nN tk
rh } z0ˆj d |¡¡ t ¡ }| 	¡ rV| 
¡  ‚ W 5 d }~X Y nX |S d S )Nz0ApplicationSession could not be instantiated: {})r   r    r!   Ú	Exceptionr   ÚerrorÚformatÚasyncioÚget_event_loopÚ
is_runningr*   )Zcfgr   ÚeÚloop©Úmaker&   r   r   Úcreate±   s    z%ApplicationRunner.run.<locals>.createZrsr   N)Ú
serializer)r   r"   r$   r%   c                 S   s   t | tƒrt| ƒS d S ©N)Ú
isinstancer	   r
   )Úresponser   r   r   ÚacceptÙ   s    
z%ApplicationRunner.run.<locals>.accepti   i   Fg      @g      ð?Tg      $@g      @é   )ZmaxFramePayloadSizeZmaxMessagePayloadSizeZautoFragmentSizeZ
failByDropZopenHandshakeTimeoutZcloseHandshakeTimeoutZ
tcpNoDelayZautoPingIntervalZautoPingTimeoutZautoPingSizeZperMessageCompressionOffersZperMessageCompressionAcceptzpssl argument value passed to %s conflicts with the "ws:" prefix of the url argument. Did you mean to use "wss:"?r3   r/   )r#   )Úlevel)(Úcallabler   Ú
startswithÚparse_rs_urlr"   r   Úparse_ws_urlr   r$   r%   r   ZsetProtocolOptionsr#   ÚRuntimeErrorÚ	__class__r   r/   r0   Ú	is_closedÚset_event_loopÚnew_event_loopÚhasattrr3   r   Z_explicit_frameworkr   ÚconfigÚcreate_connectionÚrun_until_completeZstart_loggingÚadd_signal_handlerÚsignalÚSIGTERMr*   r(   Úrun_foreverÚKeyboardInterruptÚ_sessionZleaveÚclose)r&   r5   Z
start_loopZ	log_levelr6   ZisSecureÚhostÚportr7   Ztransport_factoryÚresourceÚpathÚparamsZoffersr;   r#   r3   ÚcoroÚ	transportr   r   r4   r   Úrunœ   sr    õ

þÿzApplicationRunner.run)NNNNNN)Tr+   )r   r   r   r   r   r   r   r'   r   r*   rY   r   r   r   r   r   Y   s         ù
0
r   c                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚSessionc                 C   s   d S r8   r   )r&   Zwelcome_msgr   r   r   Ú
on_welcome(  s    zSession.on_welcomec                 C   s   d S r8   r   ©r&   Údetailsr   r   r   Úon_join+  s    zSession.on_joinc                 C   s   |   ¡  d S r8   )Z
disconnectr\   r   r   r   Úon_leave.  s    zSession.on_leavec                 C   s   |   | jj¡ d S r8   )ÚjoinrH   r    r)   r   r   r   Ú
on_connect1  s    zSession.on_connectc                 C   s   d S r8   r   r)   r   r   r   Úon_disconnect4  s    zSession.on_disconnectN)r   r   r   r[   r^   r_   ra   rb   r   r   r   r   rZ   $  s
   rZ   )#r/   rL   r   Zuse_asyncioZautobahn.utilr   Zautobahn.wampr   Zautobahn.wamp.typesr   Zautobahn.websocket.utilr   rA   Zautobahn.rawsocket.utilr@   Zautobahn.asyncio.websocketr   Zautobahn.asyncio.rawsocketr   Zautobahn.websocket.compressr   r	   r
   Zautobahn.wamp.interfacesr   r   Ú__all__r   ÚregisterZabc_registerr   Úobjectr   Z_SessionShimrZ   r   r   r   r   Ú<module>   s,   

 K