Current File : //proc/self/root/lib/python3/dist-packages/twisted/test/__pycache__/test_tcp.cpython-312.pyc
�

Ϫ�f��|�dZddlZddlZddlZddlmZddlmZmZddl	m
Z
ddlmZddl
Z
ddlmZmZmZmZmZddlmZdd	lmZmZdd
lmZddlmZddlmZdd
lm Z m!Z!ddl"m#Z#ddl$m%Z%m&Z&dcd�Z'Gd�dej4�Z(Gd�dejR�Z*Gd�d�Z+Gd�de+ejR�Z,Gd�de+ejZ�Z.Gd�de&�Z/Gd�de&�Z0Gd�d ejb�Z2Gd!�d"e.�Z3Gd#�d$e&�Z4Gd%�d&e&�Z5Gd'�d(ejZ�Z6Gd)�d*e&�Z7Gd+�d,ej4�Z8Gd-�d.ej4�Z9Gd/�d0ejZ�Z:Gd1�d2e&�Z;Gd3�d4ej4�Z<Gd5�d6ej4�Z=Gd7�d8ej4�Z>Gd9�d:e>�Z?Gd;�d<�Z@Gd=�d>e&e@�ZAGd?�d@ej��ZCGdA�dBej��ZEGdC�dDe&�ZFGdE�dFej4�ZGGdG�dHej4�ZHGdI�dJejZ�ZIGdK�dLej��ZJGdM�dNej��ZKGdO�dPe&�ZLee�GdQ�dRe��ZMGdS�dTejR�ZNGdU�dVe&�ZOGdW�dXe&�ZPGdY�dZe&�ZQGd[�d\e&�ZRGd]�d^e&�ZSGd_�d`e&�ZT	ddlUZUeUj�eUj��ddazZXeYeAdbeX�y#eZ$rYywxYw)dz.
Tests for implementations of L{IReactorTCP}.
�N��wraps)�Callable�Optional)�skipIf)�implementer)�defer�error�
interfaces�protocol�reactor)�IPv4Address)�IHalfCloseableProtocol�
IPullProducer)�Protocol)�AccumulatingProtocol)�policies)�err�msg)�platform)�SkipTest�TestCasec������ddlm}tj����fd�}|j	|���fd�}�j|��j
|�}|j�j��S)z�
    Poor excuse for an event notification helper.  This polls a condition and
    calls back a Deferred when it is seen to be true.

    Do not use this function.
    r)�taskc�<����}|r�j|�yy�N��callback)�res�d�	predicates ���7/usr/lib/python3/dist-packages/twisted/test/test_tcp.py�checkzloopUntil.<locals>.check*s����k���
�J�J�s�O��c�(���j�|Sr)�stop)�result�calls �r"r&zloopUntil.<locals>.stop1s����	�	���
r$)	�twisted.internetrr	�Deferred�LoopingCall�addCallback�start�
addErrback�errback)r!�intervalrr#r&�d2r(r s`     @@r"�	loopUntilr2sa���&�
����A��
���E�"�D���M�M�$��	
���H�	�B��M�M�!�)�)���Hr$c��eZdZd�Zd�Zy)�ClosingProtocolc�N�td�|jj�y)NzClosingProtocol.connectionMade�r�	transport�loseConnection��selfs r"�connectionMadezClosingProtocol.connectionMade<s���,�-����%�%�'r$c�X�td�|jtj�y)NzClosingProtocol.connectionLost)r�trapr
�ConnectionDone�r:�reasons  r"�connectionLostzClosingProtocol.connectionLost@s���,�-����E�(�(�)r$N��__name__�
__module__�__qualname__r;rA�r$r"r4r4;s��(�*r$r4c� �eZdZdZdZd�Zd�Zy)�ClosingFactoryz/
    Factory that closes port immediately.
    Nc�T�|jj�|_t�Sr)�port�
stopListening�
_cleanerUpperr4)r:�conns  r"�
buildProtocolzClosingFactory.buildProtocolLs ��!�Y�Y�4�4�6���� � r$c�f�|j�|jj�S|jS)zL
        Clean-up for tests to wait for the port to stop listening.
        )rLrJrKr9s r"�cleanUpzClosingFactory.cleanUpPs/�����%��9�9�*�*�,�,��!�!�!r$)rCrDrE�__doc__rLrNrPrFr$r"rHrHEs����M�!�"r$rHc�L�eZdZUdZeZdZdZdZe	e
gefed<dZ
d�Zd�Zy)�MyProtocolFactoryMixina
    Mixin for factories which create L{AccumulatingProtocol} instances.

    @type protocolFactory: no-argument callable
    @ivar protocolFactory: Factory for protocols - takes the place of the
        typical C{protocol} attribute of factories (but that name is used by
        this class for something else).

    @type protocolConnectionMade: L{None} or L{defer.Deferred}
    @ivar protocolConnectionMade: When an instance of L{AccumulatingProtocol}
        is connected, if this is not L{None}, the L{Deferred} will be called
        back with the protocol instance and the attribute set to L{None}.

    @type protocolConnectionLost: L{None} or L{defer.Deferred}
    @ivar protocolConnectionLost: When an instance of L{AccumulatingProtocol}
        is created, this will be set as its C{closedDeferred} attribute and
        then this attribute will be set to L{None} so the L{defer.Deferred} is
        not used by more than one protocol.

    @ivar protocol: The most recently created L{AccumulatingProtocol} instance
        which was returned from C{buildProtocol}.

    @type called: C{int}
    @ivar called: A counter which is incremented each time C{buildProtocol}
        is called.

    @ivar peerAddresses: A C{list} of the addresses passed to C{buildProtocol}.
    Nrrc��g|_yr)�
peerAddressesr9s r"�__init__zMyProtocolFactoryMixin.__init__~s
����r$c���|jj|�|xjdz
c_|j�}||_|j
|_d|_||_|S)zi
        Create a L{AccumulatingProtocol} and set it up to be able to perform
        callbacks.
        �N)rU�append�called�protocolFactory�factory�protocolConnectionLost�closedDeferredr�r:�addr�ps   r"rNz$MyProtocolFactoryMixin.buildProtocol�s]��
	
���!�!�$�'����q���� � �"����	��6�6���&*��#���
��r$)rCrDrErQrr[�protocolConnectionMader]rrrr�__annotations__rZrVrNrFr$r"rSrSYsA���:+�O�!��!��15�H�h�x��H��-�.�5�
�F� �r$rSc��eZdZdZy)�MyServerFactoryzI
    Server factory which creates L{AccumulatingProtocol} instances.
    N)rCrDrErQrFr$r"rere�s��r$rec�0�eZdZdZdZdZd�Zd�Zd�Zd�Z	y)�MyClientFactoryzI
    Client factory which creates L{AccumulatingProtocol} instances.
    rc��tj|�tj�|_tj�|_yr)rSrVr	r*�deferred�failDeferredr9s r"rVzMyClientFactory.__init__�s-���'�'��-����(��
�!�N�N�,��r$c�V�d|_||_|jjd�y�NrX)�failedr@rjr�r:�	connectorr@s   r"�clientConnectionFailedz&MyClientFactory.clientConnectionFailed�s$�����������"�"�4�(r$c�H�||_|jjd�yr)�
lostReasonrirrns   r"�clientConnectionLostz$MyClientFactory.clientConnectionLost�s�� ����
�
���t�$r$c��d|_yrl��stoppedr9s r"�stopFactoryzMyClientFactory.stopFactory�s	����r$N)
rCrDrErQrmrvrVrprsrwrFr$r"rgrg�s'����F��G�-�
)�
%�r$rgc�H�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�ListeningTestsc���t�}tjd|d��}|j|j�|jtjj|��y)zf
        L{IReactorTCP.listenTCP} returns an object which provides
        L{IListeningPort}.
        r�	127.0.0.1��	interfaceN)	rer
�	listenTCP�
addCleanuprK�
assertTruer�IListeningPort�
providedBy�r:�f�p1s   r"�test_listenzListeningTests.test_listen�sO��

���
�
�
�q�!�{�
;������(�(�)����
�1�1�<�<�R�@�Ar$c�����t��tjd�d��}|j�j���fd�}tj|j�}|j|�|S)a
        The L{IListeningPort} returned by L{IReactorTCP.listenTCP} can be
        stopped with its C{stopListening} method.  After the L{Deferred} it
        (optionally) returns has been called back, the port number can be bound
        to a new server.
        rr{r|c�T��tj��d��}|j�S)Nr{r|)r
r~rK)�ignoredrJr��ns  ��r"�cbStopListeningz9ListeningTests.testStopListening.<locals>.cbStopListening�s&����$�$�Q��[�A�D��%�%�'�'r$)	rer
r~�getHostrJr	�
maybeDeferredrKr,)r:rJr�r r�r�s    @@r"�testStopListeningz ListeningTests.testStopListening�s`���
���� � ��A��=���L�L�N����	(�

���� 2� 2�3��	�
�
�o�&��r$c�f�t�}tjd|d��}|j�S�Nrr{r|)rer
r~rKr�s   r"�testNumberedInterfacez$ListeningTests.testNumberedInterface�s-�����
�
�
�q�!�{�
;�����!�!r$c�T����t�}tjd|��t�j	�j
���j
t��j��dk(����fd�}tj�j�}|j|�S)Nr���c�^���jt��j��dk7�y)Nr�)�assertFalse�repr�find)�ignra�portNor:s ���r"�stoppedListeningz5ListeningTests.testPortRepr.<locals>.stoppedListening�s#������T�!�W�\�\�&�1�R�7�8r$)
rer
r~�strr�rJr�r�r�r	r�rKr,)r:r�r�r rar�s`   @@r"�testPortReprzListeningTests.testPortRepr�s~���������a��#���Q�Y�Y�[�%�%�&������a����f�-��3�4�	9�
������0���}�}�-�.�.r$c�����t�}tj�x}|_t	j
d|���j
�j�t�}tj�x}|_t	jd�j�j|�}�j
|j���fd�}tj||g�j|�S)z�
        Check that the repr string of the server transport get the good port
        number if the server listens on 0.
        rr{c���|\}}�j�j}�jt|j�d|�d��|jj�|jj�y)Nz<AccumulatingProtocol #0 on �>)r�rJ�assertEqualr�r7r8)r'�serverProto�clientProto�
portNumberrJr:s    ��r"r#z-ListeningTests.test_serverRepr.<locals>.check�sl���'-�$�K������,�,�J�����[�*�*�+�.�z�l�!�<�
�
�!�!�0�0�2��!�!�0�0�2r$)rer	r*rbr
r~rrKrg�
connectTCPr�rJ�
disconnect�
gatherResultsr,)r:�server�serverConnMade�client�clientConnMaderor#rJs`      @r"�test_serverReprzListeningTests.test_serverRepr�s����
!�"��9>���9I�I���6�� � ��F�+������*�*�+� �"��9>���9I�I���6��&�&�{�D�L�L�N�4G�4G��P�	����	�,�,�-�	3��"�"�N�N�#C�D�P�P�QV�W�Wr$c������t��tjd�d����j�j�����fd�}d��tj�j�}|j|�|S)z�
        Stop and then try to restart a L{tcp.Port}: after a restart, the
        server should be able to handle client connections.
        rr{r|c����j�t�}tj��_tj�|_tjd�j�j|�}�j|j�tj�j|jg�j��S�Nr{)
