grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026o ®û|j]ã@s¼dZddlmZddlZddlZddlZddlmZmZddlmZmZm Z gd¢Z dZ dZ dZ dZd d „Zd d „Zd d„Zdd„Zdd„Zdd„Zdd„Zeefdd„Zeefdd„ZdS)zPseudo terminal utilities.é)ÚselectN)ÚcloseÚwaitpid)ÚsetrawÚ tcgetattrÚ tcsetattr)ÚopenptyÚforkÚspawnééc Cs<zt ¡WSttfyYnwtƒ\}}t|ƒ}||fS)zdopenpty() -> (master_fd, slave_fd) Open a pty master/slave pair, using os.openpty() if possible.)ÚosrÚAttributeErrorÚOSErrorÚ_open_terminalÚ slave_open)Ú master_fdÚ slave_nameÚslave_fd©rú*/opt/alt/python310/lib64/python3.10/pty.pyrs ÿ rc CsHzt ¡\}}Wn ttfyYtƒSwt |¡}t |¡||fS)z›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.)r rrrÚttynamerr)rrrrrrÚ master_open&sù  rc CsddD]+}dD]&}d||}z t |tj¡}Wn ty Yqw|d||fSqtdƒ‚)z1Open pty master and return (master_fd, tty_name).ZpqrstuvwxyzPQRSTZ0123456789abcdefz/dev/ptyz/dev/ttyzout of pty devices)r ÚopenÚO_RDWRr)ÚxÚyZpty_nameÚfdrrrr6s  ÿúrcCsnt |tj¡}z ddlm}m}Wn ty|YSwz|||dƒ|||dƒW|Sty6Y|Sw)z©slave_open(tty_name) -> slave_fd Open the pty slave and acquire the controlling terminal, returning opened filedescriptor. Deprecated, use openpty() instead.r)ÚioctlÚI_PUSHZptemZldterm)r rrZfcntlrrÚ ImportErrorr)Ztty_nameÚresultrrrrrrBs ÿ  þþrc Csþzt ¡\}}Wn ttfyYnw|tkr.z t ¡W||fSty-Y||fSw||fStƒ\}}t ¡}|tkrvt ¡t |¡t  |t ¡t  |t ¡t  |t ¡|t krct |¡t  t t ¡tj¡}t |¡||fSt |¡||fS)zdfork() -> (pid, master_fd) Fork and make the child a session leader with a controlling terminal.)r ÚforkptyrrÚCHILDÚsetsidrr rÚdup2Ú STDIN_FILENOÚ STDOUT_FILENOÚ STDERR_FILENOrrr)ÚpidrrrZtmp_fdrrrr Ts:ÿ  ýý        ýr cCs(|rt ||¡}||d…}|sdSdS)z#Write all the data to a descriptor.N)r Úwrite)rÚdataÚnrrrÚ_writen|s   þr-cCs t |d¡S)zDefault read function.i)r Úread)rrrrÚ_read‚s r/cCs”|tg}|rHt|ggƒ\}}}||vr/z||ƒ}Wn ty$d}Ynw|s)dSt t|¡t|vrD|tƒ}|s?| t¡nt||ƒ|sdSdS)z�Parent copy loop. Copies pty master -> standard output (master_read) standard input -> pty master (stdin_read)óN)r&rrr r*r'Úremover-)rÚ master_readÚ stdin_readZfdsZrfdsZ_wfdsZ_xfdsr+rrrÚ_copy†s$  ÿ    ër4c CsÌt|ƒtdƒkr |f}t d|¡tƒ\}}|tkr%tj|dg|¢RŽz ttƒ}t tƒd}Wn t j y=d}Ynwzt |||ƒW|rOt tt j|ƒn |rZt tt j|ƒwwt|ƒt|dƒdS)zCreate a spawned process.Úz pty.spawnrTFr )ÚtypeÚsysÚauditr r#r Úexeclprr&rÚttyÚerrorr4rZ TCSAFLUSHrr)Úargvr2r3r)rÚmodeZrestorerrrr £s.  ÿ€ÿÿr )Ú__doc__rr r7r:rrrrrÚ__all__r&r'r(r#rrrrr r-r/r4r rrrrÚs*   (