%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�L���dZddlmZddlmZmZmZmZmZm	Z	ddl
mZddlm
Z
ddlmZddlmZmZmZddlmZdd	lmZmZdd
lmZddlmZmZmZmZm Z m!Z!m"Z"m#Z#ddl$m%Z%dd
l&m'Z'm(Z(m)Z)m*Z*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1m2Z2m3Z3m4Z4m5Z5ddl6m7Z7m8Z8m9Z9ddl:m;Z;ddl<m=Z=ddl>m?Z@mAZAmBZBmCZCddlDmEZEmFZFddlGmHZHddlImJZJmKZKddlLmMZMddlNmOZOddlPmQZQddlRmSZSddlTmUZUddlVmWZWddlXmYZYddlZm[Z[m\Z\dd l]mZeWd!�j�j�d"�Z`eWd!�j�j�d#�ZaeWd!�j�j�d$�ZbeWec�j�j�d%�Zdedj�d&�Zfej�e`j��Ziej�eaj��Zjej�ebj��Zkej�edj��Zlej�efj��Zm	dd'lnmoZompZqmrZrmsZsdd(ltmuZumvZvmwZwmxZxmyZydd)lzm{Z{dd*l|m}Z}euj�e`j���Z�eyj�e`j���Z�d+Z�d,Z�Gd/�d0e9�Z�ee�j�Gd1�d2e���Z�ee�j�Gd3�d4e���Z�ee�j�Gd5�d6e���Z�Gd7�d8e7�Z�Gd9�d:e7�Z�Gd;�d<e�j �Z�Gd=�d>�Z�Gd?�d@�Z�GdA�dBe�e��Z�GdC�dDe8�Z�GdE�dF�Z�GdG�dHe�j �Z�GdI�dJe jr�Z�ee�j2�GdK�dLeC��Z�eejbe��eejfe��ee�j2e��ee�j6�GdM�dN��Z�GdO�dPe�j �Z�GdQ�dRe�j �Z�GdS�dTe�j �Z�GdU�dVe�e�j �Z�GdW�dXe�e�j �Z�GdY�dZe�e�j �Z�Gd[�d\eAe=�Z�d�d]�Z�Gd^�d_e�jJ�Z�Gd`�dae�j �Z�Gdb�dce��Z�Gdd�dee�e�j �Z�Gdf�dge�e�j �Z�Gdh�die�e�j �Z�Gdj�dke�e�j �Z�Gdl�dme�jJ�Z�Gdn�doe�jJ�Z�Gdp�dqe�j �Z�Gdr�dse�j �Z�ee�e��Gdt�due�e�j ��Z�Gdv�dwe�e�j �Z�Gdx�dye�j �Z�Gdz�d{e�j �Z�d�d|�Z�Gd}�d~e�j �Z�ee�e��Gd�d�e�j ��Z�Gd��d�e�e�j �Z�Gd��d�e�j �Z�Gd��d�e�j �Z�Gd��d�e�j �Z�Gd��d�e�j �Z�Gd��d�eK�jz�Z�Gd��d�eK�j~�Z�Gd��d�eJ�j��Z�Gd��d�eëZ�Gd��d�e�j �Z�d��Z�ee�e��Gd��d�e�j ��Z�d��Z�Gd��d�e�j �Z�y.#e�$rZ�d-Z�e�e��Z�Yd.Z�[����d.Z�[�wwxYw)�z�
Test the C{I...Endpoint} implementations that wrap the L{IReactorTCP},
L{IReactorSSL}, and L{IReactorUNIX} interfaces found in
L{twisted.internet.endpoints}.
�)�EPERM)�AF_INET�AF_INET6�IPPROTO_TCP�SOCK_STREAM�
AddressFamily�gaierror)�FunctionType)�	normalize)�skipIf)�implementer�
providedBy�provider)�InterfaceClass)�verifyClass�verifyObject)�plugins)�defer�	endpoints�error�
interfaces�protocol�reactor�stdio�threads)�
isIPv6Address)�HostnameAddress�IPv4Address�IPv6Address�UNIXAddress�_ProcessAddress)�StandardErrorBehavior)�ConnectingCancelledError)�	IConsumer�IHostnameResolver�
IPushProducer�IReactorPluggableNameResolver�
ITransport)�
ClientFactory�Factory�Protocol)�PipeAddress)�Clock)�MemoryReactorClock�RaisingMemoryReactor�StringTransport� StringTransportWithDisconnection)�ILogObserver�globalLogPublisher)�
getPlugins)�basic�policies)�log)�nativeString)�proxyForInterface)�Failure)�FilePath)�	getModule)�	ListenFDs)�connectableEndpoint�connectedServerAndClient)�unittestztwisted.testz
server.pemzkey.pem.no_trailing_newlinezcert.pem.no_trailing_newline�fake_CAsz	chain.pem)�
TLS_METHOD�Context�OP_NO_SSLv3�TLSv1_2_METHOD)�Certificate�CertificateOptions�DiffieHellmanParameters�KeyPair�PrivateCertificate��TLSMemoryBIOFactory)�makeCertificateF�TNc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�TestProtocolzx
    Protocol whose only function is to callback deferreds on the
    factory when it is connected or disconnected.
    c�.�g|_g|_d|_y�Nr)�data�connectionsLost�connectionMadeCalls��selfs �F/usr/lib/python3/dist-packages/twisted/internet/test/test_endpoints.py�__init__zTestProtocol.__init__|s����	�!���#$�� �c��y)N�A Test Protocol�rVs rX�	logPrefixzTestProtocol.logPrefix�s�� rZc�.�|xjdz
c_y�N�)rUrVs rX�connectionMadezTestProtocol.connectionMade�s��� � �A�%� rZc�:�|jj|�y�N)rS�append�rWrSs  rX�dataReceivedzTestProtocol.dataReceived�s���	�	����rZc�:�|jj|�yrd)rTre�rW�reasons  rX�connectionLostzTestProtocol.connectionLost�s�����#�#�F�+rZN)	�__name__�
__module__�__qualname__�__doc__rYr^rbrgrkr]rZrXrPrPvs ���
%�
!�&��,rZrPc�"�eZdZdZd�Zd�Zd�Zy)�TestHalfCloseableProtocolab
    A Protocol that implements L{IHalfCloseableProtocol} and records whether
    its C{readConnectionLost} and {writeConnectionLost} methods are called.

    @ivar readLost: A C{bool} indicating whether C{readConnectionLost} has been
        called.

    @ivar writeLost: A C{bool} indicating whether C{writeConnectionLost} has
        been called.
    c�J�tj|�d|_d|_y)NF)rPrY�readLost�	writeLostrVs rXrYz"TestHalfCloseableProtocol.__init__�s�����d�#���
���rZc��d|_y�NT)rsrVs rX�readConnectionLostz,TestHalfCloseableProtocol.readConnectionLost�s	����
rZc��d|_yrv)rtrVs rX�writeConnectionLostz-TestHalfCloseableProtocol.writeConnectionLost�s	����rZN)rlrmrnrorYrwryr]rZrXrqrq�s��	��
�rZrqc��eZdZdZd�Zd�Zy)�"TestFileDescriptorReceiverProtocola
    A Protocol that implements L{IFileDescriptorReceiver} and records how its
    C{fileDescriptorReceived} method is called.

    @ivar receivedDescriptors: A C{list} containing all of the file descriptors
        passed to C{fileDescriptorReceived} calls made on this instance.
    c�<�tj|�g|_yrd)rPrb�receivedDescriptorsrVs rXrbz1TestFileDescriptorReceiverProtocol.connectionMade�s���#�#�D�)�#%�� rZc�:�|jj|�yrd)r}re)rW�
descriptors  rX�fileDescriptorReceivedz9TestFileDescriptorReceiverProtocol.fileDescriptorReceived�s��� � �'�'�
�3rZN)rlrmrnrorbr�r]rZrXr{r{�s���&�4rZr{c��eZdZdZd�Zd�Zy)�TestHandshakeListenera
    A Protocol that implements L{IHandshakeListener} and records the
    number of times its C{handshakeCompleted} method has been called.

    @ivar handshakeCompletedCalls: The number of times
        C{handshakeCompleted}
    @type handshakeCompletedCalls: L{int}
    c�<�tj|�d|_yrR)rPrY�handshakeCompletedCallsrVs rXrYzTestHandshakeListener.__init__�s�����d�#�'(��$rZc�.�|xjdz
c_y)zk
        Called when a TLS handshake has completed.  Implemented per
        L{IHandshakeListener}
        raN)r�rVs rX�handshakeCompletedz(TestHandshakeListener.handshakeCompleted�s��
	
�$�$��)�$rZN)rlrmrnrorYr�r]rZrXr�r��s���)�*rZr�c��eZdZdZeZy)�TestFactoryz�
    Simple factory to be used both when connecting and listening. It contains
    two deferreds which are called back when my protocol connects and
    disconnects.
    N)rlrmrnrorPrr]rZrXr�r��s����HrZr�c��eZdZdZd�Zy)�NoneFactoryzC
    A one off factory whose C{buildProtocol} returns L{None}.
    c��yrdr]�rW�addrs  rX�
buildProtocolzNoneFactory.buildProtocol�s��rZN�rlrmrnror�r]rZrXr�r��s���rZr�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�WrappingFactoryTestszS
    Test the behaviour of our ugly implementation detail C{_WrappingFactory}.
    c��t�}tj|�}|j�|j	d|j
�y)z�
        L{_WrappingFactory.doStart} passes through to the wrapped factory's
        C{doStart} method, allowing application-specific setup and logging.
        raN)r)r�_WrappingFactory�doStart�assertEqual�numPorts�rW�factory�wfs   rX�test_doStartz!WrappingFactoryTests.test_doStart�s:��
 �/��
�
'�
'��
0��
�
�
������G�,�,�-rZc��t�}d|_tj|�}|j	�|jd|j�y)z�
        L{_WrappingFactory.doStop} passes through to the wrapped factory's
        C{doStop} method, allowing application-specific cleanup and logging.
        ��N)r)r�rr��doStopr�r�s   rX�test_doStopz WrappingFactoryTests.test_doStop�sB��
 �/�����
�
'�
'��
0��
�	�	������G�,�,�-rZc����Gd�dt�}tj|��}|jd��j	|j
t�}|j�fd��|S)z�
        An exception raised in C{buildProtocol} of our wrappedFactory
        results in our C{onConnection} errback being fired.
        c��eZdZdZd�Zy)�CWrappingFactoryTests.test_failedBuildProtocol.<locals>.BogusFactoryzZ
            A one off factory whose C{buildProtocol} raises an C{Exception}.
            c��td��)N�My protocol is poorly defined.)�
