%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�fVH���dZddlmZddlmZddlmZddlmZddl	m
Z
mZmZm
Z
ddlmZmZmZmZmZmZddlmZmZdd	lmZmZdd
lmZddlmZGd�d
e�ZGd�de�Z Gd�de�Z!Gd�de�Z"Gd�de�Z#y)z)
Tests for L{twisted.internet.protocol}.
�)�BytesIO)�implementer)�verifyObject)�CancelledError)�	IConsumer�ILoggingContext�	IProtocol�IProtocolFactory)�
ClientCreator�ConsumerToProtocolAdapter�Factory�FileWrapper�Protocol�ProtocolToConsumerAdapter)�MemoryReactorClock�StringTransport)�LogLevel�globalLogPublisher)�Failure)�TestCasec�p�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zy)�ClientCreatorTestsz?
    Tests for L{twisted.internet.protocol.ClientCreator}.
    c��Gd�dt�}t�}t||�}|||�}|jd�}|j	||�y)a
        Helper for implementing a test to verify that one of the I{connect}
        methods of L{ClientCreator} passes the right arguments to the right
        reactor method.

        @param check: A function which will be invoked with a reactor and a
            L{ClientCreator} instance and which should call one of the
            L{ClientCreator}'s I{connect} methods and assert that all of its
            arguments except for the factory are passed on as expected to the
            reactor.  The factory should be returned.
        c��eZdZy)�:ClientCreatorTests._basicConnectTest.<locals>.SomeProtocolN��__name__�
__module__�__qualname__���E/usr/lib/python3/dist-packages/twisted/internet/test/test_protocol.py�SomeProtocolr5���r!r#N)rrr�
buildProtocol�assertIsInstance)�self�checkr#�reactor�cc�factory�protocols       r"�_basicConnectTestz$ClientCreatorTests._basicConnectTest(sP��	�8�	�%�&��
�7�L�
1�����$���(�(��.�����h��5r!c�2���fd�}�j|�y)z�
        L{ClientCreator.connectTCP} calls C{reactor.connectTCP} with the host
        and port information passed to it, and with a factory which will
        construct the protocol passed to L{ClientCreator.__init__}.
        c���|jdddd�|jj�\}}}}}�j|d��j|d��j|d��j|d�|S)N�example.com����)z1.2.3.4i�&)�
connectTCP�
tcpClients�pop�assertEqual)r)r*�host�portr+�timeout�bindAddressr's       �r"r(z1ClientCreatorTests.test_connectTCP.<locals>.checkEs{����M�M�-��t�5F�G�8?�8J�8J�8N�8N�8P�5�D�$���+����T�=�1����T�4�(����W�d�+����[�*;�<��Nr!N�r-�r'r(s` r"�test_connectTCPz"ClientCreatorTests.test_connectTCP>s���	�	
���u�%r!c�2���fd�}�j|�y)z�
        L{ClientCreator.connectUNIX} calls C{reactor.connectUNIX} with the
        filename passed to it, and with a factory which will construct the
        protocol passed to L{ClientCreator.__init__}.
        c����|jddd�|jj�\}}}}�j|d��j|d��j	|�|S)N�/foo/bar�{T)�connectUNIX�unixClientsr5r6�
assertTrue)r)r*�addressr+r9�checkPIDr's      �r"r(z2ClientCreatorTests.test_connectUNIX.<locals>.checkWsa����N�N�:�s�D�1�29�2E�2E�2I�2I�2K�/�G�W�g�x����W�j�1����W�c�*��O�O�H�%��Nr!Nr;r<s` r"�test_connectUNIXz#ClientCreatorTests.test_connectUNIXPs���	�	
���u�%r!c�2���fd�}�j|�y)z�
        L{ClientCreator.connectSSL} calls C{reactor.connectSSL} with the host,
        port, and context factory passed to it, and with a factory which will
        construct the protocol passed to L{ClientCreator.__init__}.
        c�<��t�}|jdd|dd�|jj�\}}}}}}�	j	|d��	j	|d��	j||��	j	|d��	j	|d�|S)Nr0r1r2)z4.3.2.1i.)�object�
connectSSL�
sslClientsr5r6�assertIs)
r)r*�expectedContextFactoryr7r8r+�contextFactoryr9r:r's
         �r"r(z1ClientCreatorTests.test_connectSSL.<locals>.checkhs����%+�X�"��M�M��t�%;�T�CT�
��"�"�&�&�(�
����������T�=�1����T�4�(��M�M�.�*@�A����W�d�+����[�*;�<��Nr!Nr;r<s` r"�test_connectSSLz"ClientCreatorTests.test_connectSSLas���	�(	
���u�%r!c�2�t�}t|t�}||�}|jj	�}|j|j�|j�|j|j�|j|t�S)a
        Helper for implementing a test to verify that cancellation of the
        L{Deferred} returned by one of L{ClientCreator}'s I{connect} methods is
        implemented to cancel the underlying connector.

        @param connect: A function which will be invoked with a L{ClientCreator}
            instance as an argument and which should call one its I{connect}
            methods and return the result.

        @return: A L{Deferred} which fires when the test is complete or fails if
            there is a problem.
        )rrr�
connectorsr5�assertFalse�
_disconnected�cancelrD�
assertFailurer�r'�connectr)r*�d�	connectors      r"�_cancelConnectTestz%ClientCreatorTests._cancelConnectTest~sw��%�&��
�7�H�
-���B�K���&�&�*�*�,�	�����0�0�1�	���
����	�/�/�0��!�!�!�^�4�4r!c�*�d�}|j|�S)��
        The L{Deferred} returned by L{ClientCreator.connectTCP} can be cancelled
        to abort the connection attempt before it completes.
        c�&�|jdd�S�Nr0r1)r3�r*s r"rXz9ClientCreatorTests.test_cancelConnectTCP.<locals>.connect�s���=�=���5�5r!�r[�r'rXs  r"�test_cancelConnectTCPz(ClientCreatorTests.test_cancelConnectTCP�s��	6��&�&�w�/�/r!c�*�d�}|j|�S)r]c�$�|jd�S�Nr@)rBr`s r"rXz:ClientCreatorTests.test_cancelConnectUNIX.<locals>.connect�s���>�>�*�-�-r!rarbs  r"�test_cancelConnectUNIXz)ClientCreatorTests.test_cancelConnectUNIX�s��	.��&�&�w�/�/r!c�*�d�}|j|�S)r]c�8�|jddt��Sr_)rKrJr`s r"rXz9ClientCreatorTests.test_cancelConnectSSL.<locals>.connect�s���=�=���f�h�?�?r!rarbs  r"�test_cancelConnectSSLz(ClientCreatorTests.test_cancelConnectSSL�s��	@��&�&�w�/�/r!c��t�}t|t�}|||�}|jj	�}|jt
|j��d�|j�|j|j�g�|j|j�|j|t�S)z�
        Like L{_cancelConnectTest}, but for the case where the L{Deferred} is
        cancelled after the connection is set up but before it is fired with the
        resulting protocol instance.
        �)
rrrrRr5r6�len�getDelayedCallsrUrDrTrVrrWs      r"�_cancelConnectTimeoutTestz,ClientCreatorTests._cancelConnectTimeoutTest�s���%�&��
�7�H�
-���G�R� ���&�&�*�*�,�	�	
����W�4�4�6�7��;�	
���
�����0�0�2�B�7�
	
���	�/�/�0��!�!�!�^�4�4r!c�*�d�}|j|�S)a�
        L{ClientCreator.connectTCP} inserts a very short delayed call between
        the time the connection is established and the time the L{Deferred}
        returned from one of its connect methods actually fires.  If the
        L{Deferred} is cancelled in this interval, the established connection is
        closed, the timeout is cancelled, and the L{Deferred} fails with
        L{CancelledError}.
        c���|jdd�}|jj�\}}}}}|jd�}t	�}	|j|	�|Sr_)r3r4r5r%r�makeConnection)
r)r*rYr7r8r+r9r:r,�	transports
          r"rXz@ClientCreatorTests.test_cancelConnectTCPTimeout.<locals>.connect�s\���
�
�m�T�2�A�8?�8J�8J�8N�8N�8P�5�D�$���+��,�,�T�2�H�'�)�I��#�#�I�.��Hr!�rorbs  r"�test_cancelConnectTCPTimeoutz/ClientCreatorTests.test_cancelConnectTCPTimeout����	��-�-�g�6�6r!c�*�d�}|j|�S)a�
        L{ClientCreator.connectUNIX} inserts a very short delayed call between
        the time the connection is established and the time the L{Deferred}
        returned from one of its connect methods actually fires.  If the
        L{Deferred} is cancelled in this interval, the established connection is
        closed, the timeout is cancelled, and the L{Deferred} fails with
        L{CancelledError}.
        c��|jd�}|jj�\}}}}|jd�}t	�}|j|�|Srf)rBrCr5r%rrr)	r)r*rYrEr+r9r:r,rss	         r"rXzAClientCreatorTests.test_cancelConnectUNIXTimeout.<locals>.connect�sX�����z�*�A�5<�5H�5H�5L�5L�5N�2�G�W�g�{��,�,�T�2�H�'�)�I��#�#�I�.��Hr!rtrbs  r"�test_cancelConnectUNIXTimeoutz0ClientCreatorTests.test_cancelConnectUNIXTimeout�rvr!c�*�d�}|j|�S)a�
        L{ClientCreator.connectSSL} inserts a very short delayed call between
        the time the connection is established and the time the L{Deferred}
        returned from one of its connect methods actually fires.  If the
        L{Deferred} is cancelled in this interval, the established connection is
        closed, the timeout is cancelled, and the L{Deferred} fails with
        L{CancelledError}.
        c���|jddt��}|jj�\}}}}}}|j	d�}	t�}
|	j
|
�|Sr_)rKrJrLr5r%rrr)r)r*rYr7r8r+rOr9�bindADdressr,rss           r"rXz@ClientCreatorTests.test_cancelConnectSSLTimeout.<locals>.connectsl���
�
�m�T�6�8�<�A��"�"�&�&�(�
��������,�,�T�2�H�'�)�I��#�#�I�.��Hr!rtrbs  r"�test_cancelConnectSSLTimeoutz/ClientCreatorTests.test_cancelConnectSSLTimeout�s��
	��-�-�g�6�6r!c��t�}t|t�}|||�\}}|jj	�}|j|t
td���|jt|j��d�|j�|j|j�g�|j|t�S)z�
        Like L{_cancelConnectTest}, but for the case where the L{Deferred} is
        cancelled after the connection attempt has failed but before it is fired
        with the resulting failure.
        zSimulated failurerl)rrrrRr5�clientConnectionFailedr�	Exceptionr6rmrnrUrVr)r'rXr)r*rYr+rZs       r"�_cancelConnectFailedTimeoutTestz2ClientCreatorTests._cancelConnectFailedTimeoutTests���%�&��
�7�H�
-���W�b�)�
��7��&�&�*�*�,�	��&�&��w�y�)<�=�>�	
�	
����W�4�4�6�7��;�	
���
�����0�0�2�B�7��!�!�!�^�4�4r!c�*�d�}|j|�S)zz
        Similar to L{test_cancelConnectTCPTimeout}, but for the case where the
        connection attempt fails.
        c�n�|jdd�}|jj�\}}}}}||fSr_)r3r4r5)r)r*rYr7r8r+r9r:s        r"rXzFClientCreatorTests.test_cancelConnectTCPFailedTimeout.<locals>.connect2s;���
�
�m�T�2�A�8?�8J�8J�8N�8N�8P�5�D�$���+��g�:�r!�r�rbs  r"�"test_cancelConnectTCPFailedTimeoutz5ClientCreatorTests.test_cancelConnectTCPFailedTimeout,���	�
�3�3�G�<�<r!c�*�d�}|j|�S)z{
        Similar to L{test_cancelConnectUNIXTimeout}, but for the case where the
        connection attempt fails.
        c�j�|jd�}|jj�\}}}}||fSrf)rBrCr5)r)r*rYrEr+r9r:s       r"rXzGClientCreatorTests.test_cancelConnectUNIXFailedTimeout.<locals>.connect?s7�����z�*�A�5<�5H�5H�5L�5L�5N�2�G�W�g�{��g�:�r!r�rbs  r"�#test_cancelConnectUNIXFailedTimeoutz6ClientCreatorTests.test_cancelConnectUNIXFailedTimeout9r�r!c�*�d�}|j|�S)zz
        Similar to L{test_cancelConnectSSLTimeout}, but for the case where the
        connection attempt fails.
        c��|jddt��}|jj�\}}}}}}||fSr_)rKrJrLr5)	r)r*rYr7r8r+rOr9r|s	         r"rXzFClientCreatorTests.test_cancelConnectSSLFailedTimeout.<locals>.connectLsK���
�
�m�T�6�8�<�A��"�"�&�&�(�
��������g�:�r!r�rbs  r"�"test_cancelConnectSSLFailedTimeoutz5ClientCreatorTests.test_cancelConnectSSLFailedTimeoutFs��
	��3�3�G�<�<r!N)rrr�__doc__r-r=rGrPr[rcrgrjroruryr}r�r�r�r�r r!r"rr#sW���6�,&�$&�"&�:5�,	0�	0�	0�5�67�(7�(7�65�2=�=�=r!rc�"�eZdZdZd�Zd�Zd�Zy)�
ProtocolTestsz:
    Tests for L{twisted.internet.protocol.Protocol}.
    c��t�}|jtt|��|jtt|��y)zT
        L{Protocol} instances provide L{IProtocol} and L{ILoggingContext}.
        N)rrDrr	r)r'�protos  r"�test_interfaceszProtocolTests.test_interfaces`s1���
