Ë
    ojVH  ã                   ó  — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
mZmZmZ ddlmZmZmZmZmZmZ ddlmZmZ dd	lmZmZ dd
lmZ ddlmZ  G d„ de«      Z G d„ de«      Z  G d„ de«      Z! G d„ de«      Z" G d„ de«      Z#y)z)
Tests for L{twisted.internet.protocol}.
é    )ÚBytesIO)Úimplementer)ÚverifyObject)ÚCancelledError)Ú	IConsumerÚILoggingContextÚ	IProtocolÚIProtocolFactory)ÚClientCreatorÚConsumerToProtocolAdapterÚFactoryÚFileWrapperÚProtocolÚProtocolToConsumerAdapter)ÚMemoryReactorClockÚStringTransport)ÚLogLevelÚglobalLogPublisher)ÚFailure)ÚTestCasec                   óp   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚClientCreatorTestsz?
    Tests for L{twisted.internet.protocol.ClientCreator}.
    c                 ó¦   —  G d„ dt         «      }t        «       }t        ||«      } |||«      }|j                  d«      }| j	                  ||«       y)a  
        Helper for implementing a test to verify that one of the I{connect}
        methods of L{ClientCreator} passes the right arguments to the right
        reactor method.

        @param check: A function which will be invoked with a reactor and a
            L{ClientCreator} instance and which should call one of the
            L{ClientCreator}'s I{connect} methods and assert that all of its
            arguments except for the factory are passed on as expected to the
            reactor.  The factory should be returned.
        c                   ó   — e Zd Zy)ú:ClientCreatorTests._basicConnectTest.<locals>.SomeProtocolN©Ú__name__Ú
__module__Ú__qualname__© ó    úE/usr/lib/python3/dist-packages/twisted/internet/test/test_protocol.pyÚSomeProtocolr   5   ó   „ Ør!   r#   N)r   r   r   ÚbuildProtocolÚassertIsInstance)ÚselfÚcheckr#   ÚreactorÚccÚfactoryÚprotocols          r"   Ú_basicConnectTestz$ClientCreatorTests._basicConnectTest(   sP   € ô	œ8ô 	ô %Ó&ˆÜ˜7 LÓ1ˆÙ˜ Ó$ˆØ×(Ñ(¨Ó.ˆØ×Ñ˜h¨Õ5r!   c                 ó2   ‡ — ˆ fd„}‰ j                  |«       y)zä
        L{ClientCreator.connectTCP} calls C{reactor.connectTCP} with the host
        and port information passed to it, and with a factory which will
        construct the protocol passed to L{ClientCreator.__init__}.
        c                 ó   •— |j                  dddd«       | j                  j                  «       \  }}}}}‰j                  |d«       ‰j                  |d«       ‰j                  |d«       ‰j                  |d«       |S )Núexample.coméÒ  éá  )z1.2.3.4i”&  )Ú
