o
    j©ZhÅ	  ã                   @   s8   d dl Z d dlmZ G dd„ dƒZd	dd„Zdd„ ZdS )
é    N)ÚHostNotFoundc                   @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚSocketIOc              	   C   sb   || _ || _|j}z| |j|jd¡ | |j|jd¡ W d S  tt	fy0   t
j d¡ Y d S w )Né   é   z WARNING: cannot set socketoption)ÚsockÚ	execmodelÚsocketÚ
setsockoptÚSOL_IPÚIP_TOSÚSOL_TCPÚTCP_NODELAYÚAttributeErrorÚOSErrorÚsysÚstderrÚwrite)Úselfr   r   r   © r   úM/var/www/html/lang_env/lib/python3.10/site-packages/execnet/gateway_socket.pyÚ__init__   s   ÿzSocketIO.__init__c                 C   sD   d}t |ƒ|k r | j |t |ƒ ¡}|st‚||7 }t |ƒ|k s|S )z+Read exactly 'bytes' bytes from the socket.ó    )Úlenr   ÚrecvÚEOFError)r   ÚnumbytesÚbufÚtr   r   r   Úread   s   üzSocketIO.readc                 C   s   | j  |¡ d S ©N)r   Úsendall)r   Údatar   r   r   r      s   zSocketIO.writec                 C   ó.   z	| j  d¡ W d S  | jjjy   Y d S w )Nr   ©r   Úshutdownr   r   Úerror©r   r   r   r   Ú
close_read   ó
   ÿzSocketIO.close_readc                 C   r"   )Nr   r#   r&   r   r   r   Úclose_write%   r(   zSocketIO.close_writec                 C   ó   d S r   r   r&   r   r   r   Úwait+   ó   zSocketIO.waitc                 C   r*   r   r   r&   r   r   r   Úkill.   r,   zSocketIO.killN)
Ú__name__Ú
__module__Ú__qualname__r   r   r   r'   r)   r+   r-   r   r   r   r   r      s    
r   c                 C   sb   |du r	d\}}n|\}}ddl m} |  |¡}| ||f¡ | ¡ \}}|r+|dkr-d}||fS )z[return a host, port tuple,
    after instantiating a socketserver on the given gateway
    N)Ú	localhostr   r   )Úsocketserverz0.0.0.0r1   )Zexecnet.scriptr2   Zremote_execÚsendZreceive)ZgatewayÚhostportÚhostÚportr2   ZchannelÚrealhostZrealportr   r   r   Ú	start_via2   s   

r8   c           	      C   s¬   | j rJ dƒ‚| j}|rt|| ƒ\}}n| j d¡\}}t|ƒ}|j}| |j|j¡}t||ƒ}d||f |_	z
| 
||f¡ W |S  |jjyU   ttt ¡ d ƒƒ‚w )Nz7socket: specifying python executables not yet supportedú:z%s:%dr   )ÚpythonZ
installviar8   r   ÚsplitÚintÚAF_INETÚSOCK_STREAMr   ZremoteaddressÚconnectÚgaierrorr   Ústrr   Úexc_info)	ÚspecÚgroupr   Z
gateway_idr5   r6   r   r   Úior   r   r   Ú	create_ioH   s    
þÿrF   r   )r   Zexecnet.gateway_bootstrapr   r   r8   rF   r   r   r   r   Ú<module>   s
    
,