
    ;e*                     8   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ ej	        s ej
        d          d dlZd dlZ ej        e j        dk    d           G d d                      Z G d d	eej                  Z G d
 deej                  Z G d de          Z G d deej                  Z G d deej                  Z G d de          Z G d deej                  Z G d deej                  Zedk    r ej                     dS dS )    N)supportztest module requires subprocessposixztests requires a posix system.c                   H    e Zd Zd Zd Zd Z	 	 ddZd ZdZd	 Z	d
 Z
d ZdS )TestFileIOSignalInterruptc                     d | _         d S N)_processselfs    +/usr/lib/python3.11/test/test_file_eintr.pysetUpzTestFileIOSignalInterrupt.setUp   s        c                     | j         rF| j                                         /	 | j                                          d S # t          $ r Y d S w xY wd S d S r   )r	   pollkillOSErrorr
   s    r   tearDownz"TestFileIOSignalInterrupt.tearDown    sp    = 	T]//119""$$$$$   	 	99s   = 
A
Ac                     	 d| j         z  S )Nz=import %s as io ;infile = io.FileIO(sys.stdin.fileno(), "rb")modnamer
   s    r   _generate_infile_setup_codez5TestFileIOSignalInterrupt._generate_infile_setup_code'   s    	? 	r   r   Tc           	         	 | j                                         ?t          j        d           	 | j                                          n# t
          $ r Y nw xY w|r&| j                                         \  }}||z  }||z  }|                     d|d|                                d|                                d           d S )Ng?zError from IO process z
:
STDOUT:
zSTDERR:

)	r	   r   timesleep	terminater   communicatefaildecode)r   whystdoutstderrr   
stdout_end
stderr_ends          r   fail_with_process_infoz0TestFileIOSignalInterrupt.fail_with_process_info0   s    	 ='JsOOO''))))    	!%)]%>%>%@%@"J
j Fj F			33: 	; 	; 	; 	; 	;s   A
 

AAc                    	 |                                  }t          j        t          j        ddd|z   dz   dz   |z   dz   dz   gt          j        t          j        t          j                  | _        | j        j                            t          d                    }|dk    r| 
                    d	|
           | j        j                            |           d}g }|st          j        | j        j        gddd          \  }}}| j                            t          j                   |dz  }|dk    r.| j                                         |                     d           || j        j                                        }|dk    r| 
                    d|
           | j                            d          \  }	}
| j        j        r(| 
                    d| j        j        z  |	|
d           d S d S )Nz-uz-czXimport signal, sys ;signal.signal(signal.SIGINT, lambda s, f: sys.stderr.write("$\n")) ;z ;z"sys.stderr.write("Worm Sign!\n") ;zinfile.close())stdinr!   r"   s   Worm Sign!
zwhile awaiting a sign)r"   r    g?      z,reader process failed to handle our signals.s   $
zwhile awaiting signal   
)inputzexited rc=%dF)r   )r   
subprocessPopensys
executablePIPEr	   r"   readlenr%   r'   writeselectsend_signalsignalSIGINTr   r   readliner   
returncode)r   data_to_writeread_and_verify_codeinfile_setup_code	worm_signsignals_sentrlist_signal_liner!   r"   s              r   _test_readingz'TestFileIOSignalInterrupt._test_readingK   sL   	 !<<>> #(tJ %% (,, 7	7
 ((
 +// "" !ojo!( ( ( M(--c/.B.BCC	''''(?/8 ( : : :!!-000  	J -)=(>BMMKE1aM%%fm444ALc!!""$$$		HIII  	J m*3355&  ''(?/: ( < < < 222??=# 	7''"T]%==F ( 7 7 7 7 7	7 	7r   zgot = infile.{read_method_name}() ;expected = {expected!r} ;assert got == expected, ("{read_method_name} returned wrong data.\n""got data %r\nexpected %r" % (got, expected))c                 j    	 |                      d| j                            dd                     d S )N   hello, world!r9   s   hello, world!
read_method_nameexpectedr;   r<   rC   _READING_CODE_TEMPLATEformatr
   s    r   test_readlinez'TestFileIOSignalInterrupt.test_readline   sQ    ?.%)%@%G%G)3!3 &H &5 &5 	 	6 	6 	6 	6 	6r   c                 n    	 |                      d| j                            dddg                     d S )N   hello
world!	readliness   hello
s   world!
rF   rI   rJ   r
   s    r   test_readlinesz(TestFileIOSignalInterrupt.test_readlines   sV    @.%)%@%G%G)4",k!: &H &< &< 	 	= 	= 	= 	= 	=r   c                     	 |                      d| j                            dd                     |                      d| j                            dd                     d S )NrO   readall   hello
world!
rF   rI   r2   rJ   r
   s    r   test_readallz&TestFileIOSignalInterrupt.test_readall   s    >.%)%@%G%G)2!3 &H &5 &5 	 	6 	6 	6 	.%)%@%G%G)/!3 &H &5 &5 	 	6 	6 	6 	6 	6r   N)r   r   T)__name__