connectTCPÚ
tcpClientsÚpopÚassertEqual)r)   r*   ÚhostÚportr+   ÚtimeoutÚbindAddressr'   s          €r"   r(   z1ClientCreatorTests.test_connectTCP.<locals>.checkE   s{   ø€ Ø�M‰M˜-¨¨tÐ5FÔGØ8?×8JÑ8J×8NÑ8NÓ8PÑ5ˆD�$˜ ¨+Ø×Ñ˜T =Ô1Ø×Ñ˜T 4Ô(Ø×Ñ˜W dÔ+Ø×Ñ˜[Ð*;Ô<ØˆNr!   N©r-   ©r'   r(   s   ` r"   Útest_connectTCPz"ClientCreatorTests.test_connectTCP>   s   ø€ ô	ð 	×Ñ˜uÕ%r!   c                 ó2   ‡ — ˆ fd„}‰ j                  |«       y)zÕ
        L{ClientCreator.connectUNIX} calls C{reactor.connectUNIX} with the
        filename passed to it, and with a factory which will construct the
        protocol passed to L{ClientCreator.__init__}.
        c                 óÖ   •— |j                  ddd«       | j                  j                  «       \  }}}}‰j                  |d«       ‰j                  |d«       ‰j	                  |«       |S )Nú/foo/baré{   T)ÚconnectUNIXÚunixClientsr5   r6   Ú
assertTrue)r)   r*   Úaddressr+   r9   ÚcheckPIDr'   s         €r"   r(   z2ClientCreatorTests.test_connectUNIX.<locals>.checkW   sa   ø€ Ø�N‰N˜: s¨DÔ1Ø29×2EÑ2E×2IÑ2IÓ2KÑ/ˆG�W˜g xØ×Ñ˜W jÔ1Ø×Ñ˜W cÔ*Ø�O‰O˜HÔ%ØˆNr!   Nr;   r<   s   ` r"   Útest_connectUNIXz#ClientCreatorTests.test_connectUNIXP   s   ø€ ô	ð 	×Ñ˜uÕ%r!   c                 ó2   ‡ — ˆ fd„}‰ j                  |«       y)zê
        L{ClientCreator.connectSSL} calls C{reactor.connectSSL} with the host,
        port, and context factory passed to it, and with a factory which will
        construct the protocol passed to L{ClientCreator.__init__}.
        c                 ó<  •— t        «       }|j                  dd|dd«       | j                  j                  «       \  }}}}}}‰	j	                  |d«       ‰	j	                  |d«       ‰	j                  ||«       ‰	j	                  |d«       ‰	j	                  |d«       |S )Nr0   r1   r2   )z4.3.2.1i.  )ÚobjectÚ
