
    Yf                         d Z ddlmZ ddlmZ ddlmZ  ej                    sddlm	Z	  G d de          Z
 e                                e
                                           dS )	z&
Tests for L{twisted.internet.stdio}.
    )Protocol)ReactorBuilder)platform)
StandardIOc                   h    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Z ej                    rd
ZdS dS )StdioFilesTestszI
    L{StandardIO} supports reading and writing to filesystem files.
    c                     |                                  }t          |d                                           t          |d          | _        |                     | j        j                   d S )Nwbzrb+)mktempopenclose	extraFile
addCleanup)selfpaths     R/var/www/html/env/lib/python3.11/site-packages/twisted/internet/test/test_stdio.pysetUpzStdioFilesTests.setUp   sY    {{}}T4   dE**,-----    c                 8   |                                   G fddt                    }|                                 }t          |d          5 }|                    d           ddd           n# 1 swxY w Y   t          |d          5 } |            }t          ||                                | j                                                   |                                ddd           n# 1 swxY w Y   | 	                    |j
        d           dS )zc
        Adding a filesystem file reader to a reactor will make sure it is
        polled.
        c                       e Zd ZdZ fdZdS )4StdioFilesTests.test_addReader.<locals>.DataProtocolr   c                 j    | xj         |z  c_         | j         dk    r                                 d S d S )N   hello!)datastop)r   r   reactors     r   dataReceivedzAStdioFilesTests.test_addReader.<locals>.DataProtocol.dataReceived&   s;    		T!		 9	))LLNNNNN *)r   N)__name__
__module____qualname__r   r   r   s   r   DataProtocolr   #   s3        D# # # # # # #r   r"   r
   r   Nrbstdinstdoutr   )buildReactorr   r   r   writer   filenor   
runReactorassertEqualr   )r   r"   r   fprotocolr   s        @r   test_addReaderzStdioFilesTests.test_addReader   s   
 ##%%		# 		# 		# 		# 		# 		# 		#8 		# 		# 		# {{}}$ 	GGI	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 $ 		%#|~~Hhhjj~,,..	    OOG$$$		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		22222s%   A11A58A5AC44C8;C8c                    |                                   G fddt                    }|                                 }t          |d          5 } |            }t	          ||                                | j                                                   |j                            d           |j                            d           |j        	                                 | 
                               ddd           n# 1 swxY w Y   t          |d          5 }|                     |                                d	           ddd           dS # 1 swxY w Y   dS )
zc
        Adding a filesystem file writer to a reactor will make sure it is
        polled.
        c                       e Zd Z fdZdS ):StdioFilesTests.test_addWriter.<locals>.DisconnectProtocolc                 0                                      d S )N)r   )r   reasonr   s     r   connectionLostzIStdioFilesTests.test_addWriter.<locals>.DisconnectProtocol.connectionLostH   s    r   N)r   r   r    r4   r!   s   r   DisconnectProtocolr1   G   s.              r   r5   r
   r&   r%   r      hellos   , worldNr#   s   hello, world)r'   r   r   r   r   r)   r   	transportr(   loseConnectionr*   r+   read)r   r5   r   r,   r-   r   s        @r   test_addWriterzStdioFilesTests.test_addWriter@   s   
 ##%%	 	 	 	 	 	 	 	 	 	 {{}}$ 	% *)++Hxxzzn++--	    $$X...$$Z000--///OOG$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%  $ 	8QVVXX777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s%   B)DDD)EEEc                 b   |                                  }|                                 }t          |d                                           t          |d          5 }t	          t                      |                                | j                                        |          }|                     |j	        |
                                           |j	                                         |                     |j	        |
                                           ddd           dS # 1 swxY w Y   dS )zq
        Removing a filesystem file reader from a reactor will make sure it is
        no longer polled.
        r
   r#   r$   N)r'   r   r   r   r   r   r)   r   assertIn_reader
getReadersstopReadingassertNotInr   r   r   r,   stdios        r   test_removeReaderz!StdioFilesTests.test_removeReader`   sX   
 ##%%{{}}T4   $ 
	B

hhjj~,,..	  E MM%-););)=)=>>>M%%'''U]G,>,>,@,@AAA
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	Bs   B<D$$D(+D(c                 .   |                                  }t          |                                 d          x| _        }t	                      }t          ||                                | j                                        |          }|j        	                    d           | 
                    |j        |                                           |j                                         |                     |j        |                                           dS )zq
        Removing a filesystem file writer from a reactor will make sure it is
        no longer polled.
        r
   r6   r7   N)r'   r   r   r,   r   r   r)   r   r8   r(   r=   _writer
getWritersstopWritingrA   )r   r   r,   r-   rC   s        r   test_removeWriterz!StdioFilesTests.test_removeWriterv   s    
 ##%% $++--... ::QXXZZt~/D/D/F/FPW
 
 
 	  ***emW%7%7%9%9:::!!###(:(:(<(<=====r   c                    |                                  }|                                 }t          |d                                           t          |d          x| _        }t          t                      |                                | j                                        |          }|	                                }| 
                    |j        |           |                     |j        |                                           dS )zk
        Calling C{removeAll} on a reactor includes descriptors that are
        filesystem files.
        r
   r#   r$   N)r'   r   r   r   r,   r   r   r)   r   	removeAllr=   r>   rA   r?   )r   r   r   r,   rC   removeds         r   test_removeAllzStdioFilesTests.test_removeAll   s    
 ##%%{{}}T4    $%%% JJ((**>((**	
 
 
 ##%%emW---(:(:(<(<=====r   c                    |                                  }|                                 }t          |d                                           t          |d          5 }t	          t                      |                                | j                                        |          }|                     |j	        |
                                           ddd           dS # 1 swxY w Y   dS )zW
        C{reactor.getReaders} includes descriptors that are filesystem files.
        r
   r#   r$   N)r'   r   r   r   r   r   r)   r   r=   r>   r?   rB   s        r   test_getReaderszStdioFilesTests.test_getReaders   s    ##%%{{}}T4    $ 	?

hhjj~,,..	  E MM%-););)=)=>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?s   A6CC"%C"c                    |                                  }t          |                                 d          x| _        }t	          t                      |                                | j                                        |          }|                     |j	        |
                                           |j	                                         |                     |j	        |
                                           dS )zW
        C{reactor.getWriters} includes descriptors that are filesystem files.
        r
   r6   N)r'   r   r   r,   r   r   r)   r   rA   rF   rG   startWritingr=   )r   r   r,   rC   s       r   test_getWriterszStdioFilesTests.test_getWriters   s     ##%% $++--... JJ88::.''))	
 
 
 	(:(:(<(<===""$$$emW%7%7%9%9:::::r   zoStandardIO does not accept stdout as an argument to Windows. Testing redirection to a file is therefore harder.N)r   r   r    __doc__r   r.   r;   rD   rI   rM   rO   rR   r   	isWindowsskip r   r   r   r      s         . . ."3 "3 "3H8 8 8@B B B,> > >(> > >2? ? ?(; ; ;( x 
A 	
 
r   r   N)rS   twisted.internet.protocolr   #twisted.internet.test.reactormixinsr   twisted.python.runtimer   rT   twisted.internet.stdior   r   globalsupdatemakeTestCaseClassesrV   r   r   <module>r^      s    
 / . . . . . > > > > > > + + + + + +x 2111111~
 ~
 ~
 ~
 ~
n ~
 ~
 ~
B 		  4466 7 7 7 7 7r   