%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�fͦ���dZddlZddlZddlZddlZddlZddlmZddlm	Z	m
Z
mZmZm
Z
mZmZddlmZddlmZmZddlmZmZddlZddlmZmZdd	lmZmZmZm Z m!Z!m"Z"dd
l#m$Z$m%Z%ddl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;dd
l<m=Z=m>Z>m?Z?ddl@mAZAmBZBmCZCmDZDmEZEmFZFmGZGddlHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQddlRmSZSmTZTmUZUddlVmWZWmXZXddlYmZZZddl[m\Z\ddl]m^Z^ddl_m`Z`ddlambZbmcZcmdZdmeZeddlfmgZgmhZhmiZi	ddljmkZkddllmmZmdZndZp	ej
ej�ej��Zpepj�d�dZtdZuep�epj��e`j��rddlzm{Z{e{j�Z}dZ~n	dd lzmZe�jZ}dZ~d"�Z�d#�Z�Gd$�d%�Z�Gd&�d'ei�Z�Gd(�d)e>�Z�ee6�Gd*�d+��Z�ee6e��Gd,�d-ei�Z�Gd.�d/ei�Z�Gd0�d1eL�Z�Gd2�d3e��Z�ee:�Gd4�d5��Z�Gd6�d7eSeKeO�Z�Gd8�d9e��Z�eeteu�Gd:�d;e���Z�Gd<�d=eS�Z�Gd>�d?e��Z�eeteu�Gd@�dAe���Z�dB�Z�GdC�dDe�Z�ee��ej�d�E�GdF�dG���Z�ee~dH�GdI�dJeh��Z�dK�Z�ee~dH�GdL�dMeh��Z�GdN�dOeM�Z�GdP�dQ�Z�GdR�dSe��Z�GdT�dUe��Z�GdV�dW�Z�GdX�dYeSe�e�e��Z�GdZ�d[eSe�e�e��Z�Gd\�d]e>�Z�d^�Z�d_�Z�d`�Z�Gda�dbeS�Z�Gdc�dd�Z�Gde�df�Z�Gdg�dhe�e�eS�Z�Gdi�dje�e�eS�Z�e���jSe��jU��e���jSe��jU��e���jSe��jU��e���jSe��jU��e���jSe��jU��e���jSe��jU��e���jSe��jU��e���jSe��jU��e���jSe��jU��Gdk�dleJ�Z�Gdm�dneJ�Z�Gdo�dpeJ�Z�Gdq�dre��Z�Gds�dteJ�Z�Gdu�dveJ�Z�Gdw�dxeJ�Z�Gdy�dze��Z�Gd{�d|e��Z�Gd}�d~e��Z�Gd�d�e��Z�Gd��d�eJ�Z�Gd��d�eJ�Z�Gd��d�e��Z�Gd��d�e��Z�Gd��d�e��Z�Gd��d�e��Z�Gd��d��Z�Gd��d�eSe��Z�e���jSe��jU��eeteu�Gd��d�ei��Z�Gd��d�eh�Z�ee~dH�Gd��d�eh��Z�Gd��d�eh�Z�y#eo$rdZnY��wxYw#ev$rZwdZtdew��ZuYdZw[w���dZw[wwwxYw#eo$rd!�Z}Y���wxYw)�zU
Tests for implementations of L{IReactorTCP} and the TCP parts of
L{IReactorSocket}.
�N��wraps)�Callable�ClassVar�List�Mapping�Optional�Sequence�Type)�skipIf)�	Interface�implementer)�verifyClass�verifyObject)�IPv4Address�IPv6Address)�Deferred�DeferredList�fail�
gatherResults�
maybeDeferred�succeed)�TCP4ClientEndpoint�TCP4ServerEndpoint)	�ConnectBindError�ConnectionAborted�ConnectionClosed�ConnectionDone�ConnectionLost�ConnectionRefusedError�DNSLookupError�
NoProtocol�	UserError)�
IConnector�IHalfCloseableProtocol�ILoggingContext�
IPullProducer�
IPushProducer�
IReactorFDSet�IReactorSocket�IReactorTCP�IReactorTime�IResolverSimple�
ITLSTransport)�
ClientFactory�Protocol�
ServerFactory)�
Connection�Server�_BuffersLogs�_FileDescriptorReservation�_IFileDescriptorReservation�_NullFileDescriptorReservation�_resolveIPv6)	�BrokenContextFactory�ConnectableProtocol�ConnectionTestsMixin�EndpointCreator�LogObserverMixin�Stop�StreamClientTestsMixin�findFreePort�runProtocolsWithReactor)�ReactorBuilder�needsRunningReactor�stopOnError)�
MemoryReactor�StringTransport)�Logger)�log)�Failure)�platform)�ClientStartStopFactory�ClosingFactory�MyClientFactory�MyServerFactory)�SkipTest�SynchronousTestCase�TestCase)�SSL)�ClientContextFactoryTF)�::1r�zIPv6 not available. )�_win32ifaces)�_posixifacesc��gS�N�rZ��@/usr/lib/python3/dist-packages/twisted/internet/test/test_tcp.py�<lambda>r]�s��B�r[c�:�t�}|r|dStd��)al
    Find and return a configured link local IPv6 address including a scope
    identifier using the % separation syntax.  If the system has no link local
    IPv6 addresses, raise L{SkipTest} instead.

    @raise SkipTest: if no link local address can be found or if the
        C{netifaces} module is not available.

    @return: a C{str} giving the address
    rz#Link local IPv6 address unavailable)�getLinkLocalIPv6AddressesrO)�	addressess r\�getLinkLocalIPv6Addressra�s%��*�+�I����|��
�8�
9�9r[c��|\}}d|vsd|vrtj||�dd}n||f}|j|�y)a7
    Connect a socket to the given destination.

    @param client: A C{socket.socket}.

    @param destination: A tuple of (host, port). The host is a C{str}, the
        port a C{int}. If the C{host} is an IPv6 IP, the address is resolved
        using C{getaddrinfo} and the first version found is used.
    �%�:r�N)�socket�getaddrinfo�connect)�client�destination�host�port�addresss     r\rhrh�sK���L�T�4�
�d�{�c�T�k��$�$�T�4�0��3�A�6����,��
�N�N�7�r[c�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�
FakeSocketz�
    A fake for L{socket.socket} objects.

    @ivar data: A C{str} giving the data which will be returned from
        L{FakeSocket.recv}.

    @ivar sendBuffer: A C{list} of the objects passed to L{FakeSocket.send}.
    c� �||_g|_yrY)�data�
sendBuffer��selfrqs  r\�__init__zFakeSocket.__init__�s����	���r[c��||_yrY)�blocking)rtrws  r\�setblockingzFakeSocket.setblocking�s	�� ��
r[c��|jSrY)rq)rt�sizes  r\�recvzFakeSocket.recv�s���y�y�r[c�N�|jj|�t|�S)z�
        I{Send} all of C{bytes} by accumulating it into C{self.sendBuffer}.

        @return: The length of C{bytes}, indicating all the data has been
            accepted.
        )rr�append�len�rt�bytess  r\�sendzFakeSocket.send�s ��	
�����u�%��5�z�r[c��y)z�
        Shutdown is not implemented.  The method is provided since real sockets
        have it and some code expects it.  No behavior of L{FakeSocket} is
        affected by a call to it.
        NrZ)rt�hows  r\�shutdownzFakeSocket.shutdown���r[c��y)z�
        Close is not implemented.  The method is provided since real sockets
        have it and some code expects it.  No behavior of L{FakeSocket} is
        affected by a call to it.
        NrZ�rts r\�closezFakeSocket.close�r�r[c��y)z�
        Setsockopt is not implemented.  The method is provided since
        real sockets have it and some code expects it.  No behavior of
        L{FakeSocket} is affected by a call to it.
        NrZ)rt�argss  r\�
setsockoptzFakeSocket.setsockopt�r�r[c��y)z�
        Return a fake file descriptor.  If actually used, this will have no
        connection to this L{FakeSocket} and will probably cause surprising
        results.
        �rZr�s r\�filenozFakeSocket.fileno�s��r[N)�__name__�
__module__�__qualname__�__doc__rurxr{r�r�r�r�r�rZr[r\roro�s/����!������r[roc�"�eZdZdZd�Zd�Zd�Zy)�FakeSocketTestszT
    Test that the FakeSocket can be used by the doRead method of L{Connection}
    c�t�td�}|jd�|j|jd�y)N�someDatar)rorx�assertEqualrw�rt�skts  r\�
test_blockingzFakeSocketTests.test_blocking�s,����%�������������q�)r[c�\�td�}|j|jd�d�y)Nr��
)ror�r{r�s  r\�	test_recvzFakeSocketTests.test_recv�s$����%��������"��{�3r[c��td�}|jd�}|j|d�|j|jdg�y)z�
        L{FakeSocket.send} accepts the entire string passed to it, adds it to
        its send buffer, and returns its length.
        r[sfoo�N)ror�r�rr)rtr��counts   r\�	test_sendzFakeSocketTests.test_send�sA��
��o������ �������"�������&��2r[N)r�r�r�r�r�r�r�rZr[r\r�r��s���*�
4�3r[r�c��eZdZdZd�Zy)�FakeProtocolzL
    An L{IProtocol} that returns a value from its dataReceived method.
    c��y)zq
        Return something other than L{None} to trigger a deprecation warning for
        that behavior.
        rZrZrss  r\�dataReceivedzFakeProtocol.dataReceiveds��
r[N�r�r�r�r�r�rZr[r\r�r�s���r[r�c�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�_FakeFDSetReactora�
    An in-memory implementation of L{IReactorFDSet}, which records the current
    sets of active L{IReadDescriptor} and L{IWriteDescriptor}s.

    @ivar _readers: The set of L{IReadDescriptor}s active on this
        L{_FakeFDSetReactor}
    @type _readers: L{set}

    @ivar _writers: The set of L{IWriteDescriptor}s active on this
        L{_FakeFDSetReactor}
    @ivar _writers: L{set}
    c�@�t�|_t�|_yrY)�set�_readers�_writersr�s r\ruz_FakeFDSetReactor.__init__s�����
����
r[c�:�|jj|�yrY)r��add�rt�readers  r\�	addReaderz_FakeFDSetReactor.addReader!����
�
���&�!r[c�X�||jvr|jj|�yyrY)r��remover�s  r\�removeReaderz_FakeFDSetReactor.removeReader$�%���T�]�]�"��M�M� � ��(�#r[c�:�|jj|�yrY)r�r��rt�writers  r\�	addWriterz_FakeFDSetReactor.addWriter(r�r[c�X�||jvr|jj|�yyrY)r�r�r�s  r\�removeWriterz_FakeFDSetReactor.removeWriter+r�r[c�h�|j�|j�z}|j�|SrY)�
getReaders�
getWritersru�rt�results  r\�	removeAllz_FakeFDSetReactor.removeAll/s(�����"�T�_�_�%6�6���
�
���
r[c�,�t|j�SrY)�listr�r�s r\r�z_FakeFDSetReactor.getReaders4����D�M�M�"�"r[c�,�t|j�SrY)r�r�r�s r\r�z_FakeFDSetReactor.getWriters7r�r[N)r�r�r�r�rur�r�r�r�r�r�r�rZr[r\r�r�s/����"�)�"�)��
#�#r[r�c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�TCPServerTestsz<
    Whitebox tests for L{twisted.internet.tcp.Server}.
    c���t�|_Gd�d�}td�|_t	�|_t
|j|j
d|�d|j�|_y)Nc��eZdZdZy)�&TCPServerTests.setUp.<locals>.FakePortr�N)r�r�r��_realPortNumberrZr[r\�FakePortr�Fs���Or[r�r[)rUr)r��reactorror�r0�protocolr3�server)rtr�s  r\�setUpzTCPServerTests.setUpCsS��(�*���	 �	 ��c�?��� �
��
���H�H�d�m�m�W�h�j�$����
��r[c���|jjttd���|jj	d�|j|jjg�y)zq
        L{Server.write} discards bytes passed to it if called after it has lost
        its connection.
        �Simulated lost connection�hello worldN)r��connectionLostrI�	Exception�writer�r�rrr�s r\�test_writeAfterDisconnectz(TCPServerTests.test_writeAfterDisconnectOsM��
	
���"�"�7�9�5P�+Q�#R�S������.�)�������,�,�b�1r[c�F�d|j_|j�y)z�
        L{Server.write} discards bytes passed to it if called after it has lost
        its connection when the connection had started TLS.
        TN)r��TLSr�r�s r\�!test_writeAfterDisconnectAfterTLSz0TCPServerTests.test_writeAfterDisconnectAfterTLSXs��
������&�&�(r[c���|jjttd���|jj	dg�|j|jjg�y)zy
        L{Server.writeSequence} discards bytes passed to it if called after it
        has lost its connection.
        r�r�N)r�r�rIr��
writeSequencer�r�rrr�s r\�!test_writeSequenceAfterDisconnectz0TCPServerTests.test_writeSequenceAfterDisconnect`sP��
	
���"�"�7�9�5P�+Q�#R�S����!�!�>�"2�3�������,�,�b�1r[c�F�d|j_|j�y)z�
        L{Server.writeSequence} discards bytes passed to it if called after it
        has lost its connection when the connection had started TLS.
        TN)r�r�r�r�s r\�)test_writeSequenceAfterDisconnectAfterTLSz8TCPServerTests.test_writeSequenceAfterDisconnectAfterTLSis��
������.�.�0r[N)	r�r�r�r�r�r�r�r�r�rZr[r\r�r�>s ���

�2�)�2�1r[r�c�<�eZdZdZd�Zd�Zeed�d��Zy)�TCPConnectionTestsz@
    Whitebox tests for L{twisted.internet.tcp.Connection}.
    c�D�td�}t�}t||�}|j�|j	tj
g�}|j
|ddt�|j
|ddd�|j
t|�d�y)z�
        When an L{IProtocol} implementation that returns a value from its
        C{dataReceived} method, a deprecated warning is emitted.
        r�r�category�messagez�Returning a value other than None from twisted.internet.test.test_tcp.FakeProtocol.dataReceived is deprecated since Twisted 11.0.0.r�N)	ror�r2�doRead�
flushWarningsr�r��DeprecationWarningr~)rtr�r��conn�warningss     r\�test_doReadWarningIsRaisedz-TCPConnectionTests.test_doReadWarningIsRaisedws���
��%���>���#�x�(�����
��%�%�|�'@�'@�&A�B������!��Z�0�2D�E�����Q�K�	�"�
2�	
�	
����X���*r[c�|�td�}t�}t||�}|j|j�y)z
        The C{TLS} attribute of a L{Connection} instance is C{False} before
        L{Connection.startTLS} is called.
        r[N)ror�r2�assertFalser��rtr�r�r�s    r\�test_noTLSBeforeStartTLSz+TCPConnectionTests.test_noTLSBeforeStartTLS�s2��
��o���>���#�x�(��������"r[zNo SSL support availablec���td�}t�}t||t���}d|_|jt
�d�|j|j�y)z}
        The C{TLS} attribute of a L{Connection} instance is C{True} after
        L{Connection.startTLS} is called.
        r[�r�TN)	ror�r2r��_tlsClientDefault�startTLSrS�
assertTruer�r�s    r\�test_tlsAfterStartTLSz(TCPConnectionTests.test_tlsAfterStartTLS�sP����o���>���#�x�1B�1D�E��!%����
�
�*�,�d�3�������!r[N)	r�r�r�r�r�r�r�useSSLr�rZr[r\r�r�rs/���+�&#���J�2�3�
"�4�
"r[r�c� �eZdZdZdZd�Zd�Zy)�
TCPCreatorzO
    Create IPv4 TCP endpoints for L{runProtocolsWithReactor}-based tests.
    �	127.0.0.1c�2�t|d|j��S)z4
        Create a server-side TCP endpoint.
        r��	interface)rr�)rtr�s  r\r�zTCPCreator.server�s��"�'�1����G�Gr[c�D�t||j|j�S)z�
        Create a client end point that will connect to the given address.

        @type serverAddress: L{IPv4Address}
        )rr�rl)rtr��
serverAddresss   r\rizTCPCreator.client�s��"�'�4�>�>�=�;M�;M�N�Nr[N)r�r�r�r�r�r�rirZr[r\r�r��s����I�H�Or[r�c��eZdZdZd�Zy)�TCP6CreatoraV
    Create IPv6 TCP endpoints for
    C{ReactorBuilder.runProtocolsWithReactor}-based tests.

    The endpoint types in question here are still the TCP4 variety, since
    these simply pass through IPv6 address literals to the reactor, and we are
    only testing address literals, not name resolution (as name resolution has
    not yet been implemented).  See http://twistedmatrix.com/trac/ticket/4470
    for more specific information about new endpoint classes.  The naming is
    slightly misleading, but presumably if you're passing an IPv6 literal, you
    know what you're asking for.
    c�"�t�|_yrY�rar�r�s r\ruzTCP6Creator.__init__����0�2��r[N)r�r�r�r�rurZr[r\rr�s���3r[rc�B�eZdZdZdeeeffd�Zd
dedeeddfd�Z	y	)�FakeResolverzR
    A resolver implementation based on a C{dict} mapping names to addresses.
    �namesc��||_yrY)r)rtrs  r\ruzFakeResolver.__init__�s	����
r[�name�timeout�returnz
Deferred[str]c��	t|j|�S#t$rtt	d|z��cYSwxYw)z�
        Return the address mapped to C{name} if it exists, or raise a
        C{DNSLookupError}.

        @param name: The name to resolve.

        @param timeout: The lookup timeout, ignore here.
        zFakeResolver couldn't find )rr�KeyErrorrr!)rtrr	s   r\�
getHostByNamezFakeResolver.getHostByName�sC��	N��4�:�:�d�+�,�,���	N���'D�t�'K�L�M�M�	N�s�� =�=N)rZ)
r�r�r�r�r�strrur
�intr
rZr[r\rr�s>����g�c�3�h�/��N�#�N���
�N��Nr[rc�X�eZdZdZefZdZed��Zed��Z	d�Z
d�Zd�Zd�Z
d	�Zy)
�TCPClientTestsBasea�
    Base class for builders defining tests related to
    L{IReactorTCP.connectTCP}.  Classes which uses this in must provide all of
    the documented instance variables in order to specify how the test works.
    These are documented as instance variables rather than declared as methods
    due to some peculiar inheritance ordering concerns, but they are
    effectively abstract methods.

    @ivar endpoints: A client/server endpoint creator appropriate to the
        address family being tested.
    @type endpoints: L{twisted.internet.test.connectionmixins.EndpointCreator}

    @ivar interface: An IP address literal to locally bind a socket to as well
        as to connect to.  This can be any valid interface for the local host.
    @type interface: C{str}

    @ivar port: An unused local listening port to listen on and connect to.
        This will be used in conjunction with the C{interface}.  (Depending on
        what they're testing, some tests will locate their own port with
        L{findFreePort} instead.)
    @type port: C{int}

    @ivar family: an address family constant, such as L{socket.AF_INET},
        L{socket.AF_INET6}, or L{socket.AF_UNIX}, which indicates the address
        family of the transport type under test.
    @type family: C{int}

    @ivar addressClass: the L{twisted.internet.interfaces.IAddress} implementor
        associated with the transport type under test.  Must also be a
        3-argument callable which produces an instance of same.
    @type addressClass: C{type}

    @ivar fakeDomainName: A fake domain name to use, to simulate hostname
        resolution and to distinguish between hostnames and IP addresses where
        necessary.
    @type fakeDomainName: C{str}
    Nc��|j�$|jj�jSt|j|j
�dS)z�
        Return the port number to connect to, using C{self._port} set up by
        C{listen} if available.

        @return: The port number to connect to.
        @rtype: C{int}
        r�)�_port�getHostrlr@r��familyr�s r\rlzTCPClientTestsBase.port
sA���:�:�!��:�:�%�%�'�,�,�,��D�N�N�D�K�K�8��;�;r[c�.�|jjS)zK
        Return the interface attribute from the endpoints object.
        )�	endpointsr�r�s r\r�zTCPClientTestsBase.interfaces��
�~�~�'�'�'r[c�`�|jd||j��|_|jS)z�
        Start a TCP server with the given C{factory}.

        @param reactor: The reactor to create the TCP port in.

        @param factory: The server factory.

        @return: A TCP port instance.
        rr�)�	listenTCPr�r�rtr��factorys   r\�listenzTCPClientTestsBase.listen!s+���&�&�q�'�T�^�^�&�L��
��z�z�r[c�P�|j|j|j|�S)z�
        Start a TCP client with the given C{factory}.

        @param reactor: The reactor to create the connection in.

        @param factory: The client factory.

        @return: A TCP connector instance.
        )�
connectTCPr�rlrs   r\rhzTCPClientTestsBase.connect.s!���!�!�$�.�.�$�)�)�W�E�Er[c���
���t���j��t�}�|_t	���Gd�dt
��
�jj��j|�}�
��fd�}|j|�}�fd�}d�}|j||��fd�}|j|�}|jtj��fd�}	|j|	��j��y)	zr
        When the factory's C{buildProtocol} returns L{None} the connection is
        gracefully closed.
        c��eZdZd�Zy)�ETCPClientTestsBase.test_buildProtocolReturnsNone.<locals>.NoneFactoryc��yrYrZ)rtrms  r\�
buildProtocolzSTCPClientTestsBase.test_buildProtocolReturnsNone.<locals>.NoneFactory.buildProtocolHs��r[N�r�r�r�r#rZr[r\�NoneFactoryr!Gs��
r[r%c�����}�jj�|j��}|j|�SrY)rrirrh)rl�
clientFactory�endpointr%r�rts   ���r\�listenedzBTCPClientTestsBase.test_buildProtocolReturnsNone.<locals>.listenedMs7���'�M�M��~�~�,�,�W�d�l�l�n�E�H��#�#�M�2�2r[c�0���jd|�d��y)Nz.Stream client endpoint connect succeeded with z%, should have failed with NoProtocol.)r)r�rts �r\�connectSucceededzJTCPClientTestsBase.test_buildProtocolReturnsNone.<locals>.connectSucceededTs����I�I�9A�D�
r[c�.�|jt�yrY)�trapr")�reasons r\�
connectFailedzGTCPClientTestsBase.test_buildProtocolReturnsNone.<locals>.connectFailedZs���K�K�
�#r[c����SrYrZ)�ignoredr�s �r\�	connectedzCTCPClientTestsBase.test_buildProtocolReturnsNone.<locals>.connected_s���"�!r[c�&���j�yrY��stop)r1r�s �r\�disconnectedzFTCPClientTestsBase.test_buildProtocolReturnsNone.<locals>.disconnectedjs���

�L�L�Nr[N)r�buildReactorrN�protocolConnectionLostrDr1rr�r�addCallback�addCallbacks�
addErrbackrH�err�
runReactor)
rt�
serverFactory�	listeningr)�
connectingr+r/r2�
disconnectingr6r%r�r�s
`         @@@r\�test_buildProtocolReturnsNonez0TCPClientTestsBase.test_buildProtocolReturnsNone:s����
"����#�#�%��'�)�
�/=�
�,�	�D�'�"�	�-�	��N�N�)�)�'�2�9�9�-�H�	�	3�
�*�*�8�4�
�	�	$�	��� 0�-�@�	"�#�.�.�y�9�
�	� � ����)�	�	�!�!�,�/����� r[c���	�
���
�t�j�j�dd\}}�j���j�
�jt
�
�ji���jdtjt�|����j�}dddd��
G��
fd�dt�}t���	|�	_
�	�
���fd�}t�|��j���	j r)�j#�	j j%��d	j'�
d
j(�
d
j*t-�
d
��}|gt/t1j2�j�	j4�dddd�z}|gt/t1j2�j|j6�dddd�z}�j9�
d
�j:dg|�����j9�
d�j:dg|�����j9t=�
d
�|�y)a�
        A client's transport's C{getHost} and C{getPeer} return L{IPv4Address}
        instances which have the dotted-quad string form of the resolved
        address of the local and remote endpoints of the connection
        respectively as their C{host} attribute, not the hostname originally
        passed in to
        L{connectTCP<twisted.internet.interfaces.IReactorTCP.connectTCP>}, if a
        hostname was used.
        N�rr�)rk�peer�instancec���eZdZ��fd�Zy)�7TCPClientTestsBase.test_addresses.<locals>.CheckAddressc�|��|j��d<|j��d<|�d<�j�y)NrkrErF)r�getPeerr5)rt�	transportr��
transportDatas  ��r\�makeConnectionzFTCPClientTestsBase.test_addresses.<locals>.CheckAddress.makeConnection�s<���(1�(9�(9�(;�
�f�%�(1�(9�(9�(;�
�f�%�,5�
�j�)����r[N�r�r�r�rM)r�rLs��r\�CheckAddressrH�s���
r[rOc�(��	t�j�j�}�j|df}tjd|���	�j��j
�j�|��|d�_y#t$rY��wxYw)Nr�z!Connect attempt with bindAddress )�bindAddress)
r@r�rrH�msgrrrl�	boundPortr)rlrQr'�
fakeDomainr�rtr�s  �����r\�	connectMez4TCPClientTestsBase.test_addresses.<locals>.connectMe�s�����#�D�N�N�D�K�K�@��#�~�~�t�A�w�7�����;�K�=�I�J���&�&�"����(�-�-�%�$/�	'��/3�1�g�M�+���	(����s�
-B�	B�Bz<{} to {} at {:x}>rF���r�rk�TCPrE)r@r�rr7�fakeDomainName�installResolverrrr1�forProtocolr0rr>r�rCr=�
failReasonr�getTraceback�format�	__class__�addr�idr�rfrgrSrlr��addressClass�repr)rtrkr1r�rOrU�
transportReprrS�
serverPortr'rTr�r�rLs`        @@@@@r\�test_addressesz!TCPClientTestsBase.test_addressesus$���%�T�^�^�T�[�[�A�"�1�E�
��g��#�#�%���(�(�
�����j�$�.�.�-I� J�K��"�"�
�}�(�(��2�d�#�
�����(�
�!%�t��F�
�	�8�	��W�
�
�!-�
��	�	�$	�G�Y�/����� ��#�#��I�I�m�.�.�;�;�=�>�,�3�3��*�%�/�/��*�%�*�*��}�Z�(�)�
�
��F�T����t�~�~�}�/F�/F�G��J�2�N�q�r�R�
�
�	��V�d����t�~�~�}�/A�/A�B�1�E�b�I�!�"�M�
�
�
�	
����v�.�0A��0A�0A�%�0T�)�0T�U�����v�.�0A��0A�0A�%�0U�*�0U�V�����m�J�7�8�-�Hr[c�������	�
���j��
t��g�tjt�}�
jd|�j��}�jj�
|j��}t�}t|_|j|�����fd��	�fd�����	�
fd�}t�
|��j�
��jt!��dd����t#�dt$�r�dj'��ddk(rt)d	���jtj*t-�d��y
)z�
        If the context factory passed to L{ITCPTransport.startTLS} raises an
        exception from its C{getContext} method, that exception is raised by
        L{ITCPTransport.startTLS}.
        rr�c����tj|j�s�jd�y�j�j	t
|jj���y)N�skip)r.�
providedByrKr}�assertRaises�
ValueErrorr�)r��
brokenFactory�resultsrts ���r\r2z5TCPClientTestsBase.test_badContext.<locals>.connected�sP��� �+�+�H�,>�,>�?����v�&�����%�%�"�H�$6�$6�$?�$?���r[c�(���j|�yrY�r})�failurerms �r\r/z9TCPClientTestsBase.test_badContext.<locals>.connectFailed�s����N�N�7�#r[c�r���j���j���j�fd��y)Nc�$���j�SrYr4��ignr�s �r\r]zETCPClientTestsBase.test_badContext.<locals>.whenRun.<locals>.<lambda>�s
�������r[)r9r;�addBoth)�connectDeferredr/r2r�s����r\�whenRunz3TCPClientTestsBase.test_badContext.<locals>.whenRun�s.����'�'�	�2��&�&�}�5��#�#�$>�?r[r�zmore than one callback result: rhz&Reactor does not support ITLSTransportN)r7r9r1rZr0rr�rrirr/r�rhrCr=r�r~�
isinstancerI�raiseExceptionrOr�r)rtr>rlr(r'rwrlrvr/r2r�rms`     @@@@@@r\�test_badContextz"TCPClientTestsBase.test_badContext�s!����#�#�%��,�.�
���%�1�1�(�;�
�� � ��M�T�^�^� �L���>�>�(�(��$�,�,�.�A��%��
�!)�
��"�*�*�=�9��	�	$�	@�
	�G�W�-����� �����W��q�,K�G�9�*U�V��g�a�j�'�*��A�J�%�%�'��1�:����C�D�D����-�5�5�s�7�1�:��Gr[)r�r�r�r�r+�requiredInterfacesr�propertyrlr�rrhrBrerzrZr[r\rr�s\��$�L&����E�
�
<��
<��(��(��
F�9!�vHI�T0Hr[rc�>�eZdZdZdZejZeZ	e
�Zy)�TCP4ClientTestsBuilderze
    Builder configured with IPv4 parameters for tests related to
    L{IReactorTCP.connectTCP}.
    zsome-fake.domain.example.comN)r�r�r�r�rXrf�AF_INETrrrar�rrZr[r\r~r~�s#���
4�N�
�^�^�F��L���Ir[r~c�2�eZdZdZej
ZeZd�Z	y)�TCP6ClientTestsBuilderze
    Builder configured with IPv6 parameters for tests related to
    L{IReactorTCP.connectTCP}.
    c�X�t�|_|jj|_yrY)rrr�rXr�s r\r�zTCP6ClientTestsBuilder.setUp	s!��%����#�n�n�6�6��r[N)
r�r�r�r�rf�AF_INET6rrrar�rZr[r\r�r��s���
�_�_�F��L�
7r[r�c�(�eZdZdZefZd�Zd�Zd�Zy)�TCPConnectorTestsBuilderzU
    Tests for the L{IConnector} provider returned by L{IReactorTCP.connectTCP}.
    c�$���	�t�}|j���jd||j��}||_|j�j}g�g�	t
�}��	fd�|_�j|_	�j|j||�}|jtj|��|j�}|j|j d�|j|j"|j�|j|j|�|j$j'�fd��|j)���	dj+t,�|j�||g�y)aU
        L{IReactorTCP.connectTCP} returns an object which provides
        L{IConnector}.  The destination of the connector is the address which
        was passed to C{connectTCP}.  The same connector object is passed to
        the factory's C{startedConnecting} method as to the factory's
        C{clientConnectionLost} method.
        rr�c�H���j|��j|�fSrYro)�	connectorr.�seenConnectors�seenFailuress  ��r\r]zATCPConnectorTestsBuilder.test_connectorIdentity.<locals>.<lambda>/s'����!�!�)�,�����'�H
�r[rWc�$���j�SrYr4��_r�s �r\r]zATCPConnectorTestsBuilder.test_connectorIdentity.<locals>.<lambda><�
���G�L�L�N�r[N)rLr7rr�rlrrK�clientConnectionLostr}�startedConnectingrr�r$ri�getDestinationr��typerk�whenStoppedrur=r-r)
rtr>�tcpPort�
portNumberr'r��destr�r�r�s
       @@@r\�test_connectorIdentityz/TCPConnectorTestsBuilder.test_connectorIdentitysA���'�(�
��#�#�%���#�#�A�}����#�O��$�
���_�_�&�+�+�
�����.�0�
�.
�
�*�+9�*?�*?�
�'��&�&�t�~�~�z�=�Q�	����
�-�-�i�8�9��'�'�)��������E�*�������D�N�N�3�������J�/��!�!�)�)�*B�C����� ��Q����^�,�����)�Y�)?�@r[c�.������t�}�j���jd|�j��}|j	�j
�g���fd�}t
��|�_�jj�fd���j����fd���j���r"�j�dj���jjt ��j#�j$d�y)z�
        Calling L{IConnector.stopConnecting} in C{Factory.startedConnecting}
        results in C{Factory.clientConnectionFailed} being called with
        L{error.UserError} as the reason.
        rr�c���	|j�y#t$r,�jt���j	�YywxYwrY)�stopConnectingr�r}rIr5)r��fatalErrorsr�s ��r\r�zATCPConnectorTestsBuilder.test_userFail.<locals>.startedConnectingPs<���
��(�(�*���
��"�"�7�9�-�����
�s��2A	�A	c�$���j�SrYr4r�s �r\r]z8TCPConnectorTestsBuilder.test_userFail.<locals>.<lambda>Zr�r[c�>���j�j���SrY)rr�)r'r�r�rts����r\r]z8TCPConnectorTestsBuilder.test_userFail.<locals>.<lambda>]s���G�&�&�t�~�~�z�=�Q�r[r�N)rNr7rr�rrlrKr�r�ru�callWhenRunningr=rr\r.r-r#r��failed)rtr>r�r�r'r�r�r�s`   @@@@r\�
test_userFailz&TCPConnectorTestsBuilder.test_userFailCs����(�)�
��#�#�%���#�#�A�}����#�O���_�_�&�+�+�
���	�/�0�
�*;�
�'��!�!�)�)�*B�C����Q�	
�	
���� ���I�I�k�!�n�1�1�3�4����!�!�)�,�����-�-�q�1r[c������t�}|j���jd||j��}||_|j�j}t
��d�}|�_�j|j|��g����fd�}�jj|�|j���jjt�|j�dg�y)z�
        Calling L{IConnector.connect} in C{Factory.clientConnectionLost} causes
        a new connection attempt to be made.
        rr�c�$�|j�yrY)rh)r�r.s  r\r�zETCPConnectorTestsBuilder.test_reconnect.<locals>.clientConnectionLostts�����r[c����j}�j|j|jf��j	�yrY)r�r}�made�closedr5)r1�pr'�protocolMadeAndClosedr�s  ���r\�reconnectFailedz@TCPConnectorTestsBuilder.test_reconnect.<locals>.reconnectFailed|s2����&�&�A�!�(�(�!�&�&�!�(�(�);�<��L�L�Nr[)r�r�N)rLr7rr�rlrrMr�r�failDeferredr9r=r.r-r r�)	rtr>r�r�r�r�r'r�r�s	      @@@r\�test_reconnectz'TCPConnectorTestsBuilder.test_reconnectgs����
'�(�
��#�#�%���#�#�A�}����#�O��$�
���_�_�&�+�+�
�'�)�
�	 �.B�
�*����4�>�>�:�}�E� "��	�
	�"�"�.�.��?����� ����!�!�"8�9����.���9r[N)	r�r�r�r�r+r{r�r�r�rZr[r\r�r�s#���&���$A�L"2�H:r[r�c�,�eZdZdZej
ZeZy)�TCP4ConnectorTestsBuilderr�N)	r�r�r�r�rfrrrrarZr[r\r�r��s���I�
�^�^�F��Lr[r�c�.�eZdZejZeZd�Zy)�TCP6ConnectorTestsBuilderc�"�t�|_yrYrr�s r\r�zTCP6ConnectorTestsBuilder.setUp�rr[N)	r�r�r�rfr�rrrar�rZr[r\r�r��s��
�_�_�F��L�3r[r�c�h�tj||�}|j|j�|S)z�
    Create a socket for the duration of the given test.

    @param test: the test to add cleanup to.

    @param addressFamily: an C{AF_*} constant

    @param socketType: a C{SOCK_*} constant.

    @return: a socket object.
    )rf�
addCleanupr�)�test�
addressFamily�
socketTyper�s    r\�createTestSocketr��s)���-�-�
�z�
2�C��O�O�C�I�I���Jr[c�"�eZdZdZd�Zd�Zd�Zy)�_IExhaustsFileDescriptorsz%
    A way to trigger C{EMFILE}.
    c��y)z�
        Open file descriptors until C{EMFILE} is reached.

        This can raise any exception except an L{OSError} whose
        C{errno} is C{EMFILE}.  Any exception raised to the caller
        implies L{release}.
        NrZrZr[r\�exhaustz!_IExhaustsFileDescriptors.exhaust�r�r[c��y�zD
        Release all file descriptors opened by L{exhaust}.
        NrZrZr[r\�releasez!_IExhaustsFileDescriptors.release�r�r[c��y)��
        Return the number of opened file descriptors.

        @return: The number of opened file descriptors; this will be
            zero if this instance has not opened any.
        @rtype: L{int}
        NrZrZr[r\r�z_IExhaustsFileDescriptors.count�r�r[N�r�r�r�r�r�r�r�rZr[r\r�r��s�����
r[r�)�auto_attribsc�,�eZdZUdZe�Zeeed<ejd�d��Z
egefed<eje
jd��Zeegdfed<ejej e�dd�	�Zeeed
<d�Zd�Zd
�Zy)�_ExhaustsFileDescriptorsa_
    A class that triggers C{EMFILE} by creating as many file
    descriptors as necessary.

    @ivar fileDescriptorFactory: A factory that creates a new file
        descriptor.
    @type fileDescriptorFactory: A L{callable} that accepts no
        arguments and returns an integral file descriptor, suitable
        for passing to L{os.close}.
    �_logc�,�tjd�S�Nr)�os�duprZr[r\r]z!_ExhaustsFileDescriptors.<lambda>�s�����q�	�r[F)�defaultrb�_fileDescriptorFactoryN�_close)r��initrb�_fileDescriptorsc��tj�			|j�}|jj	|��-#t
$r(}|jtjk(rYd}~n	�d}~wwxYw	|jjd|j���y#t$r|j��wxYw)zC
        Open file descriptors until C{EMFILE} is reached.
        NzCEMFILE reached by opening {openedFileDescriptors} file descriptors.)�openedFileDescriptors)
�gc�collectr�r�r}�OSError�errno�EMFILEr��infor�r�r��rt�fd�es   r\r�z _ExhaustsFileDescriptors.exhaust�s���
	�
�
��	��5��4�4�6�B��)�)�0�0��4������w�w�%�,�,�.�������
�I�I�N�N�=�&*�j�j�l�
�
��	�	��L�L�N��	�s9�B%�A�B%�	A5�
A0�*B%�/A0�0A5�5B%�%Cc��|jr:|jj�}	|j|�|jr�9yy#t$r(}|jtj
k(rYd}~�r�d}~wwxYwr�)r��popr�r�r��EBADFr�s   r\r�z _ExhaustsFileDescriptors.release�sd���#�#��&�&�*�*�,�B�
����B���#�#���
��7�7�e�k�k�)����
�s�A�	A9�A4�3A4�4A9c�,�t|j�S)r�)r~r�r�s r\r�z_ExhaustsFileDescriptors.counts���4�(�(�)�)r[)r�r�r�r�rGr�r�__annotations__�attr�ibr�rrr�r�r��Factoryr�r�rr�r�r�rZr[r\r�r��s���	�$�X�D�(�6�
�%�07����!��1��H�R��W�-��%,�D�G�G�B�H�H�5�$I�F�H�c�U�D�[�!�I�")�$�'�'�����T�"��U�#��d�3�i���4�*r[r��9Reserved EMFILE file descriptor not supported on Windows.c�L�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
�ExhaustsFileDescriptorsTestsz0
    Tests for L{_ExhaustsFileDescriptors}.
    c�l�t�|_|j|jj�yrY)r��	exhausterr�r�r�s r\r�z"ExhaustsFileDescriptorsTests.setUps$��1�3���	
������.�.�/r[c�R�ttj�j�y)z`
        Attempt to open a file; if successful, the file is immediately
        closed.
        N)�openr��devnullr�r�s r\�	openAFilez&ExhaustsFileDescriptorsTests.openAFiles��
	
�R�Z�Z���� r[c�8�tt|j�y)ze
        L{_ExhaustsFileDescriptors} instances provide
        L{_IExhaustsFileDescriptors}.
        N)rr�r�r�s r\�test_providesInterfacez3ExhaustsFileDescriptorsTests.test_providesInterface"s��
	�.����?r[c�h�|j|jj�d�|jj�|j	|jj�d�|jj�|j|jj�d�y)zh
        L{_ExhaustsFileDescriptors.count} returns the number of open
        file descriptors.
        rN)r�r�r�r��
assertGreaterr�r�s r\�
test_countz'ExhaustsFileDescriptorsTests.test_count)s{��
	
������-�-�/��3������ ����4�>�>�/�/�1�1�5������ �������-�-�/��3r[c��|j|jj�|jj�|j	t
|j�}|j|jtj�y)z{
        L{_ExhaustsFileDescriptors.exhaust} causes the process to
        exhaust its available file descriptors.
        N)
r�r�r�r�rj�IOErrorr�r�r�r�)rt�	exceptions  r\�test_exhaustTriggersEMFILEz7ExhaustsFileDescriptorsTests.test_exhaustTriggersEMFILE4sX��
	