connectSSLÚ
sslClientsr5   r6   ÚassertIs)
r)   r*   ÚexpectedContextFactoryr7   r8   r+   ÚcontextFactoryr9   r:   r'   s
            €r"   r(   z1ClientCreatorTests.test_connectSSL.<locals>.checkh   s¤   ø€ Ü%+£XÐ"Ø�M‰MØ˜tÐ%;¸TÐCTôð ×"Ñ"×&Ñ&Ó(ñØØØØØØà×Ñ˜T =Ô1Ø×Ñ˜T 4Ô(Ø�M‰M˜.Ð*@ÔAØ×Ñ˜W dÔ+Ø×Ñ˜[Ð*;Ô<ØˆNr!   Nr;   r<   s   ` r"   Útest_connectSSLz"ClientCreatorTests.test_connectSSLa   s   ø€ ô	ð( 	×Ñ˜uÕ%r!   c                 ó2  — t        «       }t        |t        «      } ||«      }|j                  j	                  «       }| j                  |j                  «       |j                  «        | j                  |j                  «       | j                  |t        «      S )a  
        Helper for implementing a test to verify that cancellation of the
        L{Deferred} returned by one of L{ClientCreator}'s I{connect} methods is
        implemented to cancel the underlying connector.

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

        @return: A L{Deferred} which fires when the test is complete or fails if
            there is a problem.
        )r   r   r   Ú
connectorsr5   ÚassertFalseÚ_disconnectedÚcancelrD   ÚassertFailurer   ©r'   Úconnectr)   r*   ÚdÚ	connectors         r"   Ú_cancelConnectTestz%ClientCreatorTests._cancelConnectTest~   sw   € ô %Ó&ˆÜ˜7¤HÓ-ˆÙ�B‹KˆØ×&Ñ&×*Ñ*Ó,ˆ	Ø×Ñ˜×0Ñ0Ô1Ø	�‰Œ
Ø�‰˜	×/Ñ/Ô0Ø×!Ñ! !¤^Ó4Ð4r!   c                 ó*   — d„ }| j                  |«      S )ú—
        The L{Deferred} returned by L{ClientCreator.connectTCP} can be cancelled
        to abort the connection attempt before it completes.
        c                 ó&   — | j                  dd«      S ©Nr0   r1   )r3   ©r*   s    r"   rX   z9ClientCreatorTests.test_cancelConnectTCP.<locals>.connectš   s   € Ø—=‘= °Ó5Ð5r!   ©r[   ©r'   rX   s     r"   Útest_cancelConnectTCPz(ClientCreatorTests.test_cancelConnectTCP”   s   € ò	6ð ×&Ñ& wÓ/Ð/r!   c                 ó*   — d„ }| j                  |«      S )r]   c                 ó$   — | j                  d«      S ©Nr@   )rB   r`   s    r"   rX   z:ClientCreatorTests.test_cancelConnectUNIX.<locals>.connect¥   s   € Ø—>‘> *Ó-Ð-r!   ra   rb   s     r"   Útest_cancelConnectUNIXz)ClientCreatorTests.test_cancelConnectUNIXŸ   s   € ò	.ð ×&Ñ& wÓ/Ð/r!   c                 ó*   — d„ }| j                  |«      S )r]   c                 ó8   — | j                  ddt        «       «      S r_   )rK   rJ   r`   s    r"   rX   z9ClientCreatorTests.test_cancelConnectSSL.<locals>.connect°   s   € Ø—=‘= °´f³hÓ?Ð?r!   ra   rb   s     r"   Útest_cancelConnectSSLz(ClientCreatorTests.test_cancelConnectSSLª   s   € ò	@ð ×&Ñ& wÓ/Ð/r!   c                 ó�  — t        «       }t        |t        «      } |||«      }|j                  j	                  «       }| j                  t        |j                  «       «      d«       |j                  «        | j                  |j                  «       g «       | j                  |j                  «       | j                  |t        «      S )zÍ
        Like L{_cancelConnectTest}, but for the case where the L{Deferred} is
        cancelled after the connection is set up but before it is fired with the
        resulting protocol instance.
        é   )r   r   r   rR   r5   r6   ÚlenÚgetDelayedCallsrU   rD   rT   rV   r   rW   s         r"   Ú_cancelConnectTimeoutTestz,ClientCreatorTests._cancelConnectTimeoutTestµ   s£   € ô %Ó&ˆÜ˜7¤HÓ-ˆÙ�G˜RÓ ˆØ×&Ñ&×*Ñ*Ó,ˆ	ð 	×Ñœ˜W×4Ñ4Ó6Ó7¸Ô;ð 	
�‰Œ
à×Ñ˜×0Ñ0Ó2°BÔ7ð
 	�‰˜	×/Ñ/Ô0à×!Ñ! !¤^Ó4Ð4r!   c                 ó*   — d„ }| j                  |«      S )a¡  
        L{ClientCreator.connectTCP} inserts a very short delayed call between
        the time the connection is established and the time the L{Deferred}
        returned from one of its connect methods actually fires.  If the
        L{Deferred} is cancelled in this interval, the established connection is
        closed, the timeout is cancelled, and the L{Deferred} fails with
        L{CancelledError}.
        c                 óÂ   — |j                  dd«      }| j                  j                  «       \  }}}}}|j                  d «      }t	        «       }	|j                  |	«       |S r_   )r3   r4   r5   r%   r   ÚmakeConnection)
r)   r*   rY   r7   r8   r+   r9   r:   r,   Ú	transports
             r"   rX   z@ClientCreatorTests.test_cancelConnectTCPTimeout.<locals>.connectÚ   s\   € Ø—‘˜m¨TÓ2ˆAØ8?×8JÑ8J×8NÑ8NÓ8PÑ5ˆD�$˜ ¨+Ø×,Ñ,¨TÓ2ˆHÜ'Ó)ˆIØ×#Ñ# IÔ.ØˆHr!   ©ro   rb   s     r"   Útest_cancelConnectTCPTimeoutz/ClientCreatorTests.test_cancelConnectTCPTimeoutÐ   ó   € ò	ð ×-Ñ-¨gÓ6Ð6r!   c                 ó*   — d„ }| j                  |«      S )a¢  
        L{ClientCreator.connectUNIX} inserts a very short delayed call between
        the time the connection is established and the time the L{Deferred}
        returned from one of its connect methods actually fires.  If the
        L{Deferred} is cancelled in this interval, the established connection is
        closed, the timeout is cancelled, and the L{Deferred} fails with
        L{CancelledError}.
        c                 ó¾   — |j                  d«      }| j                  j                  «       \  }}}}|j                  d «      }t	        «       }|j                  |«       |S rf   )rB   rC   r5   r%   r   rr   )	r)   r*   rY   rE   r+   r9   r:   r,   rs   s	            r"   rX   zAClientCreatorTests.test_cancelConnectUNIXTimeout.<locals>.connectî   sX   € Ø—‘˜zÓ*ˆAØ5<×5HÑ5H×5LÑ5LÓ5NÑ2ˆG�W˜g {Ø×,Ñ,¨TÓ2ˆHÜ'Ó)ˆIØ×#Ñ# IÔ.ØˆHr!   rt   rb   s     r"   Útest_cancelConnectUNIXTimeoutz0ClientCreatorTests.test_cancelConnectUNIXTimeoutä   rv   r!   c                 ó*   — d„ }| j                  |«      S )a¡  
        L{ClientCreator.connectSSL} inserts a very short delayed call between
        the time the connection is established and the time the L{Deferred}
        returned from one of its connect methods actually fires.  If the
        L{Deferred} is cancelled in this interval, the established connection is
        closed, the timeout is cancelled, and the L{Deferred} fails with
        L{CancelledError}.
        c                 óÖ   — |j                  ddt        «       «      }| j                  j                  «       \  }}}}}}|j	                  d «      }	t        «       }
|	j                  |
«       |S r_   )rK   rJ   rL   r5   r%   r   rr   )r)   r*   rY   r7   r8   r+   rO   r9   ÚbindADdressr,   rs   s              r"   rX   z@ClientCreatorTests.test_cancelConnectSSLTimeout.<locals>.connect  sl   € Ø—‘˜m¨T´6³8Ó<ˆAð ×"Ñ"×&Ñ&Ó(ñØØØØØØà×,Ñ,¨TÓ2ˆHÜ'Ó)ˆIØ×#Ñ# IÔ.ØˆHr!   rt   rb   s     r"   Útest_cancelConnectSSLTimeoutz/ClientCreatorTests.test_cancelConnectSSLTimeoutø   s   € ò	ð ×-Ñ-¨gÓ6Ð6r!   c                 ó¨  — t        «       }t        |t        «      } |||«      \  }}|j                  j	                  «       }|j                  |t        t        d«      «      «       | j                  t        |j                  «       «      d«       |j                  «        | j                  |j                  «       g «       | j                  |t        «      S )zÌ
        Like L{_cancelConnectTest}, but for the case where the L{Deferred} is
        cancelled after the connection attempt has failed but before it is fired
        with the resulting failure.
        zSimulated failurerl   )r   r   r   rR   r5   ÚclientConnectionFailedr   Ú	Exceptionr6   rm   rn   rU   rV   r   )r'   rX   r)   r*   rY   r+   rZ   s          r"   Ú_cancelConnectFailedTimeoutTestz2ClientCreatorTests._cancelConnectFailedTimeoutTest  s±   € ô %Ó&ˆÜ˜7¤HÓ-ˆÙ˜W bÓ)‰
ˆˆ7Ø×&Ñ&×*Ñ*Ó,ˆ	Ø×&Ñ&Ø”wœyÐ)<Ó=Ó>ô	
ð 	×Ñœ˜W×4Ñ4Ó6Ó7¸Ô;ð 	
�‰Œ
à×Ñ˜×0Ñ0Ó2°BÔ7à×!Ñ! !¤^Ó4Ð4r!   c                 ó*   — d„ }| j                  |«      S )zz
        Similar to L{test_cancelConnectTCPTimeout}, but for the case where the
        connection attempt fails.
        c                 ón   — |j                  dd«      }| j                  j                  «       \  }}}}}||fS r_   )r3   r4   r5   )r)   r*   rY   r7   r8   r+   r9   r:   s           r"   rX   zFClientCreatorTests.test_cancelConnectTCPFailedTimeout.<locals>.connect2  s;   € Ø—‘˜m¨TÓ2ˆAØ8?×8JÑ8J×8NÑ8NÓ8PÑ5ˆD�$˜ ¨+Ø�g�:Ðr!   ©r�   rb   s     r"   Ú"test_cancelConnectTCPFailedTimeoutz5ClientCreatorTests.test_cancelConnectTCPFailedTimeout,  ó   € ò	ð
 ×3Ñ3°GÓ<Ð<r!   c                 ó*   — d„ }| j                  |«      S )z{
        Similar to L{test_cancelConnectUNIXTimeout}, but for the case where the
        connection attempt fails.
        c                 ój   — |j                  d«      }| j                  j                  «       \  }}}}||fS rf   )rB   rC   r5   )r)   r*   rY   rE   r+   r9   r:   s          r"   rX   zGClientCreatorTests.test_cancelConnectUNIXFailedTimeout.<locals>.connect?  s7   € Ø—‘˜zÓ*ˆAØ5<×5HÑ5H×5LÑ5LÓ5NÑ2ˆG�W˜g {Ø�g�:Ðr!   r„   rb   s     r"   Ú#test_cancelConnectUNIXFailedTimeoutz6ClientCreatorTests.test_cancelConnectUNIXFailedTimeout9  r†   r!   c                 ó*   — d„ }| j                  |«      S )zz
        Similar to L{test_cancelConnectSSLTimeout}, but for the case where the
        connection attempt fails.
        c                 ó‚   — |j                  ddt        «       «      }| j                  j                  «       \  }}}}}}||fS r_   )rK   rJ   rL   r5   )	r)   r*   rY   r7   r8   r+   rO   r9   r|   s	            r"   rX   zFClientCreatorTests.test_cancelConnectSSLFailedTimeout.<locals>.connectL  sK   € Ø—‘˜m¨T´6³8Ó<ˆAð ×"Ñ"×&Ñ&Ó(ñØØØØØØà�g�:Ðr!   r„   rb   s     r"   Ú"test_cancelConnectSSLFailedTimeoutz5ClientCreatorTests.test_cancelConnectSSLFailedTimeoutF  s   € ò
	ð ×3Ñ3°GÓ<Ð<r!   N)r   r   r   Ú__doc__r-   r=   rG   rP   r[   rc   rg   rj   ro   ru   ry   r}   r�   r…   r‰   rŒ   r    r!   r"   r   r   #   sW   „ ñò6ò,&ò$&ò"&ò:5ò,	0ò	0ò	0ò5ò67ò(7ò(7ò65ò2=ò=ó=r!   r   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)ÚProtocolTestsz:
    Tests for L{twisted.internet.protocol.Protocol}.
    c                 ó”   — t        «       }| j                  t        t        |«      «       | j                  t        t        |«      «       y)zT
        L{Protocol} instances provide L{IProtocol} and L{ILoggingContext}.
        N)r   rD   r   r	   r   )r'   Úprotos     r"   Útest_interfaceszProtocolTests.test_interfaces`  s1   € ô “