ValueErrorr�s  rXr�zQWrappingFactoryTests.test_failedBuildProtocol.<locals>.BogusFactory.buildProtocols�� �!A�B�BrZNr�r]rZrX�BogusFactoryr�s
��
�
CrZr�Nc�<���j|jd�S)N)r�)r��args)�erWs �rX�<lambda>z?WrappingFactoryTests.test_failedBuildProtocol.<locals>.<lambda>s���d�&�&�q�v�v�/R�S�rZ)r)rr�r��
assertFailure�
_onConnectionr��addCallback)rWr�r��ds`   rX�test_failedBuildProtocolz-WrappingFactoryTests.test_failedBuildProtocol�sa���	C�=�	C��
'�
'���
7��
��������r�/�/��<��	�
�
�S�	
��rZc��tjt��}|jd�|j	|j
tj�y)z�
        If the wrapped factory's C{buildProtocol} returns L{None} the
        C{onConnection} errback fires with L{error.NoProtocol}.
        N)rr�r�r��failureResultOfr�r�
NoProtocol�rW�wrappingFactorys  rX�test_buildNoneProtocolz+WrappingFactoryTests.test_buildNoneProtocols@��
$�4�4�[�]�C���%�%�d�+����_�:�:�E�<L�<L�MrZc��tjt��}|jj	d��|j|j
d��y)z�
        If the wrapped factory's C{buildProtocol} returns L{None} then
        L{endpoints._WrappingFactory.buildProtocol} returns L{None}.
        c��yrdr]�rjs rXr�zDWrappingFactoryTests.test_buildProtocolReturnsNone.<locals>.<lambda>&��rZN)rr�r�r��
addErrback�assertIsNoner�r�s  rX�test_buildProtocolReturnsNonez2WrappingFactoryTests.test_buildProtocolReturnsNonesD��
$�4�4�[�]�C���%�%�0�0�1D�E����/�7�7��=�>rZc��tjt��}|jd�}|j	|j�d�y)z�
        If the wrapped protocol provides L{ILoggingContext}, whatever is
        returned from the wrapped C{logPrefix} method is returned from
        L{_WrappingProtocol.logPrefix}.
        Nr\)rr�r�r�r�r^)rWr��wps   rX�test_logPrefixPassthroughz.WrappingFactoryTests.test_logPrefixPassthrough*s=���
'�
'��
�
6��
�
�
�d�
#���������):�;rZc���Gd�d�}t�}||_tj|�}|j	d�}|j|j
�d�y)z�
        If the wrapped protocol does not provide L{ILoggingContext}, the
        wrapped protocol's class name is returned from
        L{_WrappingProtocol.logPrefix}.
        c��eZdZy)�>WrappingFactoryTests.test_logPrefixDefault.<locals>.NoProtocolN�rlrmrnr]rZrXr�r�;s��rZr�N)r�rrr�r�r�r^)rWr�r�r�r�s     rX�test_logPrefixDefaultz*WrappingFactoryTests.test_logPrefixDefault4sS��	�	��-��%���
�
'�
'��
0��
�
�
�d�
#����������6rZc�d�tjt��}|jd�}|j	d�|jd�|j
|jjdg�|jd�|j
|jjddg�y)z�
        The wrapped C{Protocol}'s C{dataReceived} will get called when our
        C{_WrappingProtocol}'s C{dataReceived} gets called.
        Nsfoosbar)	rr�r�r��makeConnectionrgr��_wrappedProtocolrS)rWr��ps   rX� test_wrappedProtocolDataReceivedz5WrappingFactoryTests.test_wrappedProtocolDataReceivedDs���
�
'�
'��
�
6�����T�"��	�����	���v������+�+�0�0�6�(�;�	���v������+�+�0�0�6�6�2B�CrZc��tjt��}|jd�}t	�}|j|�|j
|j|�|j
|jj|�y)zo
        Our transport is properly hooked up to the wrappedProtocol when a
        connection is made.
        N)	rr�r�r��objectr�r��	transportr�)rWr�r��dummyTransports    rX�test_wrappedProtocolTransportz2WrappingFactoryTests.test_wrappedProtocolTransportSsk��
�
'�
'��
�
6�����T�"�����	����(�������n�5�����+�+�5�5�~�FrZc���t�}tj|�}|jd�}|j	d�|j|jjdg�y)z�
        Our wrappedProtocol's connectionLost method is called when
        L{_WrappingProtocol.connectionLost} is called.
        N�fail)r�rr�r�rkr�r�rT)rW�tfr�r�s    rX�"test_wrappedProtocolConnectionLostz7WrappingFactoryTests.test_wrappedProtocolConnectionLostcsW��
�]��
�
'�
'��
+�����T�"��	���� �����+�+�;�;�f�X�FrZc���tjt��}tt	j
d���}|j
d|�g��fd�}|jj|�|j�|g�y)z�
        Calls to L{_WrappingFactory.clientConnectionLost} should errback the
        L{_WrappingFactory._onConnection} L{Deferred}
        r���stringNc�(���j|�yrd�re)�f�errorss �rX�gotErrorzBWrappingFactoryTests.test_clientConnectionFailed.<locals>.gotError|s����M�M�!�rZ)
rr�r�r:r�ConnectError�clientConnectionFailedr�r�r�)rWr��expectedFailurer�r�s    @rX�test_clientConnectionFailedz0WrappingFactoryTests.test_clientConnectionFailedpso���
�
'�
'��
�
6��!�%�"4�"4�F�"C�D��
�!�!�$��8���	�	���#�#�H�-�����/�!2�3rZc��d}t�}tj||�}|jtj
j
|��|jttj
|��y)zv
        Our L{_WrappingProtocol} should be an L{IFileDescriptorReceiver} if the
        wrapped protocol is.
        N)r{r�_WrappingProtocol�
assertTruer�IFileDescriptorReceiverrr)rW�connectedDeferred�applicationProtocol�wrappers    rX�+test_wrappingProtocolFileDescriptorReceiverz@WrappingFactoryTests.test_wrappingProtocolFileDescriptorReceiver�s]��
!��@�B���-�-�.?�AT�U�����
�:�:�E�E�g�N�O�����Z�%G�%G��Q�RrZc��t�}tjd|�}|jtj
j
|��y)z~
        Our L{_WrappingProtocol} does not provide L{IHalfCloseableProtocol} if
        the wrapped protocol doesn't.
        N)rPrr��assertFalserr�r�rW�tpr�s   rX�.test_wrappingProtocolNotFileDescriptorReceiverzCWrappingFactoryTests.test_wrappingProtocolNotFileDescriptorReceiver�s<��
�^���'�'��b�1������;�;�F�F�q�I�JrZc��t�}tjtj�|�}|jt
��|jd�|j|jdg�y)z�
        L{_WrappingProtocol.fileDescriptorReceived} calls the wrapped
        protocol's C{fileDescriptorReceived} method.
        �*N)
r{rr�r�Deferredr�r0r�r�r})rW�wrappedProtocolr�s   rX�*test_wrappedProtocolFileDescriptorReceivedz?WrappingFactoryTests.test_wrappedProtocolFileDescriptorReceived�s\��
=�>���-�-�e�n�n�.>��P������0�1��&�&�r�*�����<�<�r�d�CrZc��t�}t�}tj||�}|j	t
jj|�d�y)zw
        Our L{_WrappingProtocol} should be an L{IHalfCloseableProtocol} if the
        C{wrappedProtocol} is.
        TN)r�rqrr�r�r�IHalfCloseableProtocolr)rW�cd�hcpr�s    rX�"test_wrappingProtocolHalfCloseablez7WrappingFactoryTests.test_wrappingProtocolHalfCloseable�sF��
�X��'�)���'�'��C�0������:�:�E�E�a�H�$�OrZc��t�}tjd|�}|jtj
j
|�d�y)z�
        Our L{_WrappingProtocol} should not provide L{IHalfCloseableProtocol}
        if the C{WrappedProtocol} doesn't.
        NF)rPrr�r�rr�rr�s   rX�%test_wrappingProtocolNotHalfCloseablez:WrappingFactoryTests.test_wrappingProtocolNotHalfCloseable�s>��
�^���'�'��b�1������:�:�E�E�a�H�%�PrZc��t�}tjd|�}|jtj
j
|��y)zs
        Our L{_WrappingProtocol} should be an L{IHandshakeListener} if
        the C{wrappedProtocol} is.
        N)r�rr�r�r�IHandshakeListenerr)rW�handshakeListener�wrappeds   rX�&test_wrappingProtocolHandshakeListenerz;WrappingFactoryTests.test_wrappingProtocolHandshakeListener�s=��
2�3���-�-�d�4E�F�����
�5�5�@�@��I�JrZc��t�}tjd|�}|jtj
j
|��y)z~
        Our L{_WrappingProtocol} should not provide L{IHandshakeListener}
        if the C{wrappedProtocol} doesn't.
        N)rPrr�r�rr�rr�s   rX�)test_wrappingProtocolNotHandshakeListenerz>WrappingFactoryTests.test_wrappingProtocolNotHandshakeListener�s<��
�^���'�'��b�1������6�6�A�A�!�D�ErZc��t�}tjd|�}|j�|j	|j
�y)z~
        L{_WrappingProtocol.readConnectionLost} should proxy to the wrapped
        protocol's C{readConnectionLost}
        N)rqrr�rwr�rs�rWr�r�s   rX�&test_wrappedProtocolReadConnectionLostz;WrappingFactoryTests.test_wrappedProtocolReadConnectionLost�s:��
(�)���'�'��c�2��	����������%rZc��t�}tjd|�}|j�|j	|j
�y)z�
        L{_WrappingProtocol.writeConnectionLost} should proxy to the wrapped
        protocol's C{writeConnectionLost}
        N)rqrr�ryr�rtrs   rX�'test_wrappedProtocolWriteConnectionLostz<WrappingFactoryTests.test_wrappedProtocolWriteConnectionLost�s:��
(�)���'�'��c�2��	��������
�
�&rZc��t�}tjd|�}|j�|j	|j
d�y)z~
        L{_WrappingProtocol.handshakeCompleted} should proxy to the
        wrapped protocol's C{handshakeCompleted}
        Nra)r�rr�r�r�r�)rW�listenerr�s   rX�&test_wrappedProtocolHandshakeCompletedz;WrappingFactoryTests.test_wrappedProtocolHandshakeCompleted�s@��
)�*���-�-�d�H�=���"�"�$�����9�9�1�=rZN)rlrmrnror�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr]rZrXr�r��s{���.�	.��2N�	?�<�7� 
D�G� G�4�&	S�K�	D�P�Q�K�F�&�'�>rZr�c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�ClientEndpointTestCaseMixin�Q
    Generic test methods to be mixed into all client endpoint test classes.
    c��t�}|jt�|�\}}}|jt	t
j|��y)zK
        The endpoint provides L{interfaces.IStreamClientEndpoint}
        N)r��createClientEndpoint�
MemoryReactorr�rr�IStreamClientEndpoint)rW�
clientFactory�ep�ignoredArgs�addresss     rX�test_interfacez*ClientEndpointTestCaseMixin.test_interface�sD����
�#'�#<�#<��O�]�$
� ��K��	
����Z�%E�%E�r�J�KrZc�0�|j|�ddS)z�
        Retrieve a single factory that has connected using the given reactor.
        (This behavior is valid for TCP and SSL but needs to be overridden for
        UNIX.)

        @param reactor: a L{MemoryReactor}
        rr���expectedClients�rWrs  rX�retrieveConnectedFactoryz4ClientEndpointTestCaseMixin.retrieveConnectedFactory�s���#�#�G�,�Q�/��2�2rZc���t�}t�}t�}|j||�\}}}|j|�}g��fd�}|j	|�|j|�}	|	jj|�|j�|g�|j|�}
|jt|
�d�|j|
d|�y)z}
        A client endpoint can connect and returns a deferred who gets called
        back with a protocol instance.
        c�(���j|�yrdr��r��receivedProtoss �rX�
checkProtozKClientEndpointTestCaseMixin.test_endpointConnectSuccess.<locals>.checkProto�����!�!�!�$rZrarN)r�rr�connectr�rr��callbackr�r�len�assertConnectArgs�rW�proto�mreactorrr�expectedArgs�ignoredDestr�rr�rrs           @rX�test_endpointConnectSuccessz7ClientEndpointTestCaseMixin.test_endpointConnectSuccess�s����
��� �?����
�(,�(A�(A��m�)
�%��L�+�
�J�J�}�%����	%�	
�
�
�j�!��/�/��9�����&�&�u�-�����%��1��.�.�x�8������_�-�q�1�����q�1�<�@rZc��	�tjd��}t|��}t�}|j	||�\}}}|j|�}g�	�	fd�}|j
|�|j�	|g�y)�t
        If an endpoint tries to connect to a non-listening port it gets
        a C{ConnectError} failure.
        �Connection Failedr���connectExceptionc�<���j|j�yrd�re�value�r��receivedExceptionss �rX�checkFailurezMClientEndpointTestCaseMixin.test_endpointConnectFailure.<locals>.checkFailure2�����%�%�a�g�g�.rZN)rr�r/r�rrr�r�)
rW�
expectedErrorr$rrrr&r�r2r1s
         @rX�test_endpointConnectFailurez7ClientEndpointTestCaseMixin.test_endpointConnectFailures���
�*�*�2E�F�
�'��G����
�'+�'@�'@��m�(
�$��K��
�J�J�}�%����	/�	
���\�"����+�m�_�=rZc�(�
�t�}t�}|j||�\}}}|j|�}g�
�
fd�}|j	|�|j�|j
|�}|jdttj���|jt�
�d��
d}	|j|	jtj�|j|	jj |�y)��
        Calling L{Deferred.cancel} on the L{Deferred} returned from
        L{IStreamClientEndpoint.connect} is errbacked with an expected
        L{ConnectingCancelledError} exception.
        c�(���j|�yrdr�)r��receivedFailuress �rXr2zRClientEndpointTestCaseMixin.test_endpointConnectingCancelled.<locals>.checkFailureIs����#�#�A�&rZNrar)rr�rrr��cancelrr�r:r�	UserErrorr�r �assertIsInstancer/r#r)rWr$rrrrr�r2�attemptFactory�failurer9s          @rX� test_endpointConnectingCancelledz<ClientEndpointTestCaseMixin.test_endpointConnectingCancelled9s����!�?����
�#'�#<�#<�X�}�#U� ��K���J�J�}�%����	'�	
���\�"�	���
��6�6�x�@���-�-�d�G�E�O�O�<M�4N�O�	
����-�.��2�"�1�%�����g�m�m�U�-K�-K�L�������.�.��8rZc��t�}t�}|j||fi|j���\}}}|j	|�|j|�}|j
t|�d�|j|d|�y)zn
        The endpoint should pass it's connectArgs parameter to the reactor's
        listen methods.
        rarN)	r�rr�connectArgsrrr�r r!)rWr�r$rr%�ignoredHostrs       rX�"test_endpointConnectNonDefaultArgsz>ClientEndpointTestCaseMixin.test_endpointConnectNonDefaultArgs\s���
�(�� �?��(A��(A�(A��g�)
�!%�!1�!1�!3�)
�%��L�+�	�
�
�7���.�.�x�8������_�-�q�1�����q�1�<�@rZN)
rlrmrnrorrr'r5r?rCr]rZrXrr�s*���L�3�A�@>�4!9�FArZrc�(�eZdZdZd�Zd�Zd�Zd�Zy)�ServerEndpointTestCaseMixinr	c��t�}|jt�|�\}}}|jt	t
j|��y)zL
        The endpoint provides L{interfaces.IStreamServerEndpoint}.
        N)r��createServerEndpointrr�rr�IStreamServerEndpoint)rWr�rrr&s     rXrz*ServerEndpointTestCaseMixin.test_interfacevsD���(��'+�'@�'@��O�W�(
�$��K��	
����Z�%E�%E�r�J�KrZc���t�}t�}|j||�\}}}|j|�}g��fd�}|j	|�|j�|g�|j|j
|�|g�y)zs
        An endpoint can listen and returns a deferred that gets called back
        with a port instance.
        c�D���j|j��yrd)re�getHost)�port�
receivedHostss �rX�checkPortAndServerzRServerEndpointTestCaseMixin.test_endpointListenSuccess.<locals>.checkPortAndServer�s���� � �����0rZN)rr�rG�listenr�r��expectedServers)	rWr$r�rr%�expectedHostr�rNrMs	        @rX�test_endpointListenSuccessz6ServerEndpointTestCaseMixin.test_endpointListenSuccess�s����
!�?���(��)-�)B�)B�8�W�)U�&��L�,��I�I�g����
�	1�	
�
�
�(�)�������7�����-�-�h�7�,��HrZc��	�t�}tjdd|�}t|��}|j	||�\}}}|jt��}g�	�	fd�}|j
|�|j�	|g�y)z�
        When an endpoint tries to listen on an already listening port, a
        C{CannotListenError} failure is errbacked.
        rN�P)�listenExceptionc�<���j|j�yrdr.r0s �rXr2zLServerEndpointTestCaseMixin.test_endpointListenFailure.<locals>.checkFailure�r3rZN)r�r�CannotListenErrorr/rGrOr�r�)
rWr��	exceptionr$rrr&r�r2r1s
         @rX�test_endpointListenFailurez6ServerEndpointTestCaseMixin.test_endpointListenFailure�s���
�(���+�+�B��G�<�	�'�	�B��'+�'@�'@��7�'S�$��K���I�I�f�h�����	/�	
���\�"����+�i�[�9rZc���t�}t�}|j||fi|j���\}}}|j	|�|j|�}|j
||g�y)zm
        The endpoint should pass it's listenArgs parameter to the reactor's
        listen methods.
        N)r�rrG�
listenArgsrOrPr�)rWr�r$rr%rBrPs       rX�!test_endpointListenNonDefaultArgsz=ServerEndpointTestCaseMixin.test_endpointListenNonDefaultArgs�so��
�(�� �?��(A��(A�(A��g�)
�!%���!2�)
�%��L�+�	�	�	�'���.�.�x�8������<�.�9rZN)rlrmrnrorrRrYr\r]rZrXrErEqs���L�I�.:�,:rZrEc��eZdZdZy)�EndpointTestCaseMixinzJ
    Generic test methods to be mixed into all endpoint test classes.
    N�rlrmrnror]rZrXr^r^�s��rZr^c��eZdZdZd�Zd�Zy)�SpecificFactoryz�
    An L{IProtocolFactory} whose C{buildProtocol} always returns its
    C{specificProtocol} and sets C{passedAddress}.

    Raising an exception if C{specificProtocol} has already been used.
    c��||_yrd)�specificProtocol)rWrcs  rXrYzSpecificFactory.__init__�s
�� 0��rZc�~�t|jd�rtd��||j_|jS)N�
passedAddresszspecificProtocol already used.)�hasattrrcr�rer�s  rXr�zSpecificFactory.buildProtocol�s8���4�(�(�/�:��=�>�>�.2����+��$�$�$rZN)rlrmrnrorYr�r]rZrXrara�s���1�%rZrac��eZdZdZdd�Zy)�	FakeStdioz_
    A L{stdio.StandardIO} like object that simply captures its constructor
    arguments.
    Nc� �||_||_y)z�
        @param protocolInstance: like the first argument of L{stdio.StandardIO}

        @param reactor: like the reactor keyword argument of
            L{stdio.StandardIO}
        N)�protocolInstancer)rWrjrs   rXrYzFakeStdio.__init__�s��!1�����rZrd�rlrmrnrorYr]rZrXrhrh�s���
rZrhc�"�eZdZdZd�Zd�Zd�Zy)�StandardIOEndpointsTestsz*
    Tests for Standard I/O Endpoints
    c�X�t�|_tj|j�}|j	|j
tj�t|_t�|_
|j|jt|j���|_y)z�
        Construct a L{StandardIOEndpoint} with a dummy reactor and a fake
        L{stdio.StandardIO} like object.  Listening on it with a
        L{SpecificFactory}.
        N)r�rr�StandardIOEndpoint�assertIs�_stdior�
StandardIOrhr+rc�successResultOfrOra�	fakeStdio�rW�endpoints  rX�setUpzStandardIOEndpointsTests.setUp�ss���x����/�/����=���
�
�h�o�o�u�'7�'7�8�#��� (�
����-�-��O�O�O�D�,A�,A�B�C�
��rZc���|j|jj|j�|j	|jjj
t�y)z�
        L{StandardIOEndpoint} returns a L{Deferred} that fires with an instance
        of a L{stdio.StandardIO} like object that was passed the result of
        L{SpecificFactory.buildProtocol} which was passed a L{PipeAddress}.
        N)rprtrjrcr<rer,rVs rX�test_protocolCreationz.StandardIOEndpointsTests.test_protocolCreationsE��	
�
�
�d�n�n�5�5�t�7L�7L�M�����N�N�+�+�9�9�;�	
rZc�d�|j|jj|j�y)z�
        L{StandardIOEndpoint} passes its C{reactor} argument to the constructor
        of its L{stdio.StandardIO} like object.
        N)rprtrrVs rX�test_passedReactorz+StandardIOEndpointsTests.test_passedReactors ��
	
�
�
�d�n�n�,�,�d�l�l�;rZN)rlrmrnrorwryr{r]rZrXrmrm�s���
�"	
�<rZrmc��eZdZdZd�Zd�Zy)�StubApplicationProtocolz#
    An L{IProtocol} provider.
    c��||_y)zY
        @param data: The data received by the protocol.
        @type data: str
        N)rSrfs  rXrgz$StubApplicationProtocol.dataReceiveds��
��	rZc��||_y)zA
        @type reason: L{twisted.python.failure.Failure}
        Nr�ris  rXrkz&StubApplicationProtocol.connectionLosts����rZN)rlrmrnrorgrkr]rZrXr}r}s����rZr}c�N��eZdZdZd
�fd�	Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Z�xZS)�MemoryProcessTransportzC
    A fake L{IProcessTransport} provider to be used in tests.
    c���t�|�t�t���g|_t	�|_t
�|_y)N)�hostAddress�peerAddress)�superrYr!�signals�set�closedChildFDsr+r)rWr�	__class__s  �rXrYzMemoryProcessTransport.__init__,s5���
���_�%6�O�DU��V����!�e��� �
��
rZc�2�|dk(r|j|�yyrR��write)rW�childFDrSs   rX�writeToChildz#MemoryProcessTransport.writeToChild2s���a�<��J�J�t��rZc�&�|jd�yrR��closeChildFDrVs rX�
closeStdinz!MemoryProcessTransport.closeStdin6������!�rZc�&�|jd�yr`r�rVs rX�closeStdoutz"MemoryProcessTransport.closeStdout9r�rZc�&�|jd�y)Nr�r�rVs rX�closeStderrz"MemoryProcessTransport.closeStderr<r�rZc�:�|jj|�yrd)r��add)rW�fds  rXr�z#MemoryProcessTransport.closeChildFD?s��������#rZc�:�|jj|�yrd)r�re)rW�signals  rX�
signalProcessz$MemoryProcessTransport.signalProcessBs�������F�#rZc��yrdr]rVs rX�pidzMemoryProcessTransport.pidEs��rZrd)
rlrmrnrorYr�r�r�r�r�r�r��
__classcell__�r�s@rXr�r�&s0����#�����$�$�
rZr�c�&�eZdZdZdidddddfd�Zy)�MemoryProcessReactorzA
    A fake L{IReactorProcess} provider to be used in tests.
    r]Nrc
��||_||_||_||_||_||_||_||_|	|_t�|_
|jj|j�|jS)z�
        @ivar processProtocol: Stores the protocol passed to the reactor.
        @return: An L{IProcessTransport} provider.
        )�processProtocol�
executabler��env�path�uid�gid�usePTY�childFDsr��processTransportr�)
rWr�r�r�r�r�r�r�r�r�s
          rX�spawnProcessz!MemoryProcessReactor.spawnProcessUsu��  /���$�����	������	���������� ��
� 6� 8������+�+�D�,A�,A�B��$�$�$rZ)rlrmrnror�r]rZrXr�r�Os#�����
�����%rZr�c�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�ProcessEndpointsTestsz,
    Tests for child process endpoints.
    c���t�|_tj|jd�|_tj�|_t|j_y�N�/bin/executable)	r�rr�ProcessEndpointrrr*r�r}rVs rXrwzProcessEndpointsTests.setUpysA��+�-����+�+�D�L�L�:L�M����'�'�)��� 7����rZc��|j|jjt�|j	|jj
d�|j	|jjd�|j	|jji�|j|jj�|j|jj�|j|jj�|j	|jjd�|j|jj�|j	|jjtj �y)zU
        Default values are set for the optional parameters in the endpoint.
        r�r]rN)r<r�_reactorr�r��_executable�_args�_envr��_path�_uid�_gid�_usePTY�	_childFDs�_errFlagr"�LOGrVs rX�test_constructorDefaultsz.ProcessEndpointsTests.test_constructorDefaultss���	
���d�g�g�.�.�0D�E�������,�,�.@�A����������+���������r�*����$�'�'�-�-�(����$�'�'�,�,�'����$�'�'�,�,�'���������!�,����$�'�'�+�+�,�������)�)�+@�+D�+D�ErZc���ddi}tjt�ddgd|didddddd	d	d
�tj�
}|j|jt�|j|jd�|j|jdg�|j|jd|di�|j|jd�|j|jd�|j|jd�|j|j�|j|j dd	d	d
��|j|j"tj�y)zI
        The parameters passed to the endpoint are stored in it.
        �HOMENr��/runProcessHere/rar�T�w�r�r���)rr�r�r"�DROPr<r�r�r�r�r�r�r�r�r�r�r�r�)rW�environrs   rX�test_constructorNonDefaultsz1ProcessEndpointsTests.test_constructorNonDefaults�s=���D�/��
�
&�
&� �"��
� �
�g�g�&�'��
�
�����$�!�&�&�
��	
���b�k�k�+?�@�������);�<�������$6�#7�8�������7�G�G�,<�"=�>�������#6�7�������!�$�������!�$�����
�
�#�������3�3�3�'?�@�������&;�&@�&@�ArZc���|jj|j�}|j|�|jj
}|j
|tj�y)z�
        The wrapper function _WrapIProtocol gives an IProcessProtocol
        implementation that wraps over an IProtocol.
        N)	rrr�rsrr�r<r�_WrapIProtocol�rWr��wpps   rX�test_wrappedProtocolz*ProcessEndpointsTests.test_wrappedProtocol�sM��

�G�G�O�O�D�L�L�)�����Q���l�l�*�*�����c�9�#;�#;�<rZc�z�ddi}t�}tj|ddgd|didddddd	d	d
��	}|j|j�}|j|�|j
|jtj�|j|j|j�|j|j|j�|j|j|j�|j|j |j"�|j|j$|j&�|j|j(|j*�|j|j,|j.�|j|j0|j2�y)z�
        The parameters for spawnProcess stored in the endpoint are passed when
        the endpoint's connect method is invoked.
        r�Nr�r�rar�Tr�r�r�)r�rr�rr�rsr<r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�)rWr��
memoryReactorrr�s     rX�test_spawnProcessz'ProcessEndpointsTests.test_spawnProcess�sb��
�D�/��,�.�
�
�
&�
&���
� �
�g�g�&�'��
�
�����$�

��
�J�J�t�|�|�$�����Q�����m�;�;�Y�=U�=U�V�����1�1�2�>�>�B�����+�+�R�X�X�6�����*�*�B�G�G�4�����+�+�R�X�X�6�����*�*�B�G�G�4�����*�*�B�G�G�4�����-�-�r�z�z�:�����/�/����>rZc���Gd�dtj�}|�}|jj|�}|j	|�|j|jt�y)zz
        The address passed to the factory's buildProtocol in the endpoint is a
        _ProcessAddress instance.
        c��eZdZeZdZd�Zy)�BProcessEndpointsTests.test_processAddress.<locals>.TestAddrFactoryNc�B�||_|j�}||_|Srd)rrr�)rWr�r�s   rXr�zPProcessEndpointsTests.test_processAddress.<locals>.TestAddrFactory.buildProtocol�s ��#����M�M�O�� ��	��rZ)rlrmrnr}rrr�r]rZrX�TestAddrFactoryr��s��.�H��G�
rZr�N)rr*rrrsr<rr!)rWr��	myFactoryr�s    rX�test_processAddressz)ProcessEndpointsTests.test_processAddress�sT��	�h�.�.�	�$�%�	��G�G�O�O�I�&�����Q�����i�/�/��ArZc��|j|jj|j��}|j	|t
�y)zd
        L{ProcessEndpoint.connect} returns a Deferred with the connected
        protocol.
        N)rsrrr�r<r})rWr#s  rX�test_connectz"ProcessEndpointsTests.test_connect�s6��
�$�$�T�W�W�_�_�T�\�\�%B�C�����e�%<�=rZc���d�}||j_|jj|j�}|j	|�}|j
t�y)zg
        In case of failure, L{ProcessEndpoint.connect} returns a Deferred that
        fails.
        c	��t��rd)�	Exception)	�ppr�r�r�r�r�r�r�r�s	         rX�testSpawnProcesszCProcessEndpointsTests.test_connectFailure.<locals>.testSpawnProcess�s���+�rZN)r�
_spawnProcessrr�r��trapr�)rWr�r�rs    rX�test_connectFailurez)ProcessEndpointsTests.test_connectFailure�sI��	�
!1������G�G�O�O�D�L�L�)���$�$�Q�'����
�
�9�rZN)rlrmrnrorwr�r�r�r�r�r�r�r]rZrXr�r�ts3���8�
F�B�:=�?�@B�*>�rZr�c�p�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zy)�ProcessEndpointTransportTestsze
    Test the behaviour of the implementation detail
    L{endpoints._ProcessEndpointTransport}.
    c�F�t�|_tj|jd�|_|j|jj
