o
    èó·i[,  ã                   @   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   ú[C:\Users\psant\Downloads\PAF backend\school\venv\Lib\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                   @   sH   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J ‚|du st |ƒtksJ ‚|du s t |ƒtks J ‚|du s,t |ƒtks,J ‚|du s8t |ƒtks8J ‚|| _|| _|pBtƒ | _|| _|| _|| _|| _	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Ú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 ƒ ‚)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¡r-tˆjƒ\}}}ˆjr$ˆjd nd}t||d�}	n1tˆ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u rf|}nˆjrs|sstdˆjj ƒ‚ˆj}t ¡ }| ¡ r“|r“t t ¡ ¡ t ¡ }t|	dƒr“||	_tjdksšJ ‚|tj_|j|	|||d�}|s«|S | |¡\}}tj|d� z
| tj|j ¡ W n	 t!yË   Y nw z| "¡  W n	 t#yÛ   Y nw |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               
      sb   t ˆjˆjƒ} zˆ | ƒ}W |S  ty0 } zˆj d |¡¡ t ¡ }| 	¡ r+| 
¡  ‚ d }~ww )Nz0ApplicationSession could not be instantiated: {})r   r   r    Ú	Exceptionr   ÚerrorÚformatÚasyncioÚget_event_loopÚ
is_runningr)   )Úcfgr   ÚeÚloop©Úmaker%   r   r   Úcreate±   s   
ù€ûz%ApplicationRunner.run.<locals>.createÚ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.   r/   Ú	is_closedÚset_event_loopÚnew_event_loopÚhasattrr3   r   Z_explicit_frameworkÚconfigÚcreate_connectionÚrun_until_completeZstart_loggingÚadd_signal_handlerÚsignalÚSIGTERMr)   r'   Úrun_foreverÚKeyboardInterruptÚ_sessionZleaveÚclose)r%   r5   Z
start_loopÚ	log_levelr6   ZisSecureÚhostÚportr8   Ztransport_factoryÚresourceÚpathÚparamsZoffersr<   r"   r3   ÚcoroÚ	transportr   r   r4   r   Úrunœ   sv   õ

þÿ
þýzApplicationRunner.run)NNNNNN)Tr*   )r   r   r   r   r   r   r   r&   r   r)   r[   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   ó   d S r9   r   )r%   Zwelcome_msgr   r   r   Ú
on_welcome(  ó   zSession.on_welcomec                 C   r]   r9   r   ©r%   Údetailsr   r   r   Úon_join+  r_   zSession.on_joinc                 C   s   |   ¡  d S r9   )Z
disconnectr`   r   r   r   Úon_leave.  s   zSession.on_leavec                 C   s   |   | jj¡ d S r9   )ÚjoinrI   r   r(   r   r   r   Ú
on_connect1  s   zSession.on_connectc                 C   r]   r9   r   r(   r   r   r   Úon_disconnect4  r_   zSession.on_disconnectN)r   r   r   r^   rb   rc   re   rf   r   r   r   r   r\   $  s    r\   )#r.   rM   r   Zuse_asyncioZautobahn.utilr   Zautobahn.wampr   Zautobahn.wamp.typesr   Zautobahn.websocket.utilr   rB   Zautobahn.rawsocket.utilrA   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_SessionShimr\   r   r   r   r   Ú<module>   s.   

 K