
    8'h:                     R   d dl mZ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Zd d	lmZ d d
lmZmZmZ d dlmZ d dlmZ d dlZd dl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(d Z) G d dejT                        Z*ddZ+y# e$ r dZY Yw xY w)    )absolute_importprint_function)wraps)IStreamClientEndpoint)UNIXClientEndpoint)TCP4ClientEndpoint)Failure)ReactorNotRunningT)SSL4ClientEndpoint)optionsForClientTLSCertificateOptionsCertificate)IOpenSSLClientConnectionCreator)SSLFN)WampWebSocketClientFactory)WampRawSocketClientFactory)	component)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/twisted/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+   G   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.   r0   r   r/   r   optionsitemssetProtocolOptions	TypeErrorKeyErrorr+   
ValueErrorformat)reactor	transportsession_factoryr/   factoryr2   kvs           r   _create_transport_factoryrC   L   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                 z   t        j                  |      rt        |      }|S |d   dk(  r|j                  dd      }|dvrt        dj	                  |            |d   }t        |      t        j                  k7  r#t        dj	                  t        |                  |d	   }t        |      t        j                  vr#t        d
j	                  t        |                  |j                  dd      }t        |      t        j                  vr#t        dj	                  t        |                  |j                  dd      }|rt        st        d      t        j                  |      rt        |      }n5t        |t              r|j                         D ]   }	|	dvst        dj	                  |	             |j                  d|      }
t        |
      t        j                  k7  rt        dj	                  |
            d}|j                  dd      }|@t        j                   t        j"                  t%        |d      j'                                     }t)        |
|      }nFt        |t*              r|}n3|du rt)        |      }n#t        dj	                  t        |                  |dk(  rt-        | ||||      }|S |dk(  rt        d      J d       |j/                  d      r	 ddl}|j3                  ||      }|S |dk(  rt7        | |||      }|S |dk(  r	 dd!lm}  || |||      }|S J d       |d   d#k(  r0|d$   }t=        |j                  dd            }t?        | ||      }|S J d       # t4        $ r t        d j	                  |            w xY w# t4        $ r t        d"      w xY w)%zI
    Create a Twisted client endpoint for a WAMP-over-XXX transport.
    r5   tcpversion   )rG      z6invalid IP version {} in client endpoint configurationhostz9invalid type {} for host in client endpoint configurationportz9invalid type {} for port in client endpoint configurationtimeout
   z<invalid type {} for timeout in client endpoint configurationtlsNzKTLS configured in transport, but TLS support is not installed (eg OpenSSL?))hostname
