o
    >h[,                     @   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   u/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/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.
        )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jdksJ |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:"?r3   r.   )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hasattrr3   r   _explicit_frameworkconfigcreate_connectionrun_until_completestart_loggingadd_signal_handlersignalSIGTERMr)   r'   run_foreverKeyboardInterrupt_sessionleaveclose)r%   r5   
start_loop	log_levelr6   isSecurehostportr8   transport_factoryresourcepathparams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)   ro   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%   welcome_msgr   r   r   
on_welcome(     zSession.on_welcomec                 C   rq   r9   r   r%   detailsr   r   r   on_join+  rt   zSession.on_joinc                 C   s   |    d S r9   )
disconnectru   r   r   r   on_leave.  s   zSession.on_leavec                 C   s   |  | jj d S r9   )joinrW   r   r(   r   r   r   
on_connect1  s   zSession.on_connectc                 C   rq   r9   r   r(   r   r   r   on_disconnect4  rt   zSession.on_disconnectN)r   r   r   rs   rw   ry   r{   r|   r   r   r   r   rp   $  s    rp   )#r.   r\   r   use_asyncioautobahn.utilr   autobahn.wampr   autobahn.wamp.typesr   autobahn.websocket.utilr   rN   autobahn.rawsocket.utilrM   autobahn.asyncio.websocketr   autobahn.asyncio.rawsocketr   autobahn.websocket.compressr   r	   r
   autobahn.wamp.interfacesr   r   __all__r   registerabc_registerr   objectr   _SessionShimrp   r   r   r   r   <module>   s.   

 K