
    8'h+                        d dl mZ d dlZd dlZ	 d dlZd dlZ ej                          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ej:                               Z G d dej<                        Ze
 G d de             Z  G d dejB                        Z"y# e$ r d dlZY w xY w)    )absolute_importN)public)protocol)ComponentConfig)	parse_url)WampWebSocketClientFactory)WampRawSocketClientFactory)PerMessageDeflateOfferPerMessageDeflateResponsePerMessageDeflateResponseAccept)ApplicationSessionApplicationSessionFactoryApplicationRunnerc                   2    e Zd ZdZ ej
                         Zy)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     Q/var/www/html/trade_iq/venv/lib/python3.12/site-packages/autobahn/asyncio/wamp.pyr   r   >   s     %


Cr   r   c                   8    e Zd ZdZeZ	  ej                         Zy)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%     !G
 %


Cr   r   c                   h    e Zd ZdZ ej
                         Z	 	 	 	 	 	 ddZed        Z	edd       Z
y)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                 ~   t        |      t        j                  k(  sJ |t        |      t        j                  k(  sJ |t        |      t        k(  sJ |t        |      t        k(  sJ |t        |      t        k(  sJ || _        || _        |xs
 t               | _        || _        || _        || _	        || _
        y)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)   s           r   __init__zApplicationRunner.__init__f   s    F CyCMM)*)}Us}} <=<}Ut 343$w-4"787}Ut 343
_df
&
r   c                     t               )zF
        Stop reconnecting, if auto-reconnecting was enabled.
        )NotImplementedErrorr*   s    r   stopzApplicationRunner.stop   s    
 "##r   c                     t              r fd}n} j                  j                  d      rDt         j                        \  }}} j                  r j                  d   nd}t        ||      }	nt         j                        \  }}}}
}}t        | j                   j                   j                   j                        }	t               g}d }|	j                  ddd	d
dddddd||        j                  |}n< j                  r$|s"t        d j                  j                  z         j                  }t!        j"                         }|j%                         rP|rNt!        j&                  t!        j(                                t!        j"                         }t+        |	d      r||	_        t/        j0                          |t.        j2                  _        |j5                  |	|||      }|s|S |j7                  |      \  }}t/        j8                  |       	 |j;                  t<        j>                  |j@                         	 |jE                          |jH                  r)|j7                  |jH                  jK                                |jM                          y# tB        $ r Y bw xY w# tF        $ r Y `w xY w)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                  :   t        j                  j                        } 	  |       }|S # t        $ rd}j                  j                  dj                  |             t        j                         }|j                         r|j                           d }~ww xY w)Nz0ApplicationSession could not be instantiated: {})r   r$   r%   	Exceptionr   errorformatasyncioget_event_loop
is_runningr/   )cfgr   eloopmaker*   s       r   createz%ApplicationRunner.run.<locals>.create   s    %djj$**=	#"3iG #N ! HHNN#U#\#\]^#_`"113D(		s   - 	BABBrsr   N)
serializer)r#   r&   r(   r)   c                 :    t        | t              rt        |       S y N)
isinstancer   r   )responses    r   acceptz%ApplicationRunner.run.<locals>.accept   s    h(AB:8DD Cr   i   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:"?r:   )r'   )level)'callabler#   
startswithparse_rs_urlr&   r	   parse_ws_urlr   r(   r)   r
   setProtocolOptionsr'   RuntimeError	__class__r   r5   r6   	is_closedset_event_loopnew_event_loophasattrr:   r   use_asyncioconfigcreate_connectionrun_until_completestart_loggingadd_signal_handlersignalSIGTERMr/   r-   run_foreverKeyboardInterrupt_sessionleaveclose)r*   r;   
start_loop	log_levelr<   isSecurehostportr>   transport_factoryresourcepathparamsoffersrC   r'   r:   coro	transportr   s   ``                  r   runzApplicationRunner.run   s   ( D># F88u%#/#9 HdD 150@0@))!,dJ !;6j Y <H;Q8HdD(D& !;6txx]a]m]muyuu  JN  JV  JV  !W -./FE
 00WGNBG<AFIGI<@BEAC>?MSMS 1 U 88Cxx"NNN++,- - ((C %%'>>
""7#9#9#;<))+D(&1)-!& %%&7t%M K$($;$;D$A!Y i0''		B  "   ''(9(9(?(?(ABJJL# '  %  s$   !*J" J1 "	J.-J.1	J=<J=)NNNNNN)Tinfo)r   r   r   r   r   r   r   r+   r   r/   rv   r   r   r   r   r   Z   s]     %


C !.` $ $  r   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)Sessionc                      y r@   r   )r*   welcome_msgs     r   
on_welcomezSession.on_welcome$      r   c                      y r@   r   r*   detailss     r   on_joinzSession.on_join'  r}   r   c                 $    | j                          y r@   )
disconnectr   s     r   on_leavezSession.on_leave*  s    r   c                 N    | j                  | j                  j                         y r@   )joinr^   r$   r.   s    r   
on_connectzSession.on_connect-  s    		$++##$r   c                      y r@   r   r.   s    r   on_disconnectzSession.on_disconnect0  r}   r   N)r   r   r   r|   r   r   r   r   r   r   r   ry   ry      s    %r   ry   )#
__future__r   rc   r    r5   ImportErrortrolliusr   r]   autobahn.utilr   autobahn.wampr   autobahn.wamp.typesr   autobahn.websocket.utilr   rU   autobahn.rawsocket.utilrT   autobahn.asyncio.websocketr   autobahn.asyncio.rawsocketr	   autobahn.websocket.compressr
   r   r   __all__r   r   objectr   _SessionShimry   r   r   r   <module>r      s   6 '  
        " / = = A A? ? 
44 
 
 B B  B B BJh## }   s   B4 4	C ?C 