�startListeningrgr	r*rbr
r�r�rJrr�r�r,�r�r�ro�closerJr:�
serverFactorys   ����r"r�z=ListeningTests.test_restartListening.<locals>.cbStopListenings�������!�$�&�F�38�>�>�3C�M�0�,1�N�N�,<�F�)��*�*�;�����8K�8K�V�T�I��O�O�I�0�0�1��&�&��5�5�v�7T�7T�U���k�%� �
!r$c�v�|\}}|jj�|jj�yr�r7r8�r'r�r�s   r"r�z3ListeningTests.test_restartListening.<locals>.close�0��'-�$�K���!�!�0�0�2��!�!�0�0�2r$)rer
r~rrKr	r�r,)r:r�r r�rJr�s`  @@@r"�test_restartListeningz$ListeningTests.test_restartListening�sf���
(�)�
�� � ��M�[�I������*�*�+�
	!�	3�

���� 2� 2�3��	�
�
�o�&��r$c��t�}d�}||_tjd|d��}|j	|j�t�S)z�
        If the server factory raises an exception in C{stopFactory}, the
        deferred returned by L{tcp.Port.stopListening} should fail with the
        corresponding error.
        c��td���NzAn error��RuntimeErrorrFr$r"�raiseExceptionz8ListeningTests.test_exceptInStop.<locals>.raiseException"�
���z�*�*r$rr{r|)rerwr
r~�
assertFailurerKr��r:r�r�rJs    r"�test_exceptInStopz ListeningTests.test_exceptInStopsK��(�)�
�	+�%3�
�!�� � ��M�[�I���!�!�$�"4�"4�"6��E�Er$c������t��d�}|�_tjd�d����j	�j
�����fd�}d���j
�j�t�j|�S)z�
        Even if the server factory raise an exception in C{stopFactory}, the
        corresponding C{tcp.Port} instance should be in a sane state and can
        be restarted.
        c��td��r�r�rFr$r"r�z>ListeningTests.test_restartAfterExcept.<locals>.raiseException2r�r$rr{r|c����`�j�t�}tj��_tj�|_t
jd�j�j|�}�j|j�tj�j
|j
g�j��Sr�)rwr�rgr	r*rbr
r�r�rJrr�r�r,r�s   ����r"r�z?ListeningTests.test_restartAfterExcept.<locals>.cbStopListening9s�����)����!�$�&�F�38�>�>�3C�M�0�,1�N�N�,<�F�)��*�*�;�����8K�8K�V�T�I��O�O�I�0�0�1��&�&��5�5�v�7T�7T�U���k�%� �
!r$c�v�|\}}|jj�|jj�yrr�r�s   r"r�z5ListeningTests.test_restartAfterExcept.<locals>.closeFr�r$)	rerwr
r~rrKr�r�r,)r:r�r�r�rJr�s`  @@@r"�test_restartAfterExceptz&ListeningTests.test_restartAfterExcept*sz���(�)�
�	+�%3�
�!�� � ��M�[�I������*�*�+�	!�	3�
�!�!�$�"4�"4�"6��E�Q�Q��
�	
r$c���t�}tjd|d��}|j�j}|jd�t
��tj�|_	tj��_	tjd|���fd�}�jj|�S)z�
        If C{connectionLost} is called directly on a port object, it succeeds
        (and doesn't expect the presence of a C{deferred} attribute).

        C{connectionLost} is called by L{reactor.disconnectAll} at shutdown.
        rr{r|Nc�X���jjtj�yr�r@r=r
�ConnectionRefusedError)r�r�s �r"r#z;ListeningTests.test_directConnectionLostCall.<locals>.check`s����M�M���u�;�;�<r$)
rer
r~r�rJrArgr	r*rbr�rjr,)r:r�rJr�r#r�s     @r"�test_directConnectionLostCallz,ListeningTests.test_directConnectionLostCallOs����(�)�
�� � ��M�[�I���\�\�^�(�(�
����D�!� �"��/4�~�~�/?�
�,�(-���(8��%����;�
�F�;�	=��"�"�.�.�u�5�5r$c��t�}d�}||_tjd|d��}|j	t
|jd�y)a
        If C{connectionLost} is called directory on a port object and that the
        server factory raises an exception in C{stopFactory}, the exception is
        passed through to the caller.

        C{connectionLost} is called by L{reactor.disconnectAll} at shutdown.
        c��td��r�r�rFr$r"r�zFListeningTests.test_exceptInConnectionLostCall.<locals>.raiseExceptionor�r$rr{r|N)rerwr
r~�assertRaisesr�rAr�s    r"�test_exceptInConnectionLostCallz.ListeningTests.test_exceptInConnectionLostCallesG��(�)�
�	+�%3�
�!�� � ��M�[�I�����,��(;�(;�T�Br$N)
rCrDrEr�r�r�r�r�r�r�r�r�r�rFr$r"ryry�s9��B��("�
/�X�6�<F� #
�J6�,Cr$ryc�F�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�
LoopbackTestsz$
    Test loopback connections.
    c�J����t�}tjd|d����|_�j	|j
��j
�j}t��tjd|�����fd�}�jj|�S)zz
        A port created with L{IReactorTCP.listenTCP} can be connected to with
        L{IReactorTCP.connectTCP}.
        rr{r|c�����j�jj��j�j��jjtj�yr)r�r�made�disconnectedrrr=r
r>)�x�clientFrJr:s ���r"r#z<LoopbackTests.test_closePortInProtocolFactory.<locals>.check�sG����O�O�G�,�,�1�1�2��O�O�D�-�-�.����#�#�E�$8�$8�9r$)rHr
r~rJrrPr�rgr�rir,)r:r�r�r#r�rJs`   @@r"�test_closePortInProtocolFactoryz-LoopbackTests.test_closePortInProtocolFactory|s����

���� � ��A��=���������	�	�"��\�\�^�(�(�
�!�#�����;�
�G�<�	:�
���+�+�E�2�2r$c�H�t|dd��tj�y)Nr=c��yrrF)r�s r"�<lambda>z,LoopbackTests._trapCnxDone.<locals>.<lambda>�s�r$)�getattrr
r>)r:�objs  r"�_trapCnxDonezLoopbackTests._trapCnxDone�s��,���V�^�,�U�-A�-A�Br$c���t�}tj�}||_t	j
d|d��}|j
|j�|j�j}t�}tj�}||_t	jd||�tj||g�}�fd�}	|j|	�|S)z�
        Invoke the given callback with a client protocol and a server protocol
        which have been connected to each other.
        rr{r|c���|\}}�||�|jj�|jj�yrr�)r'�serverProtocol�clientProtocolrs   �r"�	connectedz>LoopbackTests._connectedClientAndServerTest.<locals>.connected�s;���-3�*�N�N��^�^�4��$�$�3�3�5��$�$�3�3�5r$)rer	r*rbr
r~rrKr�rJrgr�r�r,)
r:rr�r�rJr�r�r��	connsMader�s
 `        r"�_connectedClientAndServerTestz+LoopbackTests._connectedClientAndServerTest�s����
(�)�
����)��/=�
�,�� � ��M�[�I������*�*�+��\�\�^�(�(�
�!�#�����)��)7��&����;�
�G�<��'�'���(H�I�	�	6�	���i�(��r$c�0���fd�}�j|�S)a
        The transport of a protocol connected with L{IReactorTCP.connectTCP} or
        L{IReactor.TCP.listenTCP} can have its I{TCP_NODELAY} state inspected
        and manipulated with L{ITCPTransport.getTcpNoDelay} and
        L{ITCPTransport.setTcpNoDelay}.
        c�4��||fD]�}|j}�j|j�d�|jd��j|j�d�|jd��j|j�d���y�NrrX)r7r��
getTcpNoDelay�
setTcpNoDelay�r�r�rar7r:s    �r"r#z,LoopbackTests.test_tcpNoDelay.<locals>.check�s����$�n�5�
?���K�K�	�� � ��!8�!8�!:�A�>��'�'��*�� � ��!8�!8�!:�A�>��'�'��*�� � ��!8�!8�!:�A�>�

?r$�r��r:r#s` r"�test_tcpNoDelayzLoopbackTests.test_tcpNoDelay�s���	?��1�1�%�8�8r$c�0���fd�}�j|�S)a
        The transport of a protocol connected with L{IReactorTCP.connectTCP} or
        L{IReactor.TCP.listenTCP} can have its I{SO_KEEPALIVE} state inspected
        and manipulated with L{ITCPTransport.getTcpKeepAlive} and
        L{ITCPTransport.setTcpKeepAlive}.
        c�4��||fD]�}|j}�j|j�d�|jd��j|j�d�|jd��j|j�d���yr�)r7r��getTcpKeepAlive�setTcpKeepAliver�s    �r"r#z.LoopbackTests.test_tcpKeepAlive.<locals>.check�s����$�n�5�
A���K�K�	�� � ��!:�!:�!<�a�@��)�)�!�,�� � ��!:�!:�!<�a�@��)�)�!�,�� � ��!:�!:�!<�a�@�

Ar$r�r�s` r"�test_tcpKeepAlivezLoopbackTests.test_tcpKeepAlive�s���	A��1�1�%�8�8r$c���t��tjdd�d���fd�}�jj	|�S)Nr{�E�)�timeoutc�X���jjtj�yrr�)r�r�s �r"r#z(LoopbackTests.testFailing.<locals>.check�s����N�N���� <� <�=r$)rgr
r�rjr,)r:r#r�s  @r"�testFailingzLoopbackTests.testFailing�s=���!�#�����;��G�Q�?�	>��#�#�/�/��6�6r$c�������g�td�D]I}tj�}|jd�|jd��j	|��Ktj��tjttj������fd����}�j|tj��fd�}|j|��fd�}|j|�|S)z�
        Assert that the error number of the ConnectionRefusedError is
        ECONNREFUSED, and not some other socket related error.
        �
�r{rrXc�������fd�}�j�}|j�\}}|j��j||�}|j	|�|S)Nc�n��|jj��r��S�jd�y)z\
                Darn.  Kill it and try again, if there are any tries left.
                z?Could not fail to connect - could not test errno for that case.N)r7r8�fail)�protor:�
serverSockets�tryConnectFailures ���r"r�z]LoopbackTests.test_connectionRefusedErrorNumber.<locals>.tryConnectFailure.<locals>.connecteds0������.�.�0� �,�.�.��	�	�U�r$)�pop�getsocknamer�r�r,)	r��serverSocket�
serverHost�
serverPort�connectDeferred�
clientCreatorr:rrs	     ����r"rzJLoopbackTests.test_connectionRefusedErrorNumber.<locals>.tryConnectFailures]���	
�)�,�,�.�L�%1�%=�%=�%?�"�J�
���� �+�6�6�z�:�N�O��'�'�	�2�"�"r$c�Z���j|jtj�yr)r��osError�errno�ECONNREFUSED)�excr:s �r"�connRefusedzDLoopbackTests.test_connectionRefusedErrorNumber.<locals>.connRefuseds������S�[�[�%�*<�*<�=r$c�N���r!�j�j��r�!|Sr)rr�)�passthroughrs �r"�cleanupz@LoopbackTests.test_connectionRefusedErrorNumber.<locals>.cleanups&�����!�!�#�)�)�+� ��r$)�range�socket�bind�listenrY�random�shuffler�
ClientCreatorr
rr�r
r�r,�addBoth)	r:�ir�refusedDeferredrrr	rrs	`     @@@r"�!test_connectionRefusedErrorNumberz/LoopbackTests.test_connectionRefusedErrorNumber�s����2�
��r��	/�A�!�=�=�?�L����.�/�����"�� � ��.�		/�
	���}�%� �.�.�w��8I�8I�J�
�	#�(,�-�����?�E�,H�,H�I�	>�	�#�#�K�0�	�
	����(��r$c�v�|jtjtjddt��y)zu
        Connecting to a named service which does not exist raises
        L{error.ServiceNameUnknownError}.
        r{�thisbetternotexistN)r�r
�ServiceNameUnknownErrorr
r�rgr9s r"�test_connectByServiceFailz'LoopbackTests.test_connectByServiceFail&s0��
	
����)�)����� ���	
r$c����	�t��	tj�}|�	_t	j
d�	d��}�j
|j�|j�j�t�}tj�}||_�fd�}�jtd|�t	jdd|�tj||g�}��	fd�}|j|�|S)z�
        L{IReactorTCP.connectTCP} accepts the name of a service instead of a
        port number and connects to the port number associated with that
        service, as defined by L{socket.getservbyname}.
        rr{r|c���|dk(r|dk(r�Sy)N�http�tcpr�rF)�serviceName�protocolNamer�s  �r"�fakeGetServicePortByNamezELoopbackTests.test_connectByService.<locals>.fakeGetServicePortByNameCs����f�$���)>�!�!�r$�
getservbynamer$c���|\}}�j�jd�|jj�|jj�y)Nz7Server factory was not called upon to build a protocol.)r�rZr7r8)r'r�r�r:r�s   ��r"r�z6LoopbackTests.test_connectByService.<locals>.connectedNsK���-3�*�N�N��O�O��$�$�I�
�
�$�$�3�3�5��$�$�3�3�5r$)rer	r*rbr
r~rrKr�rJrg�patchrr�r�r,)
r:r�rJ�
clientFactoryr�r(�connMader�r�r�s
`       @@r"�test_connectByServicez#LoopbackTests.test_connectByService3s����(�)�
����)��/=�
�,�� � ��M�[�I������*�*�+��\�\�^�(�(�
�'�)�
����)��/=�
�,�	�
	
�
�
�6�?�,D�E����;��
�>��&�&���'G�H��	6�	���Y�'��r$N)
rCrDrErQr�r�r�r�r�r�rr!r.rFr$r"r�r�ws7���3�(C��89�&9�&7�E�N
�%r$r�c� �eZdZdZdZd�Zd�Zy)�StartStopFactoryrc�N�|js|jrt�d|_yrl��startedrvr�r9s r"�startFactoryzStartStopFactory.startFactory_����<�<�4�<�<�����r$c�N�|jr|jrt�d|_yrlr2r9s r"rwzStartStopFactory.stopFactoryds���|�|�t�|�|�����r$N)rCrDrEr3rvr4rwrFr$r"r0r0[s���G��G��
r$r0c�&�eZdZdZdZd�Zd�Zd�Zy)�ClientStartStopFactoryrc�h�tj|g|��i|��tj�|_yr)rgrVr	r*�whenStopped)r:�a�kws   r"rVzClientStartStopFactory.__init__ns)��� � ��0��0�R�0� �>�>�+��r$c�N�|js|jrt�d|_yrlr2r9s r"r4z#ClientStartStopFactory.startFactoryrr5r$c��|jr|jrt�d|_|jj	d�y)NrXT)r3rvr�r:rr9s r"rwz"ClientStartStopFactory.stopFactoryws0���|�|�t�|�|���������!�!�$�'r$N)rCrDrEr3rvrVr4rwrFr$r"r8r8js���G��G�,��
(r$r8c��eZdZdZd�Zd�Zy)�FactoryTestszTests for factories.c����	�t��tjd�d��}�j|j��j�j�jfd�tjd�d��}tjd�d���	�j�j�jfd�tj|j�}tj|j�}tj||g�}��	�fd�}|j|���fd�}|j|�|S)a
        The factory passed to L{IReactorTCP.listenTCP} should be started only
        when it transitions from being used on no ports to being used on one
        port and should be stopped only when it transitions from being used on
        one port to being used on no ports.
        rr{r|�rXrc�t���j�j�jfd��j�S)NrB)r�r3rvrK)r�r��p3r:s ���r"�cbClosedz3FactoryTests.test_serverStartStop.<locals>.cbClosed�s/������a�i�i����3�V�<��#�#�%�%r$c�V���j�j�jfd�y)N)rXrX)r�r3rv)r�r�r:s ��r"�cbClosedAllz6FactoryTests.test_serverStartStop.<locals>.cbClosedAll�s ������a�i�i����3�V�<r$)r0r
r~rrKr�r3rvr	r�r�r,)
r:r��p2�d1r1r^rErGr�rDs
`       @@r"�test_serverStartStopz!FactoryTests.test_serverStartStop�s���
����
�
�q�!�{�
;������(�(�)����!�)�)�Q�Y�Y�/��8��
�
�q�!�{�
;��
�
�
�q�!�{�
;�����!�)�)�Q�Y�Y�/��8��
 �
 ��!1�!1�
2��
�
 �
 ��!1�!1�
2���,�,�b�"�X�6��	&�
	�"�"�8�,�	=�	�"�"�;�/��r$c�T��t�}tjd|d��}||_|j	|j
�|j
�j}t��tjd|��|j�j�t�fd��S)z�
        The factory passed to L{IReactorTCP.connectTCP} should be started when
        the connection attempt starts and stopped when it is over.
        rr{r|c����jSrru)r\s�r"r�z3FactoryTests.test_clientStartStop.<locals>.<lambda>�s������r$)rHr
r~rJrrPr�r8r�r�r3r2)r:r�rar�r\s    @r"�test_clientStartStopz!FactoryTests.test_clientStartStop�s���

������a��k�:���������	�	�"��Y�Y�[�%�%�
�(�*�����;�
�G�<�������(��0�1�1r$N)rCrDrErQrJrMrFr$r"r@r@~s���+�Z2r$r@c�"�eZdZdZd�Zd�Zd�Zy)�CannotBindTestsz]
    Tests for correct behavior when a reactor cannot bind to the required TCP
    port.
    c���t�}tjd|d��}|j|j�|j�j}|j�}|j|jd�|j|jd�|j|j|�|jtjtj||d��y)z�
        L{IReactorTCP.listenTCP} raises L{error.CannotListenError} if the
        address to listen on is already in use.
        rr{r|�TCPN)
rer
r~rrKr�rJr��type�hostr�r
�CannotListenError)r:r�r�r��dests     r"�test_cannotBindzCannotBindTests.test_cannotBind�s���

���
�
�
�q�!�{�
;������(�(�)��J�J�L�����z�z�|��������E�*�������K�0�������A�&�	
����#�#�W�%6�%6��1��	�	
r$c�2���t����fd��}|S)z>Returns closure that when called calls f and then callbacks d.c�:���|i|��}�jd�|S)N�r)�argsr<�rtnr r�s   ��r"�newfz/CannotBindTests._fireWhenDoneFunc.<locals>.newf�s ����T�.�R�.�C�
�J�J�r�N��Jr$r)r:r r�r\s `` r"�_fireWhenDoneFuncz!CannotBindTests._fireWhenDoneFunc�s"���
�q��	�
�	�
�r$c�r�������	�
�tj�}t�}�j||j�|_tjd|d���
�j�
j���
�fd�}��fd�����	�
�fd���fd���fd����fd	��	�fd
��|j|�|S)z�
        L{IReactorTCP.connectTCP} calls C{Factory.clientConnectionFailed} with
        L{error.ConnectBindError} if the bind address specified is already in
        use.
        rr{r|c���tj�}t�}�j||j�|_tjd�j�j|d��|j�|�|S)Nr{r���bindAddress)