ˆØ�‰œ¤Y°Ó6Ô7Ø�‰œ¤_°eÓ<Õ=r!   c                 ól   —  G d„ dt         «      }| j                  d |«       j                  «       «       y)zJ
        L{Protocol.logPrefix} returns the protocol class's name.
        c                   ó   — e Zd Zy)ú/ProtocolTests.test_logPrefix.<locals>.SomeThingNr   r    r!   r"   Ú	SomeThingr•   m  r$   r!   r–   N)r   r6   Ú	logPrefix)r'   r–   s     r"   Útest_logPrefixzProtocolTests.test_logPrefixh  s+   € ô
	œô 	ð 	×Ñ˜¡i£k×&;Ñ&;Ó&=Õ>r!   c                 ó–   ‡— g Š G ˆfd„dt         «      }t        «       } |«       }|j                  |«       | j                  ‰|g«       y)zz
        L{Protocol.makeConnection} sets the given transport on itself, and
        then calls C{connectionMade}.
        c                   ó   •— e Zd Zˆ fd„Zy)ú7ProtocolTests.test_makeConnection.<locals>.SomeProtocolc                 ó<   •— ‰j                  | j                  «       y ©N)Úappendrs   )r'   Úresults    €r"   ÚconnectionMadezFProtocolTests.test_makeConnection.<locals>.SomeProtocol.connectionMadez  s   ø€ Ø—‘˜dŸn™nÕ-r!   N)r   r   r   r    ©rŸ   s   €r"   r#   r›   y  s   ø„ õ.r!   r#   N)r   rJ   rr   r6   )r'   r#   rs   r,   rŸ   s       @r"   Útest_makeConnectionz!ProtocolTests.test_makeConnectionr  sF   ø€ ð
 ˆö	.œ8ô 	.ô “Hˆ	Ù“>ˆØ×Ñ 	Ô*Ø×Ñ˜ ) Õ-r!   N)r   r   r   r�   r’   r˜   r¢   r    r!   r"   r�   r�   [  s   „ ñò>ò?ó.r!   r�   c                   ó4   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)	ÚFactoryTestsz(
    Tests for L{protocol.Factory}.
    c                 ó”   — t        «       }| j                  t        t        |«      «       | j                  t        t        |«      «       y)zg
        L{Factory} instances provide both L{IProtocolFactory} and
        L{ILoggingContext}.
        N)r   rD   r   r
   r   )r'   r+   s     r"   r’   zFactoryTests.test_interfacesˆ  s2   € ô
 “)ˆØ�‰œÔ%5°wÓ?Ô@Ø�‰œ¤_°gÓ>Õ?r!   c                 ól   —  G d„ dt         «      }| j                  d |«       j                  «       «       y)zM
        L{Factory.logPrefix} returns the name of the factory class.
        c                   ó   — e Zd Zy)ú6FactoryTests.test_logPrefix.<locals>.SomeKindOfFactoryNr   r    r!   r"   ÚSomeKindOfFactoryr¨   –  r$   r!   r©   N)r   r6   r—   )r'   r©   s     r"   r˜   zFactoryTests.test_logPrefix‘  s.   € ô
	¤ô 	ð 	×ÑÐ,Ñ.?Ó.A×.KÑ.KÓ.MÕNr!   c                 óÂ   —  G d„ dt         «      }t        «       }||_        |j                  d«      }| j	                  ||«       | j                  |j                  |«       y)z¡
        L{Factory.buildProtocol} by default constructs a protocol by calling
        its C{protocol} attribute, and attaches the factory to the result.
        c                   ó   — e Zd Zy)ú<FactoryTests.test_defaultBuildProtocol.<locals>.SomeProtocolNr   r    r!   r"   r#   r¬   ¡  r$   r!   r#   N)r   r   r,   r%   r&   rM   r+   )r'   r#   Úfr,   s       r"   Útest_defaultBuildProtocolz&FactoryTests.test_defaultBuildProtocol›  sP   € ô	œ8ô 	ô ‹IˆØ!ˆŒ
