
    h;                     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 	 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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jP                        Z(ddee(   de)de*fdZ+y# e$ r dZY _w xY w)     )wraps)List)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/Befach/backend/env/lib/python3.12/site-packages/autobahn/twisted/component.py_unique_listr   =   s/     5D@!atmDHHQKA@@@s   	222c                 f    | j                  d      }|d   dj                  d |dd  D              z   S )N_r    c              3   <   K   | ]  }|j                           y wN)
capitalize).0ss     r   	<genexpr>z._camel_case_from_snake_case.<locals>.<genexpr>G   s     @alln@s      )splitjoin)snakepartss     r   _camel_case_from_snake_caser.   E   s4    KKE8bgg@eABi@@@@    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   r2   r4   r   r3   r   optionsitemssetProtocolOptions	TypeErrorKeyErrorr.   
ValueErrorformat)reactor	transportsession_factoryr3   factoryr6   kvs           r   _create_transport_factoryrG   J   s3    ~~$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                    t        j                  |      rt        |      }|S |d   dk(  r|j                  dd      }|dvrt        dj	                  |            |d   }t        |      t        k7  r#t        dj	                  t        |                  |d	   }t        |      t        k7  r#t        d
j	                  t        |                  |j                  dd      }t        |      t        k7  r#t        dj	                  t        |                  |j                  dd      }|ryt        st        d      t        j                  |      rt        |      }nt        |t              r|j                         D ]   }	|	dvst        dj	                  |	             |j                  d|      }
t        |
      t        k7  rt        dj	                  |
            d}|j                  dd      }|-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}|j/                  ||      }|S |dk(  rt3        | |||      }|S |dk(  r	 dd!lm}  || |||      }|S J d       |d   d#k(  r0|d$   }t        |j                  dd            }t9        | ||      }|S J d       # t0        $ r t        d j	                  |            w xY w# t0        $ r t        d"      w xY w)%zI
    Create a Twisted client endpoint for a WAMP-over-XXX transport.
    r9   tcpversion   )rK      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' configrR   zAinvalid type {} for hostname in TLS client endpoint configurationrS   r)	trustRootTz4unknown type {} for "tls" configuration in transport)rO   rL   zTLS on IPv6 not implementedr7   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@   r9   strint_TLSRuntimeErrorr   
isinstancedictkeysr   loadPEMopenreadr   r   r
   endswithtxtorconTorClientEndpointImportErrorr   twisted.internet.endpointsrV   r   )rA   endpoint_configendpointrJ   rM   rN   rO   rQ   contextrE   rR   rS   
cert_fnamerf   rV   rX   s                   r   _create_transport_endpointrn   q   s    ''8(9B O} 6"e+%)))Q7Gf$ !Y!`!`ah!ijj"6*DDzS  !\!c!cdhimdn!opp"6*DDzS  !\!c!cdhimdn!opp%)))R8GG}# !_!f!fgklsgt!uvv!%%eT2C &'tuu 3==cB=cBGT* XXZ$>>",-O-V-VWX-Y"ZZ (  #wwz48HH~,()l)s)st|)}~~!%J!$t!<J!-%0%8%8j#9N9S9S9U%V
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 V$."6*D/--i<=G)'4IH
 O 43351 ' *ahh $  ' ]*+[\\]s   7M +M, $M),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)r]   r_   r   Error)selfes     r   _is_ssl_errorzComponent._is_ssl_error   s     a++r/   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      )NrQ   zb'tls' configuration must be a dict, CertificateOptions or IOpenSSLClientConnectionCreator providerzI'endpoint' configuration must be a dict or IStreamClientEndpoint provider)r   rY   r_   r`   boolr   r   r?   )rr   rk   rQ   s      r   _check_native_endpointz Component._check_native_endpoint   s     ++H5$' uocD$<04??D%78$D  !  r/   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?)
        rI   rM   rN   )r9   rM   rN   c                 V    | j                   t              fd       }|| _         y )Nc                 n     |       }t        j                        st        j                  |        |S r$   )txaio	is_calledreject)failrtndoneorigs     r   lostzFComponent._connect_transport.<locals>.on_connect_success.<locals>.lost-  s+    4jt,LLt,
r/   )connectionLostr   )protor   r   r   s     @r   on_connect_successz8Component._connect_transport.<locals>.on_connect_success#  s0     ''D4[ 
 $(E r/   c                 \    xj                   dz  c_         t        j                  |        y )Nr)   )connect_failuresr{   r}   )errr   rB   s    r   on_connect_failurez8Component._connect_transport.<locals>.on_connect_failure5  s"    &&!+&LLs#r/   N)rG   r4   rn   rk   connectr{   add_callbacks)
rr   rA   rB   rC   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r/   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   )rA   )loop)logwarntwisted.internetrA   _start)rr   rA   s     r   startzComponent.start>  s.     ?HHMM120{{{((r/   r$   )__name__
__module____qualname____doc__r{   make_loggerr   r   rC   rt   rw   r   r   r8   r/   r   r   r      s8     %


CO
./b)r/   r   
components	log_levelstop_at_closec                     ddl m} |t        j                  |       t        j                         |rfd}n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
    :param log_level: a valid log-level (or None to avoid calling start_logging)
    :param stop_at_close: Flag to control whether to stop the reactor when done.
    r   )reactN)levelc                     t        |t              r6j                  d|       	 j                  d       | j	                          y y # t
        $ r Y y w xY w)Nz#Something went wrong: {log_failure})failurezStopping reactor ..)r_   r   errorr   stopr	   )rA   argr   s     r   done_callbackzrun.<locals>.done_callbackq  sR    #w'		?	MHH23LLN	 (
 ) s   !A	 		AA)twisted.internet.taskr   r{   start_loggingr   r   _run)r   r   r   r   r   r   s        @r   r   r   R  sN    ( ,
 ),



C	 	)..:}56r/   )infoT),	functoolsr   typingr   twisted.internet.interfacesr   ri   r   r   twisted.python.failurer   twisted.internet.errorr	   r]   r
   twisted.internet.sslr   r   r   r   OpenSSLr   rh   r{   autobahn.twisted.websocketr   autobahn.twisted.rawsocketr   autobahn.wampr   autobahn.twisted.wampr   autobahn.wamp.serializerr   r   __all__r   r.   rG   rn   r   r[   rv   r   r8   r/   r   <module>r      s   8   = 9 9 * 4D=YYK  A A # ) ^
AA
$NfRu)	## u)p*7DO *7 *7T *7O	  Ds   B   B*)B*