������.�.�/������ ��%�%�g�t�~�~�>�	�������%�,�,�7r[c�`�d�}t|�}|jt|j�y)z�
        An L{OSError} raised within
        L{_ExhaustsFileDescriptors.exhaust} with an C{errno} other
        than C{EMFILE} is reraised to the caller.
        c�<�ttjdzd��)Nr�z
Not EMFILE)r�r�r�rZr[r\�raiseOSErrorzLExhaustsFileDescriptorsTests.test_exhaustRaisesOSError.<locals>.raiseOSErrorEs���%�,�,��*�L�9�9r[N)r�rjr�r�)rtr�r�s   r\�test_exhaustRaisesOSErrorz6ExhaustsFileDescriptorsTests.test_exhaustRaisesOSError>s)��	:�-�\�:�	����'�9�#4�#4�5r[c��|jj�|jj�|j�y)zc
        L{_ExhaustsFileDescriptors.release} releases all opened
        file descriptors.
        N)r�r�r�r�r�s r\�test_releasez)ExhaustsFileDescriptorsTests.test_releaseKs.��
	
����� ������ ����r[c����g��fd�}t|�}|j|j�|jt|j
�|j
t��d�|j
|j�d��D]Q}|jttj|�}|j
|jtj��Sy)z�
        L{_ExhaustsFileDescriptors.exhaust} closes any opened file
        descriptors if an exception occurs during its exhaustion loop.
        c���t��dk(rtd��tjd�}�j	|�|S)Nr�z9test_fileDescriptorsReleasedOnFailure fake open exceptionr)r~rkr�r�r}�r��fileDescriptorss �r\�failsAfterThreez[ExhaustsFileDescriptorsTests.test_fileDescriptorsReleasedOnFailure.<locals>.failsAfterThree\sB����?�#�q�(� �R����V�V�A�Y���&�&�r�*��	r[r�rN)r�r�r�rjrkr�r�r~r�r�r��fstatr�r�)rtr�r�r�r�r�s     @r\�%test_fileDescriptorsReleasedOnFailurezBExhaustsFileDescriptorsTests.test_fileDescriptorsReleasedOnFailureUs����
��	�-�_�=�	����	�)�)�*����*�i�&7�&7�8�����_�-�q�1�������*�A�.�!�	;�B��)�)�'�2�8�8�R�@�I����Y�_�_�e�k�k�:�	;r[c�P��g��fd�}t|�}|j|j�|j�|j	|j�d�t
j�d�|j�|j|j�d�y)z�
        L{_ExhaustsFileDescriptors.release} continues to close opened
        file descriptors even when closing one fails with C{EBADF}.
        c�T��tjd�}�j|�|Sr�)r�r�r}r�s �r\�recordFileDescriptorszTExhaustsFileDescriptorsTests.test_releaseIgnoresEBADF.<locals>.recordFileDescriptorsxs#��������B��"�"�2�&��Ir[rN)	r�r�r�r�r�r�r�r�r�)rtrr�r�s   @r\�test_releaseIgnoresEBADFz5ExhaustsFileDescriptorsTests.test_releaseIgnoresEBADFqs����
��	�
-�-B�C�	����	�)�)�*��������9�?�?�,�a�0�
�����#�$�����������*�A�.r[c���g��fd�}d�}t||��}|j|j�d�|j�|j	|j�d�|jt|j�y)z�
        An L{OSError} raised within
        L{_ExhaustsFileDescriptors.release} with an C{errno} other than
        C{EBADF} is reraised to the caller.
        c���t��dk(rttjd���j	d��dS)Nr�zToo many filesrV)r~r�r�r�r})�fakeFileDescriptorss�r\�
opensThreezJExhaustsFileDescriptorsTests.test_releaseRaisesOSError.<locals>.opensThree�s<����&�'�1�,��e�l�l�,<�=�=��&�&�r�*�&�r�*�*r[c��tdd��)N�z&test_releaseRaisesOSError fake OSError)r�)r�s r\�failingClosezLExhaustsFileDescriptorsTests.test_releaseRaisesOSError.<locals>.failingClose�s���"�F�G�Gr[)r�rN)r�r�r�r�r�rjr�r�)rtrr	r�rs    @r\�test_releaseRaisesOSErrorz6ExhaustsFileDescriptorsTests.test_releaseRaisesOSError�st���!��	+�	H�-�Z�|�L�	�������*�A�.��������9�?�?�,�a�0����'�9�#4�#4�5r[N)r�r�r�r�r�r�r�r�r�r�r�r�rr
rZr[r\r�r�s:���0�!�@�	4�8�6��;�8/�.6r[r�c�d�����
���|j�j�t��t�}|�_dg���fd�}|j|�t
��
tj��r)�
�����fd�}�jd�jd|�n>����}	|	j�}
��|
�
��j�j���fd�}�
jj|��
jj|�|��g}|j|j �|j#|d�|j%�
j�|j'�
j�|j)t*�
j,j.�y)a#
    Assert that an L{IListeningPort} immediately closes an accepted
    peer socket when the number of open file descriptors exceeds the
    soft resource limit.

    @param testCase: The test case under which to run this assertion.
    @type testCase: L{trial.unittest.SynchronousTestCase}

    @param exhauster: The file descriptor exhauster.
    @type exhauster: L{_ExhaustsFileDescriptors}

    @param reactor: The reactor under test.

    @param runReactor: A callable that will synchronously run the
        provided reactor.

    @param listen: A callback to bind to a port.
    @type listen: A L{callable} that accepts two arguments: the
        provided C{reactor}; and a L{ServerFactory}.  It must return
        an L{IListeningPort} provider.

    @param connect: A callback to connect a client to the listening
        port.
    @type connect: A L{callable} that accepts three arguments: the
        provided C{reactor}; the address returned by
        L{IListeningPort.getHost}; and a L{ClientFactory}.  Its return
        value is ignored.
    Fc�0���j�d�d<y)NTrr4)r�r��serverConnectionCompleteds ��r\�stopReactorIfServerAcceptedz=assertPeerClosedOnEMFILE.<locals>.stopReactorIfServerAccepted�s�������'+�!�!�$r[c�l������}|j�}��|���j�yrY)rr�)rl�
listeningHostr'rhr�rr�r>s  ������r\�innerz'assertPeerClosedOnEMFILE.<locals>.inner�s2����'�=�1�D� �L�L�N�M��G�]�M�:����r[rc�H���j��j�|SrY)r�r5)r�r�r�s ��r\�"stopReactorAndCloseFileDescriptorszDassertPeerClosedOnEMFILE.<locals>.stopReactorAndCloseFileDescriptors�s������������
r[z1Server accepted connection; EMFILE not triggered.N)r�r�rNr�protocolConnectionMader9rMr,ri�	callLaterrr�r��deferredrur�r}r��assertNoResult�successResultOfrjr�
lostReasonry)�testCaser�r�r=rrh�serverConnectionMaderrrlrr�noResultr'r
r>s `` ``       @@@r\�assertPeerClosedOnEMFILEr�sn���H
���	�)�)�*�#�%�M�#�:��+?�M�(�!&���,��$�$�%@�A�#�%�M����w�'�	 �	 �	���!�W�.�.��5�9��g�}�-������
����
�6����	� 1� 1�2��
���"�"�#E�F����&�&�'I�J��w���H�� � ����1�����#V�W����M�6�6�7����]�3�3�4������ � �/�/�r[c�L�eZdZdZee�Gd�d��Zd�Zd�Zd�Z	y)�AssertPeerClosedOnEMFILETestsz0
    Tests for L{assertPeerClosedOnEMFILE}.
    c�"�eZdZdZd�Zd�Zd�Zy)�+AssertPeerClosedOnEMFILETests.NullExhausterz1
        An exhauster that does nothing.
        c��y)zB
            See L{_IExhaustsFileDescriptors.exhaust}
            NrZr�s r\r�z3AssertPeerClosedOnEMFILETests.NullExhauster.exhaust	r�r[c��y)zB
            See L{_IExhaustsFileDescriptors.release}
            NrZr�s r\r�z3AssertPeerClosedOnEMFILETests.NullExhauster.releaser�r[c��y)z@
            See L{_IExhaustsFileDescriptors.count}
            NrZr�s r\r�z1AssertPeerClosedOnEMFILETests.NullExhauster.countr�r[Nr�rZr[r\�
NullExhausterr!s��	�	�
	�
	r[r%c�@�t�|_t�|_yrY)rEr�rPrr�s r\r�z#AssertPeerClosedOnEMFILETests.setUps��$����+�-��
r[c�@�tt|j��y)zZ
        L{NullExhauster} instances provide
        L{_IExhaustsFileDescriptors}.
        N)rr�r%r�s r\�#test_nullExhausterProvidesInterfacezAAssertPeerClosedOnEMFILETests.test_nullExhausterProvidesInterfaces��
	�.��0B�0B�0D�Er[c
�P��|j�}dg��fd�}�fd�}d�}|j|jjt|j||j
|||��}|j
dt|��|j|j
j�y)z�
        If the exhauster fails to trigger C{EMFILE} and a connection
        reaches the server, the reactor is stopped and the test fails.
        Nc���|j��djtddd��}|jt	��y)NrrWr�i�)�runr#rrMrF)r��protor>s  �r\r=z[AssertPeerClosedOnEMFILETests.test_reactorStoppedOnSuccessfulConnection.<locals>.runReactor+s@����K�K�M�!�!�$�2�2��E�;��5��E�
� � ��!2�3r[c�X��|jdd|�}|j�|�d<|S)Nr�i�r)r�doStart)r�rrlr>s   �r\rzWAssertPeerClosedOnEMFILETests.test_reactorStoppedOnSuccessfulConnection.<locals>.listen2s0����$�$�[�$��@�D��O�O��&�M�!���Kr[c�*�|jdd|�y)Nr�r)r)r�rmrs   r\rhzXAssertPeerClosedOnEMFILETests.test_reactorStoppedOnSuccessfulConnection.<locals>.connect8s�����{�A�w�7r[�rr�r�r=rrhr�)
r%rjr�failureExceptionrr��assertInrr��running)rtr�r=rrhr�r>s      @r\�)test_reactorStoppedOnSuccessfulConnectionzGAssertPeerClosedOnEMFILETests.test_reactorStoppedOnSuccessfulConnection#s����
�&�&�(�	���
�	4�	�	8��%�%��M�M�*�*�$��]�]���L�L�!���&�	
�	�	
�
�
�h��I��/�������-�-�.r[N)
r�r�r�r�rr�r%r�r(r4rZr[r\rr�s6����*�+���,��(.�F�$/r[rc�:�eZdZdZd�Zd�Zeed�d��Zy)�StreamTransportTestsMixinzR
    Mixin defining tests which apply to any port/connection based transport.
    c��|j�}|j�}tt�Gd�dt��}|�}|j||�}|j
|d�}|j|f|dd�y)zt
        When a port starts, a message including a description of the associated
        factory is logged.
        c��eZdZd�Zy)�NStreamTransportTestsMixin.test_startedListeningLogMessage.<locals>.SomeFactoryc��y)N�
Crazy FactoryrZr�s r\�	logPrefixzXStreamTransportTestsMixin.test_startedListeningLogMessage.<locals>.SomeFactory.logPrefixYs��&r[N)r�r�r�r<rZr[r\�SomeFactoryr9Ws��
'r[r=r;rr�N)�observer7rr&r1�getListeningPort�#getExpectedStartListeningLogMessager�)rt�loggedMessagesr�r=rr��expectedMessages       r\�test_startedListeningLogMessagez9StreamTransportTestsMixin.test_startedListeningLogMessageOs���
������#�#�%��	�_�	%�	'�-�	'�
&�	'��-���!�!�'�7�3���B�B�1�o�V�����/�+�^�A�->�y�-I�Jr[c�<������g��fd��|j��|j�t���|j��}t	j
����fd�����fd�}�j
|��j�|j|��y)z�
        When a connection is lost, an informative message should be logged
        (see L{getExpectedConnectionLostLogMsg}): an address identifying
        the port and the fact that it was closed.
        c�N���jtj|��yrY)r}rH�textFromEventDict)�	eventDictrAs �r\�logConnectionLostMsgzQStreamTransportTestsMixin.test_connectionLostLogMsg.<locals>.logConnectionLostMsgjs����!�!�#�"7�"7�	�"B�Cr[c�P��tj���j�yrY)rH�removeObserverr5)r1rHr�s ��r\�stopReactorzHStreamTransportTestsMixin.test_connectionLostLogMsg.<locals>.stopReactorrs������3�4��L�L�Nr[c�x��tj��t�j�j	��yrY)rH�addObserverr�
stopListeningr9)rHr�rKs���r\�doStopListeningzLStreamTransportTestsMixin.test_connectionLostLogMsg.<locals>.doStopListeningvs'����O�O�0�1��!�/�/�*�6�6�{�Cr[N)	r7r?r1�getExpectedConnectionLostLogMsgrHrMr�r+r2)rtrBrOrHrAr�r�rKs   @@@@@r\�test_connectionLostLogMsgz3StreamTransportTestsMixin.test_connectionLostLogMsgas������	D��#�#�%���!�!�'�=�?�;���>�>�q�A�����,�-�	�	D�	����0����
��
�
�o�~�6r[r�c��t|t�|j�|j|j|j
��y)z2
        See L{assertPeerClosedOnEMFILE}.
        r0N)rr�r7r=r?�connectToListenerr�s r\�test_closePeerOnEMFILEz0StreamTransportTestsMixin.test_closePeerOnEMFILEs:��
	!��.�0��%�%�'�����(�(��*�*�
	
r[N)	r�r�r�r�rCrQr�SKIP_EMFILErTrZr[r\r6r6Js/���K�$7�<�K�T�U�
�V�
r[r6c��eZdZdZdZd�Zy)�ConnectToTCPListenerMixina^
    Provides L{connectToListener} for TCP transports.

    @ivar LISTENER_HOST: The host on which the port is expected to be
        listening.  This is specific to avoid compatibility issues
        with Windows, which cannot connect to the wildcard host.
    @type LISTENER_HOST: L{str}

    @see: U{http://twistedmatrix.com/trac/ticket/1472}
    r�c�P�|j|j|j|�S)a�
        Connect to the given listening TCP port.

        @param reactor: The reactor under test.
        @type reactor: L{IReactorTCP}

        @param address: The listening port's address.  Only the
            C{port} component is used; see L{LISTENER_HOST}.
        @type address: L{IPv4Address} or L{IPv6Address}

        @param factory: The client factory.
        @type factory: L{ClientFactory}

        @return: The connector
        )r�
LISTENER_HOSTrl)rtr�rmrs    r\rSz+ConnectToTCPListenerMixin.connectToListener�s#�� �!�!�$�"4�"4�g�l�l�G�L�Lr[N)r�r�r�r�rYrSrZr[r\rWrW�s��	� �M�Mr[rWc��eZdZdZdd�Zy)�ListenTCPMixinzT
    Mixin which uses L{IReactorTCP.listenTCP} to hand out listening TCP ports.
    c�*�|j|||��S)z0
        Get a TCP port from a reactor.
        r�)r)rtr�rrlr�s     r\r?zListenTCPMixin.getListeningPort�s��� � ��w�)� �D�Dr[N�rrU�r�r�r�r�r?rZr[r\r[r[�s
���Er[r[c��eZdZdZdd�Zy)�SocketTCPMixinza
    Mixin which uses L{IReactorSocket.adoptStreamPort} to hand out
    listening TCP ports.
    c�>�tj|�r�d|vr-tj}tj||�dd}ntj
}||f}tj|�}|j
|�|jd�|jd�	|j|j�|j|�|j�|j�Std��#|j�|j�wxYw)zi
        Get a TCP port from a reactor, wrapping an already-initialized file
        descriptor.
        rdrrer�Fz'Reactor does not provide IReactorSocket)r*rirfr�rgr�bindrrx�adoptStreamPortr�rr�rO)rtr�rrlr��domainrm�portSocks        r\r?zSocketTCPMixin.getListeningPort�s���
�$�$�W�-��i������ �,�,�Y��=�a�@��C������$�d�+���}�}�V�,�H��M�M�'�"��O�O�A��� � ��'�

!��.�.��O�O�%�x��������!���� ��D�E�E�����!���� �s�$*C:�:"DNr]r^rZr[r\r`r`�s
���
Fr[r`c�T�eZdZUdZefZeeee	e
d<d�Zd�Zd�Z
eee�d��Zeee�d��Zd�Zd	�Zeee�d
��Zeee�d��Zd�Zd
�Zeee�d��Zeee�d��Zd�Zeee�d��Zeee�d��Zy)�TCPPortTestsMixinz,
    Tests for L{IReactorTCP.listenTCP}
    r{c�@�d||j�jfzS)zY
        Get the message expected to be logged when a TCP port starts listening.
        z%s starting on %d�rrl)rtrlrs   r\r@z5TCPPortTestsMixin.getExpectedStartListeningLogMessage�s ��#�g�t�|�|�~�/B�/B�%C�C�Cr[c�>�d|j�j�d�S)zJ
        Get the expected connection lost message for a TCP port.
        z
(TCP Port z Closed)ri)rtrls  r\rPz1TCPPortTestsMixin.getExpectedConnectionLostLogMsg�s ���D�L�L�N�/�/�0��9�9r[c��|j�}|j|t��}|j�}|j	|t
�y)z�
        When no interface is passed to L{IReactorTCP.listenTCP}, the returned
        listening port listens on an IPv4 address.
        N)r7r?r1r�assertIsInstancer)rtr�rlrms    r\�test_portGetHostOnIPv4z(TCPPortTestsMixin.test_portGetHostOnIPv4�sA��
�#�#�%���$�$�W�m�o�>���,�,�.�����g�{�3r[c�Z�|j�}ttjd��dd\}}|j	|t�||�}|j
�}|j|t�|jd|j�|j||j�y)z�
        When listening on an IPv6 address, L{IListeningPort.getHost} returns
        an L{IPv6Address} with C{host} and C{port} attributes reflecting the
        address the port is bound to.
        rT)rr�NrD)r7r@rfr�r?r1rrlrr�rkrl)rtr�rkr�rlrms      r\�test_portGetHostOnIPv6z(TCPPortTestsMixin.test_portGetHostOnIPv6�s����#�#�%��'�v���%�P�QS�RS�T���j��$�$�W�m�o�z�4�P���,�,�.�����g�{�3��������-�����W�\�\�2r[c���t�}|j�}|j|t�d|�}|j	�}|j|t�|j||j�y)a(
        When a link-local IPv6 address including a scope identifier is passed
        as the C{interface} argument to L{IReactorTCP.listenTCP}, the resulting
        L{IListeningPort} reports its address as an L{IPv6Address} with a host
        value that includes the scope identifier.
        rN)	rar7r?r1rrlrr�rk)rt�	linkLocalr�rlrms     r\�test_portGetHostOnIPv6ScopeIDz/TCPPortTestsMixin.test_portGetHostOnIPv6ScopeIDsa��,�-�	��#�#�%���$�$�W�m�o�q�)�L���,�,�.�����g�{�3�����G�L�L�1r[c���G�fd�dt�}|�}|j��|j�|d|�}|jd�	t	||j�j|j�jf�|j��|jS#t$rD}|j|jtjtjf�Yd}~�ed}~wwxYw)a
        Connect C{client} to a server listening on C{interface} started with
        L{IReactorTCP.listenTCP} and return the address passed to the factory's
        C{buildProtocol} method.

        @param client: A C{SOCK_STREAM} L{socket.socket} created with an address
            family such that it will be able to connect to a server listening on
            C{interface}.

        @param interface: A C{str} giving an address for a server to listen on.
            This should almost certainly be the loopback address for some
            address family supported by L{IReactorTCP.listenTCP}.

        @return: Whatever object, probably an L{IAddress} provider, is passed to
            a server factory's C{buildProtocol} method when C{client}
            establishes a connection.
        c���eZdZ�fd�Zy)�CTCPPortTestsMixin._buildProtocolAddressTest.<locals>.ObserveAddressc�F���j�||_t�SrY)r5�observedAddressr0)rtrmr�s  �r\r#zQTCPPortTestsMixin._buildProtocolAddressTest.<locals>.ObserveAddress.buildProtocol/s�������'.��$��z�!r[Nr$r�s�r\�ObserveAddressru.s���
"r[rxrFN)r1r7r?rxrhrrkrlr�r2r��EINPROGRESS�EWOULDBLOCKr=rw)rtrir�rxrrlr�r�s       @r\�_buildProtocolAddressTestz+TCPPortTestsMixin._buildProtocolAddressTests����&	"�]�	"�!�"���#�#�%���$�$�W�g�q�)�D�����5�!�	K��F�T�\�\�^�0�0�$�,�,�.�2E�2E�F�G�	
���� ��&�&�&���	K��M�M�!�'�'�E�$5�$5�u�7H�7H�#I�J�J��	K�s�>B+�+	C8�4:C3�3C8c���d}t|tjtj�}|j	||�}|jt
dg|j����|�y)z�
        When a connection is accepted over IPv4, an L{IPv4Address} is passed
        to the factory's C{buildProtocol} method giving the peer's address.
        r�rWN)r�rfr�SOCK_STREAMr{r�r�getsockname)rtr�rirws    r\�test_buildProtocolIPv4Addressz/TCPPortTestsMixin.test_buildProtocolIPv4AddressAsV��
 �	�!�$�����8J�8J�K���8�8���K������U�B�V�-?�-?�-A�B�O�Tr[c�,�d}t|tjtj�}|j	||�}|j�}tj|tj�d}|jtd||d�|�y)z�
        When a connection is accepted to an IPv6 address, an L{IPv6Address} is
        passed to the factory's C{buildProtocol} method giving the peer's
        address.
        rTrrWr�N)
r�rfr�r}r{r~�getnameinfo�NI_NUMERICHOSTr�r�rtr�rirwrE�hostnames      r\�test_buildProtocolIPv6Addressz/TCPPortTestsMixin.test_buildProtocolIPv6AddressKs{���	�!�$�����9K�9K�L���8�8���K���!�!�#���%�%�d�F�,A�,A�B�1�E������U�H�d�1�g�>��Pr[c�<�t�}t|tjtj�}|j||�}|j
�}tj|tj�d}|jtd|g|dd���|�y)z�
        When a connection is accepted to a link-local IPv6 address, an
        L{IPv6Address} is passed to the factory's C{buildProtocol} method
        giving the peer's address, including a scope identifier.
        rrWr�N)rar�rfr�r}r{r~r�r�r�rr�s      r\�$test_buildProtocolIPv6AddressScopeIDz6TCPPortTestsMixin.test_buildProtocolIPv6AddressScopeID[s���,�-�	�!�$�����9K�9K�L���8�8���K���!�!�#���%�%�d�F�,A�,A�B�1�E������U�H�@�t�A�B�x�@�/�Rr[c����G��fd�dt�}|j��t�}||_|j	�|d|�}|jd�	t
||j�j|j�jf�|j��|j S#t$rD}|j|jtjtjf�Yd}~�ed}~wwxYw)a�
        Connect C{client} to a server listening on C{interface} started with
        L{IReactorTCP.listenTCP} and return the address returned by one of the
        server transport's address lookup methods, C{getHost} or C{getPeer}.

        @param client: A C{SOCK_STREAM} L{socket.socket} created with an address
            family such that it will be able to connect to a server listening on
            C{interface}.

        @param interface: A C{str} giving an address for a server to listen on.
            This should almost certainly be the loopback address for some
            address family supported by L{IReactorTCP.listenTCP}.

        @param which: A C{str} equal to either C{"getHost"} or C{"getPeer"}
            determining which address will be returned.

        @return: Whatever object, probably an L{IAddress} provider, is returned
            from the method indicated by C{which}.
        c���eZdZ��fd�Zy)�ITCPPortTestsMixin._serverGetConnectionAddressTest.<locals>.ObserveAddressc�f���j�t|���|j_yrY)r5�getattrrrm)rtrKr��whichs  ��r\rMzXTCPPortTestsMixin._serverGetConnectionAddressTest.<locals>.ObserveAddress.makeConnection�s$�������'@�w�y�%�'@�'B����$r[NrN)r�r�s��r\rxr��s	���
Cr[rxrFN)r0r7r1r�r?rxrhrrkrlr�r2r�ryrzr=rm)	rtrir�r�rxrrlr�r�s	   `    @r\�_serverGetConnectionAddressTestz1TCPPortTestsMixin._serverGetConnectionAddressTestks����*	C�X�	C�
�#�#�%���/��)����$�$�W�g�q�)�D�����5�!�	K��F�T�\�\�^�0�0�$�,�,�.�2E�2E�F�G�	
���� �������	K��M�M�!�'�'�E�$5�$5�u�7H�7H�#I�J�J��	K�s�>B7�7	D�:C?�?Dc���d}t|tjtj�}|j	||d�}|jt
dg|j����|�y)z�
        When a connection is accepted over IPv4, the server
        L{ITransport.getHost} method returns an L{IPv4Address} giving the
        address on which the server accepted the connection.
        r�rrWN)r�rfrr}r�r�r�getpeername)rtr�ri�hostAddresss    r\�test_serverGetHostOnIPv4z*TCPPortTestsMixin.test_serverGetHostOnIPv4��X�� �	�!�$�����8J�8J�K���:�:�6�9�i�X������U�B�V�-?�-?�-A�B�K�Pr[c�.�d}t|tjtj�}|j	||d�}|j�}tj|tj�d}|jtd|g|dd���|�y)z�
        When a connection is accepted over IPv6, the server
        L{ITransport.getHost} method returns an L{IPv6Address} giving the
        address on which the server accepted the connection.
        rTrrrWr�N)
r�rfr�r}r�r�r�r�r�r�rtr�rir�rEr�s      r\�test_serverGetHostOnIPv6z*TCPPortTestsMixin.test_serverGetHostOnIPv6�����	�!�$�����9K�9K�L���:�:�6�9�i�X���!�!�#���%�%�d�F�,A�,A�B�1�E������U�H�@�t�A�B�x�@�+�Nr[c�>�t�}t|tjtj�}|j||d�}|j
�}tj|tj�d}|jtd|g|dd���|�y)z�
        When a connection is accepted over IPv6, the server
        L{ITransport.getHost} method returns an L{IPv6Address} giving the
        address on which the server accepted the connection, including the scope
        identifier.
        rrrWr�N)rar�rfr�r}r�r�r�r�r�rr�s      r\�test_serverGetHostOnIPv6ScopeIDz1TCPPortTestsMixin.test_serverGetHostOnIPv6ScopeID����,�-�	�!�$�����9K�9K�L���:�:�6�9�i�X���!�!�#���%�%�d�F�,A�,A�B�1�E������U�H�@�t�A�B�x�@�+�Nr[c���d}t|tjtj�}|j	||d�}|jt
dg|j����|�y)z�
        When a connection is accepted over IPv4, the server
        L{ITransport.getPeer} method returns an L{IPv4Address} giving the
        address of the remote end of the connection.
        r�rJrWN)r�rfrr}r�r�rr~)rtr�ri�peerAddresss    r\�test_serverGetPeerOnIPv4z*TCPPortTestsMixin.test_serverGetPeerOnIPv4�r�r[c�.�d}t|tjtj�}|j	||d�}|j�}tj|tj�d}|jtd|g|dd���|�y)z�
        When a connection is accepted over IPv6, the server
        L{ITransport.getPeer} method returns an L{IPv6Address} giving the
        address on the remote end of the connection.
        rTrJrrWr�N)
r�rfr�r}r�r~r�r�r�r�rtr�rir�rEr�s      r\�test_serverGetPeerOnIPv6z*TCPPortTestsMixin.test_serverGetPeerOnIPv6�r�r[c�>�t�}t|tjtj�}|j||d�}|j
�}tj|tj�d}|jtd|g|dd���|�y)z�
        When a connection is accepted over IPv6, the server
        L{ITransport.getPeer} method returns an L{IPv6Address} giving the
        address on the remote end of the connection, including the scope
        identifier.
        rJrrWr�N)rar�rfr�r}r�r~r�r�r�rr�s      r\�test_serverGetPeerOnIPv6ScopeIDz1TCPPortTestsMixin.test_serverGetPeerOnIPv6ScopeID�r�r[N)r�r�r�r�r+r{r	r
rr
r�r@rPrmr�ipv6Skip�ipv6SkipReasonrorrr{rr�r�r�r�r�r�r�r�r�rZr[r\rgrg�s8���@K�n����$�y�/�!:�;�L�D�:�4��H�n�%�3�&�3��H�n�%�2�&�2�$'�LU��H�n�%�
Q�&�
Q��H�n�%�
S�&�
S�$�L	Q��H�n�%�
O�&�
O��H�n�%�O�&�O� 	Q��H�n�%�
O�&�
O��H�n�%�O�&�Or[rgc��eZdZy)�TCPPortTestsBuilderN�r�r�r�rZr[r\r�r�����	r[r�c��eZdZy)�TCPFDPortTestsBuilderNr�rZr[r\r�r��r�r[r�c�"�eZdZdZd�Zd�Zd�Zy)�StopStartReadingProtocolzD
    Protocol that pauses and resumes the transport a few times
    c�4�d|_|jd�y)Nr[r�)rq�pauseResumeProducingr�s r\�connectionMadez'StopStartReadingProtocol.connectionMades����	��!�!�!�$r[c�d�|jj�|jj�|r5|jjjd|j|dz
�y|jjjd|jjj|�y)z?
        Toggle transport read state, then count down.
        rr�N)	rK�pauseProducing�resumeProducingrr�rr��ready�callback)rt�counters  r\r�z-StopStartReadingProtocol.pauseResumeProducingsz��	
���%�%�'����&�&�(���L�L� � �*�*�1�d�.G�.G��ST��U��L�L� � �*�*�1�d�l�l�.@�.@�.I�.I�4�Pr[c��tjdt|��|xj|z
c_t|j�dk(r0|jj
j
|j�yy)Nzgot datai@)rHrRr~rqrr5r�rss  r\r�z%StopStartReadingProtocol.dataReceivedsS�����
�C��I�&��	�	�T��	��t�y�y�>�X�%��L�L���&�&�t�y�y�1�&r[N)r�r�r�r�r�r�r�rZr[r\r�r��s���%�	Q�2r[r�c�.��t���fd��}|S)aG
    Decorate a L{ReactorBuilder} test function which tests one reactor and one
    connected transport.  Run that test method in the context of
    C{connectionMade}, and immediately drop the connection (and end the test)
    when that completes.

    @param testMethod: A unit test method on a L{ReactorBuilder} test suite;
        taking two additional parameters; a C{reactor} as built by the
        L{ReactorBuilder}, and an L{ITCPTransport} provider.
    @type testMethod: 3-argument C{function}

    @return: a no-argument test method.
    @rtype: 1-argument C{function}
    c�~����t��G���fd�dt�}|�}t�|�t��y)Nc���eZdZ���fd�Zy)�BoneTransportTest.<locals>.actualTestMethod.<locals>.ServerProtocolc���	��|j|j�|j�|jj��j��jj�yy#|j�|jj��j��jj�wwxYwrY)r�rK�loseConnection)rt�builder�other�
testMethods ���r\r�zQoneTransportTest.<locals>.actualTestMethod.<locals>.ServerProtocol.connectionMade,s����9��w����d�n�n�E��~�~�1����5�5�7����2����6�6�8�3���~�~�1����5�5�7����2����6�6�8�3�s�A/�/AB>N�r�r�r�r�)r�r�r�s���r\�ServerProtocolr�+s���
9r[r�)r:rAr�)r�r��serverProtocolr�r�s`  @�r\�actualTestMethodz*oneTransportTest.<locals>.actualTestMethod's7���#�%��	9�	9�0�	9�(�)������
��Mr[r)r�r�s` r\�oneTransportTestr�s&��� �:��N��N� �r[c���tj|�r!|j||j��y|j||j�|j|j�y)a^
    Use the given test to assert that the given transport is actively reading
    in the given reactor.

    @note: Maintainers; for more information on why this is a function rather
        than a method on a test case, see U{this document on how we structure
        test tools
        <http://twistedmatrix.com/trac/wiki/Design/KeepTestToolsOutOfFixtures>}

    @param testCase: a test case to perform the assertion upon.
    @type testCase: L{TestCase}

    @param reactor: A reactor, possibly one providing L{IReactorFDSet}, or an
        IOCP reactor.

    @param transport: An L{ITCPTransport}
    N)r)rir2r��handlesr��reading�rr�rKs   r\�
assertReadingr�;sU��$����(����)�W�%7�%7�%9�:�	���)�W�_�_�5����I�-�-�.r[c��tj|�r!|j||j��y|j	|j
�y)ae
    Use the given test to assert that the given transport is I{not} actively
    reading in the given reactor.

    @note: Maintainers; for more information on why this is a function rather
        than a method on a test case, see U{this document on how we structure
        test tools
        <http://twistedmatrix.com/trac/wiki/Design/KeepTestToolsOutOfFixtures>}

    @param testCase: a test case to perform the assertion upon.
    @type testCase: L{TestCase}

    @param reactor: A reactor, possibly one providing L{IReactorFDSet}, or an
        IOCP reactor.

    @param transport: An L{ITCPTransport}
    N)r)ri�assertNotInr�r�r�r�s   r\�assertNotReadingr�UsA��$����(����Y��(:�(:�(<�=�	���Y�.�.�/r[c�X�eZdZdZefZd�Zed��Zed��Z	ed��Z
d�Zd�Zy)	�TCPConnectionTestsBuilderzP
    Builder defining tests relating to L{twisted.internet.tcp.Connection}.
    c���	�
��t���j�x�
�_ddg}�
jj}||vrtj�rtd��t�_	t��_t��_�
jd��}|j�j}�	�
��fd�}�fd��	t!�
d|�}t#�}t$|_	t'|j)|��jg�j+||�}|j-t.j0��j3�
�y)	zt
        This test verifies transport socket read state after multiple
        pause/resumeProducing calls.
        �Glib2Reactor�Gtk2Reactorz.This test is broken on gtk/glib under Windows.rc� ���j|d��j|d�|dd|ddf}|djjddzddzz��jj	�||�j	�fd��S)zL
            Send several IOCPReactor's buffers' worth of data.
            rr��x� �yc�$���j�SrYr4rss �r\r]zRTCPConnectionTestsBuilder.test_stopStartReading.<locals>.proceed.<locals>.<lambda>�s
���G�L�L�N�r[)r�rKr�r5r9)�protosrl�cleanupr�rt�sfs  ����r\�proceedz@TCPConnectionTestsBuilder.test_stopStartReading.<locals>.proceed�s����
�O�O�F�1�I�&��O�O�F�1�I�&��A�Y�q�\�6�!�9�Q�<�/�F��1�I���%�%�d�h�&7�$�(�:K�&K�L��7�7�&�&�w���=�I�I�*��
r[c����j|ddzddzzd�tt|djj�t|djj�t|j
�g�S)z�
            Make sure IOCPReactor didn't start several WSARecv operations
            that clobbered each other's results.
            r�r�r�zdid not get the right datarr�)r�rrrKr�rN)rqr�rlrts   �r\r�z@TCPConnectionTestsBuilder.test_stopStartReading.<locals>.cleanup�s}���

������!�D�H�$5�5�,�
�
 �!�&��)�"5�"5�"D�"D�E�!�&��)�"5�"5�"D�"D�E�!�$�"4�"4�5���
r[r�N)r1r7r�r^r�rJ�	isWindowsrOr�r�rr�r5rrrlrr/r0rrhr9r;rHr<r=)rt�skippedReactors�reactorClassNamer�rlr��cc�cf�dr�r�r�s`        @@@r\�test_stopStartReadingz/TCPConnectionTestsBuilder.test_stopStartReadingus���
�_��#�0�0�2�2��"�*�)�=�9��"�,�,�5�5����.�8�3E�3E�3G��K�L�L�.����:����*������a��$���y�y�{����
	�	�$ ���d�
;��
�_������"�*�*�R�.�"�(�(�3�4�@�@��!�L��	���S�W�W������ r[c�x�|j�t|||�|j�t|||�y)zz
        When a L{Server} is connected, its C{resumeProducing} method adds it as
        a reader to the reactor.
        N)r�r�r�r��rtr�r�s   r\�test_resumeProducingz.TCPConnectionTestsBuilder.test_resumeProducing�s4��	������w��/���� ��d�G�V�,r[c�^�|j�|j�t|||�y)z�
        When a L{Server} has already started disconnecting via
        C{loseConnection}, its C{resumeProducing} method does not add it as a
        reader to its reactor.
        N)r�r�r�r�s   r\�&test_resumeProducingWhileDisconnectingz@TCPConnectionTestsBuilder.test_resumeProducingWhileDisconnecting�s(��	������� ���w��/r[c��|jttd���t|||�|j	�t|||�y)z�
        When a L{Server} has already lost its connection, its
        C{resumeProducing} method does not add it as a reader to its reactor.
        �dummyN)r�rIr�r�r�r�s   r\�%test_resumeProducingWhileDisconnectedz?TCPConnectionTestsBuilder.test_resumeProducingWhileDisconnected�s@��	���g�i��&8�9�:���w��/���� ���w��/r[c��Gd�dt�}Gd�dt�}|�}t|||�t��|j|jgd��y)a�
        Alice connects to Bob.  Alice writes some bytes and then shuts down the
        connection.  Bob receives the bytes from the connection and then pauses
        the transport object.  Shortly afterwards Bob resumes the transport
        object.  At that point, Bob is notified that the connection has been
        closed.

        This is no problem for most reactors.  The underlying event notification
        API will probably just remind them that the connection has been closed.
        It is a little tricky for win32eventreactor (MsgWaitForMultipleObjects).
        MsgWaitForMultipleObjects will only deliver the close notification once.
        The reactor needs to remember that notification until Bob resumes the
        transport.
        c�$�eZdZd�Zd�Zd�Zd�Zy)�QTCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport.<locals>.Pauserc��g|_yrY)�eventsr�s r\ruzZTCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport.<locals>.Pauser.__init__�s	�� ��r[c��|jjd�|jj�|jjd|j�y)N�pausedr)r�r}rKr�r�r�resumers  r\r�z^TCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport.<locals>.Pauser.dataReceived�s<�����"�"�8�,����-�-�/����&�&�q�$�+�+�6r[c�n�|jjd�|jj�y)N�resumed)r�r}rKr�r�s r\r�zXTCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport.<locals>.Pauser.resume�s$�����"�"�9�-����.�.�0r[c�f�|jjd�tj||�y)N�lost)r�r}r:r��rtr.s  r\r�z`TCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport.<locals>.Pauser.connectionLost�s$�����"�"�6�*�#�2�2�4��@r[N)r�r�r�rur�r�r�rZr[r\�Pauserr��s��
!�
7�

1�
Ar[r�c��eZdZd�Zy)�QTCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport.<locals>.Clientc�n�|jjd�|jj�y)Nssome bytes for you)rKr�r�r�s r\r�z`TCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport.<locals>.Client.connectionMade�s%�����$�$�%:�;����-�-�/r[Nr�rZr[r\�Clientr��s��
0r[r�)r�r�r�N)r:rAr�r�r�)rtr�r��pausers    r\�'test_connectionLostAfterPausedTransportzATCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport�sN�� 	A�(�	A�$	0�(�	0�
�����f�f�h�
��E�������(E�Fr[c��tt�Gd�dt��}Gd�dt�}t||�|�t	��y)a-
        If one side half-closes its connection, and then the other side of the
        connection calls C{loseWriteConnection}, and then C{loseConnection} in
        {writeConnectionLost}, the connection is closed correctly.

        This rather obscure case used to fail (see ticket #3037).
        c��eZdZd�Zd�Zy)�HTCPConnectionTestsBuilder.test_doubleHalfClose.<locals>.ListenerProtocolc�8�|jj�yrY)rK�loseWriteConnectionr�s r\�readConnectionLostz[TCPConnectionTestsBuilder.test_doubleHalfClose.<locals>.ListenerProtocol.readConnectionLosts�����2�2�4r[c�8�|jj�yrY�rKr�r�s r\�writeConnectionLostz\TCPConnectionTestsBuilder.test_doubleHalfClose.<locals>.ListenerProtocol.writeConnectionLost������-�-�/r[N)r�r�r�rrrZr[r\�ListenerProtocolrs��
5�
0r[r	c��eZdZd�Zy)�>TCPConnectionTestsBuilder.test_doubleHalfClose.<locals>.Clientc�8�|jj�yrYrr�s r\r�zMTCPConnectionTestsBuilder.test_doubleHalfClose.<locals>.Client.connectionMaderr[Nr�rZr[r\r�r
s��
0r[r�N)rr%r:rAr�)rtr	r�s   r\�test_doubleHalfClosez.TCPConnectionTestsBuilder.test_doubleHalfClose�sI��
�+�	,�	0�2�	0�
-�	0�	0�(�	0�
	 ��&6�&8�&�(�J�L�Qr[N)
r�r�r�r�r+r{r�r�r�r�r�r�r
rZr[r\r�r�ns`���&���6!�p�-��-��0��0��0��0�)G�VRr[r�c�R�eZdZUdZefZeeee	e
d<d�Zd�Zd�Z
d�Zd�Zy)	�WriteSequenceTestsMixinzM
    Test for L{twisted.internet.abstract.FileDescriptor.writeSequence}.
    r{c�<�t|dd��||_y||_y)z�
        Set the write buffer size for the given transport, mananing possible
        differences (ie, IOCP). Bug #4322 should remove the need of that hack.
        �writeBufferSizeN)r�r�
bufferSize)rtrK�values   r\�setWriteBufferSizez*WriteSequenceTestsMixin.setWriteBufferSizes$��
�9�/��6�B�(-�I�%�#(�I� r[c�����fd�}�j�}�j|dtj�}|j	|�|jtj��j|�y)zV
        C{writeSequence} sends the data even if C{write} hasn't been called.
        c�h���|\�}}��fd�}||_�jjgd��y)Nc���tjd|z��j|d��jj	�y)Nzdata received: %rsSome sequence splitted)rHrRr�rKr�)rqrirts ��r\r�z^WriteSequenceTestsMixin.test_writeSequeceWithoutWrite.<locals>.connected.<locals>.dataReceived+s8������+�d�2�3�� � ��'@�A�� � �/�/�1r[)sSome s	sequence ssplitted)r�rKr�)�	protocolsr�rlr�rirts    @�r\r2zHWriteSequenceTestsMixin.test_writeSequeceWithoutWrite.<locals>.connected(s3���#,� �F�F�D�
2�
#/�F�����*�*�+P�Qr[r�N�	r7�getConnectedClientAndServerrfrr9r;rHr<r=�rtr2r�r�s`   r\�test_writeSequeceWithoutWritez5WriteSequenceTestsMixin.test_writeSequeceWithoutWrite#sY���

	R��#�#�%���,�,�W�k�6�>�>�R��	�
�
�i� �	���S�W�W������ r[c�����fd�}�j�}�j|dtj�}|j	|�|jtj��j|�y)zo
        C{writeSequence} with an element in the sequence of type unicode raises
        C{TypeError}.
        c����|\}}}�jt|jjdg�}�j	t|�d�|jj
�y)NzUnicode is not kosherzData must be bytes)rj�	TypeErrorrKr�r�rr�)rrir�rl�excrts     �r\r2zWWriteSequenceTestsMixin.test_writeSequenceWithUnicodeRaisesException.<locals>.connected@s_���#,� �F�F�D��#�#��6�+�+�9�9�<S�;T��C�
���S��X�';�<����+�+�-r[r�Nrrs`   r\�,test_writeSequenceWithUnicodeRaisesExceptionzDWriteSequenceTestsMixin.test_writeSequenceWithUnicodeRaisesException:sX���		.��#�#�%���,�,�W�k�6�>�>�R��	�
�
�i� �	���S�W�W������ r[c�z���tt�Gd�d��}|����fd�}�j�}�j|dtj
�}|j
|�|jtj��j|��j�jddg�y)z{
        C{writeSequence} pauses its streaming producer if too much data is
        buffered, and then resumes it.
        c�,�eZdZdZdZd�Zd�Zd�Zd�Zy)�JWriteSequenceTestsMixin.test_streamingProducer.<locals>.SaveActionProducerNc��g|_yrY��actionsr�s r\ruzSWriteSequenceTestsMixin.test_streamingProducer.<locals>.SaveActionProducer.__init__\�	��!��r[c�:�|jjd�y)N�pause�r'r}r�s r\r�zYWriteSequenceTestsMixin.test_streamingProducer.<locals>.SaveActionProducer.pauseProducing_s�����#�#�G�,r[c���|jjd�|jjj	�|j
jj
�y)Nr�)r'r}rirK�unregisterProducerr�r�r�s r\r�zZWriteSequenceTestsMixin.test_streamingProducer.<locals>.SaveActionProducer.resumeProducingbsB�����#�#�H�-����%�%�8�8�:�
���%�%�4�4�6r[c�:�|jjd�y�Nr5r+r�s r\�
stopProducingzXWriteSequenceTestsMixin.test_streamingProducer.<locals>.SaveActionProducer.stopProducingl������#�#�F�+r[)	r�r�r�rir�rur�r�r0rZr[r\�SaveActionProducerr$Ws ���F��F�
"�
-�
7�
,r[r2c�R��|dd\}}|�_|�_|jj�d��j	�j
g��j
|jd�|jjdgdz��j	�j
dg�y)NrDT���2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx�r*)rir�rK�registerProducerr�r'rr�)rrir��producerrts   ��r\r2zAWriteSequenceTestsMixin.test_streamingProducer.<locals>.connectedqs����&�r��]�N�F�F�$�H�O�$�H�O�
���-�-�h��=����X�-�-�r�2��#�#�F�$4�$4�c�:����*�*�I�;��+;�<����X�-�-��y�9r[r�r*r�N)
rr(r7rrfrr9r;rHr<r=r�r')rtr2r2r�r�r8s`    @r\�test_streamingProducerz.WriteSequenceTestsMixin.test_streamingProducerQs����
�]�	#�	,�	,�
$�	,�.&�'��
	:��#�#�%���,�,�W�k�6�>�>�R��	�
�
�i� �	���S�W�W������ �	
����)�)�G�X�+>�?r[c�������tt�G�fd�d��}|����fd�}�j�}�j|dtj
�}|j
|�|jtj��j|��j�jddg�y)z�
        C{writeSequence} pauses its producer if too much data is buffered only
        if this is a streaming producer.
        c�(��eZdZdZd�Z�fd�Zd�Zy)�MWriteSequenceTestsMixin.test_nonStreamingProducer.<locals>.SaveActionProducerNc��g|_yrYr&r�s r\ruzVWriteSequenceTestsMixin.test_nonStreamingProducer.<locals>.SaveActionProducer.__init__�r(r[c�`��|jjd�|jjd�dk(r%|jjj�y�j
|jjd�|jjjdgdz�y)Nr�rDr4r5r6)r'r}r�rirK�
stopConsumingrr�)rtr�s �r\r�z]WriteSequenceTestsMixin.test_nonStreamingProducer.<locals>.SaveActionProducer.resumeProducing�s{������#�#�H�-��<�<�%�%�h�/�1�4��K�K�)�)�7�7�9��+�+�D�K�K�,A�,A�3�G��K�K�)�)�7�7���b�8H�Ir[c�:�|jjd�yr/r+r�s r\r0z[WriteSequenceTestsMixin.test_nonStreamingProducer.<locals>.SaveActionProducer.stopProducing�r1r[)r�r�r�rirur�r0)r�s�r\r2r<�s����F�
"�
J�
,r[r2c���|d}|�_|jj�d��j�jdg�y)NrFr�)rirKr7r�r')rrir8rts  ��r\r2zDWriteSequenceTestsMixin.test_nonStreamingProducer.<locals>.connected�sC����q�\�F�$�H�O�
���-�-�h��>����X�-�-��z�:r[r�r�N)
rr'r7rrfrr9r;rHr<r=r�r')rtr2r2r�r�r8r�s`    @@r\�test_nonStreamingProducerz1WriteSequenceTestsMixin.test_nonStreamingProducer�s����
��	�]�	#�	,�	,�
$�	,�"&�'��	;��#�#�%���,�,�W�k�6�>�>�R��	�
�
�i� �	���S�W�W������ �	
����)�)�H�h�+?�@r[N)r�r�r�r�r+r{r	r
rr
r�rrr!r9rBrZr[r\rrsB���@K�n����$�y�/�!:�;�L�)�!�.!�.3@�j*Ar[rc�@�eZdZdZd�Zd�Zd�Zeee	�d��Z
y)�"TCPTransportServerAddressTestMixinzE
    Test mixing for TCP server address building and log prefix.
    c��t��)z�
        Helper method returnine a L{Deferred} firing with a tuple of a client
        protocol, a server protocol, and a running TCP port.
        )�NotImplementedError)rtr�r�r�s    r\rz>TCPTransportServerAddressTestMixin.getConnectedClientAndServer�s
��
"�#�#r[c���������fd�}�j�}�j|�|�}|j|�|jtj
��j
|�y)zT
        Helper method to test TCP server addresses on either IPv4 or IPv6.
        c�z��|\}}}	�jd|jj�d|j�j�d�t|j���jd|jj�d���|jj�|jj\}�j|���jd|j��j�|j�|jj�y#|jj�wxYw)Nz<AccumulatingProtocol #z on �>zAccumulatingProtocol,�,rW)
