o
    @Bi+                     @   s  d dl mZ d dlZd dlZzd dlZW n ey!   d dlZY nw 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
Ze
G dd dejZG dd dejZe
G dd deZ G dd dej!Z"dS )    )absolute_importN)public)protocol)ComponentConfig)	parse_url)WampWebSocketClientFactory)WampRawSocketClientFactory)PerMessageDeflateOfferPerMessageDeflateResponsePerMessageDeflateResponseAccept)ApplicationSessionApplicationSessionFactoryApplicationRunnerc                   @   s   e Zd ZdZe ZdS )r   z
    WAMP application session for asyncio-based applications.

    Implements:

        * :class:`autobahn.wamp.interfaces.ITransportHandler`
        * :class:`autobahn.wamp.interfaces.ISession`
    N)__name__
__module____qualname____doc__txaiomake_loggerlog r   r   U/var/www/html/Trade-python/venv/lib/python3.10/site-packages/autobahn/asyncio/wamp.pyr   >   s    	r   c                   @   s   e Zd ZdZeZ	 e ZdS )r   zJ
    WAMP application session factory for asyncio-based applications.
    N)	r   r   r   r   r   sessionr   r   r   r   r   r   r   r   L   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jks	J |du st |tj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 || _|| _|pDt | _|| _|| _|| _	|| _
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six	text_typedicturlrealmextraserializerssslproxyheaders)selfr   r   r   r    r!   r"   r#   r   r   r   __init__f   s   #
zApplicationRunner.__init__c                 C   s   t  )zF
        Stop reconnecting, if auto-reconnecting was enabled.
        )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|rtt  t }t|	dr||	_t  |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      @   )maxFramePayloadSizemaxMessagePayloadSizeautoFragmentSize
failByDropopenHandshakeTimeoutcloseHandshakeTimeout
tcpNoDelayautoPingIntervalautoPingTimeoutautoPingSizeperMessageCompressionOffersperMessageCompressionAcceptzpssl argument value passed to %s conflicts with the "ws:" prefix of the url argument. Did you mean to use "wss:"?r2   )r!   )level)'callabler   
startswithparse_rs_urlr    r   parse_ws_urlr   r"   r#   r	   setProtocolOptionsr!   RuntimeError	__class__r   r-   r.   	is_closedset_event_loopnew_event_loophasattrr2   r   use_asyncioconfigcreate_connectionrun_until_completestart_loggingadd_signal_handlersignalSIGTERMr(   r&   run_foreverKeyboardInterrupt_sessionleaveclose)r$   r4   
start_loop	log_levelr5   isSecurehostportr7   transport_factoryresourcepathparamsoffersr;   r!   r2   coro	transportr   r   r3   r   run   sv   


zApplicationRunner.run)NNNNNN)Tr)   )r   r   r   r   r   r   r   r%   r   r(   rn   r   r   r   r   r   Z   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 r8   r   )r$   welcome_msgr   r   r   
on_welcome$     zSession.on_welcomec                 C   rp   r8   r   r$   detailsr   r   r   on_join'  rs   zSession.on_joinc                 C   s   |    d S r8   )
disconnectrt   r   r   r   on_leave*  s   zSession.on_leavec                 C   s   |  | jj d S r8   )joinrV   r   r'   r   r   r   
on_connect-  s   zSession.on_connectc                 C   rp   r8   r   r'   r   r   r   on_disconnect0  rs   zSession.on_disconnectN)r   r   r   rr   rv   rx   rz   r{   r   r   r   r   ro      s    ro   )#
__future__r   r[   r   r-   ImportErrortrolliusr   rU   autobahn.utilr   autobahn.wampr   autobahn.wamp.typesr   autobahn.websocket.utilr   rM   autobahn.rawsocket.utilrL   autobahn.asyncio.websocketr   autobahn.asyncio.rawsocketr   autobahn.websocket.compressr	   r
   r   __all__r   r   objectr   _SessionShimro   r   r   r   r   <module>   s4    F