
    af;                     `   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 n# e$ r dZY nw xY w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j(                  Z(d dee(         de)de*fdZ+dS )!    )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                 <    t                      fd| D             S )zM
    Return a list with unique elements from sequence, preserving order.
    c                 F    g | ]}|v                     |          |S  )add).0xseens     L/var/www/html/env/lib/python3.11/site-packages/autobahn/twisted/component.py
<listcomp>z _unique_list.<locals>.<listcomp>B   s,    @@@!atmmDHHQKKmAmmm    )set)seqr   s    @r   _unique_listr$   =   s(     55D@@@@s@@@@r!   c                     |                      d          }|d         d                    d |dd          D                       z   S )N_r    c              3   >   K   | ]}|                                 V  d S N)
capitalize)r   ss     r   	<genexpr>z._camel_case_from_snake_case.<locals>.<genexpr>G   s*      @@allnn@@@@@@r!      )splitjoin)snakepartss     r   _camel_case_from_snake_caser2   E   sE    KKE8bgg@@eABBi@@@@@@@r!   c           
      <   |j         dk    r-t          |          }t          ||j        ||j                  }nA|j         dk    r,t          |j        d                   }t          ||          }n
J d            |j        	                                D ]\  }}	  |j
        d	i ||i # t          t          f$ r_ 	  |j
        d	i t          |          |i n># t          t          f$ r* t          d                    |j         ||                    w xY wY w xY w|S )
z3
    Create a WAMP-over-XXX transport factory.
    	websocket)urlserializersproxy	rawsocketr   )
serializerFshould not arrive herez"Unknown {} transport option: {}={}r   )typer   r   r5   r7   r   r6   r   optionsitemssetProtocolOptions	TypeErrorKeyErrorr2   
ValueErrorformat)reactor	transportsession_factoryr6   factoryr9   kvs           r   _create_transport_factoryrI   J   s    ~$$29==,#/	
 
 
 
;	&	&01Fq1IJJ
,_TTT 	0///u !''))  1	&G&00!Q00008$ 	 	 	**  2155q9    x(    8??	PQSTUU   	 Ns*   B))D;CD;DDDc                    t          j        |          rt          |          }nD|d         dk    r|                    dd          }|dvr"t          d                    |                    |d         }t          |          t          k    r/t          d                    t          |                              |d	         }t          |          t          k    r/t          d
                    t          |                              |                    dd          }t          |          t          k    r/t          d                    t          |                              |                    dd          }|rt          st          d          t          j        |          rt          |          }n]t          |t                    r|                                D ](}	|	dvr"t          d                    |	                    )|                    d|          }
t          |
          t          k    r"t          d                    |
                    d}|                    dd          }|4t          j        t!          |d                                                    }t%          |
|          }n[t          |t&                    r|}nC|du rt%          |          }n/t          d                    t          |                              |dk    rt)          | ||||          }n3|dk    rt          d          J d            |                    d          rL	 d dl}|                    ||          }n# t0          $ r# t          d!                    |                    w xY w|dk    rt3          | |||          }n|dk    r5	 d d"lm} n# t0          $ r t          d#          w xY w || |||          }n^J d            |d         d$k    r>|d%         }t          |                    dd                    }t9          | ||          }n
J d            |S )&zI
    Create a Twisted client endpoint for a WAMP-over-XXX transport.
    r;   tcpversion   )rM      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' configrT   zAinvalid type {} for hostname in TLS client endpoint configurationrU   r)	trustRootTz4unknown type {} for "tls" configuration in transport)rQ   rN   zTLS on IPv6 not implementedFr:   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getrA   rB   r;   strint_TLSRuntimeErrorr   
isinstancedictkeysr   loadPEMopenreadr   r   r
   endswithtxtorconTorClientEndpointImportErrorr   twisted.internet.endpointsrX   r   )rC   endpoint_configendpointrL   rO   rP   rQ   rS   contextrG   rT   rU   
cert_fnamerh   rX   rZ   s                   r   _create_transport_endpointrp   q   s    '88 `4(99 6"e++%)))Q77Gf$$ !Y!`!`ah!i!ijjj"6*DDzzS   !\!c!cdhimdndn!o!oppp"6*DDzzS   !\!c!cdhimdndn!o!oppp%)))R88GG}}## !_!f!fgklsgtgt!u!uvvv!%%eT22C  >< v&'tuuu 3=cBB q=cBBGGT** q XXZZ [ [$>>>",-O-V-VWX-Y-Y"Z"ZZ ?"wwz488HH~~,,()l)s)st|)})}~~~!%J!$t!<!<J!-%0%8j#9N9N9S9S9U9U%V%V
1(jQQQGG%788 q!GGD[[1$77GG '']'d'deijmenen'o'opppa<<1'4wX_```HH\\&'DEEE;#;;;5 ==** <'#+#=#=dD#I#I&   *ahh $    \\1'4wWWWHH\\]QQQQQQQ& ] ] ]*+[\\\]11'4wWWWHH;#;;;5 V$.."6*D/--i<<==G)'4IIIHH 43335Os   ,N -N4O O9c                   P    e Zd ZdZ ej                    ZeZ	 d Z	d Z
d ZddZdS )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                 H    t           rt          |t          j                  S dS )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_   ra   r   Error)selfes     r   _is_ssl_errorzComponent._is_ssl_error   s#      	,a+++ur!   c                 F   t          j        |          rd S t          |t                    rhd|v rb|d         }t          |t          t          f          rd S t          j        |          rd S t          |t                    rd S t          d          d S t          d          )NrS   zb'tls' configuration must be a dict, CertificateOptions or IOpenSSLClientConnectionCreator providerzI'endpoint' configuration must be a dict or IStreamClientEndpoint provider)r   r[   ra   rb   boolr   r   rA   )rt   rm   rS   s      r   _check_native_endpointz Component._check_native_endpoint   s     +H55 	D$'' 	  uocD$<00 
D4?DD D%788 D$D   !    r!   c                 R   t          ||          }j        r+t          |dj        d         j        d         d          }nt          |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?)
        rK   rO   rP   )r;   rO   rP   c                 \    | j         t                    fd            }|| _         d S )Nc                 p     |           }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-  s9    d4jjt,, -Lt,,,