Ø—?‘? 4Ó(ˆØ×Ñ˜h¨Ô5Ø�‰�h×&Ñ&¨Õ*r!   c                 ó  —  G d„ dt         «      }|j                  t        ddd¬«      }| j                  |j                  t        «       | j                  |j
                  d«       | j                  |j                  ddi«       y	)
z¹
        L{Factory.forProtocol} constructs a Factory, passing along any
        additional arguments, and sets its C{protocol} attribute to the given
        Protocol subclass.
        c                   ó   — e Zd Zd„ Zy)ú7FactoryTests.test_forProtocol.<locals>.ArgTakingFactoryc                 ó"   — ||c| _         | _        y r�   )ÚargsÚkwargs)r'   r³   r´   s      r"   Ú__init__z@FactoryTests.test_forProtocol.<locals>.ArgTakingFactory.__init__²  s   € Ø)-¨vÐ&�”	˜4�;r!   N)r   r   r   rµ   r    r!   r"   ÚArgTakingFactoryr±   ±  s   „ ó6r!   r¶   rl   é   é   )Úfoo)rl   r·   r¹   N)r   ÚforProtocolr   r6   r,   r³   r´   )r'   r¶   r+   s      r"   Útest_forProtocolzFactoryTests.test_forProtocolª  sk   € ô	6œwô 	6ð #×.Ñ.¬x¸¸AÀ2Ð.ÓFˆØ×Ñ˜×)Ñ)¬8Ô4Ø×Ñ˜Ÿ™ vÔ.Ø×Ñ˜Ÿ™¨%°¨Õ5r!   c                 óP  ‡— g Št        j                  ‰j                  «       | j                  ˆfd„«       t	        «       }|j                  «        | j                  ‰d   d   |«       | j                  ‰d   d   t        j                  «       | j                  ‰d   d   d«       y)zš
        L{Factory.doStart} logs that it is starting a factory, followed by
        the L{repr} of the L{Factory} instance that is being started.
        c                  óB   •— t        j                  ‰ j                  «      S r�   ©r   ÚremoveObserverrž   ©Úeventss   €r"   ú<lambda>z;FactoryTests.test_doStartLoggingStatement.<locals>.<lambda>Á  ó   ø€ Ô 2× AÑ AÀ&Ç-Á-Ó P€ r!   r   r+   Ú	log_levelÚ
