%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/test/__pycache__/test_stdio.cpython-312.pyc

�

Ϫ�f�1��D�dZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
mZddlm
Z
mZddlmZddlmZddlmZdd	lmZmZd
Zeej4�Zej8j;ej<�ed<Gd�d
e	j>�Z Gd�de�Z!y)z�
Tests for L{twisted.internet.stdio}.

@var properEnv: A copy of L{os.environ} which has L{bytes} keys/values on POSIX
    platforms and native L{str} keys/values on Windows.
�N)�skipIf)�defer�error�protocol�reactor�stdio)�filepath�log)�
requireModule)�platform)�ConnectionLostNotifyingProtocol)�SkipTest�TestCasesxyz123abc Twisted is great!�
PYTHONPATHc�,�eZdZdZdZd�Zd�Zd�Zd�Zy)�StandardIOTestProcessProtocola�
    Test helper for collecting output from a child process and notifying
    something when it exits.

    @ivar onConnection: A L{defer.Deferred} which will be called back with
    L{None} when the connection to the child process is established.

    @ivar onCompletion: A L{defer.Deferred} which will be errbacked with the
    failure associated with the child process exiting when it exits.

    @ivar onDataReceived: A L{defer.Deferred} which will be called back with
    this instance whenever C{childDataReceived} is called, or L{None} to
    suppress these callbacks.

    @ivar data: A C{dict} mapping file descriptors to strings containing all
    bytes received from the child process on each file descriptor.
    Nc�v�tj�|_tj�|_i|_y�N)r�Deferred�onConnection�onCompletion�data��selfs �9/usr/lib/python3/dist-packages/twisted/test/test_stdio.py�__init__z&StandardIOTestProcessProtocol.__init__8s'��!�N�N�,���!�N�N�,�����	�c�:�|jjd�yr)r�callbackrs r�connectionMadez,StandardIOTestProcessProtocol.connectionMade=s�����"�"�4�(rc��|jj|d�|z|j|<|j�&|jdc}|_|j|�yy)z�
        Record all bytes received from the child process in the C{data}
        dictionary.  Fire C{onDataReceived} if it is not L{None}.
        rN)r�get�onDataReceivedr)r�name�bytes�ds    r�childDataReceivedz/StandardIOTestProcessProtocol.childDataReceived@sW��
�)�)�-�-��c�2�U�:��	�	�$�����*�%)�%8�%8�$�"�A�t�"�
�J�J�t��+rc�:�|jj|�yr)rr)r�reasons  r�processEndedz*StandardIOTestProcessProtocol.processEndedJs�����"�"�6�*r)	�__name__�
__module__�__qualname__�__doc__r#rr r'r*�rrrr#s"���$�N��
)��+rrc��eZdZej�r
ed��dZd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zd�Zeej�d�d��Zy)�StandardInputOutputTests�win32processNzIOn windows, spawnProcess is not available in the absence of win32process.c���tjdd|ztjjgt|�z}tj|tj|fdti|��S)a_
        Launch a child Python process and communicate with it using the
        given ProcessProtocol.

        @param proto: A L{ProcessProtocol} instance which will be connected
        to the child process.

        @param sibling: The basename of a file containing the Python program
        to run in the child process.

        @param *args: strings which will be passed to the child process on
        the command line as C{argv[2:]}.

        @param **kw: additional arguments to pass to L{reactor.spawnProcess}.

        @return: The L{IProcessTransport} provider for the spawned process.
        s-ms
