
    i
                       d Z ddlmZ ddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 ej                            ej                            ej                            Z G d d	e          ZddZddZddZddZddZdS )zGCode to initialize the remote side of a gateway once the IO is created.    )annotationsN   )gateway_base)IO)XSpecc                      e Zd ZdS )HostNotFoundN)__name__
__module____qualname__     `/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/execnet/gateway_bootstrap.pyr	   r	      s        Dr   r	   ior   specr   returnNonec                    t          | ddt          z  dt          z  dddd|j        z  d|j        z  	  	         |                     d	          }|d
k    sJ t          |                      d S )Nz
import syszif %r not in sys.path:z    sys.path.insert(0, %r)zDfrom execnet.gateway_base import serve, init_popen_io, get_execmodelzsys.stdout.write('1')zsys.stdout.flush()execmodel = get_execmodel(%r)z/serve(init_popen_io(execmodel), id='%s-worker')r      1)sendexec	importdir	execmodelidreadrepr)r   r   ss      r   bootstrap_importr      sw     
 9,$y0N'$.89DGC
 
 
 	

A999d1gg99999r   c           	     ^   	 t          | t          j        t                    d|j        z  ddd|j        z             |                     d          }|dk    sJ d S # t          $ rF |                                 }|dk    r%t          | d          rt          | j                  d Y d S Y d S w xY w)	Nr   zio = init_popen_io(execmodel)io.write('1'.encode('ascii'))serve(io, id='%s-worker')r   r      remoteaddress)r   inspect	getsourcer   r   r   r   EOFErrorwaithasattrr	   r#   )r   r   r   rets       r   bootstrap_execr*   (   s    ;l+++dn<++'$'1	
 	
 	
 GGAJJDyyyyyy ; ; ;ggii#::'"o66:r/00d: :::::;s   AA A	B,+B,c                    ddl m} t          | t          j        t
                    dt          j        |          dddddd	|z  
  
         |                     d
          }|dk    sJ d S )Nr   )SocketIOzimport socketztry: execmodelzexcept NameError:z&   execmodel = get_execmodel('thread')z$io = SocketIO(clientsock, execmodel)r    r!   r   r   )execnet.gateway_socketr,   r   r$   r%   r   r   )r   r   r,   r   s       r   bootstrap_socketr.   :   s    //////
,''(##0.'#b(   	

A999999r   sourcesstrc                    d                     |          }|                     t          |          dz                       d                     d S )N
zutf-8)joinwriter   encode)r   r/   sources      r   r   r   N   sD    YYwFHHd6llT!))'2233333r   execnet.Gatewayc                *   |j         r0|j        s|j        rt          | |           nWt	          | |           nF|j        s|j        rt          | |           n'|j        rt          | |           nt          d          t          j        | |          }|S )Nz%unknown gateway type, can't bootstrap)popenviapythonr*   r   sshvagrant_sshsocketr.   
ValueErrorexecnetGateway)r   r   gws      r   	bootstraprC   S   s    z 
B8 	't{ 	'2t$$$$R&&&&	 BT% Br4    	 BT""""@AAA	T	"	"BIr   )r   r   r   r   r   r   )r   r   r   r   )r   r   r/   r0   r   r   )r   r   r   r   r   r7   )__doc__
__future__r   r$   osr@    r   r   xspecr   pathdirname__file__r   	Exceptionr	   r   r*   r.   r   rC   r   r   r   <module>rM      s*   M M " " " " " "  				                   GOOBGOOG,<==>>		 	 	 	 	9 	 	 	   &; ; ; ;$   (4 4 4 4
     r   