log_formatzStarting factory {factory!r}N)
r   ÚaddObserverrž   Ú
addCleanupr   ÚdoStartrM   r6   r   Úinfo)r'   r­   rÁ   s     @r"   Útest_doStartLoggingStatementz)FactoryTests.test_doStartLoggingStatementº  s‡   ø€ ð
 ˆÜ×&Ñ& v§}¡}Ô5Ø�‰ÓPÔQä‹IˆØ	�	‰	Œà�‰�f˜Q‘i 	Ñ*¨AÔ.Ø×Ñ˜ ™ ;Ñ/´·±Ô?Ø×Ñ˜ ™ <Ñ0Ð2PÕQr!   c                 óh  ‡— g Št        j                  ‰j                  «       | j                  ˆfd„«        G d„ dt        «      } |«       }|j                  «        | j                  ‰d   d   |«       | j                  ‰d   d   t        j                  «       | j                  ‰d   d   d«       y	)
z™
        L{Factory.doStop} logs that it is stopping a factory, followed by
        the L{repr} of the L{Factory} instance that is being stopped.
        c                  óB   •— t        j                  ‰ j                  «      S r�   r¾   rÀ   s   €r"   rÂ   z:FactoryTests.test_doStopLoggingStatement.<locals>.<lambda>Ñ  rÃ   r!   c                   ó   — e Zd ZdZy)ú;FactoryTests.test_doStopLoggingStatement.<locals>.MyFactoryrl   N)r   r   r   ÚnumPortsr    r!   r"   Ú	MyFactoryrÎ   Ó  s   „ Ø‰Hr!   rÐ   r   r+   rÄ   rÅ   zStopping factory {factory!r}N)