r!   )connectionLostr   )protor   r   r   s     @r   on_connect_successz8Component._connect_transport.<locals>.on_connect_success#  sL     'D4[[     [
 $(E   r!   c                 R    xj         dz  c_         t          j        |            d S )Nr-   )connect_failuresr}   r   )errr   rD   s    r   on_connect_failurez8Component._connect_transport.<locals>.on_connect_failure5  s/    &&!+&&Ls#####r!   N)rI   r7   rp   rm   connectr}   add_callbacks)
rt   rC   rD   rE   r   transport_factorytransport_endpointdr   r   s
     ` `     r   _connect_transportzComponent._connect_transport  s     6gy/ZZ? 
	Y!;!%OF3%OF3 " " "<GYEW!X!X&&'899	( 	( 	( 	( 	($	$ 	$ 	$ 	$ 	$ 	$
 	A14888At%7888r!   Nc                 r    | | j                             d           ddlm} |                     |          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.
        NzUsing default reactorr   )rC   )loop)logwarntwisted.internetrC   _start)rt   rC   s     r   startzComponent.start>  sD     ?HMM1222000000{{{(((r!   r)   )__name__
__module____qualname____doc__r}   make_loggerr   r   rE   rv   ry   r   r   r   r!   r   r   r      s|          %


CO
 
 
  ./ / /b) ) ) ) ) )r!   r   info
components	log_levelstop_at_closec                     ddl m} |t          j        |           t          j                    |rfd}nd} |t
          j        | |f           dS )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                    rT                    d|           	                     d           |                                  d S # t
          $ r Y d S w xY wd S )Nz#Something went wrong: {log_failure})failurezStopping reactor ..)ra   r   errorr   stopr	   )rC   argr   s     r   done_callbackzrun.<locals>.done_callbackq  s    #w'' 		?	MMMHH2333LLNNNNN(   DD s   )A 
A('A()twisted.internet.taskr   r}   start_loggingr   r   _run)r   r   r   r   r   r   s        @r   r   r   R  s    ( ,+++++
 ),,,,



C 
	 	 	 	 	 	 	E).:}566666r!   )r   T),	functoolsr   typingr   twisted.internet.interfacesr   rk   r   r   twisted.python.failurer   twisted.internet.errorr	   r_   r
   twisted.internet.sslr   r   r   r   OpenSSLr   rj   r}   autobahn.twisted.websocketr   autobahn.twisted.rawsocketr   autobahn.wampr   autobahn.twisted.wampr   autobahn.wamp.serializerr   r   __all__r$   r2   rI   rp   r   r]   rx   r   r   r!   r   <module>r      s3  8             = = = = = = 9 9 9 9 9 9 9 9 9 9 9 9 * * * * * * 4 4 4 4 4 4D======YYYYYYYYYYKKKKKK   DDD
  A A A A A A A A A A A A # # # # # # ) ) ) ) ) ) ^ ^ ^ ^ ^ ^ ^ ^
A A AA A A
$ $ $Nf f fRu) u) u) u) u)	# u) u) u)p*7 *7DO *7 *7T *7 *7 *7 *7 *7 *7s   A AA