tjt���}|jj|_|j|_
yr�)r�rrr�rvrsrr*�forProtocolr+r��processr��endpointTransport)rWrs  rXrwz#ProcessEndpointTransportTests.setUp	ss��+�-���!�1�1�$�,�,�@R�S��
��'�'��M�M�!�!�'�"5�"5�h�"?�@�
���|�|�4�4���!)�!3�!3��rZc�8�tt|j�y)zE
        L{_ProcessEndpointTransport}s provide L{IConsumer}.
        N)rr$r�rVs rX�test_verifyConsumerz1ProcessEndpointTransportTests.test_verifyConsumers��	�Y�� 6� 6�7rZc�8�tt|j�y)zI
        L{_ProcessEndpointTransport}s provide L{IPushProducer}.
        N)rr&r�rVs rX�test_verifyProducerz1ProcessEndpointTransportTests.test_verifyProducers��	�]�D�$:�$:�;rZc�8�tt|j�y)zF
        L{_ProcessEndpointTransport}s provide L{ITransport}.
        N)rr(r�rVs rX�test_verifyTransportz2ProcessEndpointTransportTests.test_verifyTransports��	�Z��!7�!7�8rZc�d�|j|jj|j�y)zd
        The L{_ProcessEndpointTransport} instance stores the process passed to
        it.
        N)rpr��_processr�rVs rX�test_constructorz.ProcessEndpointTransportTests.test_constructor$s"��
	
�
�
�d�,�,�5�5�t�|�|�DrZc���tt�Gd�d��}|�}|jj|d�|j	|j
j|�y)z�
        Registering a producer with the endpoint transport registers it with
        the underlying process transport.
        c��eZdZy)�FProcessEndpointTransportTests.test_registerProducer.<locals>.AProducerNr�r]rZrX�	AProducerr�1s��rZr�FN)r
r&r��registerProducerrpr��producer)rWr��	aProducers   rX�test_registerProducerz3ProcessEndpointTransportTests.test_registerProducer+sW��
�]�	#�	�	�
$�	��K�	����/�/�	�5�A��
�
�d�l�l�+�+�Y�7rZc��|jj�|j|jjd�y)zY
        Pausing the endpoint transport pauses the underlying process transport.
        �pausedN)r��pauseProducingr�r��
producerStaterVs rX�test_pauseProducingz1ProcessEndpointTransportTests.test_pauseProducing9s0��	
���-�-�/�������3�3�X�>rZc��|j�|jj�|j|jj
d�y)zc
        Resuming the endpoint transport resumes the underlying process
        transport.
        �	producingN)rr��resumeProducingr�r�rrVs rX�test_resumeProducingz2ProcessEndpointTransportTests.test_resumeProducing@s<��
	
� � �"����.�.�0�������3�3�[�ArZc��|jj�|j|jjd�y)zo
        Stopping the endpoint transport as a producer stops the underlying
        process transport.
        �stoppedN)r��
stopProducingr�r�rrVs rX�test_stopProducingz0ProcessEndpointTransportTests.test_stopProducingIs0��
	
���,�,�.�������3�3�Y�?rZc��|j�|jj�|j|jj
�y)z�
        Unregistring the endpoint transport's producer unregisters the
        underlying process transport's producer.
        N)r�r��unregisterProducerr�r�r�rVs rX�test_unregisterProducerz5ProcessEndpointTransportTests.test_unregisterProducerQs:��
	
�"�"�$����1�1�3����$�,�,�/�/�0rZc�r�g|j_|jtt|j
d�y)z�
        L{endpoints._ProcessEndpointTransport} filters out extraneous
        attributes of its underlying transport, to present a more consistent
        cross-platform view of subprocesses and prevent accidental
        dependencies.
        �pipesN)r�r�assertRaises�AttributeError�getattrr�rVs rX�test_extraneousAttributesz7ProcessEndpointTransportTests.test_extraneousAttributesZs*�� ��������.�'�4�3I�3I�7�SrZc��|jjgd��|j|jjj�d�y)z�
        The writeSequence method of L{_ProcessEndpointTransport} writes a list
        of string passed to it to the transport's stdin.
        )stest1stest2stest3stest1test2test3N)r��
writeSequencer�r��io�getvaluerVs rX�test_writeSequencez0ProcessEndpointTransportTests.test_writeSequenceds;��
	
���,�,�-K�L���������1�1�3�5G�HrZc��|jjd�|j|jjj�d�y)z�
        The write method of L{_ProcessEndpointTransport} writes a string of
        data passed to it to the child process's stdin.
        stestN)r�r�r�r�rrrVs rX�
test_writez(ProcessEndpointTransportTests.test_writels9��
	
���$�$�W�-���������1�1�3�W�=rZc��|jj�|j|jj�y)z�
        A call to the loseConnection method of a L{_ProcessEndpointTransport}
        instance returns a call to the process transport's loseConnection.
        N)r��loseConnectionr�r��	connectedrVs rX�test_loseConnectionz1ProcessEndpointTransportTests.test_loseConnectionts.��
	
���-�-�/�������/�/�0rZc��|jj�}|j|t�|j	||j
j��y)z�
        L{_ProcessEndpointTransport.getHost} returns a L{_ProcessAddress}
        instance matching the process C{getHost}.
        N)r�rKr<r!rpr�)rW�hosts  rX�test_getHostz*ProcessEndpointTransportTests.test_getHost|�C��
�%�%�-�-�/�����d�O�4��
�
�d�D�L�L�0�0�2�3rZc��|jj�}|j|t�|j	||j
j��y)z�
        L{_ProcessEndpointTransport.getPeer} returns a L{_ProcessAddress}
        instance matching the process C{getPeer}.
        N)r��getPeerr<r!rpr�)rW�peers  rX�test_getPeerz*ProcessEndpointTransportTests.test_getPeer�r!rZN)rlrmrnrorwr�r�r�r�r�rrr	rrrrrr r%r]rZrXr�r�s\���
4�8�<�9�E�8�?�B�@�1�T�I�>�1�4�4rZr�c�F�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�WrappedIProtocolTestszL
    Test the behaviour of the implementation detail C{_WrapIProtocol}.
    c���t�|_tj|jd�|_d|_t
j�|_t|j_yr�)
r�rrr�r�eventLogrr*r�r}rVs rXrwzWrappedIProtocolTests.setUp�sH��+�-����+�+�D�L�L�:L�M�����
��'�'�)��� 7����rZc�<�|jj|j�}|j|�|jj
}|j
|jt�|j|j|jj�y)zQ
        Stores an L{IProtocol} provider and the flag to log/drop stderr
        N)rrr�rsrr�r<rr}r��errFlagr�r�s   rXr�z&WrappedIProtocolTests.test_constructor�sj��
�G�G�O�O�D�L�L�)�����Q���l�l�*�*�����c�l�l�,C�D�������d�g�g�&6�&6�7rZc��|jj|j�}|j|�|jj
}|j
|jj|j�y)zx
        Our process transport is properly hooked up to the wrappedIProtocol
        when a connection is made.
        N)	rrr�rsrr�r�rr�r�s   rX�test_makeConnectionz)WrappedIProtocolTests.test_makeConnection�sU��

�G�G�O�O�D�L�L�)�����Q���l�l�*�*��������/�/����?rZc��||_y)z!
        A log observer.
        N)r))rW�	eventDicts  rX�_stdLogzWrappedIProtocolTests._stdLog�s��"��
rZc��|jj|j�}|j|�|jj
}t
j|j�|jtj|j�|jdd�|j|jd|j�|j|jdd�|j|jd|j�|j!dt
j"|j��y)z�
        When the _errFlag is set to L{StandardErrorBehavior.LOG},
        L{endpoints._WrapIProtocol} logs stderr (in childDataReceived).
        r�sstderr1r�rSrzwrote stderr unhandled byN)rrr�rsrr�r7�addObserverr0�
addCleanup�removeObserver�childDataReceivedr�r)r�r�assertIn�textFromEventDictr�s   rX�test_logStderrz$WrappedIProtocolTests.test_logStderr�s���

�G�G�O�O�D�L�L�)�����Q���l�l�*�*��������%�����*�*�D�L�L�9����a��,�������|�4�c�n�n�E�������v�.�
�;�������z�2�C�L�L�A��
�
�1�3�3H�3H����3W�XrZc���tj|j_|jj	|j
�}|j
|�|jj}tj|j�|jtj|j�|jdd�|j|j �y)z�
        When the _errFlag is set to L{StandardErrorBehavior.DROP},
        L{endpoints._WrapIProtocol} ignores stderr.
        r�sstderr2N)r"r�rr�rr�rsrr�r7r2r0r3r4r5r�r)r�s   rX�test_stderrSkipz%WrappedIProtocolTests.test_stderrSkip�s���
1�5�5������G�G�O�O�D�L�L�)�����Q���l�l�*�*��������%�����*�*�D�L�L�9����a��,����$�-�-�(rZc��|jj|j�}|j|�|jj
}|j
dd�|j|jjd�y)z�
        In childDataReceived of L{_WrappedIProtocol} instance, the protocol's
        dataReceived is called when stdout is generated.
        rasstdoutN)
rrr�rsrr�r5r�rrSr�s   rX�test_stdoutz!WrappedIProtocolTests.test_stdout�sa��

�G�G�O�O�D�L�L�)�����Q���l�l�*�*�����a��+�������*�*�I�6rZc��|jj|j�}|j|�|jj
}|j
ttjd���|j|jjjtj�tj�y)z�
        L{error.ProcessDone} with status=0 is turned into a clean disconnect
        type, i.e. L{error.ConnectionDone}.
        rN)rrr�rsrr��processEndedr:r�ProcessDoner�rrj�check�ConnectionDoner�s   rX�test_processDonez&WrappedIProtocolTests.test_processDone�s���

�G�G�O�O�D�L�L�)�����Q���l�l�*�*�������!2�!2�1�!5�6�7�����L�L���%�%�e�&:�&:�;�U�=Q�=Q�	
rZc��|jj|j�}|j|�|jj
}|j
ttj���|j|jjjtj�tj�y)z{
        Exceptions other than L{error.ProcessDone} with status=0 are turned
        into L{error.ConnectionLost}.
        N)rrr�rsrr�r>r:r�ProcessTerminatedr�rrjr@�ConnectionLostr�s   rX�test_processEndedz'WrappedIProtocolTests.test_processEnded�s���

�G�G�O�O�D�L�L�)�����Q���l�l�*�*�������!8�!8�!:�;�<�����L�L���%�%�e�&:�&:�;�U�=Q�=Q�	
rZN)
rlrmrnrorwr�r-r0r8r:r<rBrFr]rZrXr'r'�s6���8�8�@�"�Y�"
)�
7�
�
rZr'c�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�TCP4EndpointsTestsz'
    Tests for TCP IPv4 Endpoints.
    c��|jS�zD
        @return: List of calls to L{IReactorTCP.listenTCP}
        ��
tcpServersrs  rXrPz"TCP4EndpointsTests.expectedServers����!�!�!rZc��|jS�zE
        @return: List of calls to L{IReactorTCP.connectTCP}
        ��
tcpClientsrs  rXrz"TCP4EndpointsTests.expectedClients	rMrZc��|\}}}}}|\}}	}
}}|j||�|j||	�|j||�|j||�y�a]
        Compare host, port, timeout, and bindAddress in C{receivedArgs}
        to C{expectedArgs}.  We ignore the factory because we don't
        only care what protocol comes out of the
        C{IStreamClientEndpoint.connect} call.

        @param receivedArgs: C{tuple} of (C{host}, C{port}, C{factory},
            C{timeout}, C{bindAddress}) that was passed to
            L{IReactorTCP.connectTCP}.
        @param expectedArgs: C{tuple} of (C{host}, C{port}, C{factory},
            C{timeout}, C{bindAddress}) that we expect to have been passed
            to L{IReactorTCP.connectTCP}.
        N�r��
rW�receivedArgsr%rrL�ignoredFactory�timeout�bindAddressrQ�expectedPort�_ignoredFactory�expectedTimeout�expectedBindAddresss
             rXr!z$TCP4EndpointsTests.assertConnectArgs�q��>J�:��t�^�W�k�
�
	
������	
����|�,�����|�,�����/�2�����&9�:rZc��ddd�S��K
        @return: C{dict} of keyword arguments to pass to connect.
        �
��	localhosti���rXrYr]rVs rXrAzTCP4EndpointsTests.connectArgs+����.B�C�CrZc��ddd�S��I
        @return: C{dict} of keyword arguments to pass to listen
        �d�	127.0.0.1��backlog�	interfacer]rVs rXr[zTCP4EndpointsTests.listenArgs1����[�9�9rZc��tddd�}tj||jfi|��|j||j	dd�|j	dd�f|fS)a�
        Create an L{TCP4ServerEndpoint} and return the values needed to verify
        its behaviour.

        @param reactor: A fake L{IReactorTCP} that L{TCP4ServerEndpoint} can
            call L{IReactorTCP.listenTCP} on.
        @param factory: The thing that we expect to be passed to our
            L{IStreamServerEndpoint.listen} implementation.
        @param listenArgs: Optional dictionary of arguments to
            L{IReactorTCP.listenTCP}.
        �TCP�0.0.0.0rrm�2rnrN)rr�TCP4ServerEndpointrL�get�rWrr�r[rs     rXrGz'TCP4EndpointsTests.createServerEndpoint7sg���e�Y��2��
�(�(��'�,�,�M�*�M��������y�"�-����{�B�/�	
�
�	
�		
rZc	���tddd�}tj||j|jfi|��|j|j||jdd�|jdd�f|fS)a�
        Create an L{TCP4ClientEndpoint} and return the values needed to verify
        its behavior.

        @param reactor: A fake L{IReactorTCP} that L{TCP4ClientEndpoint} can
            call L{IReactorTCP.connectTCP} on.
        @param clientFactory: The thing that we expect to be passed to our
            L{IStreamClientEndpoint.connect} implementation.
        @param connectArgs: Optional dictionary of arguments to
            L{IReactorTCP.connectTCP}
        rqrdrTrX�rYN)rr�TCP4ClientEndpointrrLru�rWrrrArs     rXrz'TCP4EndpointsTests.createClientEndpointPs|���e�[�"�5��
�(�(�����w�|�|�
�7B�
�����������	�2�.����
�t�4�
�
�
�	
rZN�rlrmrnrorPrr!rAr[rGrr]rZrXrHrH�s+���"�"�;�8D�:�
�2
rZrHc�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�TCP6EndpointsTestsz'
    Tests for TCP IPv6 Endpoints.
    c��|jSrJrKrs  rXrPz"TCP6EndpointsTests.expectedServersrrMrZc��|jSrOrPrs  rXrz"TCP6EndpointsTests.expectedClientsxrMrZc��|\}}}}}|\}}	}
}}|j||�|j||	�|j||�|j||�yrSrTrUs
             rXr!z$TCP6EndpointsTests.assertConnectArgs~r^rZc��ddd�Sr`r]rVs rXrAzTCP6EndpointsTests.connectArgs�rfrZc��ddd�S)rirj�::1rlr]rVs rXr[zTCP6EndpointsTests.listenArgs�s���U�3�3rZc���|jdd�}td|d�}tj||jfi|��|j||jdd�|f|fS)a�
        Create a L{TCP6ServerEndpoint} and return the values needed to verify
        its behaviour.

        @param reactor: A fake L{IReactorTCP} that L{TCP6ServerEndpoint} can
            call L{IReactorTCP.listenTCP} on.
        @param factory: The thing that we expect to be passed to our
            L{IStreamServerEndpoint.listen} implementation.
        @param listenArgs: Optional dictionary of arguments to
            L{IReactorTCP.listenTCP}.
        rnz::rqrrmrs)rurr�TCP6ServerEndpointrL)rWrr�r[rnrs      rXrGz'TCP6EndpointsTests.createServerEndpoint�se���N�N�;��5�	��e�Y��2��
�(�(��'�,�,�M�*�M�
�\�\�7�J�N�N�9�b�$A�9�M��
�	
rZc	���tddd�}tj||j|jfi|��|j|j||jdd�|jdd�f|fS)��
        Create a L{TCP6ClientEndpoint} and return the values needed to verify
        its behavior.

        @param reactor: A fake L{IReactorTCP} that L{TCP6ClientEndpoint} can
            call L{IReactorTCP.connectTCP} on.
        @param clientFactory: The thing that we expect to be passed to our
            L{IStreamClientEndpoint.connect} implementation.
        @param connectArgs: Optional dictionary of arguments to
            L{IReactorTCP.connectTCP}
        rqr�rTrXrxrYN)rr�TCP6ClientEndpointrrLrurzs     rXrz'TCP6EndpointsTests.createClientEndpoint�s|���e�U�B�/��
�(�(�����w�|�|�
�7B�
�����������	�2�.����
�t�4�
�
�
�	
rZNr{r]rZrXr}r}ms+���"�"�;�8D�4�
�*
rZr}c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�TCP6EndpointNameResolutionTestszl
    Tests for a TCP IPv6 Client Endpoint pointed at a hostname instead
    of an IPv6 address literal.
    c	�(��tddd�}tj|d|jfi|���_�fd�}|�j_�j|j|j||jdd�|jdd	�f|fS)
r�rq�::2rT�ipv6.example.comc�����jd|�tttddftttddftttddfg}t	j
|�S)Nr�rN)r�rrr)z::3rrr)z::4rrr)r�rrrr�succeed)rrSrWs  �rX�testNameResolutionzPTCP6EndpointNameResolutionTests.createClientEndpoint.<locals>.testNameResolution�sY������/��6��;��R�9I�J��;��R�9I�J��;��R�9I�J��D�
�=�=��&�&rZrXrxrYN)rrr�rLr�_nameResolutionrru)rWrrrArr�s`     rXrz4TCP6EndpointNameResolutionTests.createClientEndpoint�s�����e�U�B�/���.�.��'����
�9D�
���	'�#5�����
�G�G�����������	�2�.����
�t�4�
�
�

�
	