r	r*rgr]rNr
r�r�rJr,)�resultsr �cf1�_conmaderar:s   ���r"�	_connect1z2CannotBindTests.test_clientBind.<locals>._connect1�sk������ �A�!�#�C� $� 6� 6�q�#�:K�:K� L�C������Q�Y�Y�[�-�-�s�@P�
�
�M�M�(�C�(��Hr$c���tj�}�j||jj�|j_|j�|�|Sr)r	r*r]rr;r,)rbrcr �_check1connect2r:s   ��r"rdz1CannotBindTests.test_clientBind.<locals>._conmade�sJ������ �A�*.�*@�*@��3�<�<�.�.�+�C�L�L�'�
�M�M�/�3�/��Hr$c����j|jjd�tj�}tj�}|jj
j
�j}t�}�j||j�|_
�j||j�|_tjd�
j
�j|d|f��|j�||�|j�||�tj||g�}|j�	||�|S)NrXr{r`)r�rr�r	r*r7r�rJrgr]rprwr
r�r,�DeferredList)rbrcrIr1rJ�cf2�dl�
_check2failed�_check2stopped�_stoprar:s       �����r"rgz8CannotBindTests.test_clientBind.<locals>._check1connect2s������S�\�\�.�.��2����!�B����!�B��<�<�)�)�1�1�3�8�8�D�!�#�C�)-�)?�)?��C�.�.�*�C�&�#�4�4�R����I�C�O�����Q�Y�Y�[�-�-�s��d�@S�
�
�N�N�=�#�s�3��N�N�>�3��4��#�#�R��H�-�B��N�N�5�#�s�+��Ir$c����j|jd�|jjtj
��j
|jjtj
��|Srl)r�rmr@r=r
�ConnectBindErrorr�r#�rbrcrjr:s   �r"rlz6CannotBindTests.test_clientBind.<locals>._check2failedsS������S�Z�Z��+��J�J�O�O�E�2�2�3��O�O�C�J�J�,�,�U�-C�-C�D�E��Nr$c�@���j|jd�|Srl�r�rvrqs   �r"rmz7CannotBindTests.test_clientBind.<locals>._check2stoppeds������S�[�[�!�,��Nr$c����tj�}|j�|��j||j�|_|j
jj�|Sr)r	r*r,r]rwrr7r8)rbrcrjr �_check1cleanupr:s    ��r"rnz.CannotBindTests.test_clientBind.<locals>._stop sP������ �A�
�M�M�.�#�.�"�4�4�Q����H�C�O��L�L�"�"�1�1�3��Hr$c�>���j|jd�yrlrs)rbrcr:s  �r"ruz7CannotBindTests.test_clientBind.<locals>._check1cleanup's������S�[�[�!�,r$)
r	r*rer]r4r
r~rrKr,)r:�theDeferred�sfrerurgrlrmrdrnras`   @@@@@@@r"�test_clientBindzCannotBindTests.test_clientBind�s�����n�n�&��
�
���0�0��b�o�o�N������a��{�;��������(�	�	�	�	�(	�	�	�	-�	���	�*��r$N)rCrDrErQrVr]ryrFr$r"rOrO�s���

�(	�Gr$rOc��eZdZd�Zy)�MyOtherClientFactoryc�F�||_t�|_|jSr)�addressrr)r:r}s  r"rNz"MyOtherClientFactory.buildProtocol/s�����,�.��
��}�}�r$N)rCrDrErNrFr$r"r{r{.s��r$r{c��eZdZdZd�Zy)�LocalRemoteAddressTestszo
    Tests for correct getHost/getPeer values and that the correct address is
    passed to buildProtocol.
    c�������	�t�}tj�|_|j�	t	j
d|d����j
�j��j�j}t��tj�x}�_t	jd|������fd�}|j|���	fd�}|j|�|S)z
        L{IListeningPort.getHost} returns the same address as a client
        connection's L{ITCPTransport.getPeer}.
        rr{r|c�����j�j�g�j��j�j��jjj��yr)r�r�rUrr7�getPeer)r�r,rJr:s ���r"r#z7LocalRemoteAddressTests.test_hostAddress.<locals>.checkKsM������d�l�l�n�-�}�/J�/J�K����T�\�\�^�]�-C�-C�-M�-M�-U�-U�-W�Xr$c�(���j��Sr)r�)r�ro�serverConnectionLosts ��r"rz9LocalRemoteAddressTests.test_hostAddress.<locals>.cleanupQs���
� � �"�'�'r$)rer	r*r]r
r~rrKr�rJrgrbr�r,)
r:r�r��onConnectionr#rr,rorJr�s
`     @@@@r"�test_hostAddressz(LocalRemoteAddressTests.test_hostAddress;s����
(�)�
�/4�~�~�/?�
�,�,�C�C��� � ��M�[�I������*�*�+��L�L�N����'�)�
�>C�n�n�>N�N��}�;��&�&�{�A�}�E�	�	Y�	� � ��'�	(�	� � ��)��r$N)rCrDrErQr�rFr$r"rr5s���
r$rc��eZdZd�Zy)�WriterProtocolc���|jjd�gd�}|jj|�|jj�}|jdk7rtd|���d|j_|jj�}|jdk7rtd|���d|j_d|j_	|jj�y)N�Hello Cleveland!
)�Goodbye� cruel� world�
rQz!getPeer returned non-TCP socket: rXz!getHost returned non-TCP socket: )r7�write�
writeSequencer�rRrr\�problemr��doner8)r:�seq�peer�uss    r"r;zWriterProtocol.connectionMade^s���	
�����2�3�7�����$�$�S�)��~�~�%�%�'���9�9����3�D�6�:�;�#$�D�L�L� �
�^�^�
#�
#�
%��
�7�7�e���3�B�4�8�9�#$�D�L�L� ���������%�%�'r$N�rCrDrEr;rFr$r"r�r�]s��(r$r�c��eZdZd�Zd�Zy)�ReaderProtocolc�B�|jxj|z
c_yr)r\�data�r:r�s  r"�dataReceivedzReaderProtocol.dataReceivedus�������T�!�r$c�&�d|j_yrl�r\r�r?s  r"rAzReaderProtocol.connectionLostx�������r$N�rCrDrEr�rArFr$r"r�r�ts��"�r$r�c��eZdZd�Zd�Zy)�WriterClientFactoryc� �d|_d|_y)Nrr$)r�r�r9s r"rVzWriterClientFactory.__init__}s����	���	r$c�6�t�}||_||_|Sr)r�r\rr_s   r"rNz!WriterClientFactory.buildProtocol�s�������	���
��r$N�rCrDrErVrNrFr$r"r�r�|s���r$r�c��eZdZdZd�Zd�Zy)�WriteDataTestszw
    Test that connected TCP sockets can actually write data. Try to exercise
    the entire ITransport interface.
    c������tj��t�_d�_d�_t��}t
jd|d��}�j|j�|j�j}t��t��}t
jd||����fd�}tj|j |j g�}|j#|�S)z�
        L{ITCPTransport.write} and L{ITCPTransport.writeSequence} send bytes to
        the other end of the connection.
        rr{r|c����j�jd��j�jdk(d��j�jd�djgd��}�j�j|k(d�y)N�&writer didn't finish, it probably diedrzwriter indicated an error�$client didn't see connection droppedr$)r�r�r�r�r�z.client didn't receive all the data it expected)r�r�r��joinr�)r��expectedr�r�r:s  ���r"r#z)WriteDataTests.test_writer.<locals>.check�sn����O�O�A�F�F�$L�M��O�O�A�I�I��N�,G�H��O�O�G�L�L�*P�Q��x�x�P��H�
�O�O�����(�@�
r$)r�Factoryr�r�r��WiredFactoryr
r~rrKr�rJr�r�r	r��onDisconnectr,)	r:�wrappedFrar��wrappedClientFr#r r�r�s	`      @@r"�test_writerzWriteDataTests.test_writer�s����

�����#��
������	���?�����a��[�A��������(�
�I�I�K����%�'��%�g�.�����;��>�:�
	�
����!6�!6��8S�8S� T�U���}�}�U�#�#r$c�l��	�
��tjjdk(rtd��t	j
��
t	j
��G�
�fd�dtj�}t
j�}||_tjd|d��}|j|j�|j�}tt�Gd�d	���G��
�fd
�dtj�}t��	|�	_�	j"}�	fd�}|j%|�t'd
|j(�d|j*���tj,|j(|j*�	�t'd�|j/|t0j2�S)a$
        A TCP transport which is written to after the connection has been shut
        down should notify its protocol that the connection has been lost, even
        if the TCP transport is not actively being monitored for read events
        (ie, pauseProducing was called on it).
        �IOCPReactora(iocpreactor does not, in fact, stop reading immediately after pauseProducing is called. This results in a bonus disconnection notification. Under some circumstances, it might be possible to not receive this notifications (specifically, pauseProducing, deliver some data, proceed with this test). c�&��eZdZdZ�fd�Z�fd�Zy)�JWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.Disconnecterz�
            Protocol for the server side of the connection which disconnects
            itself in a callback on clientPaused and publishes notification
            when its connection is actually lost.
            c�J���td��fd�}�j|�y)z[
                Set up a callback on clientPaused to lose the connection.
                zDisconnector.connectionMadec�f��td��jj�td�y)Nz&Disconnector.connectionMade disconnectzloseConnection calledr6)r�r:s �r"r�zmWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.Disconnecter.connectionMade.<locals>.disconnect�s%����@�A��N�N�1�1�3��/�0r$N)rr,)r:r��clientPauseds` �r"r;zYWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.Disconnecter.connectionMade�s#����1�2�1�
�(�(��4r$c�T��td��jd�td�y)zt
                Notify observers that the server side of the connection has
                ended.
                zDisconnecter.connectionLostNzserverLost called back)rr)r:r@�
serverLosts  �r"rAzYWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.Disconnecter.connectionLost�s%���
�1�2��#�#�D�)��,�-r$N)rCrDrErQr;rA)r�r�s��r"�Disconnecterr��s���
�
5�
.r$r�rr{r|c�"�eZdZdZd�Zd�Zd�Zy)�FWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.Infinitez�
            A producer which will write to its consumer as long as
            resumeProducing is called.

            @ivar consumer: The L{IConsumer} which will be written to.
            c��||_yr)�consumer)r:r�s  r"rVzOWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.Infinite.__init__�s	�� (��
r$c�f�td�|jjd�td�y)NzInfinite.resumeProducing�xz*Infinite.resumeProducing wrote to consumer)rr�r�r9s r"�resumeProducingzVWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.Infinite.resumeProducing�s&���.�/��
�
�#�#�D�)��@�Ar$c��td�y)NzInfinite.stopProducing)rr9s r"�
stopProducingzTWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.Infinite.stopProducings���,�-r$N)rCrDrErQrVr�r�rFr$r"�Infiniter��s��
�
)�
B�

.r$r�c� ��eZdZdZ���fd�Zy)�MWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.UnreadingWriterz
            Trivial protocol which pauses its transport immediately and then
            writes some bytes to it.
            c����td��jj��jd�td���fd�}�j	|�y)NzUnreadingWriter.connectionMadezclientPaused called backc���td���j�}td��jj|d�td�y)Nz$UnreadingWriter.connectionMade writez5UnreadingWriter.connectionMade write created producerFz8UnreadingWriter.connectionMade write registered producer)rr7�registerProducer)r��producerr�r:s  ��r"r�zkWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.UnreadingWriter.connectionMade.<locals>.writesB����>�?� (����7�H��O�P��N�N�3�3�H�e�D��R�Sr$)rr7�pauseProducingrr,)r:r�r�r�r�s` ���r"r;z\WriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.UnreadingWriter.connectionMade
sI����4�5����-�-�/��%�%�d�+��.�/�T�$�&�&�u�-r$N)rCrDrErQr;)r�r�r�s���r"�UnreadingWriterr�s
���
�

.r$r�c�2��td��jS)N�cbClientLost)rrr)r�r�s �r"r�zJWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.cbClientLost,s�������$�$�$r$zConnecting to �:zReturning Deferred)r
�	__class__rCrr	r*rr�
ServerFactoryr~rrKr�rrrgr[rir,rrSrJr�r�r
�ConnectionLost)r:r�r�rJr`r�rsr�r�r�r�r�s        @@@@r"�%test_writeAfterShutdownWithoutReadingz4WriteDataTests.test_writeAfterShutdownWithoutReading�sb������%�%��6��?��
��~�~�'���^�^�%�
�	.�8�,�,�	.�<�'�'�)��&���� � ��F�k�B������*�*�+��|�|�~��	�]�	#�	.�	.�
$�	.�&	.�	.�h�/�/�	.�B!�"��!0���%����	%�	�(�(��6��n�T�Y�Y�K�q�����4�5����4�9�9�d�i�i��8�	� �!��!�!�"6��8L�8L�M�Mr$N)rCrDrErQr�r�rFr$r"r�r��s���
$�@INr$r�c��eZdZd�Zy)�ConnectionLosingProtocolc��|jjd�|jj�|jj	�|jj
j
|j�y)N�1)r7r�r8�master�_connectionMade�portsrYr9s r"r;z'ConnectionLosingProtocol.connectionMade;sP�������T�"����%�%�'����#�#�%������ � ����0r$Nr�rFr$r"r�r�:s��1r$r�c��eZdZd�Zd�Zy)�NoopProtocolc��tj�|_|jjj|j�yr)r	r*r r��serverConnsrYr9s r"r;zNoopProtocol.connectionMadeCs,�����!��������&�&�t�v�v�.r$c�:�|jjd�y�NT)r rr?s  r"rAzNoopProtocol.connectionLostGs��������r$NrBrFr$r"r�r�Bs��/�r$r�c��eZdZdZd�Zd�Zy)�ConnectionLostNotifyingProtocolac
    Protocol which fires a Deferred which was previously passed to
    its initializer when the connection is lost.

    @ivar onConnectionLost: The L{Deferred} which will be fired in
        C{connectionLost}.

    @ivar lostConnectionReason: L{None} until the connection is lost, then a
        reference to the reason passed to C{connectionLost}.
    c� �d|_||_yr)�lostConnectionReason�onConnectionLost)r:r�s  r"rVz(ConnectionLostNotifyingProtocol.__init__Ws��$(��!� 0��r$c�H�||_|jj|�yr)r�r�rr?s  r"rAz.ConnectionLostNotifyingProtocol.connectionLost[s��$*��!����&�&�t�,r$N)rCrDrErQrVrArFr$r"r�r�Ks��	�1�-r$r�c��eZdZdZd�Zy)�HandleSavingProtocolz�
    Protocol which grabs the platform-specific socket handle and
    saves it as an attribute on itself when the connection is
    established.
    c�l�|j�|_tjj	||�S)z\
        Save the platform-specific socket handle for future
        introspection.
        )�	getHandle�handlerr�makeConnection)r:r7s  r"r�z#HandleSavingProtocol.makeConnectiongs-��
 �)�)�+���� � �/�/��i�@�@r$N)rCrDrErQr�rFr$r"r�r�`s
���Ar$r�c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�ProperlyCloseFilesMixinzA
    Tests for platform resources properly being cleaned up.
    c��t��)z�
        Bind a server port to which connections will be made.  The server
        should use the given protocol factory.

        @return: The L{IListeningPort} for the server created.
        ��NotImplementedError�r:r}r�r\s    r"�createServerz$ProperlyCloseFilesMixin.createServeru�
��"�#�#r$c��t��)z�
        Establish a connection to the given address using the given
        L{ClientCreator} instance.

        @return: A Deferred which will fire with the connected protocol instance.
        r��r:r}r�r	s    r"�
connectClientz%ProperlyCloseFilesMixin.connectClient~r�r$c��t��)z�
        Return the exception class which will be raised when an operation is
        attempted on a closed platform handle.
        r�r9s r"�getHandleExceptionTypez.ProperlyCloseFilesMixin.getHandleExceptionType�s
��
"�#�#r$c��tj�r#tjtj
�Stjtj�S)z�
        Return a L{hamcrest.core.matcher.Matcher} that matches the
        errno expected to result from writing to a closed platform
        socket handle.
        )r�	isWindows�hamcrest�equal_tor�WSAENOTSOCK�EBADFr9s r"�getHandleErrorCodeMatcherz1ProperlyCloseFilesMixin.getHandleErrorCodeMatcher�s<�������$�$�U�%6�%6�7�7�� � ����-�-r$c�����	�
�tj��	tj�}�	fd�|_�j	dd|��
tj���
j�}tjt�fd��}�j|j|j|�}��	fd�}|j|��fd�}|j|��
fd�}|j|�|S)zp
        Test that lost connections properly have their underlying socket
        resources cleaned up.
        c���t��Sr)r�)�onServerConnectionLosts�r"r�zAProperlyCloseFilesMixin.test_properlyCloseFiles.<locals>.<lambda>�s���)H�"�*
�r$r{rc���t��Sr)r�)�onClientConnectionLosts�r"r�zAProperlyCloseFilesMixin.test_properlyCloseFiles.<locals>.<lambda>�s���1�2H�I�r$c���|jjd�|jj�tj��g�S)z�
            Disconnect the client.  Return a Deferred which fires when both
            the client and the server have received disconnect notification.
            s0some bytes to make sure the connection is set up)r7r�r8r	r�)r�rrs ��r"�clientConnectedzHProperlyCloseFilesMixin.test_properlyCloseFiles.<locals>.clientConnected�sD���

���"�"�#V�W����+�+�-��&�&�(>�@V�'W�X�Xr$c����|\}}|jjtj�st	|jd�|jjtj�st	|jd��j�}�j
�j�|jjd�}tj|jd|�y)zl
            Verify that the underlying platform socket handle has been
            cleaned up.
            z,Client lost connection for unexpected reasonz,Server lost connection for unexpected reasonsbytesrN)
r�r#r
�ConnectionClosedrrr�r�r��sendr��assert_thatrZ)r'r�r��errorCodeMatcher�	exceptionr:s     �r"�clientDisconnectedzKProperlyCloseFilesMixin.test_properlyCloseFiles.<locals>.clientDisconnected�s����
$�N�F�F��.�.�4�4�U�5K�5K�L���/�/�B���.�.�4�4�U�5K�5K�L���/�/�B�� $�=�=�?���)�)��+�+�-�v�}�}�/A�/A�8��I�
� � ����q�!� �
r$c�p���tj�j�}|j�fd��|S)zx
            Shut down the server port.  Return a Deferred which fires when
            this has completed.
            c����SrrF)r�rs �r"r�zRProperlyCloseFilesMixin.test_properlyCloseFiles.<locals>.cleanup.<locals>.<lambda>�s���;�r$)r	r�rKr,)rr'rs` �r"rz@ProperlyCloseFilesMixin.test_properlyCloseFiles.<locals>.cleanup�s/���
�(�(��)A�)A�B�F����6�7��Mr$)
r	r*rr�r�r�rr
r�rSrJr,r)r:r��
serverAddrr	�clientDeferredr
rrrrrs`       @@@r"�test_properlyCloseFilesz/ProperlyCloseFilesMixin.test_properlyCloseFiles�s����
"'���!1�� �.�.�0�
�"
�
���&�&�{�A�}�E�
�!&���!1���'�'�)�
� �.�.��I�
�
��+�+��O�O�Z�_�_�m�
��	Y�	�"�"�?�3�	�2	�"�"�#5�6�	�	���w�'��r$N)	rCrDrErQr�r�r�rrrFr$r"r�r�ps!���$�$�$�
.�Fr$r�c�"�eZdZdZd�Zd�Zd�Zy)�ProperlyCloseFilesTestsz�
    Test that the sockets created by L{IReactorTCP.connectTCP} are cleaned up
    when the connection they are associated with is closed.
    c�2�tj|||��S)zE
        Create a TCP server using L{IReactorTCP.listenTCP}.
        r|)r
r~r�s    r"r�z$ProperlyCloseFilesTests.createServer�s��� � ��W��H�Hr$c�&�|j||�S)zF
        Create a TCP client using L{IReactorTCP.connectTCP}.
        )r�r�s    r"r�z%ProperlyCloseFilesTests.connectClient�s���'�'���<�<r$c�"�tjS)z�
        Return L{socket.error} as the expected error type which will be
        raised by a write to the low-level socket object after it has been
        closed.
        )rr
r9s r"r�z.ProperlyCloseFilesTests.getHandleExceptionType�s���|�|�r$N)rCrDrErQr�r�r�rFr$r"rr�s���
I�=�r$rc��eZdZd�Zd�Zd�Zy)�WiredForDeferredsc�F�tjj|||�yr)r�ProtocolWrapperrV)r:r\�wrappedProtocols   r"rVzWiredForDeferreds.__init__�s��� � �)�)�$���Ir$c��tjj|�|jjjd�yr)rrr;r\�	onConnectrr9s r"r;z WiredForDeferreds.connectionMades.��� � �/�/��5������'�'��-r$c��tjj||�|jjjd�yr)rrrAr\r�rr?s  r"rAz WiredForDeferreds.connectionLosts0��� � �/�/��f�=����!�!�*�*�4�0r$N)rCrDrErVr;rArFr$r"rr�s��J�.�1r$rc��eZdZeZd�Zy)r�c��tjj||�tj�|_tj�|_yr)r�WrappingFactoryrVr	r*r"r��r:�wrappedFactorys  r"rVzWiredFactory.__init__s5��� � �)�)�$��?����)���!�N�N�,��r$N)rCrDrErrrVrFr$r"r�r�s�� �H�-r$r�c�"�eZdZdZd�Zd�Zd�Zy)�AddressTestszR
    Tests for address-related interactions with client and server protocols.
    c��Gd�dtj�}t�|_t	j
�x|_|j_t	j
�x|_|j_	||j�|_
t�|_t	j
�x|_
|j_t	j
�x|_|j_	||j�|_t!j"d|jd��|_t!j&|j$j)�j*|j$j)�j$|j�|_t	j.|j|jg�S)a9
        Create a port and connected client/server pair which can be used
        to test factory behavior related to addresses.

        @return: A L{defer.Deferred} which will be called back when both the
            client and server protocols have received their connection made
            callback.
        c��eZdZdZd�Zd�Zy)�.AddressTests.setUp.<locals>.RememberingWrappera�
            Simple wrapper factory which records the addresses which are
            passed to its L{buildProtocol} method and delegates actual
            protocol creation to another factory.

            @ivar addresses: A list of the objects passed to buildProtocol.
            @ivar factory: The wrapped factory to which protocol creation is
                delegated.
            c� �g|_||_yr)�	addressesr\)r:r\s  r"rVz7AddressTests.setUp.<locals>.RememberingWrapper.__init__.s��!#���&��r$c�n�|jj|�|jj|�S)z�
                Append the given address to C{self.addresses} and forward
                the call to C{self.factory}.
                )r/rYr\rN)r:r`s  r"rNz<AddressTests.setUp.<locals>.RememberingWrapper.buildProtocol5s+��
���%�%�d�+��|�|�1�1�$�7�7r$N)rCrDrErQrVrNrFr$r"�RememberingWrapperr-#s��
�
'�
8r$r1rr{r|)r�
ClientFactoryrer�r	r*r�rb�serverConnLostr]�
serverWrapperrgr�r��clientConnLost�
clientWrapperr
r~rJr�r�rSror�)r:r1s  r"�setUpzAddressTests.setUpsA��	8��!7�!7�	8�:&�'���CH�>�>�CS�S���d�k�k�@�CH�>�>�CS�S���d�k�k�@�0����<���&�'���CH�>�>�CS�S���d�k�k�@�CH�>�>�CS�S���d�k�k�@�/����<����%�%�a��);�);�{�S��	� �+�+��I�I����$�$�d�i�i�&7�&7�&9�&>�&>��@R�@R�
����"�"�D�$7�$7��9L�9L�#M�N�Nr$c���|jj�tj|j|j
tj|jj�g�S)zf
        Disconnect the client/server pair and shutdown the port created in
        L{setUp}.
        )	ror�r	r�r3r5r�rJrKr9s r"�tearDownzAddressTests.tearDownTsV��
	
���!�!�#��"�"��#�#��#�#��#�#�D�I�I�$;�$;�<�
�
�	
r$c���|jjjj�}|jjjj�}|j
|jjtd|j|j�g�|j
|jjtd|j|j�g�y)ae
        L{ClientFactory.buildProtocol} should be invoked with the address of
        the server to which a connection has been established, which should
        be the same as the address reported by the C{getHost} method of the
        transport of the server protocol and as the C{getPeer} method of the
        transport of the client protocol.
        rQN)r�rr7r�r�r�r�r6r/rrSrJ)r:r�
clientPeers   r"�test_buildProtocolClientz%AddressTests.test_buildProtocolClientbs����[�[�)�)�3�3�;�;�=�
��[�[�)�)�3�3�;�;�=�
�������(�(�
��
������
A�B�	
�	
������(�(�
��
������
A�B�	
r$N)rCrDrErQr7r9r<rFr$r"r*r*s���9O�v
�
r$r*c��eZdZd�Zy)�LargeBufferWriterProtocolc����jjd�jjdz
z��fd�}t	j
d|�y)N�XrXc����jjd�d�j_�jj	�y)Nr@rX)r7r�r\r�r8r9s�r"�finishz8LargeBufferWriterProtocol.connectionMade.<locals>.finish�s1����N�N� � ��&� !�D�L�L���N�N�)�)�+r$g����MbP?)r7r�r\�lenr
�	callLater)r:rBs` r"r;z(LargeBufferWriterProtocol.connectionMade}s@��������T�T�\�\�%5�%5��%9�:�;�	,�
	���%��(r$Nr�rFr$r"r>r>ws��)r$r>c��eZdZd�Zd�Zy)�LargeBufferReaderProtocolc�T�|jxjt|�z
c_yr)r\rCr�s  r"r�z&LargeBufferReaderProtocol.dataReceived�s�������C��I�%�r$c�&�d|j_yrlr�r?s  r"rAz(LargeBufferReaderProtocol.connectionLost�r�r$Nr�rFr$r"rFrF�s��&�r$rFc��eZdZd�Zd�Zy)�LargeBufferReaderClientFactoryc� �d|_d|_y�Nr)r�rCr9s r"rVz'LargeBufferReaderClientFactory.__init__�s����	���r$c�6�t�}||_||_|Sr)rFr\rr_s   r"rNz,LargeBufferReaderClientFactory.buildProtocol�s��%�'����	���
��r$Nr�rFr$r"rJrJ�s���r$rJc��eZdZdZd�Zy)�FireOnClosezaA wrapper around a protocol that makes it fire a deferred when
    connectionLost is called.
    c��tjj||�|jjjd�yr)rrrAr\rirr?s  r"rAzFireOnClose.connectionLost�s0��� � �/�/��f�=������&�&�t�,r$N)rCrDrErQrArFr$r"rOrO�s���-r$rOc��eZdZeZd�Zy)�FireOnCloseFactoryc�v�tjj||�tj�|_yr)rr&rVr	r*rir's  r"rVzFireOnCloseFactory.__init__�s&��� � �)�)�$��?����(��
r$N)rCrDrErOrrVrFr$r"rRrR�s���H�)r$rRc��eZdZdZdZd�Zy)�LargeBufferTestsz0Test that buffering large amounts of data works.i�c�����tj��t�_d�_d�_�j
�_t��}tjd|d��}�j|j�|j�j}t��t��}tjd||�t!j"|j$|j$g�}���fd�}|j'|�S)Nrr{r|c�~���j�jd��j�j�jk\d�j�jfz��j�j�jkd�j�jfz��j�jd�y)Nr�z9client didn't receive all the data it expected (%d != %d)z8client did receive more data than it expected (%d != %d)r�)r�r�rC�datalen)r�r�r�r:s ���r"r#z*LargeBufferTests.testWriter.<locals>.check�s�����O�O�A�F�F�$L�M��O�O����t�|�|�+�� '���T�\�\�:�;�
�

�O�O����t�|�|�+�� '���T�\�\�:�;�
�

�O�O�G�L�L�*P�Qr$)rr�r>r�r�rXrCrRr
r~rrKr�rJrJr�r	r�rir,)	r:r�rar�r�r r#r�r�s	`      @@r"�
testWriterzLargeBufferTests.testWriter�s���������.��
������	������%�a�(�����a��[�A��������(�
�I�I�K����0�2��+�G�4�����;��>�:�����!2�!2�N�4K�4K� L�M��	R��}�}�U�#�#r$N)rCrDrErQrXrYrFr$r"rUrU�s��:��G�$r$rUc� �eZdZdZdZd�Zd�Zy)�MyHCProtocolFc�N�d|_|jr|jd�yyr�)�readHalfClosed�writeHalfClosedrAr9s r"�readConnectionLostzMyHCProtocol.readConnectionLost�s&��"����������%� r$c�N�d|_|jr|jd�yyr�)r^r]rAr9s r"�writeConnectionLostz MyHCProtocol.writeConnectionLost�s&��#����������%�r$N)rCrDrEr]r^r_rarFr$r"r[r[�s���N��O�&�&r$r[c��eZdZdZdZd�Zy)�MyHCFactoryrNc�`�|xjdz
c_t�}||_||_|Srl)rZr[r\rr_s   r"rNzMyHCFactory.buildProtocol�s*�����q����N����	���
��r$)rCrDrErZrbrNrFr$r"rcrc�s��
�F�!��r$rcc�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�HalfCloseTestszTest half-closing connections.c�b���t�x�_}tjd|d��x�_��j�j�t�fd��}tjtt��_|j��fd��|j�j�|S)Nrr{r|c����jSr)r�)ras�r"r�z&HalfCloseTests.setUp.<locals>.<lambda>�s���a�k�k�r$c����jj�j�j�j�j�Sr)�cfr�r�rSrJ)�_rar:s ��r"r�z&HalfCloseTests.setUp.<locals>.<lambda>�s0������ 2� 2�1�9�9�;�3C�3C�Q�Y�Y�[�EU�EU� V�r$)rcr�r
r~rarrKr2rrr[rjr,�_setUp)r:r�r ras`  @r"r7zHalfCloseTests.setUp�s}��� �]�"�����&�&�q�!�{�C�C����������(��)�*���(�(��,�?���	�
�
�V�W�	�
�
�d�k�k�"��r$c����|�_tj�x�_�j_�j�jjjd�t�fd��S)NrXc�6��t�jdd�duS)Nr)r�r�r9s�r"r�z'HalfCloseTests._setUp.<locals>.<lambda>s��������T�!B�$�!N�r$)	r�r	r*�clientProtoConnectionLostr^r�r7r�r2�r:r�s` r"rlzHalfCloseTests._setUpsQ������FK�n�n�FV�V��&����)C�������.�.�8�8�!�<��N�O�Or$c�L���j�jjd��jjj	�tj�jj�}|j�fd��|j�j�|S)Nrc����jSr)ro)r�r:s �r"r�z)HalfCloseTests.tearDown.<locals>.<lambda>s
���$�"@�"@�r$)r�r��closedr7r8r	r�rarKr,�	_tearDown)r:r s` r"r9zHalfCloseTests.tearDownso���������+�+�Q�/������,�,�.������� 4� 4�5��	�
�
�@�A�	�
�
�d�n�n�%��r$c�����j�jjd��j�jjjd�tj����fd�}|�jj_�jjjj��j�fd���S)NrXrc�^��d�jj_�jd�yrl)r�rrsr)r@r r:s ��r"�_connectionLostz1HalfCloseTests._tearDown.<locals>._connectionLosts���%&�D�F�F�O�O�"�
�J�J�t�r$c�d���j�jjjd�Srl)r�r�rrs�r�r:s �r"r�z*HalfCloseTests._tearDown.<locals>.<lambda>s"���� 0� 0������1G�1G�� K�r$)r�r�rsr�rr	r*rAr7r8r,)r:r�rwr s`  @r"rtzHalfCloseTests._tearDowns����������+�+�Q�/�	
��������/�/��3��N�N���	�*9������&������!�!�0�0�2�	�
�
�K�L��r$c�������j��j��j��jd�t	�fd��}�fd�}���fd�}���fd�}|j|�j|�j|�S)N�helloc�4��t�j�dk(SrL)rC�_tempDataBuffer��ts�r"r�z5HalfCloseTests.testCloseWriteCloser.<locals>.<lambda>&s���c�!�"3�"3�4��9�r$c�@���j�t�fd��S)Nc����jSr)�_writeDisconnectedr~s�r"r�zHHalfCloseTests.testCloseWriteCloser.<locals>.loseWrite.<locals>.<lambda>*s
���Q�%9�%9�r$)�loseWriteConnectionr2)r�rs �r"�	loseWritez6HalfCloseTests.testCloseWriteCloser.<locals>.loseWrite(s���
�!�!�#��9�:�:r$c�����j�j��j�j��j�j�t�fd��S)Nc�0���jjSr)rr]�r�s�r"r�zDHalfCloseTests.testCloseWriteCloser.<locals>.check.<locals>.<lambda>0s���Q�Z�Z�%>�%>�r$)r�rsr�r^r]r2)r�r�r�r:s ���r"r#z2HalfCloseTests.testCloseWriteCloser.<locals>.check,sG������V�]�]�+��O�O�F�2�2�3����V�2�2�3��>�?�?r$c����jj}|d�|d��jdt�jj���j�j
jd��j�j
j��j�j
j�y)Nr�slalala fooled yourr{)r7r�r�rCr}rr�r�rsr�r])r��wr�r�r:s  ���r"r�z2HalfCloseTests.testCloseWriteCloser.<locals>.write2s����� � �&�&�A�
�i�L�
�"�#����Q��F�$4�$4�$D�$D� E�F����Q�Z�Z�_�_�h�7����Q�Z�Z�.�.�/��O�O�A�J�J�5�5�6r$)r�r�r7r�r2r,)r:r r�r#r�r�r�rs`    @@@r"�testCloseWriteCloserz#HalfCloseTests.testCloseWriteCloser sn��������F�F������	������9�:��	;�	@�	7��}�}�Y�'�3�3�E�:�F�F�u�M�Mr$c������j��jjj�t	j
t
�fd��t
�fd��g�}|j��fd��|S)Nc�0���jjSr)rr^r�s�r"r�z;HalfCloseTests.testWriteCloseNotification.<locals>.<lambda>Cs���!�*�*�"<�"<�r$c�0���jjSr)r�r]r9s�r"r�z;HalfCloseTests.testWriteCloseNotification.<locals>.<lambda>Ds���$�+�+�"<�"<�r$c�P���j�jjd�S)NF)r�rr])rkr�r:s ��r"r�z;HalfCloseTests.testWriteCloseNotification.<locals>.<lambda>Gs���� 0� 0����1J�1J�E� R�r$)r�rr7r�r	r�r2r,)r:r r�s` @r"�testWriteCloseNotificationz)HalfCloseTests.testWriteCloseNotification=s]����F�F��	�
�
���0�0�2�����<�=��<�=�
�
��	
�
�
�R�S��r$N)
rCrDrErQr7rlr9rtr�r�rFr$r"rfrf�s%��(�
�P��� N�:r$rfc�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�0HalfCloseNoNotificationAndShutdownExceptionTestsc��t�x|_}tj�|j_tjd|d��x|_}tjt
t�j|j�j|j�j�}|j|j �|Sr�)rer�r	r*rbr
r~rarrrr�r�rSrJr,�
_gotClient)r:r�rar s    r"r7z6HalfCloseNoNotificationAndShutdownExceptionTests.setUpLs���$�&�&����(-���(8����%��&�&�q�!�{�C�C����
�"�"�7�,@�A�L�L�
�I�I�K���a�i�i�k�.�.�
��	
�
�
�d�o�o�&��r$c�<�||_|jjSr)r�r�rbrps  r"r�z;HalfCloseNoNotificationAndShutdownExceptionTests._gotClientXs������v�v�,�,�,r$c�~�|jjj�|jj	�Sr)r�r7r8rarKr9s r"r9z9HalfCloseNoNotificationAndShutdownExceptionTests.tearDown_s+�������,�,�.��v�v�#�#�%�%r$c����jjjd��jjj�t	j
�x�jj_}t	j
�x�j_}|j�fd��|j�fd��t	j||g�S)z�
        TCP protocols support half-close connections, but not all of them
        support being notified of write closes.  In this case, test that
        half-closing the connection causes the peer's connection to be
        closed.
        r{c�d���j�jjjd�S)Nr{)r�r�rr�rys �r"r�zUHalfCloseNoNotificationAndShutdownExceptionTests.testNoNotification.<locals>.<lambda>ns"���� 0� 0������1E�1E�x� P�r$c�b���j�jjj�Sr�r�r�rrsrys �r"r�zUHalfCloseNoNotificationAndShutdownExceptionTests.testNoNotification.<locals>.<lambda>o������������0F�0F� G�r$)r�r7r�r�r	r*r�rr^r,r��r:r r1s`  r"�testNoNotificationzCHalfCloseNoNotificationAndShutdownExceptionTests.testNoNotificationcs����	
