
    8'h>                        d dl mZmZ d dlZd dlZd dlZd dlm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mZ d
Zd Zd Zd Z G d dej<                        ZddZy# e	$ r d dl
ZY kw xY w)    )absolute_importprint_functionN)wraps)WampWebSocketClientFactory)WampRawSocketClientFactory)	component)TransportLost)Session)create_transport_serializerscreate_transport_serializer)	Componentrunc                 n    t               }| D cg c]  }||vs|j                  |      r| c}S c c}w )zM
    Return a list with unique elements from sequence, preserving order.
    )setadd)seqseenxs      V/var/www/html/trade_iq/venv/lib/python3.12/site-packages/autobahn/asyncio/component.py_unique_listr   :   s/     5D@!atmDHHQKA@@@s   	222c                     | j                  d      }|d   dj                  |dd  D cg c]  }|j                          c}      z   S c c}w )N_r       )splitjoin
capitalize)snakepartsss      r   _camel_case_from_snake_caser!   B   sB    KKE8bgguQRyA!q||~ABBBAs   A
c           
      B   |j                   dk(  r/t        |      }t        ||j                  ||j                        }n<|j                   dk(  r&t        |j                  d         }t        ||      }nJ d       |j                  j                         D ]  \  }}	  |j                  di ||i  |S # t        t        f$ r[ 	  |j                  di t        |      |i n9# t        t        f$ r' t        dj                  |j                   ||            w xY wY w xY w)	z3
    Create a WAMP-over-XXX transport factory.
    	websocket)urlserializersproxy	rawsocketr   )
serializershould not arrive herez"Unknown {} transport option: {}={} )typer   r   r$   r&   r   r%   r   optionsitemssetProtocolOptions	TypeErrorKeyErrorr!   
ValueErrorformat)loop	transportsession_factoryr%   factoryr(   kvs           r   _create_transport_factoryr9   G   s8    ~~%29=,#//	
 
<	'01F1Fq1IJ
,_T 	0//u !!'') 1	&G&&0!Q0 N 8$ 	*** 215q9 x(  8??	PQSTU 	s*   B44DC"!D"6DDDc                   X    e Zd ZdZ ej
                         ZeZ	 d Z	d Z
d Zd ZddZy)	r   z
    A component establishes a transport and attached a session
    to a realm using the transport for communication.

    The transports a component tries to use can be configured,
    as well as the auto-reconnect strategy.
    c                 6    t        |t        j                        S )z"
        Internal helper.
        )
isinstancesslSSLError)selfes     r   _is_ssl_errorzComponent._is_ssl_error~   s     !S\\**    c                     t        |t              rGd|v rB|d   }t        |t        t        f      ry t        |t        j                        ry t        d      y t        d      )Ntlsz?'tls' configuration must be a dict, bool or SSLContext instancezI'endpoint' configuration must be a dict or IStreamClientEndpoint provider)r<   dictboolr=   
SSLContextr1   )r?   endpointrD   s      r   _check_native_endpointz Component._check_native_endpoint   sk    h%!v&cD$<0S^^4$.  "  rB   c                    t        |||      }|j                  r|j                  j                  dd      }t	        |      t
        j                  vr#t        dj                  t	        |                  |j                  ||j                  d   |j                  d         }t        j                  t        j                  ||            }| j                  |||      S |j                  d   d	k(  r|j                  j                  d