rZc��ddd�Sr`r]rVs rXrAz+TCP6EndpointNameResolutionTests.connectArgsrfrZc��|jSrOrPrs  rXrz/TCP6EndpointNameResolutionTests.expectedClientsrMrZc��|\}}}}}|\}}	}
}}|j||�|j||	�|j||�|j||�yrSrTrUs
             rXr!z1TCP6EndpointNameResolutionTests.assertConnectArgsr^rZc��tjddd�}|j|jtj
�y)zg
        By default, L{TCP6ClientEndpoint._deferToThread} is
        L{threads.deferToThread}.
        Nzwww.example.com��)rr�r��_deferToThreadr�
deferToThread�rWrs  rX�test_freeFunctionDeferToThreadz>TCP6EndpointNameResolutionTests.test_freeFunctionDeferToThread.s5��
�
)�
)�$�0A�4�
H������*�*�G�,A�,A�BrZc����g��fd�}tjtdd�}t�}||_||_|j
t��|j|ddtfifg��y)zl
        While resolving hostnames, _nameResolution calls
        _deferToThread with _getaddrinfo.
        c�T���j|||f�tj�Srd)rerr�)r�r��kwargs�callss   �rX�fakeDeferToThreadzNTCP6EndpointNameResolutionTests.test_nameResolution.<locals>.fakeDeferToThread=s#����L�L�!�T�6�*�+��>�>�#�#rZr�r�rN)
rr�rr��_getaddrinfor�rr�r�r)rWr�rv�fakegetaddrinfor�s    @rX�test_nameResolutionz3TCP6EndpointNameResolutionTests.test_nameResolution6sr���
��	$��/�/��9K�T�R�� �(�� /���"3��������'����� 2�A�x�@�"�
E�F��	
rZN)
rlrmrnrorrArr!r�r�r]rZrXr�r��s(���
&
�PD�"�;�8C�
rZr�c��eZdZdZdd�Zy)�RaisingMemoryReactorWithClockzE
    An extension of L{RaisingMemoryReactor} with L{task.Clock}.
    Nc�\�tj|�tj|||�yrd)r-rYr/)rWrUr,s   rXrYz&RaisingMemoryReactorWithClock.__init__Ps!��
���t���%�%�d�O�=M�NrZ)NNrkr]rZrXr�r�Ks
���OrZr�c�������i��j��tt�G��fd�d���tt�G�fd�dt	tdt
t|������}||�S)ap
    Create a reactor that will deterministically resolve all hostnames it is
    passed to the list of addresses given.

    @param reactor: An object that we wish to add an
        L{IReactorPluggableNameResolver} to.
    @type reactor: Any object with some formally-declared interfaces (i.e. one
        where C{list(providedBy(reactor))} is not empty); usually C{IReactor*}
        interfaces.

    @param expectedAddresses: (optional); the addresses expected to be returned
        for every address.  If these are strings, they should be IPv4 or IPv6
        literals, and they will be wrapped in L{IPv4Address} and L{IPv6Address}
        objects in the resolution result.
    @type expectedAddresses: iterable of C{object} or C{str}

    @param hostMap: (optional); the names (unicode) mapped to lists of
        addresses (str or L{IAddress}); in the same format as expectedAddress,
        which map the results for I{specific} hostnames to addresses.

    @return: A new reactor which provides all the interfaces previously
        provided by C{reactor} as well as L{IReactorPluggableNameResolver}.
        All name resolutions performed with its C{nameResolver} attribute will
        resolve reentrantly and synchronously with the given
        C{expectedAddresses}.  However, it is not a complete implementation as
        it does not have an C{installNameResolver} method.
    c�,��eZdZe			d��fd�	�Zy)�9deterministicResolvingReactor.<locals>.SimpleNameResolverNc���|jd��j|��D]B}t|t�rt	t
gt
|�d||�}|j|��D|j�y)Nrq)	�resolutionBeganru�
isinstance�strrrr�addressResolved�resolutionComplete)�resolutionReceiver�hostName�
portNumber�addressTypes�transportSemantics�expectedAddress�expectedAddresses�hostMaps      ��rX�resolveHostNamezIdeterministicResolvingReactor.<locals>.SimpleNameResolver.resolveHostNamews{���
�.�.�t�4�#*�;�;�x�9J�#K�
D���o�s�3�'2�K�&@�%�o�6�'��_�j�':�O�#�2�2�?�C�
D�
�1�1�3rZ)rNrq)rlrmrn�staticmethodr�)r�r�s��rX�SimpleNameResolverr�us ���	���$�	4�
�	4rZr�c���eZdZW��Zy)�3deterministicResolvingReactor.<locals>.WithResolverN)rlrmrn�nameResolver)r�s�rX�WithResolverr��s
���*�+�rZr��*)�copyr
r%r'r9r�tupler)rr�r�r�r�s `` @rX�deterministicResolvingReactorr�Us|���8�����l�l�n�G��"�#�4�4�$�4�$�.�/�,��.��e�J�w�4G�.H�I�J�,�0�,�
�� � rZc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�SimpleHostnameResolverTestsa�
    Tests for L{endpoints._SimpleHostnameResolver}.

    @ivar fakeResolverCalls: Arguments with which L{fakeResolver} was
        called.
    @type fakeResolverCalls: L{list} of C{(hostName, port)} L{tuple}s.

    @ivar fakeResolverReturns: The return value of L{fakeResolver}.
    @type fakeResolverReturns: L{Deferred}

    @ivar resolver: The instance to test.
    @type resolver: L{endpoints._SimpleHostnameResolver}

    @ivar resolutionBeganCalls: Arguments with which receiver's
        C{resolutionBegan} method was called.
    @type resolutionBeganCalls: L{list}

    @ivar addressResolved: Arguments with which C{addressResolved} was
        called.
    @type addressResolved: L{list}

    @ivar resolutionCompleteCallCount: The number of calls to the
        receiver's C{resolutionComplete} method.
    @type resolutionCompleteCallCount: L{int}

    @ivar receiver: A L{interfaces.IResolutionReceiver} provider.
    c���g�_tj��_t	j
�j��_g�_g�_	d�_
ttj�G�fd�d��}|�_y)Nrc�J��eZdZe�fd��Ze�fd��Ze�fd��Zy)�4SimpleHostnameResolverTests.setUp.<locals>._Receiverc�<���jj|�yrd)�resolutionBeganCallsre)�resolutionInProgressrWs �rXr�zDSimpleHostnameResolverTests.setUp.<locals>._Receiver.resolutionBegan�s����)�)�0�0�1E�FrZc�<���jj|�yrd)�addressResolvedCallsre)rrWs �rXr�zDSimpleHostnameResolverTests.setUp.<locals>._Receiver.addressResolved�s����)�)�0�0��9rZc�0���xjdz
c_yr`)�resolutionCompleteCallCountrVs�rXr�zGSimpleHostnameResolverTests.setUp.<locals>._Receiver.resolutionComplete�s����0�0�A�5�0rZN)rlrmrnr�r�r�r�rVs�rX�	_Receiverr��s?���
�
G��
G��
:��
:��
6��
6rZr�)�fakeResolverCallsrr��fakeResolverReturnsr�_SimpleHostnameResolver�fakeResolver�resolverr�r�r�rr�IResolutionReceiver�receiver)rWr�s` rXrwz!SimpleHostnameResolverTests.setUp�su���!#���#(�>�>�#3�� �!�9�9�$�:K�:K�L��
�$&��!�$&��!�+,��(�	�*�0�0�	1�	6�	6�
2�	6�"��
rZc�T�|jj||f�|jS)z�
        A fake resolver callable.

        @param hostName: The hostname to resolve.

        @param portNumber: The port number the returned address should
            include.

        @return: L{fakeResolverCalls}
        @rtype: L{Deferred}
        )r�rer�)rWr�r�s   rXr�z(SimpleHostnameResolverTests.fakeResolver�s)��	
���%�%�x��&<�=��'�'�'rZc�j�|jttj|j��y)zs
        A L{endpoints._SimpleHostnameResolver} instance provides
        L{interfaces.IHostnameResolver}.
        N)r�rrr%r�rVs rXrz*SimpleHostnameResolverTests.test_interface�s!��
	
����Z�%A�%A�4�=�=�Q�RrZc����g�tt��fd���tj��|j	�fd��|j
j
|jd�|jjt��|jdt���|jdt|jt����\}|j|jd��|j|jdd��|j|jdt!|j"���|jdt|j$��|j|j$dj&d�|j)|j*�|jd|j,�y	)
z�
        A resolution failure is logged with the name that failed to
        resolve and the callable that tried to resolve it.  The
        resolution receiver begins, receives no addresses, and
        completes.
        c�(���j|�yrdr�)�event�logss �rX�captureLogszHSimpleHostnameResolverTests.test_resolveNameFailure.<locals>.captureLogs�s����K�K��rZc�.��tj��Srd)r3r4)r�s�rXr�zESimpleHostnameResolverTests.test_resolveNameFailure.<locals>.<lambda>�s��� 2� A� A�+� N�rZ�example.comra�isError�name�callablerN)rr2r3r2r3r�r�r�r��errbackr�r�r �flushLoggedErrorsr�ru�reprr�r�r�r�r�r�)rWr�r�r�s  @@rX�test_resolveNameFailurez3SimpleHostnameResolverTests.test_resolveNameFailure�s[�����	�,�	�	�
 �	�	�&�&�{�3����N�O��
�
�%�%�d�m�m�]�C�� � �(�(���5�����C��I�&�����C�� 6� 6�y� A�B�C��������	�	�)�,�-�����	�	�&�-�8�9�����	�	�*�d�4�3D�3D�.E�F�G�����C�� 9� 9�:�;�����2�2�1�5�:�:�M�J�����2�2�3�����D�<�<�=rZc	��d}d}d}|jj|jd�|jj	t
ttd||fftttd||ffg�|jdt|j��|j|jdjd�|j|jtd||�td||�g�|j|j d�y	)
zs
        The resolution receiver begins, and resolved hostnames are
        delivered before it completes.
        rT�1.2.3.4z
1::2::3::4r�rNrarrqN)r�r�r�r�rrrrrr�r r�r�r�rrr�)rWrL�ipv4Host�ipv6Hosts    rX�test_resolveNameDeliversz4SimpleHostnameResolverTests.test_resolveNameDelivers�s���
�������
�
�%�%�d�m�m�]�C�� � �)�)��+�{�B��4�8H�I��;��R�(�D�9I�J�
�	
�	
����C�� 9� 9�:�;�����2�2�1�5�:�:�M�J�����%�%�
���$�
/��U�H�d�1S�T�	
�	
����9�9�1�=rZN)	rlrmrnrorwr�rr�r�r]rZrXr�r��s"���8"�2
(�S�>�B>rZr�c��eZdZdZd�Zy)�+HostnameEndpointFallbackNameResolutionTestszd
    L{HostnameEndpoint._fallbackNameResolution} defers a name
    resolution call to a thread.
    c�����ddlm}tj|dd��}d\��|j	���}���fd�}|j|�S)z�
        L{_fallbackNameResolution} returns a L{Deferred} that fires
        with the resoution of the the host and request port.
        r)r�ignored)rrL)r�rac�����jt|�d�|\\}}}}}�j|t��j|t��j|��f�yr`)r�r rr)�result�family�socktype�_�sockaddrrrLrWs     ���rX�assertHostPortFamilySockTypezmHostnameEndpointFallbackNameResolutionTests.test_fallbackNameResolution.<locals>.assertHostPortFamilySockType,s^������S��[�!�,�39�0�
/�f�h��1�h����V�W�-����X�{�3����X��d�|�4rZ)�twisted.internetrr�HostnameEndpoint�_fallbackNameResolutionr�)rWrr�resolutionDeferredr�rrLs`    @@rX�test_fallbackNameResolutionzGHostnameEndpointFallbackNameResolutionTests.test_fallbackNameResolutionsQ���
	-�
�
'�
'��i�a�
H��#�
��d��7�7��d�C��	5�"�-�-�.J�K�KrZN)rlrmrnror�r]rZrXr�r�s
���
LrZr�c�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�#_HostnameEndpointMemoryReactorMixinz�
    Common methods for testing L{HostnameEndpoint} against
    L{MemoryReactor} instances that do not provide
    L{IReactorPluggableNameResolver}.
    c��	||i|��}tj|�S#t$rtj�cYSwxYw)a�
        A synchronous version of L{deferToThread}.

        @param f: The callable to invoke.
        @type f: L{callable}

        @param args: Positional arguments to the callable.

        @param kwargs: Keyword arguments to the callable.

        @return: A L{Deferred} that fires with the result of applying
            C{f} to C{args} and C{kwargs} or the exception raised.
        )rr��
BaseExceptionr�)rWr�r�r�r�s     rX�synchronousDeferredToThreadz?_HostnameEndpointMemoryReactorMixin.synchronousDeferredToThread=sD��	)���'��'�F��=�=��(�(���	 ��:�:�<��	 �s��?�?c��|jS)z�
        Extract expected clients from the reactor.

        @param reactor: The L{MemoryReactor} under test.

        @return: List of calls to L{IReactorTCP.connectTCP}
        rPrs  rXrz3_HostnameEndpointMemoryReactorMixin.expectedClientsRs���!�!�!rZc��ddd�S)zL

        @return: C{dict} of keyword arguments to pass to connect.
        g$@rcrer]rVs rXrAz/_HostnameEndpointMemoryReactorMixin.connectArgs\s��
 �0D�E�ErZc��|\}}}}}|\}}	}
}}|j||�|j||	�|j||�|j||�yrSrTrUs
             rXr!z5_HostnameEndpointMemoryReactorMixin.assertConnectArgscr^rZc��tjd��}t|��}t�}|j	||�\}}}|j|�}|j
tjj�|j|j|�j|�|jg|j��y)z�
        When L{HostnameEndpoint.connect} cannot connect to its
        destination, the returned L{Deferred} will fail with
        C{ConnectError}.
        r*r�r+N�rr�r�r�rr�advancerr��_DEFAULT_ATTEMPT_DELAYr�r�r/�getDelayedCalls�rWr4r$rrrr&r�s        rXr5z?_HostnameEndpointMemoryReactorMixin.test_endpointConnectFailure����*�*�2E�F�
�0�-�P����
�'+�'@�'@��m�(
�$��K��
�J�J�}�%������3�3�J�J�K�����-�-�a�0�6�6�
�F�����X�5�5�7�8rZc�*�t�}t�}|j||�|j�}|j	dt|��|j
t|dd�|j|ddjd��y)z�
        Instantiating L{HostnameEndpoint} with a reactor that does not
        provide L{IReactorPluggableResolver} emits a deprecation warning.
        rar�category�messagez�Passing HostnameEndpoint a reactor that does not provide IReactorPluggableNameResolver (twisted.internet.testing.MemoryReactorClock) was deprecated in Twisted 17.5.0; please use a reactor that provides IReactorPluggableNameResolver insteadN)
rr�r�
flushWarningsr�r rp�DeprecationWarningr��
startswith)rWr$r�warningss    rX�test_deprecationz4_HostnameEndpointMemoryReactorMixin.test_deprecation�s���
!�?����
��!�!�(�M�:��%�%�'������C��M�*��
�
�(�(�1�+�j�*A�B�����Q�K�	�"�-�-�9�
�		
rZc�\�t�}t�}|j||�\}}}d�}||_|j	|�}|j|j
|�jtj�|jdt|jt���y)z8
        Hostname resolution errors are logged.
        c��tdd��)N���z#No address associated with hostname)r	)r�r�s  rX�getaddrinfoThatFailszS_HostnameEndpointMemoryReactorMixin.test_errorsLogged.<locals>.getaddrinfoThatFails�s���2�D�E�ErZraN)rr�rr�rr<r�r/r�DNSLookupErrorr�r r�r	)rWr$rrrr&rr�s        rX�test_errorsLoggedz5_HostnameEndpointMemoryReactorMixin.test_errorsLogged�s���!�?����
�'+�'@�'@��m�(
�$��K��	F�/����J�J�}�%�����d�2�2�1�5�;�;�U�=Q�=Q�R�����C�� 6� 6�x� @�A�BrZN)rlrmrnror�rrAr!r5rrr]rZrXr�r�6s,���)�*"�F�;�89�*
�4CrZr�c��eZdZdZd�Zy)�&HostnameEndpointMemoryIPv4ReactorTestsz�
    IPv4 resolution tests for L{HostnameEndpoint} with
    L{MemoryReactor} subclasses that do not provide
    L{IReactorPluggableNameResolver}.
    c	���d�tdd�}tj|d|jfi|��}�fd�}||_|j
|_|�|j||jdd�|jdd�f|fS)	a�
        Creates a L{HostnameEndpoint} instance where the hostname is
        resolved into a single IPv4 address.

        @param reactor: The L{MemoryReactor}

        @param clientFactory: The client L{IProtocolFactory}

        @param connectArgs: Additional arguments to
            L{HostnameEndpoint.connect}

        @return: A L{tuple} of the form C{(endpoint, (expectedAddress,
            expectedPort, clientFactory, timeout, localBindAddress,
            hostnameAddress))}
        r��example.comrTc�0��tttd�dffgS�NrNrT)rrr�rrLr�r�r�s    �rXr�zTHostnameEndpointMemoryIPv4ReactorTests.createClientEndpoint.<locals>.fakegetaddrinfo�s ����+�{�B��"�8M�N��
rZrXrxrYN�rrr�rLr�r�r�ru�rWrrrArrvr�r�s       @rXrz;HostnameEndpointMemoryIPv4ReactorTests.createClientEndpoint�s���� $��!�.�"�5���-�-��^�W�\�\�
�5@�
��	�
!0���"&�"B�"B���
���������	�2�.����
�t�4�
�
�

�
	
rZN�rlrmrnrorr]rZrXrr�����(
rZrc��eZdZdZd�Zy)�&HostnameEndpointMemoryIPv6ReactorTestsz�
    IPv6 resolution tests for L{HostnameEndpoint} with
    L{MemoryReactor} subclasses that do not provide
    L{IReactorPluggableNameResolver}.
    c	���d�tdd�}tj|d|jfi|��}�fd�}||_|j
|_|�|j||jdd�|jdd�f|fS)	a�
        Creates a L{HostnameEndpoint} instance where the hostname is
        resolved into a single IPv6 address.

        @param reactor: The L{MemoryReactor}

        @param clientFactory: The client L{IProtocolFactory}

        @param connectArgs: Additional arguments to
            L{HostnameEndpoint.connect}

        @return: A L{tuple} of the form C{(endpoint, (expectedAddress,
            expectedPort, clientFactory, timeout, localBindAddress,
            hostnameAddress))}
        �1:2::3:4�ipv6.example.comrTc�0��tttd�dffgSr)rrrrs    �rXr�zTHostnameEndpointMemoryIPv6ReactorTests.createClientEndpoint.<locals>.fakegetaddrinfos ����;��R�/�2�9N�O��
rZrXrxrYNrr s       @rXrz;HostnameEndpointMemoryIPv6ReactorTests.createClientEndpoints���� %��!�"5�r�:���-�-��(�'�,�,�
�:E�
��	�
!0���"&�"B�"B���
���������	�2�.����
�t�4�
�
�

�
	
rZNr!r]rZrXr$r$�r"rZr$c�H�eZdZdZd�Zd�Zd�Zd�Zdd�Zd�Z	d	�Z
d
�Zd�Zy)
�HostnameEndpointsOneIPv4Testsz^
    Tests for the hostname based endpoints when GAI returns only one
    (IPv4) address.
    c	���d}tdd�}tjt||g�d|jfi|��}|||j||jdd�|jdd�f|fS)z{
        Creates a L{HostnameEndpoint} instance where the hostname is resolved
        into a single IPv4 address.
        r�rrTrXrxrYN�rrr�r�rLru)rWrrrAr�rrvs       rXrz2HostnameEndpointsOneIPv4Tests.createClientEndpoint3s���
$��!�.�"�5���-�-�)�'�O�3D�E���L�L�
��	
��
���������	�2�.����
�t�4�
�
�

�
	
rZc��|jSrOrPrs  rXrz-HostnameEndpointsOneIPv4Tests.expectedClientsMrMrZc��|\}}}}}|\}}	}
}}|j||�|j||	�|j||�|j||�yrSrTrUs
             rXr!z/HostnameEndpointsOneIPv4Tests.assertConnectArgsSr^rZc��ddd�Sr`r]rVs rXrAz)HostnameEndpointsOneIPv4Tests.connectArgsorfrZNc���t�}tj�}tj|_|j	||�\}}}|j|�}|�|j
|�|j�|j|�}|jdttj���|j|�}	|j|	jtj �|j#|	jj$|�|j'|j(ddj*j,�|j#g|j/��y)z�
        Calling L{Deferred.cancel} on the L{Deferred} returned from
        L{IStreamClientEndpoint.connect} will cause it to be errbacked with a
        L{ConnectingCancelledError} exception.
        Nrr�)rrr*r+rrrr:rr�r:rr;r�r<r/r#r�rr�rQ�
_connector�stoppedConnectingr)
rWrr$rrrrr�r=r>s
          rXr?z>HostnameEndpointsOneIPv4Tests.test_endpointConnectingCancelledus ��!�?�� �(�(�*�
�!)�!2�!2�
��#'�#<�#<�X�}�#U� ��K���J�J�}�%�������W�%�	���
��6�6�x�@���-�-�d�G�E�O�O�<M�4N�O��&�&�q�)�����g�m�m�U�-K�-K�L�������.�.��8�����+�+�A�.�q�1�<�<�N�N�O�����X�5�5�7�8rZc�l�tjj}||dzz}|j|��y)a 
        Calling L{Deferred.cancel} on the L{Deferred} returned from
        L{IStreamClientEndpoint.connect} after enough time has passed that all
        connection attempts have been initiated will cause it to be errbacked
        with a L{ConnectingCancelledError} exception.
        g@)rN)rr�rr?)rW�
oneBetweenrs   rX�7test_endpointConnectingCancelledAfterAllAttemptsStartedzUHostnameEndpointsOneIPv4Tests.test_endpointConnectingCancelledAfterAllAttemptsStarted�s5���/�/�F�F�
��
�S� 0�1���-�-�g�-�>rZc��tjd��}t|��}t�}|j	||�\}}}|j|�}|j
tjj�|j|j|�j|�|jg|j��y)z�
        If L{HostnameEndpoint.connect} is invoked and there is no server
        listening for connections, the returned L{Deferred} will fail with
        C{ConnectError}.
        r*r�r+Nrrs        rXr5z9HostnameEndpointsOneIPv4Tests.test_endpointConnectFailure�r	rZc���tjd��}t�}t�}|j	||�\}}}|j|�}|j
d�|jd\}}	}
}}|
j|jd|�|j|j|�j|�|jg|j��y)a
        If a connection attempt initiated by
        L{HostnameEndpoint.connect} fails only after
        L{HostnameEndpoint} has exhausted the list of possible server
        addresses, the returned L{Deferred} will fail with
        C{ConnectError}.
        r*r��333333�?rN)rr�rr�rrrrQr��
connectorsr�r�r/r)
rWr4r$rrrr&r�rrLr�rXrYs
             rX�)test_endpointConnectFailureAfterIterationzGHostnameEndpointsOneIPv4Tests.test_endpointConnectFailureAfterIteration�s����*�*�2E�F�
� �?����
�'+�'@�'@��m�(
�$��K��
�J�J�}�%�������4<�4G�4G��4J�1��d�G�W�k��&�&�x�':�':�1�'=�}�M�����-�-�a�0�6�6�
�F�����X�5�5�7�8rZc�"��t�}t�}t�}|j||�\}}}|j|�}g��fd�}|j	|�|j|�}	|j
d�|	jj|�|j�|g�|j|�}
|jt|
�d�|j|
d|�|jg|j��y)a\
        If a connection attempt initiated by
        L{HostnameEndpoint.connect} succeeds only after
        L{HostnameEndpoint} has exhausted the list of possible server
        addresses, the returned L{Deferred} will fire with the
        connected protocol instance and the endpoint will leave no
        delayed calls in the reactor.
        c�(���j|�yrdr�rs �rXrz[HostnameEndpointsOneIPv4Tests.test_endpointConnectSuccessAfterIteration.<locals>.checkProto�rrZr8rarN)r�rrrr�rrr�rr�rr r!rr"s           @rX�)test_endpointConnectSuccessAfterIterationzGHostnameEndpointsOneIPv4Tests.test_endpointConnectSuccessAfterIteration�s������� �?����
�(,�(A�(A��m�)
�%��L�+�
�J�J�}�%����	%�	
�
�
�j�!��/�/��9����������&�&�u�-�����%��1��.�.�x�8������_�-�q�1�����q�1�<�@�����X�5�5�7�8rZrd)
rlrmrnrorrr!rAr?r5r5r:r=r]rZrXr*r*-s5���

�4"�;�8D�9�<	?�9�*9�2&9rZr*c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�HostnameEndpointsOneIPv6Testsz^
    Tests for the hostname based endpoints when GAI returns only one
    (IPv6) address.
    c	���tdd�}tjt|dg�d|jfi|��}|d|j||jdd�|jdd�f|fS)z{
        Creates a L{HostnameEndpoint} instance where the hostname is resolved
        into a single IPv6 address.
        r'rTr&rXrxrYNr,)rWrrrArrvs      rXrz2HostnameEndpointsOneIPv6Tests.createClientEndpoint�s���
"�"5�r�:���-�-�)�'�J�<�@���L�L�
��	
��
���������	�2�.����
�t�4�
�
�

�
	
rZc��|jSrOrPrs  rXrz-HostnameEndpointsOneIPv6Tests.expectedClients	rMrZc��|\}}}}}|\}}	}
}}|j||�|j||	�|j||�|j||�yrSrTrUs
             rXr!z/HostnameEndpointsOneIPv6Tests.assertConnectArgs	r^rZc��ddd�Sr`r]rVs rXrAz)HostnameEndpointsOneIPv6Tests.connectArgs5	rfrZc���t�}tj�}tj|_|j	t|dg�|�\}}}|j
|�}|j�|j|�}|jdttj���|j|�}|j|jtj �|j#|jj$|�|j'|j(ddj*j,�|j#g|j/��y)r7rkNrr�)rrr*r+rr�rr:rr�r:rr;r�r<r/r#r�rr�rQr1r2r)	rWr$rrrrr�r=r>s	         rXr?z>HostnameEndpointsOneIPv6Tests.test_endpointConnectingCancelled;	s��!�?�� �(�(�*�
�!)�!2�!2�
��#'�#<�#<�)�(�[�M�B�M�$
� ��K��
�J�J�}�%��	���
��6�6�x�@���-�-�d�G�E�O�O�<M�4N�O��&�&�q�)�����g�m�m�U�-K�-K�L�������.�.��8�����+�+�A�.�q�1�<�<�N�N�O�����X�5�5�7�8rZc�b�tjd��}t|��}t�}|j	||�\}}}|j|�}|j
d�|j|j|�j|�|jg|j��y)r)r*r�r+r8N)rr�r�r�rrrr�r�r/rrs        rXr5z9HostnameEndpointsOneIPv6Tests.test_endpointConnectFailureX	s���
�*�*�2E�F�
�0�-�P����
�'+�'@�'@��m�(
�$��K��
�J�J�}�%�����������-�-�a�0�6�6�
�F�����X�5�5�7�8rZN)
rlrmrnrorrr!rAr?r5r]rZrXr?r?�s&���

�0"�;�8D�9�:9rZr?c�0�eZdZdZdZdZd�Zd�Zd�Zd�Z	y)	�HostnameEndpointIDNATestszJ
    Tests for L{HostnameEndpoint}'s constructor's encoding behavior.
    �
bücher.chsxn--bcher-kva.chc��tjtt�dg�|jd�}|j|j|j�|j|j|j�y)z�
        A L{HostnameEndpoint} constructed with text will contain an
        IDNA-encoded bytes representation of that text.
        rkrTN�	rr�r�r�sampleIDNATextr��
_hostBytes�sampleIDNABytes�	_hostTextrus  rX�test_idnaHostnameTextz/HostnameEndpointIDNATests.test_idnaHostnameTexts	�h��
�-�-�)�-�/�K�=�I�����
��
	
����,�,�d�.B�.B�C�����+�+�T�-@�-@�ArZc��tjtt�dg�|jd�}|j|j|j�|j|j|j�y)z�
        A L{HostnameEndpoint} constructed with bytes will contain an
        IDNA-decoded textual representation of those bytes.
        rkrTNrJrus  rX�test_idnaHostnameBytesz0HostnameEndpointIDNATests.test_idnaHostnameBytes�	rPrZc��tjtt�dg�t	d|j
�d�}|j
|j|j�|j
|j|j
�y)z�
        A L{HostnameEndpoint} constructed with NFD-normalized text will store
        the NFC-normalized version of that text.
        rk�NFDrTN)
rr�r�rrrKr�rLrMrNrus  rX�test_nonNormalizedTextz0HostnameEndpointIDNATests.test_nonNormalizedText�	so��
�-�-�)�-�/�K�=�I��e�T�0�0�1��
��
	
����,�,�d�.B�.B�C�����+�+�T�-@�-@�ArZc���tjtt�dg�dd�}|j	tjt��}|j|t�}|jdt|��tjtt�dg�dd�}|j	t��}|j|t�}|jdt|��y)a&
        Since any client of L{IStreamClientEndpoint} needs to handle Deferred
        failures from C{connect}, L{HostnameEndpoint}'s constructor will not
        raise exceptions when given bad host names, instead deferring to
        returning a failing L{Deferred} from C{connect}.
        rk��-garbage-�rTz\xff-garbage-\xffu⿰-garbage-⿰z\u2ff0-garbage-\u2ff0N)rr�r�rrr*r�r+r�r�r6r�)rWrv�deferred�errs    rX�test_deferBadEncodingToConnectz8HostnameEndpointIDNATests.test_deferBadEncodingToConnect�	s����-�-�)�-�/�K�=�I� ��
��
�#�#�G�$7�$7��$A�B���"�"�8�Z�8���
�
�+�S��X�6��-�-�)�-�/�K�=�I�#��
��
�#�#�G�I�.���"�"�8�Z�8���
�
�/��S��:rZN)
rlrmrnrorKrMrOrRrUrZr]rZrXrGrGk	s*���$�N�)�O�B�B�B�;rZrGc�(�eZdZdZd�Zd�Zd�Zd�Zy)�HostnameEndpointReprTestsz@
    Tests for L{HostnameEndpoint}'s string representation.
    c���tjtt�g�dd�}t	|�}|jd|�|j
tt|��y)z�
        The string representation of L{HostnameEndpoint} includes the host and
        port passed to the constructor.
        r�rTz!<HostnameEndpoint example.com:80>N�	rr�r�r-r�r�rpr��type�rWrv�reps   rX�
test_allASCIIz'HostnameEndpointReprTests.test_allASCII�	sT��
�-�-�)�%�'�2�6���
���8�n�����<�c�B��
�
�c�4��9�%rZc���tjtt�g�dd�}t	|�}|jd|�|j
tt|��y)z�
        When IDN is passed to the L{HostnameEndpoint} constructor the string
        representation includes the punycode version of the host.
        rH�z'<HostnameEndpoint xn--bcher-kva.ch:443>Nr^r`s   rX�test_idnaHostnamez+HostnameEndpointReprTests.test_idnaHostname�	sT��
�-�-�)�%�'�2�6���
���8�n�����B�C�H��
�
�c�4��9�%rZc���tjtt�g�dd�}t	|�}|jd|�|j
tt|��y)z�
        When the host passed to L{HostnameEndpoint} is an IPv6 address it is
        wrapped in brackets in the string representation, like in a URI. This
        prevents the colon separating the host from the port from being
        ambiguous.
        s::1�z<HostnameEndpoint [::1]:22>Nr^r`s   rX�test_hostIPv6Addressz.HostnameEndpointReprTests.test_hostIPv6Address�	sT���-�-�)�%�'�2�6���
���8�n�����6��<��
�
�c�4��9�%rZc��tjtt�g�dd�}|j	dt|��y)z�
        When a bad hostname is passed to L{HostnameEndpoint}, the string
        representation displays invalid characters in backslash-escaped form.
        rWrTz'<HostnameEndpoint \xff-garbage-\xff:80>N)rr�r�r-r�r�rus  rX�test_badEncodingz*HostnameEndpointReprTests.test_badEncoding�	s?��
�-�-�)�%�'�2�6�8L�b�
��	
���7���N�	
rZN)rlrmrnrorbrerhrjr]rZrXr\r\�	s���&� &� &�$
rZr\c��eZdZdZd�Zy)� HostnameEndpointsGAIFailureTestszM
    Tests for the hostname based endpoints when GAI returns no address.
    c��tjtt�g�dd�}t	�}|j|�}|j
|tj�}|jdt|��y)z�
        If no address is returned by GAI for a hostname, the connection attempt
        fails with L{error.DNSLookupError}.
        rrTr�N)rr�r�r-r�rr�rrr6r�)rWrvr�dConnect�excs     rX�test_failurez-HostnameEndpointsGAIFailureTests.test_failure�	sg��
�-�-�)�%�'�2�6���
����
��#�#�M�2���"�"�8�U�-A�-A�B���
�
�m�S��X�.rZN)rlrmrnrorpr]rZrXrlrl�	s���/rZrlc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�&HostnameEndpointsFasterConnectionTestsz�
    Tests for the hostname based endpoints when gai returns an IPv4 and
    an IPv6 address, and one connection takes less time than the other.
    c��t�|_tjt	|jddg�dd�|_y)Nr�r&�www.example.comrT)rr$rr�r�rvrVs rXrwz,HostnameEndpointsFasterConnectionTests.setUp
s6��%���
�!�2�2�)�$�-�-�)�Z�9P�Q���
��
rZc���t�|_tjt	|jdt�dg�dd�|_d}|jj|�|jjd�|jjd\}}}}}|jt|jj�d�|j|d�|j|d�y)	z�
        If an address type other than L{IPv4Address} and L{IPv6Address} is
        returned by on address resolution, the endpoint ignores that address.
        r�r&rtrTNr8rar�)rr$rr�r�r�rvrrrQr�r )rWrrrLr�rXrYs       rX�test_ignoreUnknownAddressTypeszEHostnameEndpointsFasterConnectionTests.test_ignoreUnknownAddressTypes
s���
&���
�!�2�2�)��
�
�	�6�8�Z�@�
�
��
��
��
��
�
���m�,��
�
���c�"�6:�m�m�6N�6N�q�6Q�3��t�W�g�{�����T�]�]�5�5�6��:�����z�*�����r�"rZc��tj�}tj|_|jj	|�}g}|j|j�|jjd\}}}}}|j|d�|j|d�|j||f�}	t�}
|j|g�|	j|
�|jt|�d�|j|dj|�|jg|jj��y)a=
        The endpoint returns a connection to the IPv4 address.

        IPv4 ought to be the first attempt, since nameResolution (standing in
        for GAI here) returns it first. The IPv4 attempt succeeds, the
        connection is established, and a Deferred fires with the protocol
        constructed.
        rr�rTraN)rr*r+rvrr�rer$rQr�r�r�r�r r�r�rWrr��resultsrrLr�rXrYr#�
fakeTransports           rX�test_IPv4IsFasterz8HostnameEndpointsFasterConnectionTests.test_IPv4IsFaster1
s��!�(�(�*�
�!)�!2�!2�
���M�M�!�!�-�0����	�
�
�g�n�n�%�6:�m�m�6N�6N�q�6Q�3��t�W�g�{�����y�)�����r�"��%�%�t�T�l�3����
�����"�%�
���]�+�����W��q�)�������+�+�]�;�����T�]�]�:�:�<�=rZc���tj�}tj|_|jj	|�}g}|j|j�|jjd�|jjd\}}}}}|j|d�|j|d�|j||f�}	t�}
|j|g�|	j|
�|jt|�d�|j|dj|�|jg|jj!��y)a=
        The endpoint returns a connection to the IPv6 address.

        IPv6 ought to be the second attempt, since nameResolution (standing in
        for GAI here) returns it second. The IPv6 attempt succeeds, a
        connection is established, and a Deferred fires with the protocol
        constructed.
        r8rar&rTrN)rr*r+rvrr�rer$rrQr�r�r�r�r r�rrxs           rX�test_IPv6IsFasterz8HostnameEndpointsFasterConnectionTests.test_IPv6IsFasterP
s��!�(�(�*�
�!)�!2�!2�
���M�M�!�!�-�0����	�
�
�g�n�n�%��
�
���c�"�6:�m�m�6N�6N�q�6Q�3��t�W�g�{�����z�*�����r�"��%�%�t�T�l�3����
�����"�%�
���]�+�����W��q�)�������+�+�]�;�����T�]�]�:�:�<�=rZc�j�tj�}tj|_|jj	|�}g}|j|j�|jjd�|jjd\}}}}}|j||f�}	t�}
|	j|
�|jd|jjddjj�|jg|jj!��y)a
        Once the endpoint returns a successful connection, all the other
        pending connections are cancelled.

        Here, the second connection attempt, i.e. IPv6, succeeds, and the
        pending first attempt, i.e. IPv4, is cancelled.
        r8raTrr�N)rr*r+rvrr�rer$rrQr�r�r�r�r1r2rrxs           rX�test_otherConnectionsCancelledzEHostnameEndpointsFasterConnectionTests.test_otherConnectionsCancelledq
s���!�(�(�*�
�!)�!2�!2�
���M�M�!�!�-�0����	�
�
�g�n�n�%��
�
���c�"�6:�m�m�6N�6N�q�6Q�3��t�W�g�{��%�%�t�T�l�3����
�
���]�+�����$�-�-�*�*�1�-�a�0�;�;�M�M�	
�	
����T�]�]�:�:�<�=rZN)	rlrmrnrorwrvr{r}rr]rZrXrrrr
s!���

�#�.>�>>�B>rZrrc�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�SSL4EndpointsTestsz"
    Tests for SSL Endpoints.
    c��|jS)zD
        @return: List of calls to L{IReactorSSL.listenSSL}
        )�
sslServersrs  rXrPz"SSL4EndpointsTests.expectedServers�
rMrZc��|jS)zE
        @return: List of calls to L{IReactorSSL.connectSSL}
        )�
sslClientsrs  rXrz"SSL4EndpointsTests.expectedClients�
rMrZc���|\}}}}}}|\}	}
}}}
}|j||	�|j||
�|j||�|j||
�|j||�y)a�
        Compare host, port, contextFactory, timeout, and bindAddress in
        C{receivedArgs} to C{expectedArgs}.  We ignore the factory because we
        don't only care what protocol comes out of the
        C{IStreamClientEndpoint.connect} call.

        @param receivedArgs: C{tuple} of (C{host}, C{port}, C{factory},
            C{contextFactory}, C{timeout}, C{bindAddress}) that was passed to
            L{IReactorSSL.connectSSL}.
        @param expectedArgs: C{tuple} of (C{host}, C{port}, C{factory},
            C{contextFactory}, C{timeout}, C{bindAddress}) that we expect to
            have been passed to L{IReactorSSL.connectSSL}.
        NrT)rWrVr%rrLrW�contextFactoryrXrYrQrZr[�expectedContextFactoryr\r]s               rXr!z$SSL4EndpointsTests.assertConnectArgs�
s���*
�	
�������
�	
����"���	
����|�,�����|�,�����)?�@�����/�2�����&9�:rZc��ddd�Sr`r]rVs rXrAzSSL4EndpointsTests.connectArgs�
rfrZc��ddd�Srhr]rVs rXr[zSSL4EndpointsTests.listenArgs�
rorZc���tdd��\|_|_tdd��\|_|_t|j|jd��|_td��|_y	)
zF
        Set up client and server SSL contexts for use later.
        zServer Test Certificate�server)�O�CNzClient Test Certificate�clientF)�
privateKey�certificate�requireCertificate)r�N)rM�sKey�sCert�cKey�cCertrG�serverSSLContext�clientSSLContextrVs rXrwzSSL4EndpointsTests.setUp�
sc��!0�'�H�!
���	�4�:�!0�'�H�!
���	�4�:�!3��y�y�d�j�j�U�!
���!3�e� L��rZc	���tddd�}tj||j|jfi|��|j||j|jdd�|jdd�f|fS)a�
        Create an L{SSL4ServerEndpoint} and return the tools to verify its
        behaviour.

        @param factory: The thing that we expect to be passed to our
            L{IStreamServerEndpoint.listen} implementation.
        @param reactor: A fake L{IReactorSSL} that L{SSL4ServerEndpoint} can
            call L{IReactorSSL.listenSSL} on.
        @param listenArgs: Optional dictionary of arguments to
            L{IReactorSSL.listenSSL}.
        rqrrrrmrsrnrN)rr�SSL4ServerEndpointrLr�rurvs     rXrGz'SSL4EndpointsTests.createServerEndpoint�
s����e�Y��2��
�(�(�����t�'<�'<�
�@J�
������%�%����y�"�-����{�B�/�
�
�
�	
rZc
��tddd�}tj||j|j|j
fi|��|j|j||j
|j
dd�|j
dd�f|fS)a�
        Create an L{SSL4ClientEndpoint} and return the values needed to verify
        its behaviour.

        @param reactor: A fake L{IReactorSSL} that L{SSL4ClientEndpoint} can
            call L{IReactorSSL.connectSSL} on.
        @param clientFactory: The thing that we expect to be passed to our
            L{IStreamClientEndpoint.connect} implementation.
        @param connectArgs: Optional dictionary of arguments to
            L{IReactorSSL.connectSSL}
        rqrdrTrXrxrYN)rr�SSL4ClientEndpointrrLr�rurzs     rXrz'SSL4EndpointsTests.createClientEndpoint�
s����e�[�"�5��
�(�(���������%�%�	
�
�
���������%�%����	�2�.����
�t�4�

�
�!
�	
rZN)rlrmrnrorPrr!rAr[rwrGrr]rZrXr�r��
s2���"�"�$;�LD�:�
M�
�8
rZr�c�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�UNIXEndpointsTestsz)
    Tests for UnixSocket Endpoints.
    c�0�|j|�ddS)z�
        Override L{EndpointTestCaseMixin.retrieveConnectedFactory} to account
        for different index of 'factory' in C{connectUNIX} args.
        rrarrs  rXrz+UNIXEndpointsTests.retrieveConnectedFactory$s��
�#�#�G�,�Q�/��2�2rZc��|jS)zF
        @return: List of calls to L{IReactorUNIX.listenUNIX}
        )�unixServersrs  rXrPz"UNIXEndpointsTests.expectedServers+����"�"�"rZc��|jS)zG
        @return: List of calls to L{IReactorUNIX.connectUNIX}
        )�unixClientsrs  rXrz"UNIXEndpointsTests.expectedClients1r�rZc��|\}}}}|\}}}	}