r�rK�	sessionnorrlr�logstrr�
peerAddressesrlr�rkr�)rrir�rlr��adressClassr�rts     ���r\r2zHTCPTransportServerAddressTestMixin._testServerAddress.<locals>.connected�s����#,� �F�F�D�
2�� � ��'�'�1�1�4�<�<�>�3F�3F�H���(�(�)��� � ��'�'�1�1�9�>��$�$�+�+��!'��� <� <�
���%�%�k�;�?�� � ���(8�(8�9�� � ��K�,<�,<�=�� � �/�/�1��� � �/�/�1�s�C:D�D:N)r7rr9r;rHr<r=)rtr�r�rNr2r�r�s`` `   r\�_testServerAddressz5TCPTransportServerAddressTestMixin._testServerAddress�sT���
	2�.�#�#�%���,�,�W�i��O��	�
�
�i� �	���S�W�W������ r[c�L�|jdtjt�S)z�
        L{Server} instances have a string representation indicating on which
        port they're running, and the connected address is stored on the
        C{peerAddresses} attribute of the factory.
        r�)rOrfrrr�s r\�test_serverAddressTCP4z9TCPTransportServerAddressTestMixin.test_serverAddressTCP4�s���&�&�{�F�N�N�K�P�Pr[c�\�|jt�tjt�S)z�
        IPv6 L{Server} instances have a string representation indicating on
        which port they're running, and the connected address is stored on the
        C{peerAddresses} attribute of the factory.
        )rOrarfr�rr�s r\�test_serverAddressTCP6z9TCPTransportServerAddressTestMixin.test_serverAddressTCP6�s%���&�&�#�%�v����
�	
r[N)r�r�r�r�rrOrQrr�r�rSrZr[r\rDrD�s3���$� !�DQ��H�n�%�
�&�
r[rDc��eZdZdZd�Zy)�TCPTransportTestsBuilderzT
    Test standard L{ITCPTransport}s built with C{listenTCP} and C{connectTCP}.
    c���
��t�}t�|_t�|_t	�}t�|_t�|_�jd||���t
|j|jg�}�fd�}|j|�t
|j|jg�}t��
�
�fd�}	|j|	��j|�j�j|��
S)z�
        Return a L{Deferred} firing with a L{MyClientFactory} and
        L{MyServerFactory} connected pair, and the listening C{Port}.
        rr�c�(���j�|SrYr4�r�r�s �r\r5zBTCPTransportTestsBuilder.getConnectedClientAndServer.<locals>.stop	s����L�L�N��Mr[c���|\}}tjd|z�tjd|z��j||�f�y�Nzclient connected %szserver connected %s�rHrRr��rrir�rrls   ��r\�startzCTCPTransportTestsBuilder.getConnectedClientAndServer.<locals>.start	�E���&�N�F�F��G�G�)�F�2�3��G�G�)�F�2�3����v�v�t�4�5r[)rNrrr8rMrrrur9rrrl)rtr�r�r�r�ri�lostDeferredr5�
startDeferredr]rrls `        @@r\rz4TCPTransportTestsBuilder.getConnectedClientAndServer�s����
!�"��(0�
��%�(0�
��%� �"��(0�
��%�(0�
��%�� � ��F�i� �@��$�
�
*�
*�F�,I�,I�J�
��	�	���T�"�%�
�
*�
*�F�,I�,I�J�
�
��:��	6�	�!�!�%�(����9�d�l�l�n�&9�&9�6�B��r[N)r�r�r�r�rrZr[r\rUrU�s���)r[rUc��eZdZdZeefZd�Zy)�!AdoptStreamConnectionTestsBuilderzF
    Test server transports built using C{adoptStreamConnection}.
    c������
�t�}t�|_t��
t��
_t��
_t	�}t�|_t�|_�jd||������
fd�}|jj
|�t|j�
jg�}�fd�}|j|�t���j|�t|j�
jg�}	��fd�}
|	j
|
��j|�j�j|��S)a0
        Return a L{Deferred} firing with a L{MyClientFactory} and
        L{MyServerFactory} connected pair, and the listening C{Port}. The
        particularity is that the server protocol has been obtained after doing
        a C{adoptStreamConnection} against the original server connection.
        rr�c�����j|j��j|j��j|jj	����yrY)r�rKr��adoptStreamConnectionr�)r,r�r�r�s ���r\�firtServerConnectedzZAdoptStreamConnectionTestsBuilder.getConnectedClientAndServer.<locals>.firtServerConnectedE	sI���� � ����1�� � ����1��)�)����&�&�(�-��
r[c�@���jr�j�|SrY)r3r5rXs �r\r5zKAdoptStreamConnectionTestsBuilder.getConnectedClientAndServer.<locals>.stopR	s�����������Mr[c���|\}}tjd|z�tjd|z��j||�f�yrZr[r\s   ��r\r]zLAdoptStreamConnectionTestsBuilder.getConnectedClientAndServer.<locals>.start`	r^r[)
rNrrr8rMrr9rrur;rrrl)rtr�r�r��firstServerrirfr_r5r`r]rrlr�s ` `       @@@r\rz=AdoptStreamConnectionTestsBuilder.getConnectedClientAndServer1	s ���&�'��-5�Z��*� �"��(0�
��%�(0�
��%� �"��(0�
��%�(0�
��%�� � ��K�9� �E��	�	�*�*�6�6�7J�K�$�
�
*�
*�F�,I�,I�J�
��	�
	���T�"��:�����D�!�%�
�
*�
*�F�,I�,I�J�
�
�	6�	�!�!�%�(����9�d�l�l�n�&9�&9�6�B��r[N)r�r�r�r�r)r*r{rrZr[r\rbrb(	s���(��8��8r[rbc��eZdZdZd�Zy)�ServerAbortsTwicez'
    Call abortConnection() twice.
    c�l�|jj�|jj�yrY)rK�abortConnectionrss  r\r�zServerAbortsTwice.dataReceived|	s"�����&�&�(����&�&�(r[Nr�rZr[r\rkrkw	����)r[rkc��eZdZdZd�Zy)�ServerAbortsThenLosesz>
    Call abortConnection() followed by loseConnection().
    c�l�|jj�|jj�yrY)rKrmr�rss  r\r�z"ServerAbortsThenLoses.dataReceived�	s"�����&�&�(����%�%�'r[Nr�rZr[r\rprp�	����(r[rpc��eZdZdZd�Zy)�AbortServerWritingProtocolz4
    Protocol that writes data upon connection.
    c�:�|jjd�y)zW
        Tell the client that the connection is set up and it's time to abort.
        sreadyN�rKr�r�s r\r�z)AbortServerWritingProtocol.connectionMade�	s��	
�����X�&r[N�r�r�r�r�r�rZr[r\rtrt�	s���'r[rtc��eZdZdZd�Zy)�ReadAbortServerProtocolz�
    Server that should never receive any data, except 'X's which are written
    by the other side of the connection before abortConnection, and so might
    possibly arrive.
    c�>�|jdd�rtd��y)N�Xr[zUnexpectedly received data.)�replacer�rss  r\r�z$ReadAbortServerProtocol.dataReceived�	s!���<�<��c�"��9�:�:�#r[Nr�rZr[r\ryry�	s���;r[ryc��eZdZdZd�Zy)�NoReadServerz�
    Stop reading immediately on connection.

    This simulates a lost connection that will cause the other side to time
    out, and therefore call abortConnection().
    c�8�|jj�yrY)rK�stopReadingr�s r\r�zNoReadServer.connectionMade�	s�����"�"�$r[NrwrZr[r\r~r~�	s���%r[r~c�0�eZdZdZdZdZd�Zd�Zd�Zd�Z	y)�EventualNoReadServerz�
    Like NoReadServer, except we Wait until some bytes have been delivered
    before stopping reading. This means TLS handshake has finished, where
    applicable.
    Fc��|js?d|_|jj|d�|jjd�yy)NTF�hello)�gotDatarKr7r�rss  r\r�z!EventualNoReadServer.dataReceived�	s;���|�|��D�L��N�N�+�+�D�%�8��N�N� � ��*�r[c�`�|jryd|_|jj�y�NT)�stoppedReadingrKr�r�s r\r�z$EventualNoReadServer.resumeProducing�	s&������"������"�"�$r[c��yrYrZr�s r\r�z#EventualNoReadServer.pauseProducing�	���r[c��yrYrZr�s r\r0z"EventualNoReadServer.stopProducing�	r�r[N)
r�r�r�r�r�r�r�r�r�r0rZr[r\r�r��	s'����G��N�+�%�
�
r[r�c��eZdZdZdZd�Zy)�BaseAbortingClientz/
    Base class for abort-testing clients.
    Fc�^�|jrtd��tj||�y)Nz,BUG: connectionLost was called re-entrantly!)�inReactorMethod�RuntimeErrorr:r�r�s  r\r�z!BaseAbortingClient.connectionLost�	s'������M�N�N��*�*�4��8r[N)r�r�r�r�r�r�rZr[r\r�r��	s����O�9r[r�c��eZdZdZd�Zy)�WritingButNotAbortingClientz&
    Write data, but don't abort.
    c�:�|jjd�y)Nr�rvr�s r\r�z*WritingButNotAbortingClient.connectionMade�	s�������X�&r[NrwrZr[r\r�r��	s���'r[r�c��eZdZdZd�Zd�Zy)�AbortingClientz9
    Call abortConnection() after writing some data.
    c�@�d|_|j�d|_y)zF
        Some data was received, so the connection is set up.
        TFN)r��
writeAndAbortrss  r\r�zAbortingClient.dataReceived�	s �� $�������$��r[c��|jjddz�|jj�|jjddz�y)Nr{i'�Y)rKr�rmr�s r\r�zAbortingClient.writeAndAbort�	s@��	
�����T�E�\�*����&�&�(������T�E�\�*r[N)r�r�r�r�r�r�rZr[r\r�r��	s���%�+r[r�c��eZdZdZd�Zy)�AbortingTwiceClientz@
    Call abortConnection() twice, after writing some data.
    c�b�tj|�|jj�yrY)r�r�rKrmr�s r\r�z!AbortingTwiceClient.writeAndAbort�	s ���$�$�T�*����&�&�(r[N�r�r�r�r�r�rZr[r\r�r��	rnr[r�c��eZdZdZd�Zy)�AbortingThenLosingClientz;
    Call abortConnection() and then loseConnection().
    c�b�tj|�|jj�yrY)r�r�rKr�r�s r\r�z&AbortingThenLosingClient.writeAndAbort
s ���$�$�T�*����%�%�'r[Nr�rZr[r\r�r�
rrr[r�c�6�eZdZdZdZdZd�Zd�Zd�Zd�Z	d�Z
y	)
�ProducerAbortingClientzA
    Call abortConnection from doWrite, via resumeProducing.
    TFc��|jjddz�d|_|jj|d�d|_y)Nslalalai�TF)rKr��inRegisterProducerr7r�s r\r�zProducerAbortingClient.write
s=�������Y��/�0�"&������'�'��e�4�"'��r[c�$�|j�yrY�r�r�s r\r�z%ProducerAbortingClient.connectionMade
����
�
�r[c�l�d|_|js|jj�d|_y)NTF)r�r�rKrmr�s r\r�z&ProducerAbortingClient.resumeProducing
s+��#����&�&��N�N�*�*�,�$��r[c��d|_yr�)�producerStoppedr�s r\r0z$ProducerAbortingClient.stopProducing$
s
��#��r[c��|jstd��|jrtd��tj||�y)Nz&BUG: stopProducing() was never called.z(BUG: connectionLost called re-entrantly!)r�r�r�r:r�r�s  r\r�z%ProducerAbortingClient.connectionLost'
s<���#�#��G�H�H�����I�J�J��*�*�4��8r[N)r�r�r�r�r�r�r�r�r�r0r�rZr[r\r�r�
s,����O��O�(��%�$�9r[r�c�F�eZdZdZdZdZdZd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
y)�StreamingProducerClienta�
    Call abortConnection() when the other side has stopped reading.

    In particular, we want to call abortConnection() only once our local
    socket hits a state where it is no longer writeable. This helps emulate
    the most common use case for abortConnection(), closing a connection after
    a timeout, with write buffers being full.

    Since it's very difficult to know when this actually happens, we just
    write a lot of data, and assume at that point no more writes will happen.
    Frc�$�|j�yrYr�r�s r\r�z&StreamingProducerClient.connectionMade@
r�r[c��|jj|d�td�D] }|jjddz��"y)zh
        Write large amount to transport, then wait for a while for buffers to
        fill up.
        T�ds
1234567890i}N)rKr7�ranger�)rt�is  r\r�zStreamingProducerClient.writeC
sB��
	
���'�'��d�3��s��	8�A��N�N� � ���!6�7�	8r[c��d|_y)NF)r�r�s r\r�z'StreamingProducerClient.resumeProducingL
s	����r[c��yrYrZr�s r\r0z%StreamingProducerClient.stopProducingO
r�r[c�x�|jryd|_|jjd|j�y)a&
        Called when local buffer fills up.

        The goal is to hit the point where the local file descriptor is not
        writeable (or the moral equivalent). The fact that pauseProducing has
        been called is not sufficient, since that can happen when Twisted's
        buffers fill up but OS hasn't gotten any writes yet. We want to be as
        close as possible to every buffer (including OS buffers) being full.

        So, we wait a bit more after this for Twisted to write out a few
        chunks, then abortConnection.
        NTg{�G�z�?)r�r�r�doAbortr�s r\r�z&StreamingProducerClient.pauseProducingR
s/���;�;�����	
�����t�T�\�\�2r[c��|jstjtd��d|_|j
j
�d|_y)Nz&BUG: We should be paused a this point.TF)r�rHr<r�r�rKrmr�s r\r�zStreamingProducerClient.doAbortg
s;���{�{��G�G�L�!I�J�K�#������&�&�(�$��r[c�x�|jjj�tj||�yrY)�
otherProtocolrK�startReadingr:r�r�s  r\r�z&StreamingProducerClient.connectionLostn
s*�����$�$�1�1�3��*�*�4��8r[N)r�r�r�r�r��extraWritesr�r�r�r�r0r�r�r�rZr[r\r�r�/
s;��
��F��K��O��8��
�3�*%�9r[r�c��eZdZdZd�Zd�Zy)�StreamingProducerClientLaterzX
    Call abortConnection() from dataReceived, after bytes have been
    exchanged.
    c�H�|jjd�d|_y)Nr�F)rKr�r�r�s r\r�z+StreamingProducerClientLater.connectionMadez
s�������X�&���r[c�L�|jsd|_|j�yyr�)r�r�rss  r\r�z)StreamingProducerClientLater.dataReceived~
s���|�|��D�L��J�J�L�r[N�r�r�r�r�r�r�rZr[r\r�r�t
s���
�r[r�c��eZdZdZd�Zd�Zy)�ProducerAbortingClientLaterz�
    Call abortConnection from doWrite, via resumeProducing.

    Try to do so after some bytes have already been exchanged, so we
    don't interrupt SSL handshake.
    c��yrYrZr�s r\r�z*ProducerAbortingClientLater.connectionMade�
s��r[c�$�|j�yrYr�rss  r\r�z(ProducerAbortingClientLater.dataReceived�
r�r[Nr�rZr[r\r�r��
s���
�r[r�c��eZdZdZd�Zy)�DataReceivedRaisingClientzN
    Call abortConnection(), and then throw exception, from dataReceived.
    c�L�|jj�td��)N�ONO)rKrm�ZeroDivisionErrorrss  r\r�z&DataReceivedRaisingClient.dataReceived�
s�����&�&�(���&�&r[Nr�rZr[r\r�r��
s���'r[r�c��eZdZdZd�Zd�Zy)�ResumeThrowsClientzL
    Call abortConnection() and throw exception from resumeProducing().
    c�f�|js%|jj�td��y)Nzono!)r�rKrmr�r�s r\r�z"ResumeThrowsClient.resumeProducing�
s+���&�&��N�N�*�*�,�#�F�+�+�'r[c�0�tj||�yrY)r:r�r�s  r\r�z!ResumeThrowsClient.connectionLost�
s��	�*�*�4��8r[N)r�r�r�r�r�r�rZr[r\r�r��
s���,�
9r[r�c��eZdZUdZdZeeed<dd�Zd�Z	d�Z
d�Zd�Zd	�Z
eej j#d
d�j%�dk(xrej(�d
�d��Zeej j#d
d�j%�dk(xrej(�d
�d��Zd�Zd�Zd�Zd�Zy)�AbortConnectionMixinz7
    Unit tests for L{ITransport.abortConnection}.
    Nrc�j�ttf}ttf}tr(|tj
fz}|tj
fz}|�}|�}||_||_t||||j�}|j|j�g�|j|j�g�|�+|j|jj|f|z�n&|j|jj|�|j|jj|�y)z�
        A test runner utility function, which hooks up a matched pair of client
        and server protocols.

        We then run the reactor until both sides have disconnected, and then
        verify that the right exception resulted.
        N)rrrr�rR�Errorr�rArr�r��getDelayedCallsrl�disconnectReasonr)	rt�clientClass�serverClass�clientConnectionLostReason�clientExpectedExceptions�serverExpectedExceptionsrir�r�s	         r\�runAbortTestz!AbortConnectionMixin.runAbortTest�
s��%6�~�#F� �$2�N�#C� ��'?�3�9�9�,�'N�$�'?�3�9�9�,�'N�$�������%���%���)�$������O��	
����*�*�,�b�1�����0�0�2�B�7�%�1��!�!��'�'�-�-�+�-�0H�H�
�

�!�!��'�'�-�-�/G�
�	
���f�5�5�;�;�=U�Vr[c�6�|jtt�S)z�
        abortConnection() is called in dataReceived. The protocol should be
        disconnected, but connectionLost should not be called re-entrantly.
        )r�r�ryr�s r\�test_dataReceivedAbortz+AbortConnectionMixin.test_dataReceivedAbort�
s��
� � ��1H�I�Ir[c�6�|jtt�S)z�
        abortConnection() is called twice by client.

        No exception should be thrown, and the connection will be closed.
        )r�r�ryr�s r\� test_clientAbortsConnectionTwicez5AbortConnectionMixin.test_clientAbortsConnectionTwice�
s��� � �!4�6M�N�Nr[c�6�|jtt�S)z�
        Client calls abortConnection(), followed by loseConnection().

        No exception should be thrown, and the connection will be closed.
        )r�r�ryr�s r\�.test_clientAbortsConnectionThenLosesConnectionzCAbortConnectionMixin.test_clientAbortsConnectionThenLosesConnection�
s��� � �!9�;R�S�Sr[c�B�|jttt��S)z�
        abortConnection() is called twice by server.

        No exception should be thrown, and the connection will be closed.
        �r�)r�r�rkrr�s r\� test_serverAbortsConnectionTwicez5AbortConnectionMixin.test_serverAbortsConnectionTwice�
s%��� � �'��'5�!�
�	
r[c�B�|jttt��S)z�
        Server calls abortConnection(), followed by loseConnection().

        No exception should be thrown, and the connection will be closed.
        r�)r�r�rprr�s r\�.test_serverAbortsConnectionThenLosesConnectionzCAbortConnectionMixin.test_serverAbortsConnectionThenLosesConnection�
s%��� � �'�!�'5�!�
�	
r[�CIrU�truezFlaky on macOS on Azure.c�8�|jtt�y)z�
        abortConnection() is called in resumeProducing, before any bytes have
        been exchanged. The protocol should be disconnected, but
        connectionLost should not be called re-entrantly.
        N)r�r�r:r�s r\�test_resumeProducingAbortz.AbortConnectionMixin.test_resumeProducingAbort
s��	
���0�2E�Fr[c�6�|jtt�S)z�
        abortConnection() is called in resumeProducing, after some
        bytes have been exchanged. The protocol should be disconnected.
        )r�r�rtr�s r\�test_resumeProducingAbortLaterz3AbortConnectionMixin.test_resumeProducingAbortLaters��� � �'�)C�
�	
r[c�8�|jtt�y)a{
        abortConnection() triggered by the write buffer being full.

        In particular, the server side stops reading. This is supposed
        to simulate a realistic timeout scenario where the client
        notices the server is no longer accepting data.

        The protocol should be disconnected, but connectionLost should not be
        called re-entrantly.
        N)r�r�r~r�s r\�test_fullWriteBufferz)AbortConnectionMixin.test_fullWriteBuffer(s��	
���1�<�@r[c�6�|jtt�S)z�
        abortConnection() is triggered by a write buffer being full.

        However, this buffer is filled after some bytes have been exchanged,
        allowing a TLS handshake if we're testing TLS. The connection will
        then be lost.
        )r�r�r�r�s r\�%test_fullWriteBufferAfterByteExchangez:AbortConnectionMixin.test_fullWriteBufferAfterByteExchange5s��� � �!=�?S�T�Tr[c��|jttt��|j	t�}|jt
|�d�y)aJ
        dataReceived calls abortConnection(), and then raises an exception.

        The connection will be lost, with the thrown exception
        (C{ZeroDivisionError}) as the reason on the client. The idea here is
        that bugs should not be masked by abortConnection, in particular
        unexpected exceptions.
        r�r�N)r�r�rtr��flushLoggedErrorsr�r~�rt�errorss  r\�test_dataReceivedThrowsz,AbortConnectionMixin.test_dataReceivedThrows?sG��	
���%�&�'8�	�	
�
�'�'�(9�:������V��a�(r[c��|jttt��|j	t�}|jt
|�d�y)aM
        resumeProducing calls abortConnection(), and then raises an exception.

        The connection will be lost, with the thrown exception
        (C{ZeroDivisionError}) as the reason on the client. The idea here is
        that bugs should not be masked by abortConnection, in particular
        unexpected exceptions.
        r�r�N)r�r�r:r�r�r�r~r�s  r\�test_resumeProducingThrowsz/AbortConnectionMixin.test_resumeProducingThrowsPsG��	
�����'8�	�	
�
�'�'�(9�:������V��a�(r[rY)r�r�r�r�rr	r<r�r�r�r�r�r�r�rr��environ�get�lowerrJ�isMacOSXr�r�r�r�r�r�rZr[r\r�r��
s����
,0�I�x��(�/�#W�JJ�O�T�

�

��
�
�
���t�R� �&�&�(�F�2�J�7H�x�7H�7H�7J�"��G�	�G��
�
�
���t�R� �&�&�(�F�2�J�7H�x�7H�7H�7J�"��
�	�
�A�U�)�")r[r�c�$�eZdZdZefZe�Zy)�AbortConnectionTestsz5
    TCP-specific L{AbortConnectionMixin} tests.
    N)r�r�r�r�r+r{r�rrZr[r\r�r�bs���&�����Ir[r�c�X�eZdZdZd�Zeej�d�d��Zd�Z	y)�SimpleUtilityTestszJ
    Simple, direct tests for helpers within L{twisted.internet.tcp}.
    c��|jtjtdd�}|j	|j
dtj�y)a
        L{_resolveIPv6} raises a L{socket.gaierror} (L{socket.EAI_NONAME}) when
        invoked with a non-numeric host.  (In other words, it is passing
        L{socket.AI_NUMERICHOST} to L{socket.getaddrinfo} and will not
        accidentally block if it receives bad input.)
        �	localhostr�rN�rjrf�gaierrorr8r�r��
EAI_NONAME�rtr<s  r\�test_resolveNumericHostz*SimpleUtilityTests.test_resolveNumericHostus<���������{�A�N��������!��f�&7�&7�8r[z@The AI_NUMERICSERV flag is not supported by Microsoft providers.c��|jtjtdd�}|j	|j
dtj�y)a
        L{_resolveIPv6} raises a L{socket.gaierror} (L{socket.EAI_NONAME}) when
        invoked with a non-numeric port.  (In other words, it is passing
        L{socket.AI_NUMERICSERV} to L{socket.getaddrinfo} and will not
        accidentally block if it receives bad input.)
        rT�httprNrrs  r\�test_resolveNumericServicez-SimpleUtilityTests.test_resolveNumericServices<���������u�f�M��������!��f�&7�&7�8r[c���tdd�}|jt|�d�|j|dt�|j|dt�|j|ddd�y)zb
        L{_resolveIPv6} discovers the flow info and scope ID of an IPv6
        address.
        rTrDrer�N)rTrD)r8r�r~rlrr�s  r\�test_resolveIPv6z#SimpleUtilityTests.test_resolveIPv6�sf��
�e�Q�'������V��a�(�
	
���f�Q�i��-����f�Q�i��-�	
�������Z�0r[N)
r�r�r�r�rrrJr�rr	rZr[r\r�r�os;���9�������J��
9��
9�1r[r�c�(�eZdZdZd�Zd�Zd�Zd�Zy)�BuffersLogsTestsz$
    Tests for L{_BuffersLogs}.
    c�~�d|_g|_t|j|jj�|_y)Nz
name.space)�	namespacer�r4r}�	logBufferr�s r\r�zBuffersLogsTests.setUp�s,��%������%�d�n�n�d�k�k�6H�6H�I��r[c��|j5}|jd�|j|j�ddd�y#1swYyxYw)zj
        The context manager's logger does not log to provided observer
        inside the block.
        �An eventN)rr�r�r�)rt�loggers  r\�test_buffersInBlockz$BuffersLogsTests.test_buffersInBlock�s@��
�^�^�	*�v��K�K�
�#����T�[�[�)�	*�	*�	*�s�-A�Ac�l�|j5}|jd�|j|j�ddd�|j	dt|j��|j\}|j	|dd�|j	|d|j�y#1swY�qxYw)zw
        The context manager flushes its buffered logs when the block
        terminates without an exception.
        rNr��
log_format�
log_namespace)rr�r�r�r�r~r
)rtr�events   r\�test_flushesOnExitz#BuffersLogsTests.test_flushesOnExit�s���
�^�^�	*�v��K�K�
�#����T�[�[�)�	*�	
����C����,�-��+�+�������|�,�j�9������/����@�
	*�	*�s�-B*�*B3c���Gd�dt�}|j|�5|j5}|jd�|j	|j
�|��#1swYnxYw	ddd�n#1swYnxYw|j
dt|j
��|j
\}|j
|dd�|j
|d|j�y)zz
        The context manager flushes its buffered logs when the block
        terminates because of an exception.
        c��eZdZdZy)�GBuffersLogsTests.test_flushesOnExitWithException.<locals>.TestExceptionz@
            An exception only raised by this test.
            N�r�r�r�r�rZr[r\�
TestExceptionr����
r[rrNr�rr)	r�rjrr�r�r�r�r~r
)rtrrrs    r\�test_flushesOnExitWithExceptionz0BuffersLogsTests.test_flushesOnExitWithException�s���	�I�	�
�
�
�}�
-�	&����
&�6����J�'�� � ����-�#�o�%�
&�
&��
&�	&�	&�	&��	
����C����,�-��+�+�������|�,�j�9������/����@s�
A8�4A"�"A+	�'A8�8BN)r�r�r�r�r�rrrrZr[r\rr�s���J�
*�A�Ar[rc�L�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
�FileDescriptorReservationTestsz2
    Tests for L{_FileDescriptorReservation}.
    c�h��g�_�j��_�fd�}t|��_y)Nc����jjt�jd���jdS)N�wrV)�reservedFileObjectsr}r��tempfiler�s�r\�fakeFileFactoryz=FileDescriptorReservationTests.setUp.<locals>.fakeFileFactory�s3����$�$�+�+�D�����,D�E��+�+�B�/�/r[)r$�mktempr%r5�
reservedFD)rtr&s` r\r�z$FileDescriptorReservationTests.setUp�s+���#%�� ����
��
�	0�5�_�E��r[c�8�tt|j�y)zi
        L{_FileDescriptorReservation} instances provide
        L{_IFileDescriptorReservation}.
        N)rr6r(r�s r\r�z5FileDescriptorReservationTests.test_providesInterface�s��
	�0�$�/�/�Br[c�<�|jt|j�d�td�D]i}|jj�|jt|j�d�|j
|jdj��ky)zh
        Multiple acquisitions without releases open the reservation
        file exactly once.
        rr�r�N)r�r~r$r�r(�reserver�r�)rtr�s  r\�test_reserveOpensFileOncez8FileDescriptorReservationTests.test_reserveOpensFileOnce�s~��
	
����T�5�5�6��:��r��	A�A��O�O�#�#�%����S��!9�!9�:�A�>����T�5�5�a�8�?�?�@�	Ar[c��t�}|j|j�|j�|j	|j
j
��|j
j�|j	|j
j
��|jtt�}|jt|�d�|j|djjtj�y)z�
        If reserving the file descriptor fails because of C{EMFILE},
        the exception is suppressed but logged and the reservation
        remains unavailable.
        r�rN)r�r�r�r�r�r(�	availabler+r�r�r�r�r~rr�r�)rtr�r�s   r\�test_reserveEMFILELoggedz7FileDescriptorReservationTests.test_reserveEMFILELogged�s���-�.�	����	�)�)�*�����������2�2�4�5������!�������2�2�4�5��'�'���9������V��a�(���������.�.����=r[c��tttfD].}|fd�}t|�}|j	||j
