ΘϊfΏ c @ sΡ d Z d d l m Z d d l Z d d l Z d d d g Z d Z d Z d Z d Z d d Z d
d Z
d d
Z d d Z d d Z
d d Z d d Z e e d d Z e e d d Z d S( u Pseudo terminal utilities.i ( u selectNu openptyu forku spawni i c C sN y t j SWn t t f k
r( Yn Xt \ } } t | } | | f S( ud openpty() -> (master_fd, slave_fd)
Open a pty master/slave pair, using os.openpty() if possible.( u osu openptyu AttributeErroru OSErroru _open_terminalu
slave_open( u master_fdu
slave_nameu slave_fd( ( u( /opt/alt/python33/lib64/python3.3/pty.pyu openpty s c C s^ y t j \ } } Wn t t f k
r0 Yn' Xt j | } t j | | | f St S( u master_open() -> (master_fd, slave_name)
Open a pty master and return the fd, and the filename of the slave end.
Deprecated, use openpty() instead.( u osu openptyu AttributeErroru OSErroru ttynameu closeu _open_terminal( u master_fdu slave_fdu
slave_name( ( u( /opt/alt/python33/lib64/python3.3/pty.pyu master_open! s
u master_openc # C s y d d l } Wn t k
r$ Ynd Xy" | j t j d d \ } } Wn4 t k
r} } z t j | WYd d } ~ Xn X| | f Sxp d D]h } x_ d D]W } d | | } y t j | t j } Wn t j k
rγ w Yn X| d | | f SWq Wt j d d S( ul Open pty master and return (master_fd, tty_name).
SGI and generic BSD version, for when openpty() fails.i NiΆ u pqrstuvwxyzPQRSTu 0123456789abcdefu /dev/ptyu /dev/ttyu out of pty devices( u sgiu ImportErroru _getptyu osu O_RDWRu IOErroru erroru open( u sgiu tty_nameu master_fdu msgu xu yu pty_nameu fd( ( u( /opt/alt/python33/lib64/python3.3/pty.pyu _open_terminal1 s$
""
u _open_terminalc C s
t j | t j } y d d l m } m } Wn t k
rG | SYn Xy$ | | | d | | | d Wn t k
r Yn X| S( u© slave_open(tty_name) -> slave_fd
Open the pty slave and acquire the controlling terminal, returning
opened filedescriptor.
Deprecated, use openpty() instead.i ( u ioctlu I_PUSHu ptemu ldterm( u osu openu O_RDWRu fcntlu ioctlu I_PUSHu ImportErroru IOError( u tty_nameu resultu ioctlu I_PUSH( ( u( /opt/alt/python33/lib64/python3.3/pty.pyu
slave_openH s
u
slave_openc C s< y t j \ } } Wn t t f k
r0 Yn= X| t k rc y t j Wqc t k
r_ Yqc Xn | | f St \ } } t j } | t k r%t j t j | t j | t
t j | t t j | t | t k rχ t j | n t j
t j t t j } t j | n
t j | | | f S( ud fork() -> (pid, master_fd)
Fork and make the child a session leader with a controlling terminal.( u osu forkptyu AttributeErroru OSErroru CHILDu setsidu openptyu forku closeu dup2u STDIN_FILENOu
STDOUT_FILENOu
STDERR_FILENOu openu ttynameu O_RDWR( u pidu fdu master_fdu slave_fdu tmp_fd( ( u( /opt/alt/python33/lib64/python3.3/pty.pyu forkZ s0
c C s3 x, | r. t j | | } | | d
} q Wd S( u# Write all the data to a descriptor.N( u osu write( u fdu datau n( ( u( /opt/alt/python33/lib64/python3.3/pty.pyu _writen s u _writenc C s t j | d S( u Default read function.i ( u osu read( u fd( ( u( /opt/alt/python33/lib64/python3.3/pty.pyu _read s u _readc C s° | t g } x t | g g \ } } } | | k rk | | } | sX | j | qk t j t | n t | k r | t } | s | j t q© t | | q q d S( u Parent copy loop.
Copies
pty master -> standard output (master_read)
standard input -> pty master (stdin_read)N( u STDIN_FILENOu selectu removeu osu writeu
STDOUT_FILENOu _writen( u master_fdu master_readu
stdin_readu fdsu rfdsu wfdsu xfdsu data( ( u( /opt/alt/python33/lib64/python3.3/pty.pyu _copy s u _copyc C sω t | t d k r$ | f } n t \ } } | t k rV t j | d | n y&