|j||�|j||	�|j||
�y)a
        Compare path, timeout, checkPID in C{receivedArgs} to C{expectedArgs}.
        We ignore the factory because we don't only care what protocol comes
        out of the C{IStreamClientEndpoint.connect} call.

        @param receivedArgs: C{tuple} of (C{path}, C{timeout}, C{checkPID})
            that was passed to L{IReactorUNIX.connectUNIX}.
        @param expectedArgs: C{tuple} of (C{path}, C{timeout}, C{checkPID})
            that we expect to have been passed to L{IReactorUNIX.connectUNIX}.
        NrT)rWrVr%r�rWrX�checkPID�expectedPathr[r\�expectedCheckPIDs           rXr!z$UNIXEndpointsTests.assertConnectArgs7s\��5A�1��~�w��
�	
�����	
����|�,�����/�2�����#3�4rZc��ddd�S)rarbra)rXr�r]rVs rXrAzUNIXEndpointsTests.connectArgsPs���1�-�-rZc��dddd�S)rirji�ra)rm�mode�wantPIDr]rVs rXr[zUNIXEndpointsTests.listenArgsVs����!�<�<rZc	��t|j��}tj||jfi|��|j||jdd�|jdd�|jdd�f|fS)a�
        Create an L{UNIXServerEndpoint} and return the tools to verify its
        behaviour.

        @param reactor: A fake L{IReactorUNIX} that L{UNIXServerEndpoint} can
            call L{IReactorUNIX.listenUNIX} on.
        @param factory: The thing that we expect to be passed to our
            L{IStreamServerEndpoint.listen} implementation.
        @param listenArgs: Optional dictionary of arguments to
            L{IReactorUNIX.listenUNIX}.
        rmrsr��r�r)r �mktempr�UNIXServerEndpointr�rurvs     rXrGz'UNIXEndpointsTests.createServerEndpoint\sw���d�k�k�m�,��
�(�(��'�,�,�M�*�M��������y�"�-����v�u�-����y�!�,�
�
�

�
	
rZc���t|j��}tj||jfi|��|j||jdd�|jdd�f|fS)a�
        Create an L{UNIXClientEndpoint} and return the values needed to verify
        its behaviour.

        @param reactor: A fake L{IReactorUNIX} that L{UNIXClientEndpoint} can
            call L{IReactorUNIX.connectUNIX} on.
        @param clientFactory: The thing that we expect to be passed to our
            L{IStreamClientEndpoint.connect} implementation.
        @param connectArgs: Optional dictionary of arguments to
            L{IReactorUNIX.connectUNIX}
        rXrxr�r)r r�r�UNIXClientEndpointr�rurzs     rXrz'UNIXEndpointsTests.createClientEndpointvsi���d�k�k�m�,��
�(�(��'�,�,�N�+�N��������	�2�.����
�A�.�	
�
�	
�		
rZN)rlrmrnrorrPrr!rAr[rGrr]rZrXr�r�s/���3�#�#�5�2.�=�
�4
rZr�c�V�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zy)�ParserTestszK
    Tests for L{endpoints._parseServer}, the low-level parsing logic.
    r*c�,�tj|i|��S)zT
        Provide a hook for test_strports to substitute the deprecated API.
        )r�_parseServer)rW�a�kws   rX�parsezParserTests.parse�s���%�%�q�/�B�/�/rZc��|j|jd|j�dd|jfddd�f�y)zN
        Simple strings with a 'tcp:' prefix should be parsed as TCP.
        ztcp:80rqrTrNrs�rnrmN�r�r�r�rVs rX�test_simpleTCPzParserTests.test_simpleTCP�s;��	
����J�J�x����(�
�R����L��r�"B�C�	
rZc��|j|jd|j�dd|jfddd�f�y)zU
        TCP port descriptions parse their 'interface' argument as a string.
        ztcp:80:interface=127.0.0.1rqrTrkrsr�Nr�rVs rX�test_interfaceTCPzParserTests.test_interfaceTCP�s<��	
����J�J�3�T�V�V�<�
�R����L���"K�L�	
rZc��|j|jd|j�dd|jfddd�f�y)zU
        TCP port descriptions parse their 'backlog' argument as an integer.
        ztcp:80:backlog=6rqrTrN�r�Nr�rVs rX�test_backlogTCPzParserTests.test_backlogTCP�s<��	
����J�J�)�4�6�6�2�
�R����L��q�"A�B�	
rZc	��|j|jd|j�dd|jfdddd�f�y)	z�
        L{endpoints._parseServer} returns a C{'UNIX'} port description with
        defaults for C{'mode'}, C{'backlog'}, and C{'wantPID'} when passed a
        string with the C{'unix:'} prefix and no other parameter values.
        zunix:/var/run/finger�UNIX�/var/run/fingerr�rsT�r�rmr�Nr�rVs rX�test_simpleUNIXzParserTests.test_simpleUNIX�sC��	
����J�J�-�t�v�v�6��"�D�F�F�+��2�$�?�
�	
rZc	��|j|jd|j�dd|jfdddd�f�y)	zK
        C{mode} can be set by including C{"mode=<some integer>"}.
        zunix:/var/run/finger:mode=0660r�r�i�rsTr�Nr�rVs rX�
test_modeUNIXzParserTests.test_modeUNIX�sC��	
����J�J�7����@��"�D�F�F�+��2�$�?�
�	
rZc	��|j|jd|j�dd|jfdddd�f�y)	zM
        C{wantPID} can be set to false by included C{"lockfile=0"}.
        zunix:/var/run/finger:lockfile=0r�r�r�rsFr�Nr�rVs rX�test_wantPIDUNIXzParserTests.test_wantPIDUNIX�sC��	
����J�J�8�$�&�&�A��"�D�F�F�+��2�%�@�
�	
rZc	��|j|jd|j�dd|jfdddd�f�y)	zf
        Backslash can be used to escape colons and backslashes in port
        descriptions.
        zunix:foo\:bar\=baz\:qux\\r�zfoo:bar=baz:qux\r�rsTr�Nr�rVs rX�test_escapezParserTests.test_escape�sC��
	
����J�J�A�4�6�6�J��&����/��2�$�?�
�	
rZc�N�|jtjd�d�y)z�
        L{endpoints.quoteStringArgument} should quote backslashes and colons
        for interpolation into L{endpoints.serverFromString} and
        L{endpoints.clientFactory} arguments.
        zsome : stuff \zsome \: stuff \\N)r�r�quoteStringArgumentrVs rX�test_quoteStringArgumentz$ParserTests.test_quoteStringArgument�s$��	
����)�)�*=�>�'�	
rZc	��|j|jd|j�dd|jfdddd�f�y)	z�
        In strports descriptions, '=' in a parameter value does not need to be
        quoted; it will simply be parsed as part of the value.
        zunix:address=foo=barr�zfoo=barr�rsTr�Nr�rVs rX�test_impliedEscapezParserTests.test_impliedEscape�sC��
	
����J�J�.����7���D�F�F�#��2�$�?�
�	
rZc�\�|jt|jd|j�y)ze
        L{strports.parse} raises C{ValueError} when given an unknown endpoint
        type.
        zbogus-type:nothingN)rr�r�r�rVs rX�test_unknownTypezParserTests.test_unknownTypes!��
	
���*�d�j�j�2F����OrZN)rlrmrnror�r�r�r�r�r�r�r�r�r�r�r�r]rZrXr�r��sF���	�A�0�
�
�
�

�
�
�
�	
�
�PrZr�c���eZdZdZd�Zeee�d��Zeee�d��Z	dZ
eee�d��Zeee�d��Zeee�d��Z
eee�d	��Zd
�Zd�Zd�Zy
)�ServerStringTestszC
    Tests for L{twisted.internet.endpoints.serverFromString}.
    c�d�t�}tj|d�}|j|tj�|j|j|�|j|jd�|j|jd�|j|jd�y)z�
        When passed a TCP strports description, L{endpoints.serverFromString}
        returns a L{TCP4ServerEndpoint} instance initialized with the values
        from the string.
        z&tcp:1234:backlog=12:interface=10.0.0.1r���10.0.0.1N)r�r�serverFromStringr<rtrpr�r��_port�_backlog�
_interface)rWrr�s   rX�test_tcpzServerStringTests.test_tcps����(���+�+��=�
��	
���f�i�&B�&B�C��
�
�f�o�o�w�/�������t�,�������"�-�����*�*�J�7rZc�6�t�}tj|dt�dt�d��}|j	|tj
�|j
|j|�|j|jd�|j|jd�|j|jd�|j|jjt�|jj�}|j	|t �y)z�
        When passed an SSL strports description, L{endpoints.serverFromString}
        returns a L{SSL4ServerEndpoint} instance initialized with the values
        from the string.
        �ssl:1234:backlog=12:privateKey=�	:certKey=�,:sslmethod=TLSv1_2_METHOD:interface=10.0.0.1r�r�r�N)r�rr��escapedPEMPathNamer<r�rpr�r�r�r�r��_sslContextFactory�methodrE�
getContext�ContextType�rWrr��ctxs    rX�test_sslzServerStringTests.test_ssl%s����(���+�+��"�#5�
7�
��	
���f�i�&B�&B�C��
�
�f�o�o�w�/�������t�,�������"�-�����*�*�J�7�����2�2�9�9�>�J��'�'�2�2�4�����c�;�/rZc�~�t�}tj|dt���}|j	|tj
�|j
|j|�|j|jd�|j|jd�|j|jd�|j|jjt�|j|jj t"z�|jj%�}|j	|t&�y)z�
        An SSL string endpoint description with minimal arguments returns
        a properly initialized L{SSL4ServerEndpoint} instance.
        zssl:4321:privateKey=��rsrNN)r�rr�r�r<r�rpr�r�r�r�r�r�r�rBr��_optionsrDr�r�r�s    rX�test_sslWithDefaultsz&ServerStringTests.test_sslWithDefaults<s����(���+�+��+�,>�+?�@�
��	
���f�i�&B�&B�C��
�
�f�o�o�w�/�������t�,�������"�-�����*�*�B�/�����2�2�9�9�:�F�����%�%�.�.��<�	
��'�'�2�2�4�����c�;�/rZz(ssl:1234:privateKey=%s:extraCertChain=%sc	��tjt�|jtt
fz�}dD�cgc]<}t
jtjd|fz�j����>}}|j}|j|jdjd�|djd��|j|jdjd�|djd��ycc}w)zf
        Specifying a chain file loads the contained certificates in the right
        order.
        )rar�zthing%d.pemr�sha1raN)rr�r��SSL_CHAIN_TEMPLATEr��escapedChainPathNamerF�loadPEM�casPath�child�
getContentr�r��extraCertChain�digest)rWr��n�expectedChainCerts�cfs     rX�test_sslChainLoadsz$ServerStringTests.test_sslChainLoadsVs����+�+��H��#�#�"�$��
�
���
��
����
�
�m�q�d�.B� C� N� N� P�Q�
��
��
&�
&��������a� �'�'��/�1C�A�1F�1M�1M�f�1U�	
�	
������a� �'�'��/�1C�A�1F�1M�1M�f�1U�	
��
s�AD
c	���t|j��}|j�j�|j	t
�5}t
jt�|jtt
j|j�fz�ddd�|jtj�d|j�d��y#1swY�=xYw)zy
        If C{extraCertChain} is passed, it has to contain at least one valid
        certificate in PEM format.
        NzSpecified chain file 'z7' doesn't contain any valid certificates in PEM format.)r;r��create�closerr�rr�r�r�r�r�r�r�r�rX)rW�fp�caughts   rX� test_sslChainFileMustContainCertz2ServerStringTests.test_sslChainFileMustContainCertss����d�k�k�m�
$��
�	�	������
�
�z�
*�	�f��&�&����'�'�&��1�1�"�'�'�:���
�	�	
����� � �!�
�w�w�	
�	
�	�	�s
�
AC�C!c�0�d}t�}tj|djtt|��}|j
}|j
|jt�|jt|�|jj�y)z�
        If C{dhParameters} are specified, they are passed as
        L{DiffieHellmanParameters} into L{CertificateOptions}.
        �someFilez1ssl:4321:privateKey={}:certKey={}:dhParameters={}N)r�rr��formatr�r�r<�dhParametersrHr�r;�_dhFile)rW�fileNamerr�r�s     rX�test_sslDHparametersz&ServerStringTests.test_sslDHparameters�sz�����(���+�+��?�F�F�"�$6��
�
���
&�
&�����b�o�o�/F�G�����(�+�R�_�_�-D�-D�ErZc�6�t�}tj|dt�dt�d��}|j|tj�|j|j|�|j|jd�|j|jd�|j|jd�|j|jjt�|jj!�}|j|t"�y)zq
        Lack of a trailing newline in key and cert .pem files should not
        generate an exception.
        r�r�r�r�r�r�N)r�rr��&escapedNoTrailingNewlineKeyPEMPathName�'escapedNoTrailingNewlineCertPEMPathNamer<r�rpr�r�r�r�r�r�r�rEr�r�r�s    rX�test_sslNoTrailingNewlinePemz.ServerStringTests.test_sslNoTrailingNewlinePem�s����(���+�+��7�7�	
�
��	
���f�i�&B�&B�C��
�
�f�o�o�w�/�������t�,�������"�-�����*�*�J�7�����2�2�9�9�>�J��'�'�2�2�4�����c�;�/rZc��t�}tj|d�}|j|tj�|j|j|�|j|jd�|j|jd�|j|jd�|j|j�y)z�
        When passed a UNIX strports description, L{endpoint.serverFromString}
        returns a L{UNIXServerEndpoint} instance initialized with the values
        from the string.
        z0unix:/var/foo/bar:backlog=7:mode=0123:lockfile=1�/var/foo/bar��SN)
r�rr�r<r�rpr�r��_addressr��_moder��_wantPID)rWrrvs   rX�	test_unixzServerStringTests.test_unix�s����(���-�-��G�
��	
���h�	�(D�(D�E��
�
�h�'�'��1�����*�*�N�;�����*�*�A�.��������/�����)�)�*rZc��|jttjdd�}|j	t|�d�y)zq
        L{endpoints.serverFromString} raises C{ValueError} when given an
        unknown endpoint type.
        N�ftl:andromeda/carcosa/hali/2387�Unknown endpoint type: 'ftl')rr�rr�r�r��rWr/s  rXr�z"ServerStringTests.test_unknownType��=��
�!�!���&�&��-�
��	
����U��%C�DrZc�*�t|�t�}tj|d�}ddlm}|j
|j|�|j|j|ddf�|j|jtdd���y	)
z�
        L{endpoints.serverFromString} looks up plugins of type
        L{IStreamServerEndpoint} and constructs endpoints from them.
        zfake:hello:world:yes=no:up=downr)�fake�hello�world�no�down)�yes�upN)�
addFakePluginr�rr��twisted.plugins.fakeendpointrrp�parserr�r�r��dict)rW�notAReactor�fakeEndpointrs    rX�test_typeFromPluginz%ServerStringTests.test_typeFromPlugin�s|��	�d���h�� �1�1��:�
��	6��
�
�l�)�)�4�0�����*�*�[�'�7�,K�L�����,�,�d�t��.G�HrZN)rlrmrnror�r�skipSSL�
skipSSLReasonr�r�r�r�rr	r
rr�r)r]rZrXr�r�s����8� �G�]�#�0�$�0�,�G�]�#�0�$�0�.D���G�]�#�
�$�
�8�G�]�#�
�$�
�>�G�]�#�F�$�F�"�G�]�#�0�$�0�0+�"E�IrZr�c������ddl��jj��ttj
�����fd�}|j
|�t|j��}|j�tt�jj|�j|j|��tj
j!|j"�y)z�
    For the duration of C{testCase}, add a fake plugin to twisted.plugins which
    contains some sample endpoint parsers.
    rNc����jj��jj���tjddyrd)�modules�clear�updater�__path__)�savedModules�savedPluginPath�syss���rX�cleanupzaddFakePlugin.<locals>.cleanup�s5��������������<�(�-�����rZ)r4r.r��listrr1r3r;r��createDirectoryr<rl�filePath�sibling�copyTor�rer�)�testCase�dropinSourcer5rr2r3r4s    @@@rXr#r#�s����
��;�;�#�#�%�L��7�+�+�,�O�.�

���� �	�(�/�/�#�	$�B�����
�h�� � �(�(��6�=�=�b�h�h�|�>T�U������B�G�G�$rZc�R�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy
)�ClientStringTestszC
    Tests for L{twisted.internet.endpoints.clientFromString}.
    c��t�}tj|d�}|j|tj�|j|j|�|j|jd�|j|jd�|j|jd�|j|jd�y)z�
        When passed a TCP strports description, L{endpoints.clientFromString}
        returns a L{TCP4ClientEndpoint} instance initialized with the values
        from the string.
        z=tcp:host=example.com:port=1234:timeout=7:bindAddress=10.0.0.2r�r�r�z10.0.0.2rN�r�r�clientFromStringr<ryrpr�r��_hostr��_timeout�_bindAddress�rWrr�s   rXr�zClientStringTests.test_tcp
s����(���+�+��T�
��	
���f�i�&B�&B�C��
�
�f�o�o�w�/�������}�5�������t�,�������!�,�����,�,�o�>rZc��t�}tj|d�}|j|tj�|j|j|�|j|jd�|j|jd�|j|jd�|j|jd�y)z�
        When passed a TCP strports description using positional arguments,
        L{endpoints.clientFromString} returns a L{TCP4ClientEndpoint} instance
        initialized with the values from the string.
        z3tcp:example.com:1234:timeout=7:bindAddress=10.0.0.2r�r�rr@NrArFs   rX�test_tcpPositionalArgsz(ClientStringTests.test_tcpPositionalArgs
s����(���+�+��J�
��	
���f�i�&B�&B�C��
�
�f�o�o�w�/�������}�5�������t�,�������!�,�����,�,�o�>rZc��t�}tj|d�}|j|jd�|j|j
d�y)z�
        When passed a TCP strports description specifying host as a positional
        argument, L{endpoints.clientFromString} returns a L{TCP4ClientEndpoint}
        instance initialized with the values from the string.
        z8tcp:example.com:port=1234:timeout=7:bindAddress=10.0.0.2r�r�N�r�rrBr�rCr�rFs   rX�test_tcpHostPositionalArgz+ClientStringTests.test_tcpHostPositionalArg.
sK���(���+�+��O�
��	
������}�5�������t�,rZc��t�}tj|d�}|j|jd�|j|j
d�y)z�
        When passed a TCP strports description specifying port as a positional
        argument, L{endpoints.clientFromString} returns a L{TCP4ClientEndpoint}
        instance initialized with the values from the string.
        z8tcp:host=example.com:1234:timeout=7:bindAddress=10.0.0.2r�r�NrJrFs   rX�test_tcpPortPositionalArgz+ClientStringTests.test_tcpPortPositionalArg<
sK���(���+�+��O�
��	
������}�5�������t�,rZc��t�}tj|d�}|j|jd�|j|j�y)z{
        A TCP strports description may omit I{timeout} or I{bindAddress} to
        allow the default to be used.
        ztcp:host=example.com:port=1234rxN)r�rrBr�rDr�rErFs   rX�test_tcpDefaultsz"ClientStringTests.test_tcpDefaultsI
sF��
�(���+�+�G�5U�V��������"�-����&�-�-�.rZc�b�t�}tj|d�}|j|tj�|j|j|�|j|jd�|j|jd�|j|j�y)z�
        When passed a UNIX strports description, L{endpoints.clientFromString}
        returns a L{UNIXClientEndpoint} instance initialized with the values
        from the string.
        z+unix:path=/var/foo/bar:lockfile=1:timeout=9r�	N�r�rrBr<r�rpr�r�r�rDr��	_checkPIDrFs   rXrzClientStringTests.test_unixS
s����(���+�+��B�
��	
���f�i�&B�&B�C��
�
�f�o�o�w�/�������~�6�������!�,�����(�(�)rZc��tjt�d�}|j|jd�|j|j�y)zz
        A UNIX strports description may omit I{lockfile} or I{timeout} to allow
        the defaults to be used.
        zunix:path=/var/foo/barrxN)rrBr�r�rDr�rS)rWr�s  rX�test_unixDefaultsz#ClientStringTests.test_unixDefaultsc
sA��
�+�+�F�H�6N�O��������"�-�����)�)�*rZc�b�t�}tj|d�}|j|tj�|j|j|�|j|jd�|j|jd�|j|j�y)z�
        When passed a UNIX strports description specifying path as a positional
        argument, L{endpoints.clientFromString} returns a L{UNIXClientEndpoint}
        instance initialized with the values from the string.
        z&unix:/var/foo/bar:lockfile=1:timeout=9rrQNrRrFs   rX�test_unixPathPositionalArgz,ClientStringTests.test_unixPathPositionalArgl
