o
    "ÂifÒ
  ã                   @  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„Zddd„Zddd„Zddd„Z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   úR/var/www/html/corbot_env/lib/python3.10/site-packages/execnet/gateway_bootstrap.pyr      s    r   Úior   Úspecr   ÚreturnÚNonec                 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)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 d S  ty@   |  ¡ }|dkr:t	| dƒr=t
| jƒd ‚Y d S Y d S 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   Ú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   )Úexecnet.gateway_socketr&   r   r   r    r   r   )r   r   r&   r   r   r   r   Úbootstrap_socket:   s   ö
r(   ÚsourcesÚstrc                 G  s&   d  |¡}|  t|ƒd  d¡¡ d S )NÚ
zutf-8)ÚjoinÚwriter   Úencode)r   r)   Úsourcer   r   r   r   N   s   
r   úexecnet.Gatewayc                 C  sl   |j r|js	|jrt| |ƒ nt| |ƒ n|js|jr!t| |ƒ n|jr*t| |ƒ nt	dƒ‚t
 | |¡}|S )Nz%unknown gateway type, can't bootstrap)ÚpopenÚviaÚpythonr%   r   ÚsshÚvagrant_sshÚsocketr(   Ú
ValueErrorÚexecnetÚGateway)r   r   Úgwr   r   r   Ú	bootstrapS   s   r;   )r   r   r   r   r   r   )r   r   r   r   )r   r   r)   r*   r   r   )r   r   r   r   r   r0   )Ú__doc__Ú
__future__r   r   Úosr8   Ú r   r   Úxspecr   ÚpathÚdirnameÚ__file__r   Ú	Exceptionr   r   r%   r(   r   r;   r   r   r   r   Ú<module>   s    