�����#�#�H�-������1�1�3�-2�^�^�-=�=������&��*/�.�.�*:�:����"�R�	�
�
�P�Q�	�
�
�G�H��"�"�A�r�7�+�+r$c�����jjjj��jjjd��jjj
�tj�x�jj_	}tj�x�j_	}|j�fd��tj||g�S)zx
        If the other side has already closed its connection,
        loseWriteConnection should pass silently.
        r@c�b���j�jjj�Srr�rys �r"r�zXHalfCloseNoNotificationAndShutdownExceptionTests.testShutdownException.<locals>.<lambda>|r�r$)r�rr7r8r�r�r�r	r*r^r,r�r�s`  r"�testShutdownExceptionzFHalfCloseNoNotificationAndShutdownExceptionTests.testShutdownExceptionrs����
	
�����!�!�0�0�2������#�#�D�)������1�1�3�-2�^�^�-=�=������&��*/�.�.�*:�:����"�R�	�
�
�G�H��"�"�A�r�7�+�+r$N)rCrDrEr7r�r9r�r�rFr$r"r�r�Ks��
�-�&�
,�,r$r�c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�HalfCloseBuggyApplicationTestszI
    Test half-closing connections where notification code has bugs.
    c�>��t��_tj��j_tjd�jd���_�j�jj��jj�}tjt
t�}|j|j|j�}�fd�}|j!|�tj"�jj|g�S)z|
        Set up a server and connect a client to it.  Return a Deferred which
        only fires once this is done.
        rr{r|c���|�_yr)r�)r�r:s �r"�	setClientz7HalfCloseBuggyApplicationTests.setUp.<locals>.setClient�s���"0�D�r$)rcr�r	r*rbr
r~rJrrKr�rrr[r�rSr,r�)r:r`�creatorrr�s`    r"r7z$HalfCloseBuggyApplicationTests.setUp�s����
)�]���49�N�N�4D����1��%�%�a��);�);�{�S��	�����	�	�/�/�0��y�y� � �"���(�(��,�?�� �+�+�D�I�I�t�y�y�A��	1�	�"�"�9�-��"�"�
�
�
�
6�
6��G�
�	
r$c��td��)z`
        Fake implementation of a callback which illegally raises an
        exception.
        zONO I AM BUGGY CODEr�)r:rZs  r"�aBugz#HalfCloseBuggyApplicationTests.aBug�s��
�0�1�1r$c����tj�x}�j_�jjj��fd�}|j
|�|S)z~
        Helper for testing that an exception is logged by the time the
        client protocol loses its connection.
        c�f���jt�}�jt|�d�yrl)�flushLoggedErrorsr�r�rC)r��errorsr:s  �r"r#zEHalfCloseBuggyApplicationTests._notificationRaisesTest.<locals>.check�s'����+�+�L�9�F����S��[�!�,r$)r	r*r�r^r7r�r,)r:rsr#s`  r"�_notificationRaisesTestz6HalfCloseBuggyApplicationTests._notificationRaisesTest�sQ���
7<�n�n�6F�F���$�$�3����%�%�9�9�;�	-�	���5�!��
r$c�l�|j|jj_|j	�S)z�
        If C{readConnectionLost} raises an exception when the transport
        calls it to notify the protocol of that event, the exception should
        be logged and the protocol should be disconnected completely.
        )r�r�rr_r�r9s r"�test_readNotificationRaisesz:HalfCloseBuggyApplicationTests.test_readNotificationRaises�s+��:>������#�#�6��+�+�-�-r$c�X�|j|j_|j�S)z�
        If C{writeConnectionLost} raises an exception when the transport
        calls it to notify the protocol of that event, the exception should
        be logged and the protocol should be disconnected completely.
        )r�r�rar�r9s r"�test_writeNotificationRaisesz;HalfCloseBuggyApplicationTests.test_writeNotificationRaises�s%��37�)�)����/��+�+�-�-r$N)	rCrDrErQr7r�r�r�r�rFr$r"r�r��s ���
�*2�
�.�.r$r�c��eZdZdZd�Zy)�LogTestsz4
    Test logging facility of TCP base classes.
    c�0���t�}t�}tj�|_tjd|d��}�j|j�tj|j�j|j�j|���j�j��j�jj d���fd�}|jj#|�|jS)zx
        Check that the log customization of the client transport happens
        once the client is connected.
        rr{r|�
Uninitializedc�R���j�jjd�y)NzAccumulatingProtocol,client)r�r7�logstr)r�ror:s ��r"�cbz+LogTests.test_logstrClientSetup.<locals>.cb�s ������Y�0�0�7�7�9V�Wr$)rergr	r*rbr
r~rrKr�r�rSrJr�r�r7r�r,)r:r�r�rJr�ros`    @r"�test_logstrClientSetupzLogTests.test_logstrClientSetup�s����
!�"�� �"��(-���(8��%�� � ��F�k�B������*�*�+��&�&�t�|�|�~�':�':�D�L�L�N�<O�<O�QW�X�	����	�,�,�-�	
����,�,�3�3�_�E�	X�	�%�%�1�1�"�5��,�,�,r$N)rCrDrErQr�rFr$r"r�r��s���-r$r�c�b�eZdZdZeejje�d�d��Z	y)�PauseProducingTestszG
    Test some behaviors of pausing the production of a transport.
    z#Reactor not providing IReactorFDSetc�����t�}t�}tj�|_tjd|d��}�j|j�tj|j�j|j�j|�}�j|j���fd�}�fd��|jj|�|jS)z�
        In C{connectionMade} of a client protocol, C{pauseProducing} used to be
        ignored: this test is here to ensure it's not ignored.
        rr{r|c����|j}�j|tj�tj�z�|jj��j
|tj�tj�z�tj�}|j��tjd|j|�|SrL)r7�assertInr
�
getReaders�
getWritersr��assertNotInr	r*r,rDr)r�trr �checkAfterConnectionMader:s   ��r"�checkInConnectionMadezVPauseProducingTests.test_pauseProducingInConnectionMade.<locals>.checkInConnectionMade�s�������B��M�M�"�g�0�0�2�W�5G�5G�5I�I�J��O�O�*�*�,����R��!3�!3�!5��8J�8J�8L�!L�M���� �A�
�M�M�2�3����a����U�3��Hr$c���|j}�j|tj�tj�z�yr)r7r�r
r�r�)rr�r:s  �r"r�zYPauseProducingTests.test_pauseProducingInConnectionMade.<locals>.checkAfterConnectionMades3������B����R��!3�!3�!5��8J�8J�8L�!L�Mr$)rergr	r*rbr
r~rrKr�r�rSrJr�r,)r:r�r�rJror�r�s`     @r"�#test_pauseProducingInConnectionMadez7PauseProducingTests.test_pauseProducingInConnectionMade�s����!�"�� �"��(-���(8��%�� � ��F�k�B������*�*�+��&�&�t�|�|�~�':�':�D�L�L�N�<O�<O�QW�X�	����	�,�,�-�		�	N�
	�%�%�1�1�2G�H��,�,�,r$N)