r   rÆ   rž   rÇ   r   ÚdoStoprM   r6   r   rÉ   )r'   rÐ   r­   rÁ   s      @r"   Útest_doStopLoggingStatementz(FactoryTests.test_doStopLoggingStatementÊ  s•   ø€ ð
 ˆÜ×&Ñ& v§}¡}Ô5Ø�‰ÓPÔQô	œô 	ñ ‹KˆØ	�‰Œ
à�‰�f˜Q‘i 	Ñ*¨AÔ.Ø×Ñ˜ ™ ;Ñ/´·±Ô?Ø×Ñ˜ ™ <Ñ0Ð2PÕQr!   N)
r   r   r   r�   r’   r˜   r®   r»   rÊ   rÒ   r    r!   r"   r¤   r¤   ƒ  s)   „ ñò@òOò+ò6ò Ró Rr!   r¤   c                   ó   — e Zd ZdZd„ Zd„ Zy)ÚAdapterTestszR
    Tests for L{ProtocolToConsumerAdapter} and L{ConsumerToProtocolAdapter}.
    c                 óÈ   — g }t        «       }|j                  |_        t        |«      }|j	                  d«       | j                  |dg«       | j                  |t        «       y)z}
        L{IProtocol} providers can be adapted to L{IConsumer} providers using
        L{ProtocolToConsumerAdapter}.
        ó   helloN)r   rž   ÚdataReceivedr   Úwriter6   r&   r   )r'   rŸ   ÚpÚconsumers       r"   Útest_protocolToConsumerz$AdapterTests.test_protocolToConsumerã  sS   € ð
 ˆÜ‹JˆØŸ™ˆŒÜ˜Q“<ˆØ�‰�xÔ Ø×Ñ˜ ( Ô,Ø×Ñ˜hÔ(AÕBr!   c                 óÞ   ‡— g Št        t        «       G ˆfd„d«      «       } |«       }t        |«      }|j                  d«       | j	                  ‰dg«       | j                  |t        «       y)z}
        L{IConsumer} providers can be adapted to L{IProtocol} providers using
        L{ProtocolToConsumerAdapter}.
        c                   ó   •— e Zd Zˆ fd„Zy)ú6AdapterTests.test_consumerToProtocol.<locals>.Consumerc                 ó(   •— ‰j                  |«       y r�   )rž   )r'   rY   rŸ   s     €r"   rØ   z<AdapterTests.test_consumerToProtocol.<locals>.Consumer.writeù  s   ø€ Ø—‘˜aÕ r!   N)r   r   r   rØ   r¡   s   €r"   ÚConsumerrÞ   ÷  s   ø„ õ!r!   rà   rÖ   N)r   r   r	   r×   r6   r&   r   )r'   rà   Úcr,   rŸ   s       @r"   Útest_consumerToProtocolz$AdapterTests.test_consumerToProtocolð  si   ø€ ð
 ˆä	”YÓ	÷	!ò 	!ó 
 ð	!ñ ‹JˆÜ˜Q“<ˆØ×Ñ˜hÔ'Ø×Ñ˜ ( Ô,Ø×Ñ˜hÔ(AÕBr!   N)r   r   r   r�   rÛ   râ   r    r!   r"   rÔ   rÔ   Þ  s   „ ñòCóCr!   rÔ   c                   ó   — e Zd ZdZd„ Zd„ Zy)ÚFileWrapperTestsz2
    L{twisted.internet.protocol.FileWrapper}
    c                 ó<  — t        t        «       «      }|j                  d«       | j                  |j                  j                  «       d«       t        t        «       «      }|j                  d«       | j                  |j                  j                  «       d«       y)z@
        L{twisted.internet.protocol.FileWrapper.write}
        ó   test1ÚstuffN)r   r   rØ   r6   ÚfileÚgetvalueÚassertNotEqual©r'   Úwrappers     r"   Ú