��0y)z�
        Any exception raised while opening the reserve file that is
        not an L{OSError} or L{IOError} whose errno is C{EMFILE} is
        allowed through to the caller.
        c�6�|tjdzd��)Nr�r�)r�r�)�
errorClasss r\�	failsWithzWFileDescriptorReservationTests.test_reserveRaisesNonEMFILEExceptions.<locals>.failsWiths�� �����!1�9�=�=r[N)r�r�rkr5rjr+)rtr2r3�	reserveFDs    r\�%test_reserveRaisesNonEMFILEExceptionszDFileDescriptorReservationTests.test_reserveRaisesNonEMFILEExceptionssF��#�G�Z�8�	=�J�&0�
>�3�9�=�I����j�)�*;�*;�<�	=r[c���|j|jj��|jj�|j	|jj��y)z]
        The reservation is available after the file descriptor is
        reserved.
        N)r�r(r.r+r�r�s r\�test_availablez-FileDescriptorReservationTests.test_availablesH��
	
������2�2�4�5������!�������1�1�3�4r[c��|jt�5|j5	ddd�ddd�y#1swY�xYw#1swYyxYw)zp
        A reservation without an open file used as a context manager
        raises a L{RuntimeError}.
        N)rjr�r(r�s r\�test_enterFailsWithoutFilez9FileDescriptorReservationTests.test_enterFailsWithoutFile$sK��
�
�
�|�
,�	=����
=�<�
=�	=�	=�
=�
=��	=�	=�s�
A�6�A�?	�A�Ac�p�|jj�|j|jj��|j5|j	|jj��ddd�|j|jj��y#1swY�3xYw)zq
        Entering a reservation closes its file for the duration of the
        context manager's block.
        N)r(r+r�r.r�r�s r\�!test_enterClosesFileExitOpensFilez@FileDescriptorReservationTests.test_enterClosesFileExitOpensFile-s}��
	
�����!�������1�1�3�4�
�_�_�	:����T�_�_�6�6�8�9�	:�������1�1�3�4�	:�	:�s�*B,�,B5c���Gd�dt�}|jj�|j|�5|j5|��#1swYnxYw	ddd�y#1swYyxYw)z�
        An exception raised within a reservation context manager's
        block does not prevent the file from being reopened.
        c��eZdZdZy)�SFileDescriptorReservationTests.test_exitOpensFileOnException.<locals>.TestExceptionz>
            An exception only used by this test.
            NrrZr[r\rr>>rr[rN)r�r(r+rj)rtrs  r\�test_exitOpensFileOnExceptionz<FileDescriptorReservationTests.test_exitOpensFileOnException8sg��	�I�	�
	
�����!�
�
�
�}�
-�	&����
&�#�o�%�
&�
&��
&�	&�	&�	&�s�
A&�A�A	�A&�&A/c����Gd�dt�}Gd�dt��dg���fd�}t|�}|j�|j|j	��|j|�5|5|��#1swYnxYw	ddd�n#1swYnxYw|j
��}|jt|�d�y)	z�
        An exception raised while re-opening the reserve file exiting
        a reservation's context manager block is suppressed but
        logged, allowing an exception raised within the block through.
        c��eZdZdZy)�`FileDescriptorReservationTests.test_exitSuppressesReservationException.<locals>.AllowedExceptionzA
            The exception allowed out of the block.
            NrrZr[r\�AllowedExceptionrBOrr[rCc��eZdZdZy)�cFileDescriptorReservationTests.test_exitSuppressesReservationException.<locals>.SuppressedExceptionzM
            An exception raised by the file descriptor factory.
            NrrZr[r\�SuppressedExceptionrETrr[rFFc�N���dr���d�d<tj�S)NrT)�io�BytesIO)rF�calleds��r\�+failsWithSuppressedExceptionAfterSecondOpenz{FileDescriptorReservationTests.test_exitSuppressesReservationException.<locals>.failsWithSuppressedExceptionAfterSecondOpen[s(����a�y�)�+�+� ��q�	��z�z�|�#r[Nr�)	r�r5r+r�r.rjr�r�r~)rtrCrKr(r�rFrJs     @@r\�'test_exitSuppressesReservationExceptionzFFileDescriptorReservationTests.test_exitSuppressesReservationExceptionHs����	�y�	�
	�)�	�
���	$�0�7�
�
�	�������
�,�,�.�/�
�
�
�/�
0�	)��
)�&�(�(�
)�
)��
)�	)�	)�	)���'�'�(;�<������V��a�(s�5B�8B�B		�B�BN)r�r�r�r�r�r�r,r/r5r7r9r;r?rLrZr[r\r r �s<���F�C�
A�>�$
=�5�=�	5�&� &)r[r c�(�eZdZdZd�Zd�Zd�Zd�Zy)�"NullFileDescriptorReservationTestsz6
    Tests for L{_NullFileDescriptorReservation}.
    c�"�t�|_yrY)r7�nullReservedFDr�s r\r�z(NullFileDescriptorReservationTests.setUpvs
��<�>��r[c�8�tt|j�y)zd
        L{_NullFileDescriptorReservation} provides
        L{_IFileDescriptorReservation}.
        N)rr6rPr�s r\r�z9NullFileDescriptorReservationTests.test_providesInterfaceys��
	�0�$�2E�2E�Fr[c�V�|j|jj��y)zG
        The null reserved file descriptor is never available.
        N�r�rPr.r�s r\r7z1NullFileDescriptorReservationTests.test_available�s!��	
����,�,�6�6�8�9r[c�<�|j|jj��|j5|j|jj��ddd�|j|jj��y#1swY�3xYw)zN
        The null reserved file descriptor is a null context manager.
        NrSr�s r\�test_contextManagerz6NullFileDescriptorReservationTests.test_contextManager�sy��	
����,�,�6�6�8�9�
�
 �
 �	>����T�0�0�:�:�<�=�	>�����,�,�6�6�8�9�	>�	>�s�*B�BN)r�r�r�r�r�r�r7rUrZr[r\rNrNqs���?�G�:�:r[rN)�r�r�r�rHr�rf�	functoolsr�typingrrrrr	r
r�unittestr�zope.interfacer
r�zope.interface.verifyrrr��twisted.internet.addressrr�twisted.internet.deferrrrrrr�twisted.internet.endpointsrr�twisted.internet.errorrrrrrr r!r"r#�twisted.internet.interfacesr$r%r&r'r(r)r*r+r,r-r.�twisted.internet.protocolr/r0r1�twisted.internet.tcpr2r3r4r5r6r7r8�&twisted.internet.test.connectionmixinsr9r:r;r<r=r>r?r@rA�#twisted.internet.test.reactormixinsrBrCrD�twisted.internet.testingrErF�twisted.loggerrG�twisted.pythonrH�twisted.python.failurerI�twisted.python.runtimerJ�twisted.test.test_tcprKrLrMrN�twisted.trial.unittestrOrPrQ�OpenSSLrR�twisted.internet.sslrSr��ImportError�sr�r}rbr�r�r�r�r�r��twisted.internet.testrV�win32GetLinkLocalIPv6Addressesr_rUrW�posixGetLinkLocalIPv6Addressesrarhror�r�r�r�r�r�rrrr~r�r�r�r�r�r�r�r�rrr6rWr[r`rgr�r�r�r�r�r�r�rrDrUrb�globals�update�makeTestCaseClassesrkrprtryr~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr rNrZr[r\�<module>rus����
�	�	�	�
��N�N�N��1�;��=���N�
�
�
�����M�L����
�
�
���
D�!��*�+���K�J���:�
�F������
�
�f�o�o�v�'9�'9�:�A��F�F�:��
�H��N��=��G�G�I��8����2� ,� K� K���K�P�6�%1�$O�$O�!��K�:�"�$9�9�x3�h�3�2
�8�
�
�]��)#�)#��)#�X�M�,�-�11�X�11�h-"��-"�`O��O�,3�*�3�$
�_��N�N��N�.MH��)=�?U�MH�`
�/�
���.�!�7�/�7�"�7�,p:�~�p:�f� 8����.�!�3� 8�3�"�3��"�	��:
�
&�'�����T��D*�D*��(�D*�N��P�Q�N6�#6�N6�R�N6�bY�x��P�Q�I/�$7�I/�R�I/�XA
� 0�A
�HM�M�B	E�.�	E�"F�.�"F�JGO�GO�T	�����		�	�����		�2�x�2�6!�H/�40�2aR��aR�H^A�^A�B?
�?
�D0�&�(?��0�fA�&�(?��A�H�	���'�;�;�=�>��	���'�;�;�=�>��	���$�8�8�:�;��	���&�:�:�<�=��	���*�>�>�@�A��	���*�>�>�@�A��	���*�>�>�@�A��	���)�=�=�?�@��	���2�F�F�H�I�)�+�)�(�/�(�	'�!4�	'�	;�8�	;�	%�&�	%�
�.�
�<
9�,�
9�'�"4�'�+�'�+�,)�.�)�(�~�(�9�0�9�DB9�1�B9�J
�#:�
� 
�"8�
� '��'�9�/�9�"p)�p)�f�>�+?���	���%�9�9�;�<���.�!�-1��-1�"�-1�`4A�*�4A�n��P�Q�V)�%8�V)�R�V)�r:�)<�:��]`��
�F����0��H�+�A�3�/�N��0��&�/�$.�!�/�s<�X"�8X0�Y
�"X-�,X-�0Y�5Y�Y�
Y�Y

Zerion Mini Shell 1.0