rCrDrErQrr�
IReactorFDSetr�r
r�rFr$r"r�r��s:�����$�$�/�/��8�8�-��!-�	�!-r$r�c��eZdZdZd�Zy)�CallBackOrderTestsz-
    Test the order of reactor callbacks
    c���	�t�}tj�j�fd��|_t��	tj��	_tj��	_�	fd�}�	jj|�tjd|d��}�j|j�tj|j�j|j�j�	�}�j|j�d�}d�}�fd�}tj �	jj|��	j"j|�g�}|j|�S)	zl
        Check that Protocol.connectionLost is called before factory's
        clientConnectionLost
        c�N���j|jj�Sr)rr7r8)rr:s �r"r�z3CallBackOrderTests.test_loseOrder.<locals>.<lambda>s���$�/�/�%�/�/�*H�*H�I�r$c�n��tjd�jjj�y)z:
            protocol.connectionMade callback
            rN)r
rDrr7r8)rr�s �r"�_cbCMz0CallBackOrderTests.test_loseOrder.<locals>._cbCM"s%���
���a����!:�!:�!I�!I�Jr$rr{r|c��y)z?
            factory.clientConnectionLost callback
            �CCLrF�rs r"�_cbCCLz1CallBackOrderTests.test_loseOrder.<locals>._cbCCL0s��r$c��y)z:
            protocol.connectionLost callback
            �CLrFr�s r"�_cbCLz0CallBackOrderTests.test_loseOrder.<locals>._cbCL6s��r$c�.���j|ddg�y)Nr�r�)r�)rr:s �r"�	_cbGatherz4CallBackOrderTests.test_loseOrder.<locals>._cbGather<s������S�4��-�0r$)rer	r*r,rbrgr]r
r~rrKr�r�rSrJr�r�ri)
r:r�r�rJror�r�r�r r�s
`        @r"�test_loseOrderz!CallBackOrderTests.test_loseOrders0���
!�"��(-���(8�(D�(D�I�)
��%�!�"��(-���(8��%�(-���(8��%�	K�	�%�%�1�1�%�8�� � ��F�k�B������*�*�+��&�&�t�|�|�~�':�':�D�L�L�N�<O�<O�QW�X�	����	�,�,�-�	�	�	1�
����-�-�9�9�%�@����+�+�F�3�
�
���}�}�Y�'�'r$N)rCrDrErQr�rFr$r"r�r�s���1(r$r�r��numberRounds)r)[rQrrr�	functoolsr�typingrr�unittestr�zope.interfacerr�r)r	r
rrr
�twisted.internet.addressr�twisted.internet.interfacesrr�twisted.internet.protocolr�twisted.internet.testingr�twisted.protocolsr�twisted.python.logrr�twisted.python.runtimer�twisted.trial.unittestrrr2r4r�rHrSrer2rgryr�r�r0r8r@rOr{rr�r�r�r�r�r�r�r�r�rrrr&r�r*r>rFrJrOrRrUr[rcrfr�r�r�r�r��resource�	getrlimit�
RLIMIT_NOFILE�	numRounds�setattr�ImportErrorrFr$r"�<module>r�s.���

�
�
��%��&��H�H�0�M�.�9�&�'�+�5�
�8*�h�'�'�*�"�X�+�+�"�(4�4�n�,�h�.D�.D���,�h�.D�.D��4DC�X�DC�Na�H�a�H�x�'�'��(�_�(�(>2�8�>2�Bl�h�l�^�8�1�1��%�h�%�P(�X�&�&�(�.�X�&�&��	�(�0�0�	�oN�X�oN�d1�x�0�0�1��8�$�$��-�h�&7�&7�-�*
A�:�
A� p�p�f�h�(?��6
1��0�0�
1�-�8�+�+�-�`
�8�`
�F)�� 1� 1�)�"�� 1� 1��	�X�%;�%;�	�-�(�*�*�-�)��1�1�)�#$�x�#$�L
�
#�$�&�'�&�%�&�"	�(�(�(�	�V�X�V�r2,�x�2,�j@.�X�@.�F-�x�-�>*-�(�*-�Z6(��6(�r@��#��"�"�8�#9�#9�:�1�=��B�I��#�^�Y�?��	�	��	�s�L3�3L;�:L;
¿Qué es la limpieza dental de perros? - Clínica veterinaria


Es la eliminación del sarro y la placa adherida a la superficie de los dientes mediante un equipo de ultrasonidos que garantiza la integridad de las piezas dentales a la vez que elimina en profundidad cualquier resto de suciedad.

A continuación se procede al pulido de los dientes mediante una fresa especial que elimina la placa bacteriana y devuelve a los dientes el aspecto sano que deben tener.

Una vez terminado todo el proceso, se mantiene al perro en observación hasta que se despierta de la anestesia, bajo la atenta supervisión de un veterinario.

¿Cada cuánto tiempo tengo que hacerle una limpieza dental a mi perro?

A partir de cierta edad, los perros pueden necesitar una limpieza dental anual o bianual. Depende de cada caso. En líneas generales, puede decirse que los perros de razas pequeñas suelen acumular más sarro y suelen necesitar una atención mayor en cuanto a higiene dental.


Riesgos de una mala higiene


Los riesgos más evidentes de una mala higiene dental en los perros son los siguientes:

  • Cuando la acumulación de sarro no se trata, se puede producir una inflamación y retracción de las encías que puede descalzar el diente y provocar caídas.
  • Mal aliento (halitosis).
  • Sarro perros
  • Puede ir a más
  • Las bacterias de la placa pueden trasladarse a través del torrente circulatorio a órganos vitales como el corazón ocasionando problemas de endocarditis en las válvulas. Las bacterias pueden incluso acantonarse en huesos (La osteomielitis es la infección ósea, tanto cortical como medular) provocando mucho dolor y una artritis séptica).

¿Cómo se forma el sarro?

El sarro es la calcificación de la placa dental. Los restos de alimentos, junto con las bacterias presentes en la boca, van a formar la placa bacteriana o placa dental. Si la placa no se retira, al mezclarse con la saliva y los minerales presentes en ella, reaccionará formando una costra. La placa se calcifica y se forma el sarro.

El sarro, cuando se forma, es de color blanquecino pero a medida que pasa el tiempo se va poniendo amarillo y luego marrón.

Síntomas de una pobre higiene dental
La señal más obvia de una mala salud dental canina es el mal aliento.

Sin embargo, a veces no es tan fácil de detectar
Y hay perros que no se dejan abrir la boca por su dueño. Por ejemplo…

Recientemente nos trajeron a la clínica a un perro que parpadeaba de un ojo y decía su dueño que le picaba un lado de la cara. Tenía molestias y dificultad para comer, lo que había llevado a sus dueños a comprarle comida blanda (que suele ser un poco más cara y llevar más contenido en grasa) durante medio año. Después de una exploración oftalmológica, nos dimos cuenta de que el ojo tenía una úlcera en la córnea probablemente de rascarse . Además, el canto lateral del ojo estaba inflamado. Tenía lo que en humanos llamamos flemón pero como era un perro de pelo largo, no se le notaba a simple vista. Al abrirle la boca nos llamó la atención el ver una muela llena de sarro. Le realizamos una radiografía y encontramos una fístula que llegaba hasta la parte inferior del ojo.

Le tuvimos que extraer la muela. Tras esto, el ojo se curó completamente con unos colirios y una lentilla protectora de úlcera. Afortunadamente, la úlcera no profundizó y no perforó el ojo. Ahora el perro come perfectamente a pesar de haber perdido una muela.

¿Cómo mantener la higiene dental de tu perro?
Hay varias maneras de prevenir problemas derivados de la salud dental de tu perro.

Limpiezas de dientes en casa
Es recomendable limpiar los dientes de tu perro semanal o diariamente si se puede. Existe una gran variedad de productos que se pueden utilizar:

Pastas de dientes.
Cepillos de dientes o dedales para el dedo índice, que hacen más fácil la limpieza.
Colutorios para echar en agua de bebida o directamente sobre el diente en líquido o en spray.

En la Clínica Tus Veterinarios enseñamos a nuestros clientes a tomar el hábito de limpiar los dientes de sus perros desde que son cachorros. Esto responde a nuestro compromiso con la prevención de enfermedades caninas.

Hoy en día tenemos muchos clientes que limpian los dientes todos los días a su mascota, y como resultado, se ahorran el dinero de hacer limpiezas dentales profesionales y consiguen una mejor salud de su perro.


Limpiezas dentales profesionales de perros y gatos

Recomendamos hacer una limpieza dental especializada anualmente. La realizamos con un aparato de ultrasonidos que utiliza agua para quitar el sarro. Después, procedemos a pulir los dientes con un cepillo de alta velocidad y una pasta especial. Hacemos esto para proteger el esmalte.

La frecuencia de limpiezas dentales necesaria varía mucho entre razas. En general, las razas grandes tienen buena calidad de esmalte, por lo que no necesitan hacerlo tan a menudo e incluso pueden pasarse la vida sin requerir una limpieza. Sin embargo, razas pequeñas como el Yorkshire o el Maltés, deben hacérselas todos los años desde cachorros si se quiere conservar sus piezas dentales.

Otro factor fundamental es la calidad del pienso. Algunas marcas han diseñado croquetas que limpian la superficie del diente y de la muela al masticarse.

Ultrasonido para perros

¿Se necesita anestesia para las limpiezas dentales de perros y gatos?

La limpieza dental en perros no es una técnica que pueda practicarse sin anestesia general , aunque hay veces que los propietarios no quieren anestesiar y si tiene poco sarro y el perro es muy bueno se puede intentar…… , pero no se va a poder pulir ni acceder a todas la zona de la boca …. Además los limpiadores dentales van a irrigar agua y hay riesgo de aspiración a vías respiratorias si no se realiza una anestesia correcta con intubación traqueal . En resumen , sin anestesia no se va hacer una correcta limpieza dental.

Tampoco sirve la sedación ya que necesitamos que el animal esté totalmente quieto, y el veterinario tenga un acceso completo a todas sus piezas dentales y encías.

Alimentos para la limpieza dental

Hay que tener cierto cuidado a la hora de comprar determinados alimentos porque no todos son saludables. Algunos tienen demasiado contenido graso, que en exceso puede causar problemas cardiovasculares y obesidad.

Los mejores alimentos para los dientes son aquellos que están elaborados por empresas farmacéuticas y llevan componentes químicos con tratamientos específicos para el diente del perro. Esto implica no solo limpieza a través de la acción mecánica de morder sino también un tratamiento antibacteriano para prevenir el sarro.

Conclusión

Si eres como la mayoría de dueños, por falta de tiempo , es probable que no estés prestando la suficiente atención a la limpieza dental de tu perro. Por eso te animamos a que comiences a limpiar los dientes de tu perro y consideres atender a su higiene bucal con frecuencia.

Estas simples medidas pueden conllevar a que tu perro tenga una vida más larga y mucho más saludable.

Si te resulta imposible introducir un cepillo de dientes a tu perro en la boca, pásate con él por clínica Tus Veterinarios y te explicamos cómo hacerlo.

Necesitas hacer una limpieza dental profesional a tu mascota?
Llámanos al 622575274 o contacta con nosotros

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

¡Hola!