test_writezFileWrapperTests.test_write  sp   € ô œg›iÓ(ˆØ�‰�hÔØ×Ñ˜Ÿ™×.Ñ.Ó0°(Ô;äœg›iÓ(ˆð 	�‰�gÔØ×Ñ˜GŸL™L×1Ñ1Ó3°WÕ=r!   c                 ó  — t        t        «       «      }|j                  ddg«       | j                  |j                  j                  «       d«       t        t        «       «      }| j                  t        |j                  ddg«       y)zH
        L{twisted.internet.protocol.FileWrapper.writeSequence}
        ræ   s   test2s
   test1test2Útest3Útest4N)r   r   ÚwriteSequencer6   rè   ré   ÚassertRaisesÚ	TypeErrorrë   s     r"   Útest_writeSequencez#FileWrapperTests.test_writeSequence  si   € ô œg›iÓ(ˆØ×Ñ˜x¨Ð2Ô3Ø×Ñ˜Ÿ™×.Ñ.Ó0°-Ô@äœg›iÓ(ˆà×Ñœ) W×%:Ñ%:¸WÀgÐ<NÕOr!   N)r   r   r   r�   rí   rô   r    r!   r"   rä   rä     s   „ ñò>ó
Pr!   rä   N)$r�   Úior   Úzope.interfacer   Úzope.interface.verifyr   Útwisted.internet.deferr   Útwisted.internet.interfacesr   r   r	   r
   Útwisted.internet.protocolr   r   r   r   r   r   Útwisted.internet.testingr   r   Útwisted.loggerr   r   Útwisted.python.failurer   Útwisted.trial.unittestr   r   r�   r¤   rÔ   rä   r    r!   r"   ú<module>rÿ      s…   ðñõ
 å &Ý .å 1÷ó ÷÷ ÷ Iß 7Ý *Ý +ôu=˜ô u=ôp	%.�Hô %.ôPXR�8ô XRôv"C�8ô "CôJP�xõ Pr!   