o
    j©Zh®  ã                   @   sŽ   d Z ddlZddlZddlZddlmZ ddlmZ ej 	ej 	ej
¡¡ZG dd„ deƒZdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )zH
code to initialize the remote side of a gateway once the io is created
é    Né   )Úgateway_base)ÚGatewayc                   @   s   e Zd ZdS )ÚHostNotFoundN)Ú__name__Ú
__module__Ú__qualname__© r	   r	   úP/var/www/html/lang_env/lib/python3.10/site-packages/execnet/gateway_bootstrap.pyr      s    r   c                 C   sN   t | ddt dt dddd|j d|j ƒ	 |  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)ÚioÚspecÚsr	   r	   r
   Úbootstrap_import   s   ÷
r   c                 C   sp   z t | t t¡d|j ddd|j ƒ |  d¡}|dksJ ‚W d S  ty7   |  ¡ }|dkr4t	| j
ƒ‚Y d S w )Nr   zio = init_popen_io(execmodel)úio.write('1'.encode('ascii'))úserve(io, id='%s-worker')r   r   éÿ   )r   ÚinspectÚ	getsourcer   r   r   r   ÚEOFErrorÚwaitr   Zremoteaddress)r   r   r   Úretr	   r	   r
   Úbootstrap_exec&   s"   ú

ÿþr   c                 C   sP   ddl m} t| t t¡dt |¡dddddd	| ƒ
 |  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   )Zexecnet.gateway_socketr    r   r   r   r   r   )r   r   r    r   r	   r	   r
   Úbootstrap_socket8   s   ö
r!   c                 G   s&   d  |¡}|  t|ƒd  d¡¡ d S )NÚ
zutf-8)ÚjoinÚwriter   Úencode)r   ÚsourcesÚsourcer	   r	   r
   r   L   s   
r   c                 C   sH   | j | j}}|jr|js |jjdu r"|  d¡ ¡ |j_dS dS dS dS )z
    fix for jython 2.5.1
    Nz$import os; channel.send(os.getpid()))r   Ú_ioÚpopenÚviaÚpidZremote_execZreceive)Úgwr   r   r	   r	   r
   Úfix_pid_for_jython_popenQ   s   ÿ
þür-   c                 C   sr   |j r|js	|jrt| |ƒ nt| |ƒ n|js|jr!t| |ƒ n|jr*t| |ƒ nt	dƒ‚t
| |ƒ}t|ƒ |S )Nz%unknown gateway type, can't bootstrap)r)   r*   Úpythonr   r   ÚsshZvagrant_sshÚsocketr!   Ú
ValueErrorr   r-   )r   r   r,   r	   r	   r
   Ú	bootstrap_   s   
r2   )Ú__doc__r   ÚosZexecnetÚ r   Zgatewayr   ÚpathÚdirnameÚ__file__r   Ú	Exceptionr   r   r   r!   r   r-   r2   r	   r	   r	   r
   Ú<module>   s    