d      }	|	dvrt        dj                  |	            |j                  d   }
t	        |
      t
        j                  k7  r#t        dj                  t	        |
                  |j                  d   }t	        |      t
        j                  vr#t        dj                  t	        |                  |j                  j                  dd      }t	        |      t
        j                  vr#t        dj                  t	        |                  |j                  j                  dd      }d}|rt        |t               r|j#                         D ]   }|dvst        dj                  |             |j                  d|
      }t	        |      t
        j                  k7  rt        dj                  |            |j                  dd      }|}d}|yt%        j&                  t$        j(                  j*                  |      }nIt        |t$        j,                        r|
}n,|dv r|r&|
}n#t/        dj                  t	        |                  |j                  ||
|||      }t        j                  t        j                  ||            }| j                  |||      S |j                  d   dk(  r|j                  d   }t1        |j                  j                  dd            }|j3                  ||      }t        j                  t        j                  ||            }| j                  |||      S J d       ) z?
        Create and connect a WAMP-over-XXX transport.
        timeout
   z<invalid type {} for timeout in client endpoint configurationhostport)protocol_factoryrM   rN   )rK   r+   tcpversion   )rR      z6invalid IP version {} in client endpoint configurationz9invalid type {} for host in client endpoint configurationz9invalid type {} for port in client endpoint configurationrD   N)hostname