trust_rootz Invalid key '{}' in 'tls' configrN   zAinvalid type {} for hostname in TLS client endpoint configurationrO   r)	trustRootTz4unknown type {} for "tls" configuration in transport)rK   rH   zTLS on IPv6 not implementedr3   z.onionr   zC{} appears to be a Tor Onion service, but txtorcon is not installed)TCP6ClientEndpointz.IPv6 is not supported (please upgrade Twisted)unixpath) r   
providedBygetr;   r<   r5   six	text_typeinteger_types_TLSRuntimeErrorr   
isinstancedictkeysr   loadPEMuopenreadr   r   r   endswithtxtorconTorClientEndpointImportErrorr   twisted.internet.endpointsrR   intr   )r=   endpoint_configendpointrF   rI   rJ   rK   rM   contextrA   rN   rO   
cert_fnamerd   rR   rT   s                   r   _create_transport_endpointrm   s   s    ''8(9B O} 7#v-%))*a8Gf$ !Y!`!`ah!ijj"7+DDzS]]* !\!c!cdhimdn!opp"7+DDz!2!22 !\!c!cdhimdn!opp%))*b9GG}C$5$55 !_!f!fgklsgt!uvv!%%fd3C &'tuu 3==cB=cBGT* XXZ [$@@",-O-V-VWX-Y"ZZ[  #ww{D9HH~6()l)s)st|)}~~!%J!$!=J!-%0%8%8tJPS?T?Y?Y?[9\%]
1(jQG%78!GD[1$7G '']'d'deijmen'oppa<1'4wX_`HR OQ \&'DEE;#;;5 ==*'#+#=#=dD#I6 O) \1'4wWH& O% \]Q  2'4wWH O <#;;5 W%0"7+D/--j"=>G)'4IH
 O 43351 ' *ahh $  ' ]*+[\\]s   0M> $N% >$N"%N:c                   R    e Zd ZdZ ej
                         Ze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                 D    t         rt        |t        j                        S y)z
        Internal helper.

        This is so we can just return False if we didn't import any
        TLS/SSL libraries. Otherwise, returns True if this is an
        OpenSSL.SSL.Error
        F)rZ   r\   r   Error)selfes     r   _is_ssl_errorzComponent._is_ssl_error   s     a++    c                 
   t        j                  |      ry t        |t              rSd|v rN|d   }t        |t        t        f      ry t        j                  |      ry t        |t              ry t        d      y t        d      )NrM   zb'tls' configuration must be a dict, CertificateOptions or IOpenSSLClientConnectionCreator providerzI'endpoint' configuration must be a dict or IStreamClientEndpoint provider)r   rU   r\   r]   boolr   r   r;   )rq   rj   rM   s      r   _check_native_endpointz Component._check_native_endpoint   s     ++H5$'!v&cD$<04??D%78$D  "  rt   c                 R   t        ||      }j                  r+t        |dj                  d   j                  d   d      }nt        |j                        }|j	                  |      }fd}fd}	t        j                  ||d       t        j                  |d|	       |S )z
        Create and connect a WAMP-over-XXX transport.

        :param done: is a Deferred/Future from the parent which we
            should signal upon error if it is not done yet (XXX maybe an
            "on_error" callable instead?)
        rE   rI   rJ   )r5   rI   rJ   c                 V    | j                   t              fd       }|| _         y )Nc                 n     |       }t        j                        st        j                  |        |S N)txaio	is_calledreject)failrtndoneorigs     r   lostzFComponent._connect_transport.<locals>.on_connect_success.<locals>.lost/  s+    4jt,LLt,
rt   )connectionLostr   )protor   r   r   s     @r   on_connect_successz8Component._connect_transport.<locals>.on_connect_success%  s0     ''D4[ 
 $(E rt   c                 \    xj                   dz  c_         t        j                  |        y )Nr$   )connect_failuresr|   r~   )errr   r>   s    r   on_connect_failurez8Component._connect_transport.<locals>.on_connect_failure7  s"    &&!+&LLs#rt   N)rC   r0   rm   rj   connectr|   add_callbacks)
rq   r=   r>   r?   r   transport_factorytransport_endpointdr   r   s
     ` `     r   _connect_transportzComponent._connect_transport  s     6gy/Z??!;!%OOF3%OOF3" "<GYEWEW!X&&'89	($	$
 	A148At%78rt   Nc                 l    |!| j                   j                  d       ddlm} | 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 Deferred that fires (with ``None``) when we are
            "done" or with a Failure if something went wrong.
        zUsing default reactorr   )r=   )loop)logwarntwisted.internetr=   _start)rq   r=   s     r   startzComponent.start@  s.     ?HHMM120{{{((rt   r{   )__name__
__module____qualname____doc__r|   make_loggerr   r   r?   rs   rw   r   r   r4   rt   r   r   r      s8     %


CO
./b)rt   r   c                     ddl m} |t        j                  |       t        j                         fd} |t
        j                  | |f       y)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
    :meth:`twisted.internet.reactor.run` -- if you wish to manage the
    reactor loop yourself, use the
    :meth:`autobahn.twisted.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.twisted.component.Component`

    :param log_level: a valid log-level (or None to avoid calling start_logging)
    :type log_level: string
    r   )reactN)levelc                     t        |t              rj                  d|       	 | j                          y # t        $ r Y y w xY w)Nz#Something went wrong: {log_failure})failure)r\   r	   errorstopr
   )r=   argr   s     r   done_callbackzrun.<locals>.done_callbackt  s>    c7#II;SII	LLN  		s   7 	AA)twisted.internet.taskr   r|   start_loggingr   r   _run)
components	log_levelr   r   r   s       @r   r   r   T  sF    , ,
 ),



C 
)..:}56rt   )info),
__future__r   r   	functoolsr   twisted.internet.interfacesr   rg   r   r   twisted.python.failurer	   twisted.internet.errorr
   rZ   r   twisted.internet.sslr   r   r   r   OpenSSLr   rf   rW   r|   autobahn.twisted.websocketr   autobahn.twisted.rawsocketr   autobahn.wampr   autobahn.twisted.wampr   autobahn.wamp.serializerr   r   __all__r    r+   rC   rm   r   r   r4   rt   r   <module>r      s   8 7  = 9 9 * 4D=YYK   A A # ) ^
AC
$NfRu)	## u)p(7Q	  Ds   B B&%B&