������Y��6�7�����_�e�<�=r!c�l�Gd�dt�}|jd|�j��y)zJ
        L{Protocol.logPrefix} returns the protocol class's name.
        c��eZdZy)�/ProtocolTests.test_logPrefix.<locals>.SomeThingNrr r!r"�	SomeThingr�mr$r!r�N)rr6�	logPrefix)r'r�s  r"�test_logPrefixzProtocolTests.test_logPrefixhs+��
	��	�	
����i�k�&;�&;�&=�>r!c���g�G�fd�dt�}t�}|�}|j|�|j�|g�y)zz
        L{Protocol.makeConnection} sets the given transport on itself, and
        then calls C{connectionMade}.
        c���eZdZ�fd�Zy)�7ProtocolTests.test_makeConnection.<locals>.SomeProtocolc�<���j|j�y�N)�appendrs)r'�results �r"�connectionMadezFProtocolTests.test_makeConnection.<locals>.SomeProtocol.connectionMadezs����
�
�d�n�n�-r!N)rrrr��r�s�r"r#r�ys���
.r!r#N)rrJrrr6)r'r#rsr,r�s    @r"�test_makeConnectionz!ProtocolTests.test_makeConnectionrsF���
��	.�8�	.��H�	��>�����	�*�����)��-r!N)rrrr�r�r�r�r r!r"r�r�[s���>�?�.r!r�c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�FactoryTestsz(
    Tests for L{protocol.Factory}.
    c��t�}|jtt|��|jtt|��y)zg
        L{Factory} instances provide both L{IProtocolFactory} and
        L{ILoggingContext}.
        N)r
