a �DOg��@s�ddlmZddlZddlZddlZgd�ZdZdZdZdZdd�Z dd �Z d d �Z d d �Z dd�Z dd�Zdd�Zeefdd�Zeefdd�ZdS)�)�selectN)�openpty�fork�spawn��c Cs<z t��WSttfy Yn0t�\}}t|�}||fS�N)�osr�AttributeError�OSError�_open_terminal� slave_open)� master_fd� slave_name�slave_fd�r�/usr/lib64/python3.9/pty.pyrs  rc CsJzt��\}}Wnttfy&Yn0t�|�}t�|�||fSt�Sr)r rr r �ttyname�closer )rrrrrr� master_open"s  rc CsldD]Z}dD]P}d||}zt�|tj�}WntyDYq Yn0|d||fSqtd��dS)NZpqrstuvwxyzPQRSTZ0123456789abcdefz/dev/ptyz/dev/ttyzout of pty devices)r �open�O_RDWRr )�x�yZpty_name�fdrrrr 2s   r cCsnt�|tj�}zddlm}m}Wnty8|YS0z|||d�|||d�WntyhYn0|S)Nr)�ioctl�I_PUSHZptemZldterm)r rrZfcntlrr� ImportErrorr )Ztty_name�resultrrrrrr >s    r c Cs�zt��\}}Wnttfy&Yn20|tkrPz t��WntyNYn0||fSt�\}}t��}|tkr�t��t�|�t� |t �t� |t �t� |t �|t kr�t�|�t� t�t �tj�}t�|�n t�|�||fSr)r �forkptyr r �CHILD�setsidrrr�dup2� STDIN_FILENO� STDOUT_FILENO� STDERR_FILENOrrr)�pidrrrZtmp_fdrrrrPs0          rcCs"|rt�||�}||d�}qdSr)r �write)r�data�nrrr�_writenxs r*cCs t�|d�S)Ni)r �read)rrrr�_read~sr,cCsv|tg}t|gg�\}}}||vrF||�}|s:|�|�n t�t|�t|vr|t�}|sf|�t�qt||�qdSr)r#r�remover r'r$r*)r� master_read� stdin_read�fdsZrfdsZwfdsZxfdsr(rrr�_copy�s   r1cCs�t|�td�kr|f}t�d|�t�\}}|tkrJtj|dg|�R�zt�t �}t� t �d}Wntj y~d}Yn0zt |||�Wn&t y�|r�t�t tj|�Yn0t�|�t�|d�dS)N�z pty.spawnrr)�type�sys�auditrr r �execlp�ttyZ tcgetattrr#Zsetraw�errorr1r Z tcsetattrZ TCSAFLUSHr�waitpid)�argvr.r/r&r�modeZrestorerrrr�s&       r)rr r4r7�__all__r#r$r%r rrr r rr*r,r1rrrrr� s"   (