o
    "Âif)
  ã                   @   s    d Z ddl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
 de
fdd„ZG d	d
„ d
eƒZeƒ  d¡ZedurKeeƒZe ¡  edƒ dS eƒ  dS )z:
a remote python shell

for injection into startserver.py
é    N)ÚThread)Ú	print_exc)ÚNoReturnÚreturnc                  C   s  t dƒ tjd  d¡\} }t|ƒ}ttj tjd ¡ƒ 	¡ }t
 
t
jt
j¡}| | |f¡ | t|ƒd  ¡ ¡ t dƒ |tjg}z3	 t |g g ¡\}}}tj|v r_tƒ }	| |	d  ¡ ¡ ||v ru| d¡ ¡ }	tj |	¡ tj ¡  qD ty†   dd l}
|
 ¡  Y nw t d¡ d S )Nzclient side startingé   ú:r   Ú
zsend boot stringi   )ÚprintÚsysÚargvÚsplitÚintÚopenÚosÚpathÚabspathÚreadÚsocketÚAF_INETÚSOCK_STREAMÚconnectÚsendallÚreprÚencodeÚstdinÚselectÚinputÚrecvÚdecodeÚstdoutÚwriteÚflushÚBaseExceptionÚ	tracebackr   Úexit)ÚhostÚportstrÚportÚmyselfÚsockÚ	inputlistÚrÚwÚeÚliner#   © r/   úM/var/www/html/corbot_env/lib/python3.10/site-packages/execnet/script/shell.pyÚ
clientside   s2   


ø	ýr1   c                       s(   e Zd Zd‡ fdd„Zddd„Z‡  ZS )Úpromptagentr   Nc                    s   t dƒ t ¡  || _d S )Nzserver side starting)r	   ÚsuperÚ__init__Ú
clientsock)Úselfr5   ©Ú	__class__r/   r0   r4   .   s   
zpromptagent.__init__c                 C   s
  t dƒ | j d¡}| j d¡}| j ¡ }	 zW| dj|Ž ¡ | ¡  | ¡ }|s-tdƒ‚| 	¡ rht
jt
j}}||t
_t
_z!ztt|d dd	ƒƒ W n tyX   tƒ  Y nw W |t
_|t
_n|t
_|t
_w | ¡  W n ty|   t
j d
¡ Y nw q| j ¡  d S )NzEntering thread prompt loopr,   r+   r   z
{} {} >>> Únothingr   z<remote pyin>Úsinglez'connection close, prompt thread returns)r	   r5   ÚmakefileÚgetsocknamer    Úformatr!   ÚreadlineÚEOFErrorÚstripr
   r   ÚstderrÚexecÚcompiler"   r   Úclose)r6   Ú
clientfileÚfileinÚlocr.   ÚoldoutÚolderrr/   r/   r0   Úrun3   s@   

ÿ€ÿþízpromptagent.run)r   N)Ú__name__Ú
__module__Ú__qualname__r4   rJ   Ú__classcell__r/   r/   r7   r0   r2   -   s    r2   r5   zpromptagent - thread started)Ú__doc__r   r   r   r
   Ú	threadingr   r#   r   Útypingr   r1   r2   ÚglobalsÚgetr)   ÚprompterÚstartr	   r/   r/   r/   r0   Ú<module>   s    '