rDrr
r)r'r+s  r"r�zFactoryTests.test_interfaces�s2��
�)������%5�w�?�@�����_�g�>�?r!c�l�Gd�dt�}|jd|�j��y)zM
        L{Factory.logPrefix} returns the name of the factory class.
        c��eZdZy)�6FactoryTests.test_logPrefix.<locals>.SomeKindOfFactoryNrr r!r"�SomeKindOfFactoryr��r$r!r�N)r
r6r�)r'r�s  r"r�zFactoryTests.test_logPrefix�s.��
	��	�	
���,�.?�.A�.K�.K�.M�Nr!c���Gd�dt�}t�}||_|jd�}|j	||�|j|j|�y)z�
        L{Factory.buildProtocol} by default constructs a protocol by calling
        its C{protocol} attribute, and attaches the factory to the result.
        c��eZdZy)�<FactoryTests.test_defaultBuildProtocol.<locals>.SomeProtocolNrr r!r"r#r��r$r!r#N)rr
r,r%r&rMr+)r'r#�fr,s    r"�test_defaultBuildProtocolz&FactoryTests.test_defaultBuildProtocol�sP��	�8�	�
�I��!��
��?�?�4�(�����h��5��
�
�h�&�&��*r!c��Gd�dt�}|jtddd��}|j|jt�|j|j
d�|j|jddi�y	)
z�
        L{Factory.forProtocol} constructs a Factory, passing along any
        additional arguments, and sets its C{protocol} attribute to the given
        Protocol subclass.
        c��eZdZd�Zy)�7FactoryTests.test_forProtocol.<locals>.ArgTakingFactoryc�"�||c|_|_yr�)�args�kwargs)r'r�r�s   r"�__init__z@FactoryTests.test_forProtocol.<locals>.ArgTakingFactory.__init__�s��)-�v�&��	�4�;r!N)rrrr�r r!r"�ArgTakingFactoryr��s��
6r!r�rl��)�foo)rlr�r�N)r
�forProtocolrr6r,r�r�)r'r�r+s   r"�test_forProtocolzFactoryTests.test_forProtocol�sk��	6�w�	6�#�.�.�x��A�2�.�F������)�)�8�4�������v�.�������%���5r!c�P��g�tj�j�|j�fd��t	�}|j�|j
�dd|�|j�ddtj�|j�ddd�y)z�
        L{Factory.doStart} logs that it is starting a factory, followed by
        the L{repr} of the L{Factory} instance that is being started.
        c�B��tj�j�Sr��r�removeObserverr���eventss�r"�<lambda>z;FactoryTests.test_doStartLoggingStatement.<locals>.<lambda>����� 2� A� A�&�-�-� P�r!rr+�	log_level�
log_formatzStarting factory {factory!r}N)
r�addObserverr��
addCleanupr
�doStartrMr6r�info)r'r�r�s  @r"�test_doStartLoggingStatementz)FactoryTests.test_doStartLoggingStatement�s����
���&�&�v�}�}�5����P�Q��I��	�	�	���
�
�f�Q�i�	�*�A�.�������;�/����?�������<�0�2P�Qr!c�h��g�tj�j�|j�fd��Gd�dt�}|�}|j�|j
�dd|�|j�ddtj�|j�ddd�y	)
z�
        L{Factory.doStop} logs that it is stopping a factory, followed by
        the L{repr} of the L{Factory} instance that is being stopped.
        c�B��tj�j�Sr�r�r�s�r"r�z:FactoryTests.test_doStopLoggingStatement.<locals>.<lambda>�r�r!c��eZdZdZy)�;FactoryTests.test_doStopLoggingStatement.<locals>.MyFactoryrlN)rrr�numPortsr r!r"�	MyFactoryr��s���Hr!r�rr+r�r�zStopping factory {factory!r}N)
rr�r�r�r
�doStoprMr6rr�)r'r�r�r�s   @r"�test_doStopLoggingStatementz(FactoryTests.test_doStopLoggingStatement�s����
���&�&�v�}�}�5����P�Q�	��	�
�K��	���
��
�
�f�Q�i�	�*�A�.�������;�/����?�������<�0�2P�Qr!N)
rrrr�r�r�r�r�r�r�r r!r"r�r��s)���@�O�
+�6� R� Rr!r�c��eZdZdZd�Zd�Zy)�AdapterTestszR
    Tests for L{ProtocolToConsumerAdapter} and L{ConsumerToProtocolAdapter}.
    c���g}t�}|j|_t|�}|j	d�|j|dg�|j
|t�y)z}
        L{IProtocol} providers can be adapted to L{IConsumer} providers using
        L{ProtocolToConsumerAdapter}.
        �helloN)rr��dataReceivedr�writer6r&r)r'r��p�consumers    r"�test_protocolToConsumerz$AdapterTests.test_protocolToConsumer�sS��
���J��������Q�<�����x� �����(��,����h�(A�Br!c����g�tt�G�fd�d��}|�}t|�}|jd�|j	�dg�|j|t�y)z}
        L{IConsumer} providers can be adapted to L{IProtocol} providers using
        L{ProtocolToConsumerAdapter}.
        c���eZdZ�fd�Zy)�6AdapterTests.test_consumerToProtocol.<locals>.Consumerc�(���j|�yr�)r�)r'rYr�s  �r"r�z<AdapterTests.test_consumerToProtocol.<locals>.Consumer.write�s����
�
�a� r!N)rrrr�r�s�r"�Consumerr��s���
!r!r�r�N)rrr	r�r6r&r)r'r��cr,r�s    @r"�test_consumerToProtocolz$AdapterTests.test_consumerToProtocol�si���
��	�Y�	�	!�	!�
 �	!�
�J���Q�<�����h�'�����(��,����h�(A�Br!N)rrrr�r�r�r r!r"r�r��s���C�Cr!r�c��eZdZdZd�Zd�Zy)�FileWrapperTestsz2
    L{twisted.internet.protocol.FileWrapper}
    c�<�tt��}|jd�|j|jj�d�tt��}|jd�|j
|jj�d�y)z@
        L{twisted.internet.protocol.FileWrapper.write}
        �test1�stuffN)rrr�r6�file�getvalue�assertNotEqual�r'�wrappers  r"�
test_writezFileWrapperTests.test_writesp���g�i�(���
�
�h��������.�.�0�(�;��g�i�(��	�
�
�g�����G�L�L�1�1�3�W�=r!c��tt��}|jddg�|j|jj�d�tt��}|j
t|jddg�y)zH
        L{twisted.internet.protocol.FileWrapper.writeSequence}
        r�stest2s
test1test2�test3�test4N)rr�
writeSequencer6r�r��assertRaises�	TypeErrorr�s  r"�test_writeSequencez#FileWrapperTests.test_writeSequencesi���g�i�(�����x��2�3�������.�.�0�-�@��g�i�(�����)�W�%:�%:�W�g�<N�Or!N)rrrr�r�r�r r!r"r�r�s���
>�
Pr!r�N)$r��ior�zope.interfacer�zope.interface.verifyr�twisted.internet.deferr�twisted.internet.interfacesrrr	r
�twisted.internet.protocolrrr
rrr�twisted.internet.testingrr�twisted.loggerrr�twisted.python.failurer�twisted.trial.unittestrrr�r�r�r�r r!r"�<module>r�s����
�&�.�1�����I�7�*�+�u=��u=�p	%.�H�%.�PXR�8�XR�v"C�8�"C�JP�x�Pr!

Zerion Mini Shell 1.0