twisted.test.�env)�sys�
executabler�	__class__r,�list�spawnProcess�	properEnv)r�proto�sibling�args�kws     r�
_spawnProcessz&StandardInputOutputTests._spawnProcessUs`��&
�N�N���w�&����(�(�	
�

��J����#�#�E�3�>�>�4�U�Y�U�RT�U�Urc�>����fd�}�fd�}|j||�S)Nc�.���jd|���y)Nz%Process terminated with non-Failure: )�fail)�resultrs �r�cbz4StandardInputOutputTests._requireFailure.<locals>.cbps����I�I�=�f�Z�H�Irc����|�Srr/)�errrs �r�ebz4StandardInputOutputTests._requireFailure.<locals>.ebss
����C�=� r)�addCallbacks)rr&rrDrGs` `  r�_requireFailurez(StandardInputOutputTests._requireFailureos!���	J�	!��~�~�b�"�%�%rc�������j��tjd�z�t���j}�j�d�����fd�}�j
||�S)z�
        Verify that a protocol connected to L{StandardIO} can disconnect
        itself using C{transport.loseConnection}.
        �Child process logging to sstdio_test_loseconnc���t��5}|D](}tjd|j�z��*	ddd��j	d�j
�|j
tj�y#1swY�ExYw)NzChild logged: �)	�openr
�msg�rstrip�failIfInr�trapr�ProcessDone)r)�f�line�errorLogFile�prs   ���rr*zBStandardInputOutputTests.test_loseConnection.<locals>.processEnded�so����l�#�
>�q��>�D��G�G�,�t�{�{�}�<�=�>�
>�
�M�M�!�Q�V�V�$��K�K��)�)�*�
>�
>�s�.B�B	)�mktempr
rOrrr?rI)rr&r*rVrWs`  @@r�test_loseConnectionz,StandardInputOutputTests.test_loseConnectionxs`���
�{�{�}�����+�l�:�;�)�+��
�N�N�����1�4�l�C�	+��#�#�A�|�4�4rc�B��|j�}tjd|z�t��t	j
��_�fd�}�jj|�d�}|j�j|�}|j�d|�|S)z�
        When stdin is closed and the protocol connected to it implements
        L{IHalfCloseableProtocol}, the protocol's C{readConnectionLost} method
        is called.
        rKc�T���j}�jj�|Sr)r�	transport�
closeStdin)�ignoredr&rWs  �r�cbByteszAStandardInputOutputTests.test_readConnectionLost.<locals>.cbBytes�s!������A�
�K�K�"�"�$��Hrc�B�|jtj�yr)rRrrS)r)s rr*zFStandardInputOutputTests.test_readConnectionLost.<locals>.processEnded�s���K�K��)�)�*rsstdio_test_halfclose)
rXr
rOrrrr#�addCallbackrIr?)rrVr_r*r&rWs     @r�test_readConnectionLostz0StandardInputOutputTests.test_readConnectionLost�s�����{�{�}�����+�l�:�;�)�+�� �>�>�+���	�
	
���$�$�W�-�	+�
� � ��!1�!1�<�@�����1�5�|�D��rc�����t��	�j�dtd����fd�}�j
�j|�S#t$r}t	t|���d}~wwxYw)z�
        Verify that a write made directly to stdout using L{os.write}
        after StandardIO has finished is reliably received by the
        process reading that stdout.
        sstdio_test_lastwriteT)�usePTYNc�����j�jdjt�d�j�d��|j	t
j�y)z�
            Asserts that the parent received the bytes written by the child
            immediately after the child starts.
            rMz	Received z) from child, did not find expected bytes.N)�
assertTruer�endswith�UNIQUE_LAST_WRITE_STRINGrRrrS�r)rWrs ��rr*zEStandardInputOutputTests.test_lastWriteReceived.<locals>.processEnded�sM���

�O�O����q�	�"�"�#;�<��A�F�F�:�%N�O�
�
�K�K��)�)�*r)rr?rh�
ValueErrorr�strrIr)r�er*rWs`  @r�test_lastWriteReceivedz/StandardInputOutputTests.test_lastWriteReceived�so���
*�+��	#�����*�,D�T�
�
�		+��#�#�A�N�N�L�A�A���	#��3�q�6�"�"��	#�s�A	�		A+�A&�&A+c����t���j}�j�d���fd�}�j||�S)z�
        Verify that the transport of a protocol connected to L{StandardIO}
        has C{getHost} and C{getPeer} methods.
        sstdio_test_hostpeerc�����jdj�\}}�j|��j|�|jtj
�y)NrM)r�
splitlinesrfrRrrS)r)�host�peerrWrs   ��rr*z?StandardInputOutputTests.test_hostAndPeer.<locals>.processEnded�sG��������-�-�/�J�D�$��O�O�D�!��O�O�D�!��K�K��)�)�*r�rrr?rI�rr&r*rWs`  @r�test_hostAndPeerz)StandardInputOutputTests.test_hostAndPeer�sA���

*�+��
�N�N�����1�4�5�	+��#�#�A�|�4�4rc����t���j}�j�d���fd�}�j||�S)z�
        Verify that the C{write} method of the transport of a protocol
        connected to L{StandardIO} sends bytes to standard out.
        sstdio_test_writec����j�jdd�|jtj�y�NrMsok!��assertEqualrrRrrSris ��rr*z9StandardInputOutputTests.test_write.<locals>.processEnded��-������Q�V�V�A�Y��/��K�K��)�)�*rrsrts`  @r�
test_writez#StandardInputOutputTests.test_write�sA���

*�+��
�N�N�����1�1�2�	+��#�#�A�|�4�4rc����t���j}�j�d���fd�}�j||�S)z�
        Verify that the C{writeSequence} method of the transport of a
        protocol connected to L{StandardIO} sends bytes to standard out.
        sstdio_test_writeseqc����j�jdd�|jtj�yrxryris ��rr*zAStandardInputOutputTests.test_writeSequence.<locals>.processEnded�r{rrsrts`  @r�test_writeSequencez+StandardInputOutputTests.test_writeSequence�sA���

*�+��
�N�N�����1�4�5�	+��#�#�A�|�4�4rc��|j�}t|d�5}td�D]}|jd|fz��	ddd�|S#1swY|SxYw)N�wbi�%d
)rXrN�range�write)r�junkPath�junkFile�is    r�	_junkPathz"StandardInputOutputTests._junkPaths\���;�;�=��
�(�D�
!�	/�X��4�[�
/�����w�!��~�.�
/�	/���	/���s�&A�Ac��������t���j}g�ttd�������fd���j	�d���j
j
������fd�}�j||�S)z�
        Verify that the transport of a protocol connected to L{StandardIO}
        is a working L{IProducer} provider.
        �dc����rO�jd�j�fz��j�d�tjd�d�yy)Nr����g{�G�z�?)�append�popr�r�	callLater)�ignr �proc�toWrite�writtens ����rr z>StandardInputOutputTests.test_producer.<locals>.connectionMadesG�������w�'�+�+�-�)9�9�:��
�
�7�2�;�'��!�!�$���=�rsstdio_test_producerc�����j�jddj����j�dt	��fz�|jtj�y)NrMrz*Connection lost with %d writes left to go.)rzr�join�assertFalse�lenrRrrS)r)rWrr�r�s ����rr*z<StandardInputOutputTests.test_producer.<locals>.processEndedsW������Q�V�V�A�Y�����(9�:�����E��W���W�
�
�K�K��)�)�*r)rrr8r�r?rrarI)rr&r*r rWr�r�r�s`  @@@@@r�
test_producerz&StandardInputOutputTests.test_producerso���

*�+��
�N�N�����u�S�z�"��	>��!�!�!�%;�<��	���"�"�>�2�	+��#�#�A�|�4�4rc�����t���j}�j���j�d�����fd�}�j	||�S)z�
        Verify that the transport of a protocol connected to L{StandardIO}
        is a working L{IConsumer} provider.
        sstdio_test_consumerc����t�d�5}�j�jd|j��ddd�|j	t
j�y#1swY�)xYw)N�rbrM)rNrzr�readrRrrS)r)rTr�rWrs  ���rr*z<StandardInputOutputTests.test_consumer.<locals>.processEnded1sT����h��%�
6��� � ������A�F�F�H�5�
6��K�K��)�)�*�
6�
6�s�.A$�$A-)rrr�r?rI)rr&r*r�rWs`  @@r�
test_consumerz&StandardInputOutputTests.test_consumer%sO���

*�+��
�N�N���>�>�#�����1�4�h�?�	+�
�#�#�A�|�4�4rzpStandardIO does not accept stdout as an argument to Windows.  Testing redirection to a file is therefore harder.c�����	�
���tj�}t|�}tj�j����j
d�x�_}�j|j�t|j���}tj�s\tj�\}}�jtj|��jtj|�||d<t!j"|fi|���d�
t%j&��	��	�
�fd��t)j*d���	�
��fd�}|j-|�|S)aE
        If L{StandardIO} is created with a file descriptor which refers to a
        normal file (ie, a file from the filesystem), L{StandardIO.write}
        writes bytes to that file.  In particular, it does not immediately
        consider the file closed or call its protocol's C{connectionLost}
        method.
        r�)�stdout�stdin�c����D]/}|�k(r�j�y�jd|fz�ntjd��y)N�%dr)�loseConnectionr�rr�)�value�
connection�count�howMany�spins ����rr�zAStandardInputOutputTests.test_normalFileStandardOut.<locals>.spin\sS����
���G�#��-�-�/��� � ��%��!1�2��
�
���a��&rrc	����jt���dz��j�j�djd�t	��D���y)NrMrc3�(K�|]
}d|fz���y�w)r�Nr/)�.0r�s  r�	<genexpr>zVStandardInputOutputTests.test_normalFileStandardOut.<locals>.cbLost.<locals>.<genexpr>ls����+Q�Q�E�Q�D�L�+Q�s�)rz�next�
getContentr�r�)r)r�r��pathrs ����r�cbLostzCStandardInputOutputTests.test_normalFileStandardOut.<locals>.cbLostisH������T�%�[�'�A�+�6�������!�3�8�8�+Q�%��.�+Q�#Q�
r)rrr
r	�FilePathrXrN�normal�
addCleanup�close�dict�filenor�	isWindows�os�piper�
StandardIO�	itertoolsr�rr�ra)
r�
onConnLostr;r��kwargs�r�wr�r�r�r�r�r�s
`       @@@@@r�test_normalFileStandardOutz3StandardInputOutputTests.test_normalFileStandardOut8s	����^�^�%�
�/�
�;��� � �����/��#�y�y���.���f�������%��V�]�]�_�-���!�!�#��7�7�9�D�A�q��O�O�B�H�H�a�(��O�O�B�H�H�a�(��F�7�O��%�%�e�6�v�6�
������!��	'�	���!�T�"�	�	���v�&��r)r+r,r-rr�r�skipr?rIrYrbrmrur|rr�r�r�rr�r/rrr1r1Ns����x����
�n� =� E�
'�	
�
V�4&�5�,�4%B�N5�"5� 5� �5�<5�&������	=��
3��
3rr1)"r.r�r�r5�unittestr�twisted.internetrrrrr�twisted.pythonr	r
�twisted.python.reflectr�twisted.python.runtimer�twisted.test.test_tcpr
�twisted.trial.unittestrrrhr��environr:�pathsepr�r��ProcessProtocolrr1r/rr�<module>r�s����	�
��C�C�(�0�+�A�5�:�������	��*�*�/�/�#�(�(�3�	�,��(+�H�$<�$<�(+�Vb�x�br

Zerion Mini Shell 1.0