s����(���+�+��=�
��	
���f�i�&B�&B�C��
�
�f�o�o�w�/�������~�6�������!�,�����(�(�)rZc�*�t|�t�}tj|d�}ddlm}|j
|j|�|j|j|ddf�|j|jtdd���y	)
z�
        L{endpoints.clientFromString} looks up plugins of type
        L{IStreamClientEndpoint} and constructs endpoints from them.
        �crfake:alpha:beta:cee=dee:num=1r��fakeClientWithReactor�alpha�beta�dee�1��cee�numN)r#r�rrBr$r[rpr%r�r�r�r&)rWr'�clientEndpointr[s    rXr)z%ClientStringTests.test_typeFromPlugin|
s~��
	�d���h��"�3�3��:�
��	G��
�
�n�+�+�-B�C�����,�,�{�G�V�.L�M�����.�.���C�0H�IrZc��|jttjdd�}|j	t|�d�y)zq
        L{endpoints.clientFromString} raises C{ValueError} when given an
        unknown endpoint type.
        Nrr)rr�rrBr�r�rs  rXr�z"ClientStringTests.test_unknownType�
rrZc	���t|�t�}tj|d�}ddlm}|j
|j|j|jf||ddftdd��f�y	)
z�
        L{endpoints.clientFromString} will pass a reactor to plugins
        implementing the L{IStreamClientEndpointStringParserWithReactor}
        interface.
        rYrrZr\r]r^r_r`N)r#r�rrBr$r[r�r%r�r�r&)rWrrcr[s    rX�test_stringParserWithReactorz.ClientStringTests.test_stringParserWithReactor�
su��	�d���(��"�3�3��6�
��	G����
�
"�
"�N�$7�$7��9N�9N�O�%��'�6�*���C�(�
�	
rZN)rlrmrnror�rHrKrMrOrrUrWr)r�rfr]rZrXr>r>
s@���?�"?�"-�-�/�*� +�*� J� E�
rZr>c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�SSLClientStringTestszU
    Tests for L{twisted.internet.endpoints.clientFromString} which require SSL.
    c	��	�t�}tj|dt�dt�dt���}|j|tj�|j|j|�|j|jd�|j|jd�|j|jd�|j|jd�|j}|j|t�|j|j t"�|j%|j&t(z�|j+�}|j|t,�|jt/|j0�t2�t5|j0�}|j7t9|j:��|j|t<�t>jAd�t>jAd	�fD�cgc]R}|jC�jE�jGd
�r#t/jH|jK����T}}g�	G�	fd�d�}|jLjO|��|jtQd
��	D�d���tQ|d����ycc}w)��
        When passed an SSL strports description, L{clientFromString} returns a
        L{SSL4ClientEndpoint} instance initialized with the values from the
        string.
        z*ssl:host=example.net:port=4321:privateKey=r��+:bindAddress=10.0.0.3:timeout=3:caCertsDir=�example.netr�r��z10.0.0.3r�
thing1.pem�
thing2.pemz.pemc���eZdZ�fd�Zy)�.SSLClientStringTests.test_ssl.<locals>.ListCtxc�*��G�fd�d�}|�S)Nc���eZdZ�fd�Zy)�LSSLClientStringTests.test_ssl.<locals>.ListCtx.get_cert_store.<locals>.Storec�(���j|�yrdr�)rW�cert�
addedCertss  �rX�add_certzUSSLClientStringTests.test_ssl.<locals>.ListCtx.get_cert_store.<locals>.Store.add_cert�
s���"�)�)�$�/rZN)rlrmrnrx�rws�rX�Storert�
s���0rZrzr])rWrzrws  �rX�get_cert_storez=SSLClientStringTests.test_ssl.<locals>.ListCtx.get_cert_store�
s���0�0��w�rZN)rlrmrnr{rys�rX�ListCtxrq�
s���
rZr|c3�2K�|]}t|����y�wrd)rF)�.0�xs  rX�	<genexpr>z0SSLClientStringTests.test_ssl.<locals>.<genexpr>�
s����4�A��Q��4�s�c�"�|j�Srd�r��rvs rXr�z/SSLClientStringTests.test_ssl.<locals>.<lambda>�
s��t�{�{�}�rZ)�keyc�"�|j�Srdr�r�s rXr�z/SSLClientStringTests.test_ssl.<locals>.<lambda>�
s��4�;�;�=�rZN))r�rrBr��escapedCAsPathNamer<r�rpr�r�rCr�rDrEr�rGr�rBr�r�rDr�r�rFr��testCertificaterJ�_setPrivateKeyrIr��testPrivateCertificater�r��basename�lower�endswithr�r��	trustRoot�_addCACertsToContext�sorted)
rWrr��certOptionsr��privateCertr�
expectedCertsr|rws
         @rXr�zSSLClientStringTests.test_ssl�
s(����(���+�+��"�#5�7I�
K�
��	
���f�i�&B�&B�C��
�
�f�o�o�w�/�������}�5�������t�,�������!�,�����,�,�o�>��/�/�����k�+=�>�����+�+�Z�8�����,�,�{�:�;��$�$�&�����c�;�/�����[�%<�%<�=��O�(��)@�)@�A���"�"�7�;�+A�+A�#B�C�����&<�=��m�m�L�1�7�=�=��3N�O�
���z�z�|�!�!�#�,�,�V�4�
�������/�
�
�
�
�
�	�	�	���2�2�7�9�=�����4��4�:T�
�
�=�&@�A�		
��!
s�AK
c	���t�}tj|dt�dt�dt���}|j|tj�|j|j|�|j|jd�|j|jd�|j|jd�|j|jd�y)	rjz ssl:example.net:4321:privateKey=r�rkrlr�r�rmN)r�rrBr�r�r<r�rpr�r�rCr�rDrErFs   rX�test_sslPositionalArgsz+SSLClientStringTests.test_sslPositionalArgs�
s����(���+�+��"�#5�7I�
K�
��	
���f�i�&B�&B�C��
�
�f�o�o�w�/�������}�5�������t�,�������!�,�����,�,�o�>rZc���t�}tj|d�}|j|tj�|j|j|�|j|jd�|j|jd�|j}|j|jt�|j|j�|j|j�y)z�
        When passed an SSL strports description without extra arguments,
        L{clientFromString} returns a L{SSL4ClientEndpoint} instance
        whose context factory is initialized with default values.
        zssl:example.net:4321rlr�N)r�rrBr<r�rpr�r�rCr�r�r�rBr�r�r�)rWrr�r�s    rXr�z)SSLClientStringTests.test_sslWithDefaults�
s����(���+�+�G�5K�L�����f�i�&B�&B�C��
�
�f�o�o�w�/�������}�5�������t�,��/�/������+�+�Z�8����+�1�1�2����+�0�0�1rZc�v�Gd�dt�}tjd�j�}||_|jt
j|�jD�cgc]
}t|���c}tjtjd�j��g�ycc}w)z�
        If a certificate in the directory is unreadable,
        L{endpoints._loadCAsFromDir} will ignore that certificate.
        c��eZdZd�Zy)�KSSLClientStringTests.test_unreadableCertificate.<locals>.UnreadableFilePathc��tj|�}|tjd�j�k(rt	t
��|S)Nro)r;r�r�r��OSErrorrrfs  rXr�zVSSLClientStringTests.test_unreadableCertificate.<locals>.UnreadableFilePath.getContents=���*�*�4�0���7�=�=��6�A�A�C�C�!�%�.�(��KrZN)rlrmrnr�r]rZrX�UnreadableFilePathr�s��
 rZr�r�rnN)r;r�r��parent�	clonePathr�r�_loadCAsFromDir�_caCertsrFr�r�)rWr��casPathCloners    rX�test_unreadableCertificatez/SSLClientStringTests.test_unreadableCertificates���	 ��	 ��}�}�Y�/�6�6�8��!3������%.�%>�%>�|�%L�%U�%U�V��[��^�V�
�
 �
 ����|�!<�!G�!G�!I�
J�K�	
��Vs�&B6c�
�t�}tj|d�}|j}|j	|t
�|j
|j�|j�}|j	|t�y)z�
        When passed an SSL strports description without any extra parameters,
        L{clientFromString} returns a simple non-verifying endpoint that will
        speak SSL.
        z%ssl:host=simple.example.org:port=4321N)
r�rrBr�r<rGr��verifyr�r�)rWrr�r�r�s     rX�test_sslSimplez#SSLClientStringTests.test_sslSimple'sq���(���+�+��<�
���/�/�����k�+=�>�����+�+�,��$�$�&�����c�;�/rZN)	rlrmrnror�r�r�r�r�r]rZrXrhrh�
s!���2
�h?�(2�"
�.0rZrhc�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
� AdoptedStreamServerEndpointTestszA
    Tests for adopted socket-based stream server endpoints.
    c�T�tj|||�}d�|_d�|_|S)z�
        Create an L{AdoptedStreamServerEndpoint} which may safely be used with
        an invalid file descriptor.  This is convenient for a number of unit
        tests.
        c��yrdr]�r�s rXr�zPAdoptedStreamServerEndpointTests._createStubbedAdoptedEndpoint.<locals>.<lambda>Fr�rZc��yrdr]r�s rXr�zPAdoptedStreamServerEndpointTests._createStubbedAdoptedEndpoint.<locals>.<lambda>Gr�rZ)r�AdoptedStreamServerEndpoint�_close�_setNonBlocking)rWr�fileno�
addressFamilyr�s     rX�_createStubbedAdoptedEndpointz>AdoptedStreamServerEndpointTests._createStubbedAdoptedEndpoint=s.��
�1�1�'�6�=�Q��#���+����rZc�b�d}t}|j|||�}tddd�}||||f|fS)a�
        Create a new L{AdoptedStreamServerEndpoint} for use by a test.

        @return: A three-tuple:
            - The endpoint
            - A tuple of the arguments expected to be passed to the underlying
              reactor method
            - An IAddress object which will match the result of
              L{IListeningPort.getHost} on the port returned by the endpoint.
        r�rqrrr�)rr�r)rWrr�r�r�rvrs       rXrGz5AdoptedStreamServerEndpointTests.createServerEndpointJsD�����
��5�5�g�v�}�U���e�Y��5���6�=�'�:�G�D�DrZc��|jS)z�
        @return: The ports which were actually adopted by C{reactor} via calls
            to its L{IReactorSocket.adoptStreamPort} implementation.
        )�adoptedPortsrs  rXrPz0AdoptedStreamServerEndpointTests.expectedServers\s��
�#�#�#rZc��iS)zx
        @return: A C{dict} of additional keyword arguments to pass to the
            C{createServerEndpoint}.
        r]rVs rXr[z+AdoptedStreamServerEndpointTests.listenArgscs	��
�	rZc����t���j�dt�}|jt	���j|jt	��tj�}��fd�}|j|�|S)z�
        L{AdoptedStreamServerEndpoint.listen} can only be used once.  The file
        descriptor given is closed after the first use, and subsequent calls to
        C{listen} return a L{Deferred} that fails with L{AlreadyListened}.
        �
c�P���jdt�j��yr`)r�r r�)r�rrWs ��rX�listenFailedzEAdoptedStreamServerEndpointTests.test_singleUse.<locals>.listenFailedus������Q��G�$8�$8� 9�:rZ)	rr�rrOr�r�r�AlreadyListenedr�)rWrvr�r�rs`   @rX�test_singleUsez/AdoptedStreamServerEndpointTests.test_singleUsejsi��� �/���5�5�g�r�7�K�������!����x���v�x�8�%�:O�:O�P��	;�	
�
�
�l�#��rZc�����t�}�j|dt�}g��fd�}||_|j	t��}��fd�}|j
|�|S)zv
        L{AdoptedStreamServerEndpoint.listen} sets the file description given
        to it to non-blocking.
        r�c�,���jd|f�y)N�setNonBlockingr�)r��eventss �rXr�zTAdoptedStreamServerEndpointTests.test_descriptionNonBlocking.<locals>.setNonBlocking�s����M�M�+�V�4�5rZc�,���jdg��y)N)r�r�rT�r�r�rWs ��rX�listenedzNAdoptedStreamServerEndpointTests.test_descriptionNonBlocking.<locals>.listened�s������4�5�v�>rZ)rr�rr�rOr�r�)rWrrvr�r�r�r�s`     @rX�test_descriptionNonBlockingz<AdoptedStreamServerEndpointTests.test_descriptionNonBlocking{s\���
 �/���5�5�g�r�7�K����	6�$2�� ��O�O�F�H�%��	?�	
�
�
�h���rZc������t���j�dt�}g���fd�}||_|j	t��}��fd�}|j
|�|S)z�
        L{AdoptedStreamServerEndpoint.listen} closes its file descriptor after
        adding it to the reactor with L{IReactorSocket.adoptStreamPort}.
        r�c�T���jd|t�j�f�y)Nr�)rer r�)r�r�rs ��rXr�zEAdoptedStreamServerEndpointTests.test_descriptorClosed.<locals>.close�s!����M�M�7�F�C��0D�0D�,E�F�GrZc�,���jdg��y)N)r�r�rarTr�s ��rXr�zHAdoptedStreamServerEndpointTests.test_descriptorClosed.<locals>.listened�s������.�/��8rZ)rr�rr�rOr�r�)rWrvr�r�r�r�rs`    @@rX�test_descriptorClosedz6AdoptedStreamServerEndpointTests.test_descriptorClosed�s\���
 �/���5�5�g�r�7�K����	H� ����O�O�F�H�%��	9�	
�
�
�h���rZN)rlrmrnror�rGrPr[r�r�r�r]rZrXr�r�8s+����E�$$���"�,rZr�c��eZdZdZej
Zd�Zd�Zde	de
ddfd�Zde	de
ddfd	�Zdd
�Z
dd�Zdd�Zdd
�Zdd�Zdd�Zdd�Zy)�SystemdEndpointPluginTestsz�
    Unit tests for the systemd stream server endpoint and endpoint string
    description parser.

    @see: U{systemd<http://www.freedesktop.org/wiki/Software/systemd>}
    c��tttj��}|D]}t	||j
�s�y|j
d|���y)z�
        L{endpoints._SystemdParser} is found as a plugin for
        L{interfaces.IStreamServerEndpointStringParser} interface.
        zDid not find systemd parser in N�r6r4r�!IStreamServerEndpointStringParserr��_parserClassr��rW�parsersr�s   rX�test_pluginDiscoveryz/SystemdEndpointPluginTests.test_pluginDiscovery�sS��
�z�*�"N�"N�O�P���	E�A��!�T�.�.�/��	E�
�I�I�7��{�C�DrZc�v�|j�}|jttj|��y)zx
        L{endpoints._SystemdParser} instances provide
        L{interfaces.IStreamServerEndpointStringParser}.
        N�r�r�rrr��rWr%s  rXrz)SystemdEndpointPluginTests.test_interface��.��
�"�"�$�������E�E�v�N�	
rZr��addressFamilyString�returnNc�V�t�}gd�}gd�}d}|j�}t||�|_|j	||t|���}|j
|j|�|j|j|�|j|j||�y)a
        Helper for tests for L{endpoints._SystemdParser.parseStreamServer}
        for different address families with a descriptor identified by index.

        Handling of the address family given will be verify.  If there is a
        problem a test-failing exception will be raised.

        @param addressFamily: An address family constant, like
            L{socket.AF_INET}.

        @param addressFamilyString: A string which should be recognized by the
            parser as representing C{addressFamily}.
        �r�r�r�rQ�z5.socketz6.socket�fooz8.socketz9.socketr�)�domain�indexN)r�r�r=�	_sddaemon�parseStreamServerr�rprr�r�r�)	rWr�r�r�descriptors�namesr�r%r�s	         rX�_parseIndexStreamServerTestz6SystemdEndpointPluginTests._parseIndexStreamServerTest�s��� �(��%��G�����"�"�$��$�[�%�8����)�)��/�s�5�z�*�
��	
�
�
�f�n�n�g�.�����-�-�}�=��������E�(:�;rZc�b�t�}gd�}gd�}d}|j�}t||�|_|j	|||��}|j|j|�|j|j|�|j|j||j|��y)ze
        Like L{_parseIndexStreamServerTest} but for descriptors identified by
        name.
        r�r�r�)r�r�N)r�r�r=r�r�rprr�r�r�r�)	rWr�r�rr�r�r�r%r�s	         rX�_parseNameStreamServerTestz5SystemdEndpointPluginTests._parseNameStreamServerTest�s����(��%��G�����"�"�$��$�[�%�8����)�)��&��*�
��
	
�
�
�f�n�n�g�.�����-�-�}�=��������E�K�K��4E�(F�GrZc�0�|jtd�y�zC
        IPv4 can be specified using the string C{"INET"}.
        �INETN)r�rrVs rX�test_parseIndexStreamServerINETz:SystemdEndpointPluginTests.test_parseIndexStreamServerINETs��	
�(�(��&�9rZc�0�|jtd�y�zD
        IPv6 can be specified using the string C{"INET6"}.
        �INET6N)r�rrVs rX� test_parseIndexStreamServerINET6z;SystemdEndpointPluginTests.test_parseIndexStreamServerINET6s��	
�(�(��7�;rZc�z�	ddlm}|j|d�y#t$rt	j
d��wxYw�zS
        A UNIX domain socket can be specified using the string C{"UNIX"}.
        r)�AF_UNIXr�zPlatform lacks AF_UNIX supportN)�socketr�r��ImportErrorr@�SkipTest�rWr�s  rX�test_parseIndexStreamServerUNIXz:SystemdEndpointPluginTests.test_parseIndexStreamServerUNIXsA��	>�&�
�,�,�W�f�=���	F��#�#�$D�E�E�	F����:c�0�|jtd�yr�)r�rrVs rX�test_parseNameStreamServerINETz9SystemdEndpointPluginTests.test_parseNameStreamServerINETs��	
�'�'���8rZc�0�|jtd�yr�)r�rrVs rX�test_parseNameStreamServerINET6z:SystemdEndpointPluginTests.test_parseNameStreamServerINET6s��	
�'�'��'�:rZc�z�	ddlm}|j|d�y#t$rt	j
d��wxYwr�)r�r�r�r�r@r�r�s  rX�test_parseNameStreamServerUNIXz9SystemdEndpointPluginTests.test_parseNameStreamServerUNIX#sA��	=�&�
�+�+�G�V�<���	F��#�#�$D�E�E�	F�r�c���|j�}tgd�|_|jt�5|jtddd��ddd�y#1swYyxYw)zQ
        The endpoint cannot be defined using both C{index} and C{name}.
        r]r�rr�)r�r�r�N)r�r=r�rr�r�rr�s  rX�"test_indexAndNameMutuallyExclusivez=SystemdEndpointPluginTests.test_indexAndNameMutuallyExclusive.s_���"�"�$��$�R��,���
�
�
�z�
*�	R��$�$�W�V�1�5�$�Q�	R�	R�	R�s�A�A#)r�N)rlrmrnror�_SystemdParserr�r�rrr�r�r�r�r�r�r�r�r�r�r]rZrXr�r��s�����+�+�L�E�
�<�*�<�AD�<�	
�<�>H�*�H�AD�H�	
�H�0:�<�	>�9�;�	=�RrZr�c�:�eZdZdZej
Zd�Zd�Zd�Z	y)�TCP6ServerEndpointPluginTestsz[
    Unit tests for the TCP IPv6 stream server endpoint string description
    parser.
    c��tttj��}|D]}t	||j
�s�y|j
d|���y)z�
        L{endpoints._TCP6ServerParser} is found as a plugin for
        L{interfaces.IStreamServerEndpointStringParser} interface.
        z*Did not find TCP6ServerEndpoint parser in Nr�r�s   rXr�z2TCP6ServerEndpointPluginTests.test_pluginDiscovery@�S��
�z�*�"N�"N�O�P���	P�A��!�T�.�.�/��	P�
�I�I�B�7�+�N�OrZc�v�|j�}|jttj|��y)z{
        L{endpoints._TCP6ServerParser} instances provide
        L{interfaces.IStreamServerEndpointStringParser}.
        Nr�r�s  rXrz,TCP6ServerEndpointPluginTests.test_interfaceLr�rZc�h�tjt�d�}|j|tj�|j|j
t�|j
|jd�|j
|jd�|j
|jd�y)z�
        L{serverFromString} returns a L{TCP6ServerEndpoint} instance with a
        'tcp6' endpoint string description.
        z$tcp6:8080:backlog=12:interface=\:\:1i�r�r�N)
rr�rr<r�r�r�r�r�r�r�s  rX�test_stringDescriptionz4TCP6ServerEndpointPluginTests.test_stringDescriptionVs���
�
'�
'��O�D�
��	
���b�)�">�">�?����b�k�k�=�9�������4�(�������b�)��������.rZN)
rlrmrnror�_TCP6ServerParserr�r�rrr]rZrXr�r�8s$���
�.�.�L�
P�
�/rZr�c�:�eZdZdZej
Zd�Zd�Zd�Z	y)�StandardIOEndpointPluginTestszM
    Unit tests for the Standard I/O endpoint string description parser.
    c��tttj��}|D]}t	||j
�s�y|j
d|���y)z�
        L{endpoints._StandardIOParser} is found as a plugin for
        L{interfaces.IStreamServerEndpointStringParser} interface.
        z*Did not find StandardIOEndpoint parser in Nr�r�s   rXr�z2StandardIOEndpointPluginTests.test_pluginDiscoverylrrZc�v�|j�}|jttj|��y)z{
        L{endpoints._StandardIOParser} instances provide
        L{interfaces.IStreamServerEndpointStringParser}.
        Nr�r�s  rXrz,StandardIOEndpointPluginTests.test_interfacexr�rZc��tjt�d�}|j|tj�|j|j
t�y)z�
        L{serverFromString} returns a L{StandardIOEndpoint} instance with a
        'stdio' endpoint string description.
        zstdio:N)rr�rr<ror�r�s  rXrz4StandardIOEndpointPluginTests.test_stringDescription�sB��
�
'�
'�
���
B�����b�)�">�">�?����b�k�k�=�9rZN)
rlrmrnror�_StandardIOParserr�r�rrr]rZrXrres$����.�.�L�
P�
�:rZrc��eZdZdZd�Zd�Zy)�ConnectProtocolTestsz'
    Tests for C{connectProtocol}.
    c��t�}tj|dd�}t�}tj||�|jt
|j�d�|jddj}|j|tj�|j|jd�|�y)z�
        C{endpoints.connectProtocol} calls the given endpoint's C{connect()}
        method with a factory that will build the given protocol.
        rkrrar�N)rrryr��connectProtocolr�r rQ�_wrappedFactoryr<rr*rpr�)rWrrv�theProtocolr�s     rX�"test_connectProtocolCreatesFactoryz7ConnectProtocolTests.test_connectProtocolCreatesFactory�s���
 �/���/�/���a�H���h���!�!�(�K�8�	
����W�/�/�0�!�4��$�$�Q�'��*�:�:�����g�x�'7�'7�8��
�
�g�+�+�D�1�;�?rZc���tj��G�fd�d�}|�}|j�tj|t���y)z~
        C{endpoints.connectProtocol} returns the result of calling the given
        endpoint's C{connect()} method.
        c���eZdZ�fd�Zy)�OConnectProtocolTests.test_connectProtocolReturnsConnectResult.<locals>.Endpointc����S)zR
                Return a marker object for use in our assertion.
                r])rWr�r�s  �rXrzWConnectProtocolTests.test_connectProtocolReturnsConnectResult.<locals>.Endpoint.connect�s
����
rZN)rlrmrnr)r�s�rX�Endpointr�s���
rZrN)rr�rprrr�)rWrrvr�s   @rX�(test_connectProtocolReturnsConnectResultz=ConnectProtocolTests.test_connectProtocolReturnsConnectResult�sA���
���!��	�	��:���
�
�f�i�7�7��&�(�K�LrZN)rlrmrnrorrr]rZrXr
r
�s���@�$MrZr
c�2��eZdZdZ�fd�Z�fd�Zd�Z�xZS)�UppercaseWrapperProtocolzL
    A wrapper protocol which uppercases all strings passed through it.
    c�@��t�|�|j��y)z�
        Uppercase a string passed in from the transport.

        @param data: The string to uppercase.
        @type data: L{bytes}
        N)r�rg�upper�rWrSr�s  �rXrgz%UppercaseWrapperProtocol.dataReceived�s���	���T�Z�Z�\�*rZc�@��t�|�|j��y)z�
        Uppercase a string passed out to the transport.

        @param data: The string to uppercase.
        @type data: L{bytes}
        N)r�r�rrs  �rXr�zUppercaseWrapperProtocol.write�s���	��
�d�j�j�l�#rZc�4�|D]}|j|��y)zy
        Uppercase a series of strings passed out to the transport.

        @param seq: An iterable of strings.
        Nr�)rW�seqrSs   rXrz&UppercaseWrapperProtocol.writeSequence�s���	�D��J�J�t��	rZ)rlrmrnrorgr�rr�r�s@rXrr�s����+�$�rZrc��eZdZdZeZy)�UppercaseWrapperFactoryzK
    A wrapper factory which uppercases all strings passed through it.
    N)rlrmrnrorrr]rZrXr"r"�s���(�HrZr"c��eZdZdZd�Zd�Zy)�NetstringTrackerz�
    A netstring receiver which keeps track of the strings received.

    @ivar strings: A L{list} of received strings, in order.
    c��g|_yrd)�stringsrVs rXrYzNetstringTracker.__init__�s	����rZc�:�|jj|�y)z�
        Receive a string and append it to C{self.strings}.

        @param string: The string to be appended to C{self.strings}.
        N)r&re)rWr�s  rX�stringReceivedzNetstringTracker.stringReceived�s��	
�����F�#rZN)rlrmrnrorYr(r]rZrXr$r$�s����$rZr$c��eZdZdZy)�	FakeErrorz�
    An error which isn't really an error.

    This is raised in the L{wrapClientTLS} tests in place of a
    'real' exception.
    Nr_r]rZrXr*r*�s��rZr*c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�WrapperClientEndpointTestsz.
    Tests for L{_WrapperClientEndpoint}.
    c���t�\|_|_t�|_tj|jt�|_tjt�|_yrd)
r>rv�	completerr��contextr�_WrapperEndpointr"r�r*r�r$r�rVs rXrwz WrapperClientEndpointTests.setUp�sM��(;�(=�%��
�t�~��x��� �1�1��M�M�2�
����*�*�+;�<��rZc�H�|jj|j�}|jj	�}|j|�}|jjjd�|j�|j|jdg�y)z�
        Any modifications performed by the underlying L{ProtocolWrapper}
        propagate through to the wrapped L{Protocol}.
        s5:hello,sHELLON)r�rr�r.�succeedOncersr�r�r��flushr�r&�rW�
connecting�pumpr#s    rX�test_wrappingBehaviorz0WrapperClientEndpointTests.test_wrappingBehaviorsu��
�\�\�)�)�$�,�,�7�
��~�~�)�)�+���$�$�Z�0�������#�#�K�0��
�
���������
�3rZc��|jj|j�}|jj	�}|j|�}|j
d�|j|jj�d�y)z�
        Methods defined on the wrapped L{Protocol} are accessible from the
        L{Protocol} returned from C{connect}'s L{Deferred}.
        sspams4:SPAM,N)
r�rr�r.r2rs�
sendStringr��clientIO�getOutBufferr4s    rX�test_methodsAvailablez0WrapperClientEndpointTests.test_methodsAvailablesi��
�\�\�)�)�$�,�,�7�
��~�~�)�)�+���$�$�Z�0��
����!�������3�3�5�z�BrZc���|jj|j�}|j|�|jjt
��|j|t�y)zS
        Connection failures propagate upward to C{connect}'s L{Deferred}.
        N)r�rr��assertNoResultr.�failOncer*r��rWr�s  rX�test_connectionFailurez1WrapperClientEndpointTests.test_connectionFailuresN��
�L�L� � ����.�����A�������	��,����Q�	�*rZc��|jj|j�}|j|�|j	�|j|t�y)zM
        Cancellation propagates upward to C{connect}'s L{Deferred}.
        N)r�rr�r>r:r�r#r@s  rX�test_connectionCancellationz6WrapperClientEndpointTests.test_connectionCancellation'sD��
�L�L� � ����.�����A��	���
����Q� 8�9rZc��|jj|j�}|jj	�}|j|�}|j
|jj|j�y)z|
        The transport of the wrapped L{Protocol}'s transport is the transport
        passed to C{makeConnection}.
        N)	r�rr�r.r2rsrpr�r:r4s    rX�*test_transportOfTransportOfWrappedProtocolzEWrapperClientEndpointTests.test_transportOfTransportOfWrappedProtocol0sZ��
�\�\�)�)�$�,�,�7�
��~�~�)�)�+���$�$�Z�0���
�
�e�o�o�/�/����?rZN)
rlrmrnrorwr7r<rArCrEr]rZrXr,r,�s'���=�
4�	C�+�:�@rZr,c�8�|jd�jS)a,
    Given a L{MemoryReactor} and the result of calling L{wrapClientTLS},
    extract the L{IOpenSSLClientConnectionCreator} associated with it.

    Implementation presently uses private attributes but could (and should) be
    refactored to just call C{.connect()} on the endpoint, when
    L{HostnameEndpoint} starts directing its C{getaddrinfo} call through the
    reactor it is passed somehow rather than via the global threadpool.

    @param memoryReactor: the reactor attached to the given endpoint.
        (Presently unused, but included so tests won't need to be modified to
        honor it.)

    @param tlsEndpoint: The result of calling L{wrapClientTLS}.

    @return: the client connection creator associated with the endpoint
        wrapper.
    @rtype: L{IOpenSSLClientConnectionCreator}
    N)�_wrapperFactory�_connectionCreator)r��tlsEndpoints  rX�connectionCreatorFromEndpointrJ;s��(�&�&�t�,�?�?�?rZc�(�eZdZdZd�Zd�Zd�Zd�Zy)�WrapClientTLSParserTestsz0
    Tests for L{_TLSClientEndpointParser}.
    c��t�}tj|td��}|j}|j|j|�|j|jd�|j|jd�|j|jd�|j|jtd��y)zm
        A L{HostnameEndpoint} is constructed from parameters passed to
        L{clientFromString}.
        z4tls:example.com:443:timeout=10:bindAddress=127.0.0.1rrdrbrkN)r�rrBr8�_wrappedEndpointrpr�r�rLr�rDrE)rWrrv�hostnameEndpoints    rX�!test_hostnameEndpointConstructionz:WrapClientTLSParserTests.test_hostnameEndpointConstructionXs���
�(���-�-���O�P�
��$�4�4���
�
�&�/�/��9����)�4�4�n�E����)�/�/��5����)�2�2�B�7����)�6�6��[�8Q�RrZc���t�}tj|d�}|j|jj
d�t
||�}|j|jd�y)z�
        The hostname passed to L{clientFromString} is treated as utf-8 bytes;
        it is then encoded as IDNA when it is passed along to
        L{HostnameEndpoint}, and passed as unicode to L{optionsForClientTLS}.
        stls:éxample.example.com:443sxn--xample-9ua.example.comuéxample.example.comN)r�rrBr�rNrLrJ�	_hostname)rWrrv�connectionCreators    rX�test_utf8Encodingz*WrapClientTLSParserTests.test_utf8Encodingisj���(���-�-��:�
��	
����%�%�0�0�2O�	
�:�'�8�L�����*�4�4�6N�OrZc�����t�}tjt|dg�dj	t
t
tjtj�j��jd��}|jtjt��}|jj!�\}}}}}|j#d��|j%|���J�t'j(tj+��}	t-|	j.j0|	j0t3j(t4j+��j0g|	��}
t��t7|
dtj�fd����j#d��t9�fd	��fd
��\}}}
�j:j=d�|j?|�}|j:j=d�|
jA�|jC�j:jD�|jC|j:jD�|jC�j:jF�|jC|j:jF�t3jH�j:�}|jK|t3j(tj+���y)
z�
        When passed a string endpoint description beginning with C{tls:},
        L{clientFromString} returns a client endpoint initialized with the
        values from the string.
        rkz=tls:localhost:4321:privateKey={}:certificate={}:trustRoots={}�asciiN)r�r�r�r�Fc����Srdr])�plainServers�rXr�z3WrapClientTLSParserTests.test_tls.<locals>.<lambda>�s���{�rZ)�isClient�wrappedFactoryc����Srdr])�serverProtocols�rXr�z3WrapClientTLSParserTests.test_tls.<locals>.<lambda>�����N�rZc����Srdr])�clientProtocols�rXr�z3WrapClientTLSParserTests.test_tls.<locals>.<lambda>�r]rZshello
shi you too
)&rrrBr�rr�r��pemPathr�r��encoderr*r�r+rQ�popr�r>rJr�r�rGr��originalrF�	chainPathrLr?r�r�rsr3r��
disconnecting�disconnected�peerFromTransportr�)rWrrvr�rrLr�rXrY�
serverCert�
serverOptions�sProto�cProtor6�plainClient�peerCertificater_rXr\s                @@@rX�test_tlsz!WrapClientTLSParserTests.test_tlsys^���$ �/��
�-�-�)�'�K�=�A�K�R�R�"�"��-�-�g�n�n�.>�.C�.C�D�
��f�W�o�

��
���W�0�0��:�;��4;�4F�4F�4J�4J�4L�1��d�G�W�k� �.�.�t�4�����A���)�)�)�'�/�/��0B�0B�0D�E�
�*�!�,�,�5�5�"�+�+�'�/�/�	�0D�0D�0F�G�P�P�Q� �	
�
��j��,���"�.�.�/B�C�
��-��
�		�
 8�"�"� 
�����
	���#�#�L�1��*�*�1�-�����#�#�$5�6��
�
������.�.�<�<�=�����.�.�<�<�=�����.�.�;�;�<�����.�.�;�;�<�%�7�7��8M�8M�N������+�*=�*=�g�>P�>P�>R�*S�TrZc���t�}tj|d�}t||�}|j	|j
d�|j	|jjd�y)z�
        When passed a C{tls:} strports description without extra arguments,
        L{clientFromString} returns a client endpoint whose context factory is
        initialized with default values.
        stls:example.com:443r�rN)r�rrBrJr�rRrNrL)rWrrv�creators    rX�test_tlsWithDefaultsz-WrapClientTLSParserTests.test_tlsWithDefaults�s\���(���-�-�g�7M�N��/���B������*�*�M�:�����2�2�=�=�~�NrZN)rlrmrnrorPrTrnrqr]rZrXrLrLRs ���S�"P� ?U�B
OrZrLc�N�	|j}|j}|D] }||vs�tdj
|���i}|j|�|j|�t||�}|||j<|S#t$r|j}|j}Y��wxYw)a�
    Create a copy of the given function with the given globals substituted.

    The globals must already exist in the function's existing global scope.

    @param function: any function object.
    @type function: L{types.FunctionType}

    @param newGlobals: each keyword argument should be a global to set in the
        new function's returned scope.
    @type newGlobals: L{dict}

    @return: a new function, like C{function}, but with new global scope.
    z<Name bound by replacingGlobals but not present in module: {})
�	func_code�func_globalsr�__code__�__globals__�	TypeErrorrr0r
rl)�function�
newGlobals�
codeObject�funcGlobalsr��
mergedGlobals�newFunctions       rX�replacingGlobalsr~�s���+��'�'�
��+�+������k�!��N�U�U����
���M�����%�����$��z�=�9�K�'2�M�(�#�#�$�����+��&�&�
��*�*��+�s�B�!B$�#B$c��eZdZdZd�Zy)�WrapClientTLSTestszj
    Tests for the error-reporting behavior of L{wrapClientTLS} when
    C{pyOpenSSL} is unavailable.
    c��ttjd��}|jt|dd�}|jdt
|��y)z�
        If SSL is not supported, L{TLSMemoryBIOFactory} will be L{None}, which
        causes C{_wrapper} to also be L{None}.  If C{_wrapper} is L{None}, then
        an exception is raised.
        NrKzOpenSSL not available)r~r�
wrapClientTLSr�NotImplementedErrorr6r�)rW�replaced�notImplementeds   rX�test_noOpenSSLz!WrapClientTLSTests.test_noOpenSSL�sC��$�I�$;�$;�QU�V���*�*�+>��$�PT�U���
�
�-�s�>�/B�CrZN)rlrmrnror�r]rZrXr�r��s
���
DrZr�)r]N)zfakeendpoint.py)�ro�errnorr�rrrrrr	�typesr
�unicodedatarr@r�zope.interfacer
rr�zope.interface.interfacer�zope.interface.verifyrr�twistedrr�rrrrrrrr�twisted.internet.abstractr�twisted.internet.addressrrrr r!�twisted.internet.endpointsr"�twisted.internet.errorr#�twisted.internet.interfacesr$r%r&r'r(�twisted.internet.protocolr)r*r+�twisted.internet.stdior,�twisted.internet.taskr-�twisted.internet.testingr.rr/r0r1�twisted.loggerr2r3�twisted.pluginr4�twisted.protocolsr5r6�twisted.pythonr7�twisted.python.compatr8�twisted.python.componentsr9�twisted.python.failurer:�twisted.python.filepathr;�twisted.python.modulesr<�twisted.python.systemdr=�twisted.test.iosimr>r?�
twisted.trialr8r9r`�noTrailingNewlineKeyPemPath�noTrailingNewlineCertPemPathrlr�r�rdr�r�r�rrr�r��OpenSSL.SSLrBrCr�rDrE�twisted.internet.sslrFrGrHrIrJ�twisted.protocols.tlsrL�twisted.test.test_sslverifyrMr�r�r�r�r*r+r�r�r�rPr�rqr�r{r�r�r�r��TestCaser�rrEr^rarhrmr}�IProcessTransportr��IReactorProcessr�r�r�r'rHr}r�r�r��SynchronousTestCaser�r�r�rr$r*r?rGr\rlrrr�r�r�r�r#r>rhr�r�r�rr
�ProtocolWrapperr�WrappingFactoryr"�NetstringReceiverr$r�r*r,rJrLr~r�r]rZrX�<module>r�s����W�W��!��<�<�3�;��	�	�	�4���=�;���G�F�.�'���<�%�-��.�7�*�,�,�,�L�"�
�N�
#�
,�
,�
4�
4�\�
B��'��7�@�@�H�H�!��� )��8�A�A�I�I�"� ���H�
�
&�
&�
.�
.�z�
:���M�M�+�&�	�2�Y�2�2�7�<�<�@��)F��)F�)F��$�$�*�&�+H�)�*G�*G� �%�%�+�'�3�Y�2�2�7�<�<�@��4�y�4�4�Y�^�^�D�������:�;�)�k�)�)�'�*<�*<�*>�?�O�7�/�7�7��8J�8J�8L�M���G��M�,�8�,�0
�Z�
.�
.�/����0��0
�Z�
/�
/�0�4��4�1�4�"
�Z�
*�
*�+�*�L�*�,�*�,�-���-��@>�8�,�,�@>�FHA�HA�VM:�M:�`�7�9T��%�g�%�$��"&<�x�0�0�&<�R�h�/�/��&
�Z�
)�
)�*� 
�=� 
�+� 
�F�J� � �"8�9��J�$�$�&<�=��J�(�(�*@�A�
�Z�
'�
'�(�!%�!%�)�!%�HL�H�-�-�L�^I4�H�$5�$5�I4�Xl
�H�-�-�l
�^l
�.��0A�0A�l
�^h
�.��0A�0A�h
�Vp
�&A�8�CT�CT�p
�fO�$8�%�O�9!�xE>�(�">�">�E>�PL�(�2C�2C�L�:LC�*E�LC�^1
�'��):�):�1
�h1
�'��):�):�1
�hE9�$?��AR�AR�E9�Ps9�$?��AR�AR�s9�lE;�� <� <�E;�PC
�� <� <�C
�L/�x�'8�'8�/�&>�X�->�->�>�D����M
�.��0A�0A�M
� �M
�`n
�.��0A�0A�n
�b}P�(�#�#�}P�@^I��)�)�^I�B%�,g
��)�)�g
�T����C0�8�,�,�C0� �C0�Lm�'B�H�DU�DU�m�`MR��!2�!2�MR�`*/�H�$5�$5�*/�Z$:�H�$5�$5�$:�N&M�8�,�,�&M�R�x�7�7��B(�h�6�6�(�$�u�.�.�$�&�	��>@��!2�!2�>@�B@�.����qO�x�0�0�qO� �qO�h!�HD��*�*�D��uC���G���F�M���s�A*\1�1]�6
]�]

Zerion Mini Shell 1.0