U
    „ª/e:	  ã                   @   sL   d Z ddlZddlZddlmZmZmZmZ ddlm	Z	 dd„ Z
dd	„ ZdS )
z<Substitute for the forkpty system call, to support Solaris.
é    N)ÚSTDIN_FILENOÚSTDOUT_FILENOÚSTDERR_FILENOÚCHILDé   )ÚPtyProcessErrorc                  C   s~   t  ¡ \} }| dk s|dk r$tdƒ‚t  ¡ }|tkrlt  | ¡ t|ƒ t  |t¡ t  |t	¡ t  |t
¡ n
t  |¡ || fS )aá  This implements a substitute for the forkpty system call. This
    should be more portable than the pty.fork() function. Specifically,
    this should work on Solaris.

    Modified 10.06.05 by Geoff Marshall: Implemented __fork_pty() method to
    resolve the issue with Python's pty.fork() not supporting Solaris,
    particularly ssh. Based on patch to posixmodule.c authored by Noah
    Spurrier::

        http://mail.python.org/pipermail/python-dev/2003-May/035281.html

    r   zos.openpty() failed)ÚosÚopenptyÚOSErrorÚforkr   ÚcloseÚpty_make_controlling_ttyÚdup2r   r   r   )Z	parent_fdZchild_fdÚpid© r   ú8/tmp/pip-unpacked-wheel-_09wuhje/ptyprocess/_fork_pty.pyÚfork_pty	   s    

r   c              
   C   sö   t  | ¡}z"t  dt jt jB ¡}t  |¡ W n0 tk
r\ } z|jtjkrL‚ W 5 d}~X Y nX t  	¡  z*t  dt jt jB ¡}t  |¡ t
dƒ‚W n0 tk
rÀ } z|jtjkr°‚ W 5 d}~X Y nX t  |t j¡}t  |¡ t  dt j¡}t  |¡ dS )z¢This makes the pseudo-terminal the controlling tty. This should be
    more portable than the pty.fork() function. Specifically, this should
    work on Solaris. z/dev/ttyNz(OSError of errno.ENXIO should be raised.)r   ÚttynameÚopenÚO_RDWRÚO_NOCTTYr   r
   ÚerrnoZENXIOÚsetsidr   ÚO_WRONLY)Ztty_fdZ
child_nameÚfdÚerrr   r   r   r   +   s&    


r   )Ú__doc__r   r   Zptyr   r   r   r   Úutilr   r   r   r   r   r   r   Ú<module>   s   "