trust_rootz Invalid key '{}' in 'tls' configrT   zAinvalid type {} for hostname in TLS client endpoint configurationrU   T)purposecafile)FTz4unknown type {} for "tls" configuration in transport)rO   rM   rN   r=   server_hostnameunixpath)rO   rZ   r)   )r9   r&   rH   getr+   sixinteger_typesr1   r2   create_connectionasyncioensure_futurewait_for_wrap_connection_future	text_typer<   rE   keysr=   create_default_contextPurposeSERVER_AUTHrG   RuntimeErrorintcreate_unix_connection)r?   r3   r4   r5   doner6   rK   ftime_frQ   rM   rN   rD   tls_hostnamer7   rT   
cert_fnamerZ   s                     r   _connect_transportzComponent._connect_transport   s    ,D)_M
 ??((,,Z<GG}C$5$55 !_!f!fgklsgt!uvv &&!(__V,__V, ' A
 **7+;+;Aw+OPF//	4HH(F2((,,Z;Gf$ !Y!`!`ah!ijj%%g.DDzS]]* !\!c!cdhimdn!opp%%g.DDz!2!22 !\!c!cdhimdn!opp((,,Z<GG}C$5$55 !_!f!fgklsgt!uvv$$((6CL c4( XXZ [$@@",-O-V-VWX-Y"ZZ[  #ww{D9HH~6()l)s)st|)}~~!$!=J#+LC!-!88$'KK$;$;#-
  S^^4#'LM)'+ '']'d'deijmen'opp&&!( , ' A **7+;+;Aw+OPF//	4HH(G3%%g.D),,00R@AG++!( , A **7+;+;Aw+OPF//	4HH 4335rB   c                 |    fd}fd}t        j                  ||d        t        j                  |d |       |S )Nc                    | \  }}|j                         rBt        j                        s,t        |dd      }t        j                  t        |             y |j                  t              fd       }||_        y )N_onclose_reasonzConnection already closedc                      |       }t        j                        s#| t        d      } t        j                  |        |S )Nzfailed to complete connection)txaio	is_calledr	   reject)failrtnrk   origs     r   lostzKComponent._wrap_connection_future.<locals>.on_connect_success.<locals>.lost  s=    4jt, |,-LMLLt,
rB   )
is_closingru   rv   getattrrw   r	   connection_lostr   )resultr4   protoreasonr{   rz   rk   s        @r   on_connect_successz=Component._wrap_connection_future.<locals>.on_connect_success   sz    %Iu ##%t,$U,=?Z[FLL}V'<= ((D4[	 	 %)E!rB   c                 \    xj                   dz  c_         t        j                  |        y )Nr   )connect_failuresru   rw   )errrk   r4   s    r   on_connect_failurez=Component._wrap_connection_future.<locals>.on_connect_failure$  s"    &&!+&LLs#rB   )ru   add_callbacks)r?   r4   rk   conn_fr   r   s    ``   r   rb   z!Component._wrap_connection_future   s=    &	)P	$
 	F$6= 	FD*<=rB   Nc                     |/| j                   j                  d       t        j                         }| j	                  |      S )a~  
        This starts the Component, which means it will start connecting
        (and re-connecting) to its configured transports. A Component
        runs until it is "done", which means one of:
        - There was a "main" function defined, and it completed successfully;
        - Something called ``.leave()`` on our session, and we left successfully;
        - ``.stop()`` was called, and completed successfully;
        - none of our transports were able to connect successfully (failure);

        :returns: a Future which will resolve (to ``None``) when we are
            "done" or with an error if something went wrong.
        zUsing default loop)r3   )logwarnr_   get_event_loop_start)r?   r3   s     r   startzComponent.start0  s9     <HHMM./))+D{{{%%rB   N)__name__
__module____qualname____doc__ru   make_loggerr   r
   r5   rA   rI   rp   rb   r   r*   rB   r   r   r   n   s?     %


CO+(`4D3l&rB   r   c                    |t        j                  |       t        j                         j	                         rPt        j
                  t        j                                t        j                         t         j                  _        t        j                         t        j                  fd       	 j                  t        j                  fd       j                  t        j                  fd       d }t!        j"                  | |       |r"	 j%                          j)                          yy# t        $ r Y Jw xY w# t        j&                  $ r Y 6w xY w)a.  
    High-level API to run a series of components.

    This will only return once all the components have stopped
    (including, possibly, after all re-connections have failed if you
    have re-connections enabled). Under the hood, this calls

    XXX fixme for asyncio

    -- if you wish to manage the loop yourself, use the
    :meth:`autobahn.asyncio.component.Component.start` method to start
    each component yourself.

    :param components: the Component(s) you wish to run
    :type components: instance or list of :class:`autobahn.asyncio.component.Component`

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

    :param log_level: a valid log-level (or None to avoid calling start_logging)
    :type log_level: string
    N)levelc                 *   j                  d|        t        j                  j                         }|D ]3  }|t        j                  j	                         us$|j                          5 fd}t        j                  | }|j                  |       y )NzShutting down due to {signal})signalc                    	 | j                          j                          y # t        j                  $ r j                  d       Y 7t        $ r}j                  d|       Y d }~Wd }~ww xY w# j                          w xY w)NzAll task cancelledz&Error while shutting down: {exception})	exception)r   r_   CancelledErrordebug	Exceptionerrorstop)futr@   r   r3   s     r   cancel_all_callbackz5run.<locals>.nicely_exit.<locals>.cancel_all_callback{  sk    

 		 )) 0		./ Q		Ba	PPQ 		s3   $ $A/A2 
A/A*%A2 *A//A2 2B)infor_   Task	all_taskscurrent_taskcancelgatheradd_done_callback)r   taskstaskr   r   r   r3   s        r   nicely_exitzrun.<locals>.nicely_exitq  sw    0@&&( 	D7<<4466	
	 nne$12rB   c                  :    t        j                    d            S )NSIGINTr_   r`   r   s   r   <lambda>zrun.<locals>.<lambda>  s    w7L7L[YaMb7c rB   c                  :    t        j                    d            S )NSIGTERMr   r   s   r   r   zrun.<locals>.<lambda>  s    8M8MkZcNd8e rB   c                 $    | j                          y r   )r   )r3   args     r   done_callbackzrun.<locals>.done_callback  s    		rB   )ru   start_loggingr_   r   	is_closedset_event_loopnew_event_loopconfigr3   r   	coroutineadd_signal_handlerr   r   r   NotImplementedErrorr   _runrun_foreverr   close)
components
start_loop	log_levelr   r   r3   r   s       @@@r   r   r   E  s!   8 ),!!#D~~w5578%%' 



C 3 3,/cd0ef
 NN4]3	 	

     %% 		s%   >AE !E 	EEE('E()Tr   ) 
__future__r   r   r\   r=   r   	functoolsr   r_   ImportErrortrolliusru   use_asyncioautobahn.asyncio.websocketr   autobahn.asyncio.rawsocketr   autobahn.wampr   autobahn.wamp.exceptionr	   autobahn.asyncio.wampr
   autobahn.wamp.serializerr   r   __all__r   r!   r9   r   r   r*   rB   r   <module>r      s   8 7 
 
        A A # 1 ) ^ AC
$NT&	## T&n^A	   s   B   	BB