zfc@sdZddlmZddlZddlZdddgZdZdZd ZdZd Z d Z d Z d Z dZ dZdZeedZeedZdS(sPseudo terminal utilities.i(tselectNtopenptytforktspawniiicCsMytjSWnttfk r'nXt\}}t|}||fS(sdopenpty() -> (master_fd, slave_fd) Open a pty master/slave pair, using os.openpty() if possible.(tosRtAttributeErrortOSErrort_open_terminalt slave_open(t master_fdt slave_nametslave_fd((s/usr/lib64/python2.7/pty.pyRs cCs]ytj\}}Wnttfk r/n'Xtj|}tj|||fStS(smaster_open() -> (master_fd, slave_name) Open a pty master and return the fd, and the filename of the slave end. Deprecated, use openpty() instead.(RRRRtttynametcloseR(R R R ((s/usr/lib64/python2.7/pty.pyt master_open!s  cCsyddl}Wntk r#nOXy"|jtjdd\}}Wntk rg}tj|nX||fSxodD]g}x^dD]V}d||}ytj|tj}Wntjk rqnX|d||fSWqyWtjd dS( slOpen pty master and return (master_fd, tty_name). SGI and generic BSD version, for when openpty() fails.iNiitpqrstuvwxyzPQRSTt0123456789abcdefs/dev/ptys/dev/ttysout of pty devices(tsgit ImportErrort_getptyRtO_RDWRtIOErrorterrortopen(Rttty_nameR tmsgtxtytpty_nametfd((s/usr/lib64/python2.7/pty.pyR1s$ "   cCstj|tj}yddlm}m}Wntk rC|SXy$|||d|||dWntk r{nX|S(sslave_open(tty_name) -> slave_fd Open the pty slave and acquire the controlling terminal, returning opened filedescriptor. Deprecated, use openpty() instead.i(tioctltI_PUSHtptemtldterm(RRRtfcntlRRRR(RtresultRR((s/usr/lib64/python2.7/pty.pyRHs  cCs:ytj\}}Wnttfk r/n<X|tkraytjWqatk r]qaXn||fSt\}}tj}|tkr#tjtj|tj |t tj |t tj |t |t krtj|ntj tjt tj}tj|n tj|||fS(sdfork() -> (pid, master_fd) Fork and make the child a session leader with a controlling terminal.(RtforkptyRRtCHILDtsetsidRRR tdup2t STDIN_FILENOt STDOUT_FILENOt STDERR_FILENORR R(tpidRR R ttmp_fd((s/usr/lib64/python2.7/pty.pyRZs0         cCs3x,|dkr.tj||}||}qWdS(s#Write all the data to a descriptor.tN(Rtwrite(Rtdatatn((s/usr/lib64/python2.7/pty.pyt_writenscCstj|dS(sDefault read function.i(Rtread(R((s/usr/lib64/python2.7/pty.pyt_readscCs|tg}xtrt|gg\}}}||krq||}|s^|j|qqtjt|nt|kr|t}|s|jtqt||qqWdS(sParent copy loop. Copies pty master -> standard output (master_read) standard input -> pty master (stdin_read)N(R(tTrueRtremoveRR.R)R1(R t master_readt stdin_readtfdstrfdstwfdstxfdsR/((s/usr/lib64/python2.7/pty.pyt_copys      cCst|tdkr$|f}nt\}}|tkrVtj|d|ny&tjt}tjtd}Wntj k rd}nXyt |||Wn6t t fk r|rtj ttj|qnXtj|dS(sCreate a spawned process.R-iiN(ttypeRR%Rtexeclptttyt tcgetattrR(tsetrawRR<RRt tcsetattrt TCSAFLUSHR (targvR6R7R+R tmodetrestore((s/usr/lib64/python2.7/pty.pyRs"     (t__doc__RRR?t__all__R(R)R*R%RRRRRR1R3R<R(((s/usr/lib64/python2.7/pty.pyts"      (