__module____qualname__r   r   r   r%   rC   rK   rM   rQ   rU   r(   r   r   r   r      s               >A+/; ; ; ;6D7 D7 D7RE 6 6 6= = =6 6 6 6 6r   r   c                       e Zd ZdZdS )CTestFileIOSignalInterrupt_ioNrV   rW   rX   r   r(   r   r   rZ   rZ              GGGr   rZ   c                       e Zd ZdZdS )PyTestFileIOSignalInterrupt_pyioNr\   r(   r   r   r_   r_              GGGr   r_   c                       e Zd Zd Zd ZdS )TestBufferedIOSignalInterruptc                     	 d| j         z  S )Nziimport %s as io ;infile = io.open(sys.stdin.fileno(), "rb") ;assert isinstance(infile, io.BufferedReader)r   r
   s    r   r   z9TestBufferedIOSignalInterrupt._generate_infile_setup_code   s    M? 	r   c                 j    	 |                      d| j                            dd                     d S )NrO   r2   rT   rF   rI   rJ   r
   s    r   rU   z*TestBufferedIOSignalInterrupt.test_readall   sQ    J.%)%@%G%G)/!3 &H &5 &5 	 	6 	6 	6 	6 	6r   N)rV   rW   rX   r   rU   r(   r   r   rc   rc      s2          6 6 6 6 6r   rc   c                       e Zd ZdZdS )CTestBufferedIOSignalInterruptr[   Nr\   r(   r   r   rg   rg      r]   r   rg   c                       e Zd ZdZdS )PyTestBufferedIOSignalInterruptr`   Nr\   r(   r   r   ri   ri      ra   r   ri   c                   &    e Zd Zd Zd Zd Zd ZdS )TestTextIOSignalInterruptc                     	 d| j         z  S )Nzimport %s as io ;infile = io.open(sys.stdin.fileno(), encoding="utf-8", newline=None) ;assert isinstance(infile, io.TextIOWrapper)r   r
   s    r   r   z5TestTextIOSignalInterrupt._generate_infile_setup_code   s    L>  	r   c                 j    	 |                      d| j                            dd                     d S )NrE   r9   zhello, world!
rF   rI   rJ   r
   s    r   rM   z'TestTextIOSignalInterrupt.test_readline   sQ    ?.%)%@%G%G)3!2 &H &4 &4 	 	5 	5 	5 	5 	5r   c                 n    	 |                      d| j                            dddg                     d S )Ns   hello
world!rP   zhello
zworld!
rF   rI   rJ   r
   s    r   rQ   z(TestTextIOSignalInterrupt.test_readlines   sV    @0%)%@%G%G)4"+Z!8 &H &: &: 	 	; 	; 	; 	; 	;r   c                 j    	 |                      d| j                            dd                     d S )NrO   r2   zhello
world!
rF   rI   rJ   r
   s    r   rU   z&TestTextIOSignalInterrupt.test_readall   sQ    ;.%)%@%G%G)/!2 &H &4 &4 	 	5 	5 	5 	5 	5r   N)rV   rW   rX   r   rM   rQ   rU   r(   r   r   rk   rk      sP          5 5 5; ; ;5 5 5 5 5r   rk   c                       e Zd ZdZdS )CTestTextIOSignalInterruptr[   Nr\   r(   r   r   rq   rq      r]   r   rq   c                       e Zd ZdZdS )PyTestTextIOSignalInterruptr`   Nr\   r(   r   r   rs   rs      ra   r   rs   __main__)osr5   r7   r-   r/   r   unittesttestr   has_subprocess_supportSkipTestr[   r`   
skipUnlessnamer   TestCaserZ   r_   rc   rg   ri   rk   rq   rs   rV   mainr(   r   r   <module>r~      s   
			       



        % ?
(
=
>
>> 


 RW')IJJ[6 [6 [6 [6 [6 [6 [6 KJ[6|    !:H<M       ";X=N   6 6 6 6 6$= 6 6 6    %BHDU       &CXEV   5 5 5 5 5 9 5 5 5@    !:H<M       ";X=N    zHMOOOOO r   