a
    &ñ»jÒ
  ã                   @  sÎ   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	„ d	eƒZd
dddœdd„Zd
dddœdd„Zd
ddœdd„Zd
dddœdd„Zd
dddœdd„ZdS )zGCode to initialize the remote side of a gateway once the IO is created.é    )ÚannotationsNé   )Úgateway_base)ÚIO)ÚXSpecc                   @  s   e Zd ZdS )ÚHostNotFoundN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú?E:\soccer\ml_env\Lib\site-packages\execnet/gateway_bootstrap.pyr      s   r   r   r   ÚNone)ÚioÚspecÚreturnc                 C  sN   t | ddt dt dddd|j d|j ƒ	 |  d	¡}|d
ksJJ 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   Úsr   r   r   Úbootstrap_import   s    ÷
r   c                 C  s|   z>t | t t¡d|j ddd|j ƒ |  d¡}|dks<J ‚W n8 tyv   |  ¡ }|dkrrt	| dƒrrt
| jƒd ‚Y n0 d S )	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   Úretr   r   r   Úbootstrap_exec(   s    ú
r%   )r   r   c                 C  sP   ddl m} t| t t¡dt |¡dddddd	| ƒ
 |  d
¡}|dksLJ ‚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_socket:   s    ö
r'   Ústr)r   Úsourcesr   c                 G  s&   d  |¡}|  t|ƒd  d¡¡ d S )NÚ
zutf-8)ÚjoinÚwriter   Úencode)r   r)   Úsourcer   r   r   r   N   s    
r   zexecnet.Gatewayc                 C  sl   |j r*|js|jrt| |ƒ q\t| |ƒ n2|js6|jrBt| |ƒ n|jrTt| |ƒ nt	dƒ‚t
 | |¡}|S )Nz%unknown gateway type, can't bootstrap)ÚpopenZviaÚpythonr%   r   ÚsshZvagrant_sshÚsocketr'   Ú
ValueErrorÚexecnetZGateway)r   r   Zgwr   r   r   Ú	bootstrapS   s    r5   )Ú__doc__Ú
__future__r   r   Úosr4   Ú r   r   Zxspecr   ÚpathÚdirnameÚ__file__r   Ú	Exceptionr   r   r%   r'   r   r5   r   r   r   r   Ú<module>   s   