QfdZddlmZddlZddlZddlZddlmZmZddlmZmZm Z gdZ dZ dZ dZ dZd Zd Zd Zd Zd ZdZeefdZeefdZy)zPseudo terminal utilities.)selectN)closewaitpid)setraw tcgetattr tcsetattr)openptyforkspawnc tjS#ttf$rYnwxYwt \}}t |}||fS)zdopenpty() -> (master_fd, slave_fd) Open a pty master/slave pair, using os.openpty() if possible.)osr AttributeErrorOSError_open_terminal slave_open) master_fd slave_nameslave_fds */opt/alt/python312/lib64/python3.12/pty.pyr r sL zz| G $   *,Iz*%H h s ((cddl}|jdtd tj\}}tj |}tj |||fS#ttf$r YtSwxYw)zmaster_open() -> (master_fd, slave_name) Open a pty master and return the fd, and the filename of the slave end. Deprecated, use openpty() instead.rNUse pty.openpty() instead.r  stacklevel) warningswarnDeprecationWarningrr ttynamerrrr)rrrrs r master_openr &s{  MM.0BqMQ% jjl 8ZZ)  *$$ G $    sA##A>=A>cdD]C}dD]<}d|z|z} tj|tj}|d|z|zfccSEtd#t$rYWwxYw)z1Open pty master and return (master_fd, tty_name).pqrstuvwxyzPQRST0123456789abcdefz/dev/ptyz/dev/ttyzout of pty devices)ropenO_RDWRr)xypty_namefds rrr9su #A!A~)H WWXryy1 Q*+ + $  & ''  s$A A A cddl}|jdtdtj|tj } ddlm}m} |||d|||d|S#t$r|cYSwxYw#t$rY|SwxYw) zslave_open(tty_name) -> slave_fd Open the pty slave and acquire the controlling terminal, returning opened filedescriptor. Deprecated, use openpty() instead.rNrr r)ioctlI_PUSHptemldterm) rrrrr$r%fcntlr+r, ImportErrorr)tty_namerresultr+r,s rrrEs  MM.0BqMQ WWXryy )F'  fff% ffh' M     M s$A! A2! A/.A/2 A?>A?c tj\}}|tk(r tj||fS||fS#t$rY||fSwxYw#t tf$rYnwxYwt \}}tj}|tk(r.tj|tj|||fStj|||fS)zdfork() -> (pid, master_fd) Fork and make the child a session leader with a controlling terminal.) rforkptyCHILDsetsidrrr r r login_tty)pidr)rrs rr r Zs **,R %<  BwsBw Bw  G $   ")Ix '')C e|  X  >   >s A? A AA#"A#c.tj|dS)zDefault read function.i)rread)r)s r_readr;vs 772t ctj|r standard output (master_read) standard input -> pty master (stdin_read)F) master_read stdin_readTNir<r) r get_blocking set_blocking_copy STDIN_FILENO STDOUT_FILENOlenappendrwriter) rr>r?high_waterlevel stdin_avail stdout_availi_bufo_bufrfdswfds_xfdsndatas rrBrBzs  y!  5) - ) L OOIt ,O|+K -L E E  3u:7 KK % CJ8 KK " CJN KK & u:> KK ""4r2dE D  %HH]E2ab    "9- TME  E*A!"IE <4/l+D#  U  OOIt ,2 %$  %  s/FF#7F4F # F10F14 GGc t|tr|f}tjd|t \}}|t k(rt j|dg| tt}ttd} t||||r tttj t!|t#|ddS#tj$rd}YawxYw#|r tttjwwxYw)zCreate a spawned process.z pty.spawnrTFr ) isinstancestrsysauditr r5rexeclprrCrttyerrorrBr TCSAFLUSHrr)argvr>r?r8rmoderestores rr r s$wIIk4 VNC e| $q'!D!&|9 ij1  lCMM4 8 ) 3?1  99  lCMM4 8 s C; CCC$D)__doc__rrrUrXrrrrr__all__rCrD STDERR_FILENOr5r r rrr r;rBr r<rrbsq  ,, &     & (*8"'5?B"er<