+
    Dfjr                   &   R t ^ RIHt ^ RIt^ RIHt ^ RIHtHtH	t	 ^ RI
Ht ^ RIHtHt ^ RIHt ^ RIHtHt ^ R	IHt  ^ R
IHt ^ RIHtHtHtHtHtHtH t H!t!H"t" ^ RI#H$t$H%t%H&t&H't'H(t( ^ RI)H*t*H+t+ ^ RI,H-t-H.t.H/t/ ^ RI0H1t1 ^ RI4H5t5H6t6 ^ RI7H8t8H9t9 ^ RI:H;t;H<t<H=t=H>t>H?t?H@t@HAtA ^ RIBHCtCHDtDHEtEHFtF ^ RIHGtG ^ RIHHItIHJtJ ^ RIKHLtLHMtM ^ RINHOtO ^ RIPHQtQ ^ RIRHStS ^ RITHUtU ^ RIVHWtW ^ RIXHYtYHZtZ  ! R R4      t[ ! R  R!]E4      t\R4R" lt] ! R# R$]Z4      t^R5R% lt_ ! R& R']Y4      t` ! R( R)]Z4      ta ! R* R+]Z4      tb ! R, R-]Z4      tc]	! ]>4       ! R. R/]C4      4       td]	! ]>4       ! R0 R1]F4      4       te ! R2 R3]Y4      tfR#   ]2 d    Rt3R;t;t!;tt  ELi ; i)6z%
Tests for L{twisted.protocols.tls}.
)annotationsN)Union)	InterfacedirectlyProvidesimplementer)verifyObject)given
strategies)reactor)Clock
deferLater)	iterbytes)crypto)	SSL_CB_HANDSHAKE_DONE
TLS_METHOD
ConnectionContextErrorTLSv1_1_METHODTLSv1_2_METHODTLSv1_METHODWantReadError)TLSMemoryBIOFactoryTLSMemoryBIOProtocol_AggregateSmallWrites_ProducerMembrane_PullToPush)PrivateCertificateoptionsForClientTLS)ClientTLSContextServerTLSContextcertPath)!certificatesForAuthorityAndServerz;pyOpenSSL 16.0.0 or newer required for twisted.protocol.tls)DeferredgatherResults)ConnectionDoneConnectionLost)IHandshakeListenerIOpenSSLClientConnectionCreatorIOpenSSLServerConnectionCreatorIProtocolNegotiationFactoryIPushProducerISSLTransportISystemHandle)ClientFactoryFactoryProtocolServerFactory)TaskStopped)NonStreamingProducerStringTransport)collapsingPumpPolicyloopbackAsync)log)Failure)FilePath)connectedServerAndClientConnectionLostNotifyingProtocol)SynchronousTestCaseTestCasec                  B    ] tR t^KtRt]3R lt]R 4       tR t	R t
RtR# )HandshakeCallbackContextFactoryz
L{HandshakeCallbackContextFactory} is a factory for SSL contexts which
allows applications to get notification when the SSL handshake completes.

@ivar _finished: A L{Deferred} which will be called back when the handshake
    is done.
c                	0    \        4       V n        Wn        R # N)r#   	_finished_method)selfmethods   &&A/usr/lib/python3/dist-packages/twisted/protocols/test/test_tls.py__init__(HandshakeCallbackContextFactory.__init__T   s    !    c                *    V ! 4       pWP                   3# )z
Create a new L{HandshakeCallbackContextFactory} and return a two-tuple
of it and a L{Deferred} which will fire when a connection created with
it completes a TLS handshake.
)rC   )clscontextFactorys   & rG   factoryAndDeferred2HandshakeCallbackContextFactory.factoryAndDeferredX   s     7777rJ   c                f    V\         ,          '       d   V P                  P                  R4       R# R# )z
This is the "info callback" on the context.  It will be called
periodically by pyOpenSSL with information about the state of a
connection.  When it indicates the handshake is complete, it will fire
C{self._finished}.
N)r   rC   callback)rE   
connectionwhererets   &&&&rG   _info%HandshakeCallbackContextFactory._infob   s'     (((NN##D) )rJ   c                f    \        V P                  4      pVP                  V P                  4       V# )zX
Create and return an SSL context configured to use L{self._info} as the
info callback.
)r   rD   set_info_callbackrU   )rE   contexts   & rG   
getContext*HandshakeCallbackContextFactory.getContextl   s)    
 $,,'!!$**-rJ   )rC   rD   N)__name__
__module____qualname____firstlineno____doc__r   rH   classmethodrN   rU   rZ   __static_attributes__ rJ   rG   r@   r@   K   s/     )  8 8*rJ   r@   c                  2    ] tR t^vtRtR tR tR tR tRt	R# )AccumulatingProtocola  
A protocol which collects the bytes it receives and closes its connection
after receiving a certain minimum of data.

@ivar howMany: The number of bytes of data to wait for before closing the
    connection.

@ivar received: A L{list} of L{bytes} of the bytes received so far.
c                	    Wn         R # rB   )howMany)rE   rg   s   &&rG   rH   AccumulatingProtocol.__init__   s    rJ   c                	    . V n         R # rB   )receivedrE   s   &rG   connectionMade#AccumulatingProtocol.connectionMade   s	    rJ   c                	    V P                   P                  V4       \        \        \        V P                   4      4      V P
                  8  d   V P                  P                  4        R # R # rB   )rj   appendsummaplenrg   	transportloseConnectionrE   datas   &&rG   dataReceived!AccumulatingProtocol.dataReceived   sE    T"s3&'4<<7NN))+ 8rJ   c                	l    VP                  \        4      '       g   \        P                  ! V4       R # R # rB   )checkr%   r7   errrE   reasons   &&rG   connectionLost#AccumulatingProtocol.connectionLost   s!    ||N++GGFO ,rJ   )rg   rj   N)
r\   r]   r^   r_   r`   rH   rl   rw   r~   rb   rc   rJ   rG   re   re   v   s    ,
rJ   re   c                  aa
 \        R4      o
\        4       pV
3R lVn        S'       d-   \        \        \
        4       ! V3R lR4      4       pV! 4       pMV '       d   \        VR7      pM
\        4       p\        4       p\        W`'       * WG4      pVP                  R4      p	Vf   \        4       pV	P                  V4       S
V	3# )z
Create a protocol hooked up to a TLS transport hooked up to a
StringTransport.

@param serverMethod: The TLS method accepted by the server-side and used by the created protocol. Set to to C{None} to use the default method used by your OpenSSL library.
l   J)c                    < S # rB   rc   clientProtocols   rG   <lambda>"buildTLSProtocol.<locals>.<lambda>   s    ^rJ   c                  (   < ] tR t^tV 3R lt]tRtR# )-buildTLSProtocol.<locals>.HardCodedConnectionc                	   < S# rB   rc   )rE   tlsProtocolfakeConnections   &&rG   clientConnectionForTLSDbuildTLSProtocol.<locals>.HardCodedConnection.clientConnectionForTLS   s	    %%rJ   rc   N)r\   r]   r^   r_   r   serverConnectionForTLSrb   r   s   rG   HardCodedConnectionr      s    & &<"rJ   r   rF   N)re   r.   protocolr   r)   r(   r    r   r   r   buildProtocolr4   makeConnection)serverrs   r   serverMethodclientFactoryr   rM   clockwrapperFactorysslProtocolr   s   &&f&      @rG   buildTLSProtocolr      s     *,7N!OM3M	46U	V	< 	< 
W	< -.-\BN-/NGE(
MN !..t4K#%	y);&&rJ   c                  ,    ] tR t^tRtR tR tR tRtR# )TLSMemoryBIOFactoryTestsz4
Ensure TLSMemoryBIOFactory logging acts correctly.
c                T   \        4       p. pVP                  p\        P                  ! V4       V P	                  \        P
                  V4       \        4       pR Vn        R Vn        \        VRV4      pVP                  4        VP                  4        V P                  V. 4       R# )z[
L{TLSMemoryBIOFactory.doStart} and L{TLSMemoryBIOFactory.doStop} do
not log any messages.
c                     R # rB   rc   rc   rJ   rG   r   5TLSMemoryBIOFactoryTests.test_quiet.<locals>.<lambda>   s    rJ   c                     R # rB   rc   rc   rJ   rG   r   r      s    rJ   FN)r    ro   r7   addObserver
addCleanupremoveObserverr1   doStartdoStopr   assertEqual)rE   rM   logsloggerwrappedFactoryfactorys   &     rG   
test_quiet#TLSMemoryBIOFactoryTests.test_quiet   s    
 *+**F3&!- ,%ne^Lr"rJ   c                    \        4       p\        VR\        4       4      pV P                  RVP	                  4       4       R# )z
L{TLSMemoryBIOFactory.logPrefix} amends the wrapped factory's log prefix
with a short string (C{"TLS"}) indicating the wrapping, rather than its
full class name.
FzServerFactory (TLS)N)r    r   r1   r   	logPrefix)rE   rM   r   s   &  rG   test_logPrefix'TLSMemoryBIOFactoryTests.test_logPrefix   s6     *+%ne]_M.0A0A0CDrJ   c                     ! R R4      p\        4       p\        VRV! 4       4      pV P                  RVP                  4       4       R# )z
If the wrapped factory does not provide L{ILoggingContext},
L{TLSMemoryBIOFactory.logPrefix} uses the wrapped factory's class name.
c                      ] tR t^tRtR# )BTLSMemoryBIOFactoryTests.test_logPrefixFallback.<locals>.NoFactoryrc   Nr\   r]   r^   r_   rb   rc   rJ   rG   	NoFactoryr          rJ   r   FzNoFactory (TLS)N)r    r   r   r   )rE   r   rM   r   s   &   rG   test_logPrefixFallback/TLSMemoryBIOFactoryTests.test_logPrefixFallback   s@    	 	 *+%neY[I*G,=,=,?@rJ   rc   N)	r\   r]   r^   r_   r`   r   r   r   rb   rc   rJ   rG   r   r      s    #(EArJ   r   c                  a aaa	a
a \        4       w  r#\        4       p\        \        4       ! VV 3R lR\        4      4       o\        \        4       ! R R\        4      4       o	\        \        RVR7      R\        P                  ! V3R l4      VR	7      o
\        VP                  4       R
\        P                  ! V	3R l4      VR	7      o\        V3R lV
3R lR
VR7      w  rVpWVV3# )z
Construct a client and server L{TLSMemoryBIOProtocol} connected by an IO
pump.

@param greetingData: The data which should be written in L{connectionMade}.
@type greetingData: L{bytes}

@return: 3-tuple of client, server, L{twisted.test.iosim.IOPump}
c                  F   <a  ] tR t^tRtRtV V3R ltV3R ltR tRt	V ;t
# )*handshakingClientAndServer.<locals>.ClientFNc                	f   < \         SV `  4        Se   V P                  P                  S4       R # R # rB   )superrl   rs   write)rE   	__class__clientGreetingDatas   &rG   rl   9handshakingClientAndServer.<locals>.Client.connectionMade   s,    G"$!-$$%78 .rJ   c                	   < R V n         V P                  P                  4       V n        S'       d   V P                  P	                  4        R# R# TN)	handshookrs   getPeerCertificatepeerAfterHandshakeabortConnection)rE   clientAbortAfterHandshakes   &rG   handshakeCompleted=handshakingClientAndServer.<locals>.Client.handshakeCompleted  s7    !DN&*nn&G&G&ID#(..0 )rJ   c                	    R # rB   rc   r|   s   &&rG   r~   9handshakingClientAndServer.<locals>.Client.connectionLost      rJ   )r   r   )r\   r]   r^   r_   r   r   rl   r   r~   rb   __classcell__)r   r   r   s   @rG   Clientr      s"    	!	9
	1	 	rJ   r   c                  &    ] tR tRtRtR tR tRtR# )*handshakingClientAndServer.<locals>.Serveri  Fc                	    R V n         R# r   
handshakedrk   s   &rG   r   =handshakingClientAndServer.<locals>.Server.handshakeCompleted  s	    "DOrJ   c                	    R # rB   rc   r|   s   &&rG   r~   9handshakingClientAndServer.<locals>.Server.connectionLost  r   rJ   r   N)r\   r]   r^   r_   r   r   r~   rb   rc   rJ   rG   Serverr     s    
	#	rJ   r   example.com	trustRootTc                    < S ! R 4      # i?B rc   )r   s   rG   r   ,handshakingClientAndServer.<locals>.<lambda>  	    rJ   )isClientr   r   Fc                    < S ! R 4      # r   rc   )r   s   rG   r   r   !  r   rJ   c                 &   < S P                  R 4      # rB   r   )serverFs   rG   r   r   %      %%d+rJ   c                 &   < S P                  R 4      # rB   r   )clientFs   rG   r   r   &  r   rJ   )greetr   )r"   r   r   r'   re   r   r   r.   forProtocoloptionsr1   r:   )r   r   authCert
serverCertr   clientr   pumpr   r   r   r   s   ff      @@@@rG   handshakingClientAndServerr      s     =>HGE#$ %  %$ #$%  % "MX>$001GH	G "$001GH	G 4++	FD 4rJ   c                  ,    ] tR tRtRtR tR tR tRtR# )DeterministicTLSMemoryBIOTestsi-  z
Test for the implementation of L{ISSLTransport} which runs over another
transport.

@note: Prefer to add test cases to this suite, in this style, using
    L{connectedServerAndClient}, rather than returning L{Deferred}s.
c                   \        4       w  rpV P                  VP                  P                  R4       V P                  VP                  P                  R4       VP                  4        V P                  VP                  P                  R4       V P                  VP                  P                  R4       V P                  VP                  P                  R4       R# )z
The completion of the TLS handshake calls C{handshakeCompleted} on
L{Protocol} objects that provide L{IHandshakeListener}.  At the time
C{handshakeCompleted} is invoked, the transport's peer certificate will
have been initialized.
FTN)r   r   wrappedProtocolr   r   flushassertIsNotr   )rE   r   r   r   s   &   rG   test_handshakeNotification9DeterministicTLSMemoryBIOTests.test_handshakeNotification6  s      :;//995A//::EB

//994@//::DA//BBDIrJ   c                    \        RR4      w  rpVP                  pVP                  4        V P                  VP                  . 4       R# )z
If some data is written to the transport in C{connectionMade}, but
C{handshakeDone} doesn't like something it sees about the handshake, it
can use C{abortConnection} to ensure that the application never
receives that data.
s   untrustworthyTN)r   r   r   r   rj   rE   r   r   r   wrappedServerProtocols   &    rG   test_handshakeStopWriting8DeterministicTLSMemoryBIOTests.test_handshakeStopWritingE  sB      ::JDQ & 6 6

.77<rJ   c                   \        4       w  rpVP                  pVP                  4        V P                  VP                  . 4       VP                  R4       VP                  R4       V P                  VP                  . 4       VP                  RR7       V P                  VP                  . 4       VP                  RR7       V P                  RP                  VP                  4      R4       R# )	z
If a small amount data is written to the TLS transport, it is only
delivered if time passes, indicating small-write buffering is in
effect.
s   hels   loF)advanceClockTrJ      helloN)r   r   r   r   rj   r   joinr   s   &    rG   test_smalWriteBuffering6DeterministicTLSMemoryBIOTests.test_smalWriteBufferingQ  s      :; & 6 6

.77<VU.77<


&.77<


%"7"@"@A8LrJ   rc   N)	r\   r]   r^   r_   r`   r   r   r  rb   rc   rJ   rG   r   r   -  s    J
=MrJ   r   c                      ] tR tRtRtR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tR tR tR t]3R ltR tR tR tR tR tR tR tR tR tR tRt R# )TLSMemoryBIOTestsid  zY
Tests for the implementation of L{ISSLTransport} which runs over another
L{ITransport}.
c                    \        RR4      pV P                  \        P                  ! V4      4       V P                  \        P                  ! V4      4       R# )zR
L{TLSMemoryBIOProtocol} instances provide L{ISSLTransport} and
L{ISystemHandle}.
N)r   
assertTruer,   
providedByr-   )rE   protos   & rG   test_interfaces!TLSMemoryBIOTests.test_interfacesj  s>    
 %T4000780078rJ   c                (    ! R R\         4      p ! R R4      p\        4       p\        4       p\        VRV4      pV! 4       p\	        Wa4       \        V\        4       4      pVP                  V4       V P                  VP                  V4      4       R# )z_
L{TLSMemoryBIOProtocol} instances provide the interfaces provided by
the transport they wrap.
c                      ] tR tRtRtR# )DTLSMemoryBIOTests.test_wrappedProtocolInterfaces.<locals>.ITransportiy  rc   Nr   rc   rJ   rG   
ITransportr  y  r   rJ   r  c                      ] tR tRtR tRtR# )ETLSMemoryBIOTests.test_wrappedProtocolInterfaces.<locals>.MyTransporti|  c                	    R # rB   rc   ru   s   &&rG   r   KTLSMemoryBIOTests.test_wrappedProtocolInterfaces.<locals>.MyTransport.write}      rJ   rc   N)r\   r]   r^   r_   r   rb   rc   rJ   rG   MyTransportr  |  s    rJ   r  TN)
r   r.   r   r   r   r   r0   r   r  r  )rE   r  r  r   rM   r   rs   r   s   &       rG   test_wrappedProtocolInterfaces0TLSMemoryBIOTests.test_wrappedProtocolInterfacess  sy    	 		 	 &)+,^T=QM	/*>8:F""9-
--k:;rJ   c                    \        4       p\        4       p\        VRV4      p\        V\	        4       4      p\        4       pVP                  V4       V P                  VP                  4       \        4       R# )a  
L{TLSMemoryBIOProtocol.getHandle} returns the L{OpenSSL.SSL.Connection}
instance it uses to actually implement TLS.

This may seem odd.  In fact, it is.  The L{OpenSSL.SSL.Connection} is
not actually the "system handle" here, nor even an object the reactor
knows about directly.  However, L{twisted.internet.ssl.Certificate}'s
C{peerFromTransport} and C{hostFromTransport} methods depend on being
able to get an L{OpenSSL.SSL.Connection} object in order to work
properly.  Implementing L{ISystemHandle.getHandle} like this is the
easiest way for those APIs to be made to work.  If they are changed,
then it may make sense to get rid of this implementation of
L{ISystemHandle} and return the underlying socket instead.
TN)
r.   r   r   r   r0   r4   r   assertIsInstance	getHandler   )rE   r   rM   r   r  rs   s   &     rG   test_getHandle TLSMemoryBIOTests.test_getHandle  s\      /)+,^T7K$^XZ@#%	Y'eoo/<rJ   c                r  a \        4       o\        4       pV3R lVn        \        4       p\	        VRV4      pVP                  R4      p\        4       pVP                  V4       V P                  SP                  4       V P                  SP                  V4       V P                  SP                  V4       R# )zm
When L{TLSMemoryBIOProtocol} is connected to a transport, it connects
the protocol it wraps to a transport.
c                    < S # rB   rc   r   s   rG   r   7TLSMemoryBIOTests.test_makeConnection.<locals>.<lambda>      rJ   TN)r0   r.   r   r   r   r   r4   r   assertIsNotNoners   r   assertIs)rE   r   rM   r   r   rs   r   s   &     @rG   test_makeConnection%TLSMemoryBIOTests.test_makeConnection  s    
 "%!7)+,^T=Q$2248#%	""9-^556119=n..<rJ   c                2   \        4       p\        Vn        \        P	                  4       w  pp\        VRV4      pVP                  R4      p\        4       p\        Vn        \        4       p\        VRV4      pVP                  R4      p\        W4      p	VVVV	3# )z0
Start handshake between TLS client and server.
TNF)
r.   r0   r   r@   rN   r   r   r1   r    r6   )
rE   r   clientContextFactoryhandshakeDeferredr   sslClientProtocolserverFactoryserverContextFactorysslServerProtocolconnectionDeferreds
   &         rG   handshakeProtocols$TLSMemoryBIOTests.handshakeProtocols  s     &!)
 ,>>@	
 ,-A4W*88>%!)/1,-A5-X*88>*+<P	
 	
rJ   c                ,    V P                  4       w  rr4V# )zZ
The TLS handshake is performed when L{TLSMemoryBIOProtocol} is
connected to a transport.
)r,  )rE   	tlsClient	tlsServerr&  _s   &    rG   test_handshake TLSMemoryBIOTests.test_handshake  s     
 6:5L5L5N2	/ ! rJ   c                  aa \        4       o\        4       pV3R lVn        \        4       p\	        VRV4      pVP                  R4      p\        4       o\        4       pV3R lVn        \        \        4      P                  4       p\        P                  ! V4      pVP                  V4      p\	        VRV4      pVP                  R4      p	\        W4      p
R pSP                  V4       SP                  V4       \        SSV
.4      # )z
L{TLSMemoryBIOProtocol} reports errors in the handshake process to the
application-level protocol object using its C{connectionLost} method
and disconnects the underlying transport.
c                    < \        S 4      # rB   r;   clientConnectionLosts   rG   r   9TLSMemoryBIOTests.test_handshakeFailure.<locals>.<lambda>      )H *
rJ   TNc                    < \        S 4      # rB   r;   )serverConnectionLosts   rG   r   r8    r9  rJ   Fc                D    V P                   P                  \        4       R # rB   )lostConnectionReasontrapr   )r   s   &rG   cbConnectionLostATLSMemoryBIOTests.test_handshakeFailure.<locals>.cbConnectionLost  s    
 ))..u5rJ   )r#   r.   r   r@   r   r   r1   r9   r!   
getContentr   loadPEMr   r6   addCallbackr$   )rE   r   r%  r   r'  r(  certificateDatacertificater)  r*  r+  r?  r7  r;  s   &           @@rG   test_handshakeFailure'TLSMemoryBIOTests.test_handshakeFailure  s     (z%"
  ?@,-A4W*88>'z%"
 #8,779(00A*22;?,-A5-X*88>*+<P	6 	(()9:(()9: !#79KL
 	
rJ   c                `  a a	 \        4       p\        Vn        \        P	                  4       w  pp\        VRV4      pVP                  R4      o	\        4       p\        Vn        \        4       p\        VRV4      pVP                  R4      p\        VS	4       V V	3R lpVP                  V4       V# )z}
L{TLSMemoryBIOProtocol.getPeerCertificate} returns the
L{OpenSSL.crypto.X509} instance representing the peer's
certificate.
TNFc                   < SP                  4       pSP                  V\        P                  4       SP	                  VP                  R 4      R4       R# )sha256s_   D6:F2:2C:74:3B:E2:5E:F9:CA:DA:47:08:14:78:20:75:78:95:9E:52:BD:D2:7C:77:DD:D4:EE:DE:33:BF:34:40N)r   r  r   X509r   digest)ignoredcertrE   r'  s   & rG   cbHandshook>TLSMemoryBIOTests.test_getPeerCertificate.<locals>.cbHandshook(  sD    $779D!!$4H%8	rJ   )r.   r0   r   r@   rN   r   r   r1   r    r6   rC  )
rE   r   r%  r&  r   r(  r)  r*  rO  r'  s
   f        @rG   test_getPeerCertificate)TLSMemoryBIOTests.test_getPeerCertificate  s     &!)
 ,>>@	
 ,-A4W*88>%!)/1,-A5-X*88>'):;
	 	%%k2  rJ   c                  a aaaa Ro\        4       o\        4       pV3R lVn        \        P	                  4       w  pp\        VRV4      pVP                  R4      p\        \        S4      4      o\        4       pV3R lVn        \        4       p\        VRV4      pVP                  R4      p\        W4      oVVV3R lp	VP                  V	4       VV V3R lp
VP                  V
4       V# )	
Bytes written to L{TLSMemoryBIOProtocol} before the handshake is
complete are received by the protocol on the other side of the
connection once the handshake succeeds.

   some bytesc                    < S # rB   rc   r   s   rG   r   <TLSMemoryBIOTests.test_writeAfterHandshake.<locals>.<lambda>A  r  rJ   TNc                    < S # rB   rc   serverProtocols   rG   r   rW  L  r  rJ   Fc                >   < SP                   P                  S4       S# rB   rs   r   )rM  r   r+  rv   s   &rG   rO  ?TLSMemoryBIOTests.test_writeAfterHandshake.<locals>.cbHandshookU  s    $$**40 &%rJ   c                ^   < SP                  R P                  SP                  4      S4       R# rJ   Nr   r   rj   rM  rv   rE   rZ  s   &rG   cbDisconnectedBTLSMemoryBIOTests.test_writeAfterHandshake.<locals>.cbDisconnected_  "    SXXn&=&=>ErJ   )r0   r.   r   r@   rN   r   r   re   rr   r1   r    r6   rC  )rE   r   r%  r&  r   r'  r(  r)  r*  rO  rb  r   r+  rv   rZ  s   f          @@@@rG   test_writeAfterHandshake*TLSMemoryBIOTests.test_writeAfterHandshake7  s     !%!7
 ,>>@	
 ,-A4W*88>-c$i8%!7/1,-A5-X*88>*+<P	& 	%%k2	F 	%%n5  rJ   c                  a aa \        4       pWn        \        P                  4       w  pp\	        VRV4      pVP                  R4      p\        \        S4      4      o\        4       pV3R lVn        \        4       p	\	        V	RV4      pVP                  R4      p
\        W4      pVV V3R lpVP                  V4       V# )zc
Run test where client sends data before handshake, given the sending
protocol and expected bytes.
TNc                    < S # rB   rc   rY  s   rG   r   <TLSMemoryBIOTests.writeBeforeHandshakeTest.<locals>.<lambda>w  r  rJ   Fc                ^   < SP                  R P                  SP                  4      S4       R# r_  r`  ra  s   &rG   cbConnectionDoneDTLSMemoryBIOTests.writeBeforeHandshakeTest.<locals>.cbConnectionDone  rd  rJ   )r.   r   r@   rN   r   r   re   rr   r1   r    r6   rC  )rE   sendingProtocolrv   r   r%  r&  r   r'  r(  r)  r*  r+  rk  rZ  s   f&f          @rG   writeBeforeHandshakeTest*TLSMemoryBIOTests.writeBeforeHandshakeTestf  s    
 &!0
 ,>>@	
 ,-A4W*88>-c$i8%!7/1,-A5-X*88>*+<P	F 	&&'78!!rJ   c                P   a Ro ! V3R lR\         4      pV P                  VS4      # )rT  rU  c                  $   < ] tR tRtV 3R ltRtR# )JTLSMemoryBIOTests.test_writeBeforeHandshake.<locals>.SimpleSendingProtocoli  c                	>   < V P                   P                  S4       R # rB   r\  ru   s   &rG   rl   YTLSMemoryBIOTests.test_writeBeforeHandshake.<locals>.SimpleSendingProtocol.connectionMade  s    $$T*rJ   rc   Nr\   r]   r^   r_   rl   rb   rv   s   rG   SimpleSendingProtocolrr    s    + +rJ   rw  r0   rn  rE   rw  rv   s   & @rG   test_writeBeforeHandshake+TLSMemoryBIOTests.test_writeBeforeHandshake  s,     	+H 	+ ,,-BDIIrJ   c                P   a Ro ! V3R lR\         4      pV P                  VS4      # )z
Bytes written to L{TLSMemoryBIOProtocol} with C{writeSequence} are
received by the protocol on the other side of the connection.
rU  c                  $   < ] tR tRtV 3R ltRtR# )CTLSMemoryBIOTests.test_writeSequence.<locals>.SimpleSendingProtocoli  c                	b   < V P                   P                  \        \        S4      4      4       R # rB   )rs   writeSequencelistr   ru   s   &rG   rl   RTLSMemoryBIOTests.test_writeSequence.<locals>.SimpleSendingProtocol.connectionMade  s    ,,T)D/-BCrJ   rc   Nru  rv  s   rG   rw  r~    s    D DrJ   rw  rx  ry  s   & @rG   test_writeSequence$TLSMemoryBIOTests.test_writeSequence  s.    
 	DH 	D ,,-BDIIrJ   c                P   a Ro ! V3R lR\         4      pV P                  VS4      # )z
Bytes written to L{TLSMemoryBIOProtocol} after C{loseConnection} is
called are not transmitted (unless there is a registered producer,
which will be tested elsewhere).
rU  c                  $   < ] tR tRtV 3R ltRtR# )NTLSMemoryBIOTests.test_writeAfterLoseConnection.<locals>.SimpleSendingProtocoli  c                	   < V P                   P                  S4       V P                   P                  4        V P                   P                  R 4       V P                   P                  R.4       R# )r      worldN)rs   r   rt   r  ru   s   &rG   rl   ]TLSMemoryBIOTests.test_writeAfterLoseConnection.<locals>.SimpleSendingProtocol.connectionMade  sK    $$T*--/$$X.,,hZ8rJ   rc   Nru  rv  s   rG   rw  r    s    9 9rJ   rw  rx  ry  s   & @rG   test_writeAfterLoseConnection/TLSMemoryBIOTests.test_writeAfterLoseConnection  s,     	9H 	9 ,,-BDIIrJ   c                   a aaa Ro. o ! VV3R lR\         4      pV 3R loS P                  VR4      pVP                  VV 3R l4       VP                  V3R l4       V# )zF
Writing C{unicode} to L{TLSMemoryBIOProtocol} throws a C{TypeError}.
helloc                  &   < ] tR tRtV V3R ltRtR# )QTLSMemoryBIOTests.test_writeUnicodeRaisesTypeError.<locals>.SimpleSendingProtocoli  c                	$  <  V P                   P                  S4       V P                   P                  R 4       V P                   P                  4        R#   \         d0    SP	                  R4       T P                   P                  4         R# i ; i)   bytesTN)rs   r   rt   	TypeErrorro   r   )rE   notBytesresults   &rG   rl   `TLSMemoryBIOTests.test_writeUnicodeRaisesTypeError.<locals>.SimpleSendingProtocol.connectionMade  sg    5NN((2NN((2NN113  5MM$'NN2245s   AA 6BBrc   Nru  )r  r  s   rG   rw  r    s    5 5rJ   rw  c                 n   < S P                  \        S P                  \        \        4      4      ^4       R#    N)r   rr   flushLoggedErrorsr&   r  rk   s   rG   flush_logged_errorsOTLSMemoryBIOTests.test_writeUnicodeRaisesTypeError.<locals>.flush_logged_errors  s&    S!7!7	!RSUVWrJ   r  c                *   < SP                  SR .4      # )T)r   )ignr  rE   s   &rG   r   DTLSMemoryBIOTests.test_writeUnicodeRaisesTypeError.<locals>.<lambda>  s    d..vv>rJ   c                &   < \        \        ^ S4      # )    )r   r
   )r  r  s   &rG   r   r    s    j!5HIrJ   )r0   rn  addBoth)rE   rw  dr  r  r  s   f  @@@rG    test_writeUnicodeRaisesTypeError2TLSMemoryBIOTests.test_writeUnicodeRaisesTypeError  sZ     	5 	5H 	5	X ))*?J			>?			IJrJ   c                  a aa . ROo ! V3R lR\         4      p\        4       pWn        \        4       p\	        VRV4      pVP                  R4      p\        \        \        \        S4      4      4      o\        4       pV3R lVn        \        4       p\	        VRV4      pVP                  R4      p\        W\        4      p	VV V3R lp
V	P                  V
4       V	# )	z
If multiple separate TLS messages are received in a single chunk from
the underlying transport, all of the application bytes from each
message are delivered to the application-level protocol.
c                  $   < ] tR tRtV 3R ltRtR# )DTLSMemoryBIOTests.test_multipleWrites.<locals>.SimpleSendingProtocoli  c                	P   < S F  pV P                   P                  V4       K   	  R # rB   r\  )rE   brv   s   & rG   rl   STLSMemoryBIOTests.test_multipleWrites.<locals>.SimpleSendingProtocol.connectionMade  s    ANN((+ rJ   rc   Nru  rv  s   rG   rw  r    s    , ,rJ   rw  TNc                    < S # rB   rc   rY  s   rG   r   7TLSMemoryBIOTests.test_multipleWrites.<locals>.<lambda>  r  rJ   Fc                |   < SP                  R P                  SP                  4      R P                  S4      4       R# r_  r`  ra  s   &rG   rk  ?TLSMemoryBIOTests.test_multipleWrites.<locals>.cbConnectionDone  s*    SXXn&=&=>OrJ   )	   a   b   c   d   e   f   g   h   i)r0   r.   r   r@   r   r   re   rp   rq   rr   r1   r    r6   r5   rC  )rE   rw  r   r%  r   r'  r(  r)  r*  r+  rk  rv   rZ  s   f          @@rG   test_multipleWrites%TLSMemoryBIOTests.test_multipleWrites  s     F	,H 	,
 &!6>@,-A4W*88>-c#c4..AB%!7/1,-A5-X*88>*2F
	P 	&&'78!!rJ   c                  a aaa RoR
o ! VV3R lR\         4      p\        4       pW#n        \        VR7      p\	        VRV4      pVP                  R4      p\        \        S4      S,          4      o\        4       pV3R lVn        \        VR7      p\	        VRV4      pVP                  R4      p	\        W4      p
VVV V3R	 lpV
P                  V4       V
# )z
If a very long string is passed to L{TLSMemoryBIOProtocol.write}, any
trailing part of it which cannot be send immediately is buffered and
sent later.
rU  c                  &   < ] tR tRtV V3R ltRtR# ):TLSMemoryBIOTests.hugeWrite.<locals>.SimpleSendingProtocoli  c                	L   < V P                   P                  SS,          4       R # rB   r\  )rE   rv   factors   &rG   rl   ITLSMemoryBIOTests.hugeWrite.<locals>.SimpleSendingProtocol.connectionMade  s    $$TF]3rJ   rc   Nru  )rv   r  s   rG   rw  r    s    4 4rJ   rw  r   TNc                    < S # rB   rc   rY  s   rG   r   -TLSMemoryBIOTests.hugeWrite.<locals>.<lambda>
  r  rJ   Fc                l   < SP                  R P                  SP                  4      SS,          4       R# r_  r`  )rM  rv   r  rE   rZ  s   &rG   rk  5TLSMemoryBIOTests.hugeWrite.<locals>.cbConnectionDone  s&    SXXn&=&=>vNrJ   i   )r0   r.   r   r@   r   r   re   rr   r1   r    r6   rC  )rE   rF   rw  r   r%  r   r'  r(  r)  r*  r+  rk  rv   r  rZ  s   f&          @@@rG   	hugeWriteTLSMemoryBIOTests.hugeWrite  s     	4 	4H 	4 &!6>fM,-A4W*88>-c$i&.@A%!7/v>,-A5-X*88>*+<P	O 	O 	&&'78!!rJ   c                	"    V P                  4       # rB   )r  rk   s   &rG   test_hugeWrite TLSMemoryBIOTests.test_hugeWrite  s    ~~rJ   c                	.    V P                  \        R 7      # )r   )r  r   rk   s   &rG   test_hugeWrite_TLSv1_2(TLSMemoryBIOTests.test_hugeWrite_TLSv1_2  s    ~~^~44rJ   c                  a \        4       o\        4       pV3R lVn        \        4       p\	        VRV4      pVP                  R4      p\        4       p\        WT4       VP                  P                  4        R pSP                  V4       S# )zf
If a L{TLSMemoryBIOProtocol} loses its connection unexpectedly, this is
reported to the application.
c                    < \        S 4      # rB   r;   r6  s   rG   r   ;TLSMemoryBIOTests.test_disorderlyShutdown.<locals>.<lambda>'  r9  rJ   TNc                N    V P                   P                  \        \        4       R # rB   )r=  r>  r   r&   r   s   &rG   rb  ATLSMemoryBIOTests.test_disorderlyShutdown.<locals>.cbDisconnected8  s    //44UNKrJ   )r#   r.   r   r@   r   r   r0   r6   rs   rt   rC  )rE   r   r%  r   r'  rZ  rb  r7  s   &      @rG   test_disorderlyShutdown)TLSMemoryBIOTests.test_disorderlyShutdown   s    
  (z%"
  ?@,-A4W*88> "n8 	  //1	L 	((8##rJ   c                  a aaaaa  ! R R\         4      p\        4       o\        4       pV! S4      oV3R lVn        \        P                  4       w  pp\        VRV4      pVP                  R4      p\        4       oV! S4      o\        4       pV3R lVn        \        4       p\        VRV4      pVP                  R4      p	\        W4       RR	,          oVVVVV3R
 lp
VP                  V
4       VV 3R lpVP                  V4       V# )z
L{TLSMemoryBIOProtocol.loseConnection} sends a TLS close alert and
shuts down the underlying connection cleanly on both sides, after
transmitting all buffered data.
c                  "    ] tR tRtR tR tRtR# )NTLSMemoryBIOTests.test_loseConnectionAfterHandshake.<locals>.NotifyingProtocoliE  c                	@    \         P                  ! W4       . V n        R # rB   )r<   rH   rv   )rE   onConnectionLosts   &&rG   rH   WTLSMemoryBIOTests.test_loseConnectionAfterHandshake.<locals>.NotifyingProtocol.__init__F  s    /88P	rJ   c                	<    V P                   P                  V4       R # rB   )rv   ro   ru   s   &&rG   rw   [TLSMemoryBIOTests.test_loseConnectionAfterHandshake.<locals>.NotifyingProtocol.dataReceivedJ  s    		  &rJ   rv  N)r\   r]   r^   r_   rH   rw   rb   rc   rJ   rG   NotifyingProtocolr  E  s    'rJ   r  c                    < S # rB   rc   r   s   rG   r   ETLSMemoryBIOTests.test_loseConnectionAfterHandshake.<locals>.<lambda>P  r  rJ   TNc                    < S # rB   rc   rY  s   rG   r   r  \  r  rJ   Fs	   123456890順 c                   < SP                   P                  S4       SP                   P                  R 4       SP                   P                  4        \        SS.4      # )   x)rs   r   rt   r$   )rM  chunkOfBytesr7  r   r;  rZ  s   &rG   cbHandshakeHTLSMemoryBIOTests.test_loseConnectionAfterHandshake.<locals>.cbHandshakef  sS     $$**<8$$**40$$335 !"68L!MNNrJ   c                  < V w  rVP                   P                  \        4       VP                   P                  \        4       SP                  R P	                  VP
                  4      S4       SP                  VP                  P                  P                  4       SP                  VP                  P                  P                  4       R# r_  )
r=  r>  r%   r   r   rv   r  rs   q
disconnect)r  r   rZ  r  rE   s   &  rG   rk  MTLSMemoryBIOTests.test_loseConnectionAfterHandshake.<locals>.cbConnectionDoney  s    /5,^//44^D//44^D SXXn&9&9:LI OON4466AAB
 OON4466AABrJ   )r<   r#   r.   r   r@   rN   r   r   r1   r    r6   rC  )rE   r  r   r%  r&  r   r'  r(  r)  r*  r  rk  r  r7  r   r;  rZ  s   f           @@@@@rG   !test_loseConnectionAfterHandshake3TLSMemoryBIOTests.test_loseConnectionAfterHandshake>  s   	' ? 	'  (z%*+?@!7
 ,>>@	
 ,-A4W*88>'z*+?@%!7/1,-A5-X*88>';#f,	O 	O 	%%k2
	C" 	%%&67  rJ   c                H    ! R R\         4      p\        \        4       R\        4       4      pV! 4       p\	        W#4      p\        4       pVP                  V4       VP                  R4       V P                  VP                  4       V P                  VP                  4       VP                  \        \        R4      4      4       V P                  VP                  P                  \        4      4       V P!                  VP                  P"                  P$                  R4       R# )zb
The user protocol's connectionLost is only called when transport
underlying TLS is disconnected.
c                       ] tR tRtRtR tRtR# )TTLSMemoryBIOTests.test_connectionLostOnlyAfterUnderlyingCloses.<locals>.LostProtocoli  Nc                	    Wn         R # rB   disconnectedr|   s   &&rG   r~   cTLSMemoryBIOTests.test_connectionLostOnlyAfterUnderlyingCloses.<locals>.LostProtocol.connectionLost  s    $*!rJ   r  )r\   r]   r^   r_   r  r~   rb   rc   rJ   rG   LostProtocolr    s    L+rJ   r  TNono)r  )r0   r   r   r.   r   r4   r   _tlsShutdownFinishedr  disconnectingassertIsNoner  r~   r8   r&   rz   r   valueargs)rE   r  r   r   r   rs   s   &     rG   ,test_connectionLostOnlyAfterUnderlyingCloses>TLSMemoryBIOTests.test_connectionLostOnlyAfterUnderlyingCloses  s    	+8 	+ --=-?}W>*>D#%	""9-
 	((.	//0(//0 	""7>%+@#AB--33NCD..44998DrJ   c                n  a V P                  4       w  ppppV P                  V4       . oVP                  3V3R llpWQn        VP                  R4       VP	                  4        V P                  VP                  4       V P                  S^.4       VP	                  4        V P                  S^.4       V# )zi
If TLSMemoryBIOProtocol.loseConnection is called multiple times, all
but the first call have no effect.
c                4   < SP                  ^4       V ! 4       #    ro   shutdowncallss   &rG   _shutdownTLS@TLSMemoryBIOTests.test_loseConnectionTwice.<locals>._shutdownTLS      LLO:rJ   r  )r,  successResultOfr  r   rt   r  r  r   )rE   r/  r0  r&  disconnectDeferredr  r  s   &     @rG   test_loseConnectionTwice*TLSMemoryBIOTests.test_loseConnectionTwice  s     ##%	
./ "+"8"8 	 ".  "	//0$ 	  "$ "!rJ   c                   a aa S P                  4       w  popp. oVP                  3V3R llpVSn        SP                  R4       VP                  4        VV V3R lpVP	                  V4       V# )zY
If TLSMemoryBIOProtocol.loseConnection is called after connectionLost,
it does nothing.
c                4   < SP                  ^4       V ! 4       # r  r   r  s   &rG   r  NTLSMemoryBIOTests.test_loseConnectionAfterConnectionLost.<locals>._shutdownTLS  r  rJ   r  c                t   < SP                  S^.4       SP                  4        SP                  S^.4       R# r  N)r   rt   )r1  r  rE   r0  s   &rG   r  NTLSMemoryBIOTests.test_loseConnectionAfterConnectionLost.<locals>.disconnected  s5    UQC( $$&UQC(rJ   )r,  r  r   rt   rC  )rE   r/  r&  r  r  r  r  r0  s   f     @@rG   &test_loseConnectionAfterConnectionLost8TLSMemoryBIOTests.test_loseConnectionAfterConnectionLost  st     ##%	

 "+"8"8 	 ".	  "	) 	&&|4!!rJ   c                   a aa	 S P                  4       w  o	pppVP                  p. p. oVP                  Vn        SP                  Vn        V	3R lpVP                  V4       VV 3R lpVP                  V4       V# )z@
Unexpected disconnects get converted to ConnectionLost errors.
c                ^   < SP                  R 4       SP                  P                  4        R# r   N)r   rs   rt   r  r/  s   &rG   handshakeDone;TLSMemoryBIOTests.test_unexpectedEOF.<locals>.handshakeDone  s!    OOH%..0rJ   c                n   < SP                  S^ ,          P                  \        4      S^ ,          4       R# r  N)r  rz   r&   r  r}   rE   s   &rG   r  :TLSMemoryBIOTests.test_unexpectedEOF.<locals>.disconnected
  s"    OOF1IOON;VAYGrJ   )r,  r   ro   rw   r~   rC  )
rE   r0  r&  r  rZ  rv   r  r  r}   r/  s
   f       @@rG   test_unexpectedEOF$TLSMemoryBIOTests.test_unexpectedEOF  s     ##%	
"22&*kk#(.%	1 	%%m4	H 	&&|4!!rJ   c                  a aa S P                  4       w  oppp. oSP                  SP                  n         ! R R4      pV! SP                  4      Sn        V3R lpVP                  V4       VV 3R lpVP                  V4       V# )z>
Errors while writing cause the protocols to be disconnected.
c                  (    ] tR tRtR tR tR tRtR# )4TLSMemoryBIOTests.test_errorWriting.<locals>.Wrapperi  c                	    Wn         R # rB   _wrapped)rE   wrappeds   &&rG   rH   =TLSMemoryBIOTests.test_errorWriting.<locals>.Wrapper.__init__  s     'rJ   c                	.    \        V P                  V4      # rB   )getattrr$  )rE   attrs   &&rG   __getattr__@TLSMemoryBIOTests.test_errorWriting.<locals>.Wrapper.__getattr__"  s    t}}d33rJ   c                	    \        R.4      h)SSL routines)r-   z this message is probably useless)r   )rE   r  s   &*rG   send9TLSMemoryBIOTests.test_errorWriting.<locals>.Wrapper.send%  s    UVWWrJ   r#  N)r\   r]   r^   r_   rH   r*  r/  rb   rc   rJ   rG   Wrapperr!    s    (4XrJ   r1  c                *   < SP                  R 4       R# r  )r   r  s   &rG   r  :TLSMemoryBIOTests.test_errorWriting.<locals>.handshakeDone+  s    OOH%rJ   c                n   < SP                  S^ ,          P                  \        4      S^ ,          4       R# r  )r  rz   r   r  s   &rG   r  9TLSMemoryBIOTests.test_errorWriting.<locals>.disconnected1  s"    OOF1IOOE2F1I>rJ   )r,  ro   r   r~   _tlsConnectionrC  )	rE   r0  r&  r  r1  r  r  r}   r/  s	   f      @@rG   test_errorWriting#TLSMemoryBIOTests.test_errorWriting  s     ##%	
39==	!!0	X 	X $+9+C+C#D	 	& 	%%m4	? 	&&|4!!rJ   c                b   R pV P                  \        P                  4       \        P                  ! 4         ! R R\        4      p ! R R\        4      pV! \
        4      pV! V4      p\        4       w  rg\        VP                  4       R\        P                  ! V4      4      p\        \        RVR7      R	\        P                  ! V4      4      p	\        \        W! 4       4      \        W! 4       4      4       V! \
        4      p
V! V4      pV P                  W4       V P                  W4       R
# )zk
TLSMemoryBIOProtocol doesn't leave circular references that keep
it in memory after connection is closed.
c                T   a  \        V 3R l\        P                  ! 4        4       4      # )z
Return the number of instances of a given type in memory.

@param type: Type whose instances to find.

@return: The number of instances found.
c              3  P   <"   T F  p\        VS4      '       g   K  ^x  K  	  R# 5ir  )
isinstance).0xtypes   & rG   	<genexpr>VTLSMemoryBIOTests.test_noCircularReferences.<locals>.nObjectsOfType.<locals>.<genexpr>E  s     J"2QjD6Iqq"2s   &
&)rp   gcget_objects)r?  s   frG   nObjectsOfTypeCTLSMemoryBIOTests.test_noCircularReferences.<locals>.nObjectsOfType=  s     J".."2JJJrJ   c                      ] tR tRtR tRtR# )CTLSMemoryBIOTests.test_noCircularReferences.<locals>.CloserProtocoliJ  c                	:    V P                   P                  4        R # rB   )rs   rt   ru   s   &&rG   rw   PTLSMemoryBIOTests.test_noCircularReferences.<locals>.CloserProtocol.dataReceivedK  s    --/rJ   rc   N)r\   r]   r^   r_   rw   rb   rc   rJ   rG   CloserProtocolrG  J  s    0rJ   rJ  c                      ] tR tRtR tRtR# )DTLSMemoryBIOTests.test_noCircularReferences.<locals>.GreeterProtocoliN  c                	<    V P                   P                  R 4       R# r  r\  rk   s   &rG   rl   STLSMemoryBIOTests.test_noCircularReferences.<locals>.GreeterProtocol.connectionMadeO  s    $$X.rJ   rc   Nru  rc   rJ   rG   GreeterProtocolrL  N  s    /rJ   rO  Fr   r   TN)r   rB  enabledisabler0   r   r"   r   r   r/   r   r   r6   r   )rE   rD  rJ  rO  origTLSProtosorigServerProtosr   r   r(  r   newTLSProtosnewServerProtoss   &           rG   test_noCircularReferences+TLSMemoryBIOTests.test_noCircularReferences7  s   	K 			"


	0X 	0	/h 	/ '';<).9@B+ %)<)<^)L
 ,B0

 	 0@A 0AB	

 &&:;(85;rJ   rc   N)!r\   r]   r^   r_   r`   r	  r  r  r"  r,  r2  rF  rQ  re  rn  rz  r  r  r  r  r   r  r  r  r  r  r  r	  r  r  r7  rV  rb   rc   rJ   rG   r  r  d  s    
9<.=.=(
:	!.
`(!T-!^"BJJJ"2&"P  * $"L 5$<M!^E>"B!"F"@%"N/<rJ   r  c                      ] tR tRtRtRR ltRR ltR tR tR t	R	 t
R
 tR tR tR tR tR tR tR tR tR tR tR tR tR tRtR# )TLSProducerTestsii  z9
The TLS transport must support the IConsumer interface.
c                    VP                  4       pVP                  4        T P                  \        T;'       g    T4      R4       V# )a  
Drain the bytes currently pending write from a L{StringTransport}, then
clear it, since those bytes have been consumed.

@param transport: The L{StringTransport} to get the bytes from.
@type transport: L{StringTransport}

@param allowEmpty: Allow the test to pass even if the transport has no
    outgoing bytes in it.
@type allowEmpty: L{bool}

@return: the outgoing bytes from the given transport
@rtype: L{bytes}
T)r  clearr   bool)rE   rs   
allowEmptyr  s   &&& rG   drainTLSProducerTests.drainn  s<     !j11E2D9rJ   Nc                     ! R R\         4      p\        VVVVR7      w  rgV! 4       pVP                  P                  VR4       V P	                  VP                  P
                  4       WgV3# )al  
Create a new client-side protocol that is connected to a remote TLS server.

@param serverMethod: The TLS method accepted by the server-side. Set to to C{None} to use the default method used by your OpenSSL library.

@return: A tuple with high level client protocol, the low-level client-side TLS protocol, and a producer that is used to send data to the client.
c                  .    ] tR tRtR tR tR tR tRtR# )GTLSProducerTests.setupStreamingProducer.<locals>.HistoryStringTransporti  c                	@    \         P                  ! V 4       . V n        R # rB   )r4   rH   producerHistoryrk   s   &rG   rH   PTLSProducerTests.setupStreamingProducer.<locals>.HistoryStringTransport.__init__  s    ((.')$rJ   c                	h    V P                   P                  R 4       \        P                  ! V 4       R# )pauseN)rd  ro   r4   pauseProducingrk   s   &rG   rh  VTLSProducerTests.setupStreamingProducer.<locals>.HistoryStringTransport.pauseProducing  s$    $$++G4..t4rJ   c                	h    V P                   P                  R 4       \        P                  ! V 4       R# )resumeN)rd  ro   r4   resumeProducingrk   s   &rG   rl  WTLSProducerTests.setupStreamingProducer.<locals>.HistoryStringTransport.resumeProducing  s$    $$++H5//5rJ   c                	h    V P                   P                  R 4       \        P                  ! V 4       R# )stopN)rd  ro   r4   stopProducingrk   s   &rG   rp  UTLSProducerTests.setupStreamingProducer.<locals>.HistoryStringTransport.stopProducing  s$    $$++F3--d3rJ   )rd  N)	r\   r]   r^   r_   rH   rh  rl  rp  rb   rc   rJ   rG   HistoryStringTransportrb    s    *564rJ   rr  )rs   r   r   r   T)r4   r   rs   registerProducerr  	streaming)	rE   rs   r   r   r   rr  applicationProtocolr   producers	   &&&&&    rG   setupStreamingProducer'TLSProducerTests.setupStreamingProducer  sm    	4_ 	4" ,<)%	,
( *+%%66xF--778"99rJ   c                   \        ^4       F  pV P                  VP                  R4      pV'       d   VP                  V4       V P                  VP                  R4      pV'       d   VP                  V4       V'       d   Kw  V'       d   K   M	  V P	                  VP                  P                  4       R4       V P	                  VP                  P                  4       R4       R# )z:
Transfer bytes back and forth between two TLS protocols.
TrJ   N)ranger^  rs   rw   r   r  )rE   r   serverTLSProtocoli
clientData
serverDatas   &&&   rG   flushTwoTLSProtocols%TLSProducerTests.flushTwoTLSProtocols  s     qAK$9$94@J!..z:$5$?$?FJ((4:jj  	..446<*44::<cBrJ   c                0   V P                  4       w  rpVP                  P                  P                  4        V P	                  VP
                  R4       V P	                  VP                  R.4       V P                  VP                  P                  4       R# )zo
When the TLS transport is not blocked on reads, it correctly calls
pauseProducing on the registered producer.
pausedrg  N)
rw  rs   rv  rh  r   producerStaterd  r  	_producer_producerPausedrE   r1  r   rv  s   &   rG   (test_streamingProducerPausedInNormalMode9TLSProducerTests.test_streamingProducerPausedInNormalMode  sw    
 $(#>#>#@  	&&557//:11G9=--==>rJ   c                   V P                  4       w  rpVP                  P                  P                  4        V P	                  VP
                  R.4       VP                  P                  P                  4        V P	                  VP                  R4       V P	                  VP
                  RR.4       V P                  VP                  P                  4       R# )zp
When the TLS transport is not blocked on reads, it correctly calls
resumeProducing on the registered producer.
rg  	producingrk  N)rw  rs   rv  rh  r   rd  rl  r  assertFalser  r  r  s   &   rG   )test_streamingProducerResumedInNormalMode:TLSProducerTests.test_streamingProducerResumedInNormalMode  s    
 $(#>#>#@ &&55711G9= 	&&668//=11GX3FG..>>?rJ   c                h   V P                  4       w  rpVP                  P                  R4       VP                  P                  P                  ^ 4       V P                  VP                  R4       V P                  VP                  R.4       V P                  VP                  P                  4       R# )zk
When the TLS transport is blocked on reads, it correctly calls
pauseProducing on the registered producer.
r   r  rg  N)rw  rs   r   r   _clockadvancer   r  rd  r  r  r  rE   r   r   rv  s   &   rG   4test_streamingProducerPausedInWriteBlockedOnReadModeETLSProducerTests.test_streamingProducerPausedInWriteBlockedOnReadMode  s    
 150K0K0M-X 	  &&x0""**1-//:11G9=--==>rJ   c                   V P                  4       w  rpVP                  P                  RR,          4       V P                  VP                  R.4       \        RR7      w  rEV P                  W%4       V P                  VP                  RR.4       V P                  VP                  P                  4       V P                  VP                  P                  4       V P                  VP                  R4       R# )	zl
When the TLS transport is blocked on reads, it correctly calls
resumeProducing on the registered producer.
s   hello worldi  rg  Tr   rk  r  N)rw  rs   r   r   rd  r   r  r  r  r  r  r  )rE   r   r   rv  rZ  r{  s   &     rG   5test_streamingProducerResumedInWriteBlockedOnReadModeFTLSProducerTests.test_streamingProducerResumedInWriteBlockedOnReadMode  s    
 150K0K0M-X
 	  &&~'>?11G9= -=D,I)!!+A11GX3FG..>>? 	..<<=//=rJ   c                    V P                  4       w  rpVP                  p\        4       pV P                  \        VP
                  P                  VR4       V P                  VP                  V4       R# )z=
Registering a streaming producer twice throws an exception.
TN)rw  r  objectassertRaisesRuntimeErrorrs   rs  r!  )rE   r   r   rv  originalProducer	producer2s   &     rG   test_streamingProducerTwice,TLSProducerTests.test_streamingProducerTwice  se     150K0K0M-X&00H	.22CCYPT	
 	k++-=>rJ   c                    V P                  4       w  rpVP                  P                  4        V P                  VP                  4       V P                  VP                  P
                  4       R# )zL
Unregistering a streaming producer removes it, reverting to initial state.
Nrw  rs   unregisterProducerr  r  rv  r  s   &   rG    test_streamingProducerUnregister1TLSProducerTests.test_streamingProducerUnregister  sW     150K0K0M-X  335+//0+//889rJ   c                   V P                  4       w  rpVP                  P                  4        VP                  P                  4        V P                  VP                  4       V P                  VP                  P
                  4       R# )zL
Unregistering a streaming producer when no producer is registered is
safe.
Nr  r  s   &   rG   %test_streamingProducerUnregisterTwice6TLSProducerTests.test_streamingProducerUnregisterTwice  si    
 150K0K0M-X  335  335+//0+//889rJ   c                   V P                  4       w  r#p\        RR7      w  rVV'       g   V P                  W64       M VP                  P	                  R4       VP                  P                  4        V P                  W64       V P                  VP                  P                  4       V P                  RVP                  9   4       VP                  P	                  R4       VP                  P                  RR.4       VP                  P                  P                  ^ 4       VP                  P                  4        V P                  VP                  P                  4       R4       V P                  VP                  P                  4       VP                  P	                  R	4       VP                  P                  R
.4       VP                  P                  P                  ^ 4       V P                  W64       V P!                  VP                  P                  4       V P#                  RP%                  VP&                  4      R4       R# )zT
Common code for tests involving writes by producer after
loseConnection is called.
Tr  s   x ro  r       r  rJ   s   won'ts   won't!s   x hello worldN)rw  r   r  rs   r   rt   r  r  rd  r  r   r  r  r  assertNotEqualr  r  r   r   rj   )rE   writeBlockedOnReadr   r   rv  rZ  r{  s   &&     rG   loseConnectionWithProducer+TLSProducerTests.loseConnectionWithProducer#  s   
 150K0K0M-X,<D,I)!%%kE  	  &&u-  //1!!+A 	..<<=8#;#;;< 	  &&x0  ..h/?@""**1- 	  335K117793?..<<= 	  &&x0  ..	{;""**1- 	!!+A--;;< 	."9"9:<LMrJ   c                $    V P                  R4      # )z
loseConnection() waits for the producer to unregister itself, then
does a clean TLS close alert, then closes the underlying connection.
Fr  rk   s   &rG   0test_streamingProducerLoseConnectionWithProducerATLSProducerTests.test_streamingProducerLoseConnectionWithProducerU  s    
 ..u55rJ   c                $    V P                  R4      # )z
Even when writes are blocked on reading, loseConnection() waits for
the producer to unregister itself, then does a clean TLS close alert,
then closes the underlying connection.
Tr  rk   s   &rG   4test_streamingProducerLoseConnectionWithProducerWBORETLSProducerTests.test_streamingProducerLoseConnectionWithProducerWBOR\  s     ..t44rJ   c                    ! R R\         4      p ! R R4      pV! 4       pV P                  W2! 4       R7      w  rEpV P                  VP                  R4       VP                  P                  R4       VP                  P                  P                  ^ 4       V P                  VP                  R4       V P                  VP                  R	.4       VP                  P                  P                  4        V P                  VP                  R4       V P                  VP                  R	R
.4       VP                  R4       V P                  VP                  R4       V P                  VP                  R	R
.4       R# )z
pauseProducing() events can come from both the TLS transport layer and
the underlying transport. In this case, both decide to pause,
underlying first.
c                       ] tR tRtRtR tRtR# )bTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.PausingStringTransportik  Fc                	    V P                   '       g0   V P                  e"   RV n         V P                  P                  4        \        P                  ! W4       R # )NT)	_didPauserv  rh  r4   r   ru   s   &&rG   r   hTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.PausingStringTransport.writen  s9    ~~~$--*C%)DNMM002%%d1rJ   )r  N)r\   r]   r^   r_   r  r   rb   rc   rJ   rG   PausingStringTransportr  k  s    I2rJ   r  c                  @    ] tR tRtR tR tR tR tR tR t	R t
R	tR
# )YTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnectionit  c                	    . V n         R # rB   lrk   s   &rG   rH   bTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnection.__init__u  s	    rJ   c                	    V P                   '       g   VR R p\        V P                   4      ^8X  d&   V P                   P                  R4       \        4       hV P                   P                  V4       \        V4      # )Nr  )r  rr   ro   r   ru   s   &&rG   r/  ^TLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnection.sendx  sX    vvv9Dtvv;!#FFMM(+'/)d#4y rJ   c                	    R # rB   rc   rk   s   &rG   set_connect_statekTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnection.set_connect_state  r  rJ   c                	    R # rB   rc   rk   s   &rG   do_handshakefTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnection.do_handshake  r  rJ   c                	    R # rB   rc   ru   s   &&rG   	bio_writecTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnection.bio_write  r  rJ   c                	    R # )   Xrc   rE   sizes   &&rG   bio_readbTLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnection.bio_read  s    rJ   c                	    \        4       hrB   )r   r  s   &&rG   recv^TLSProducerTests.test_streamingProducerBothTransportsDecideToPause.<locals>.TLSConnection.recv  s
    #o%rJ   r  N)r\   r]   r^   r_   rH   r/  r  r  r  r  r  rb   rc   rJ   rG   TLSConnectionr  t  s%    
!&rJ   r  r   r  r   r  rg  rk  N)r4   rw  r   r  rs   r   r   r  r  rd  rv  rl  rw   )rE   r  r  rs   r   r   rv  s   &      rG   1test_streamingProducerBothTransportsDecideToPauseBTLSProducerTests.test_streamingProducerBothTransportsDecideToPaused  sD   	2_ 	2	& 	&> +,	040K0Kmo 1L 1
-X 	//= 	  &&x0""**1-//:11G9= 	&&668//=11GX3FG  *//=11GX3FGrJ   c                    V P                  4       w  rpVP                  P                  P                  4        V P	                  VP
                  R4       R# )zr
If the underlying transport tells its producer to stopProducing(),
this is passed on to the high-level producer.
stoppedN)rw  rs   rv  rp  r   r  r  s   &   rG   #test_streamingProducerStopProducing4TLSProducerTests.test_streamingProducerStopProducing  sE    
 $(#>#>#@ &&446//;rJ   c                `  a aaa \        4       w  po\        VP                  4      oVP                  P                  SR4       SP                  P                  P
                  oS P                  S\        4       S P                  SP
                  S4       S P                  SP                  VP                  4       S P                  SP                  P                  4       VV VV3R lpSP                  P                  V4       \        RR7      w  r4S P                  SV4       SP                  # )z=
Non-streaming producers get wrapped as streaming producers.
Fc                   < SP                  SP                  4       SP                  SP                  P                  4       SP	                  SP
                  4       R # rB   )r  consumerrs   rv  r  rC   )ignorerv  rE   streamingProducerr   s   &rG   done8TLSProducerTests.test_nonStreamingProducer.<locals>.done  sD    h//0k33<<=OO-778rJ   Tr  )r   r3   rs   rs  rv  r  r  r   r   	_consumerr  rt  r  rC  r  )rE   r   r  rZ  r{  rv  r  r   s   f    @@@rG   test_nonStreamingProducer*TLSProducerTests.test_nonStreamingProducer  s     '7&8#'(@(@A 	  11(EB'11::DD 	/=*44h?*44n6N6NO--778	9 	9 	##D),<D,I)!!+/@ArJ   c                n    \        4       p\        V4      pV P                  \        \        V4      4       R# )z3
L{_ProducerMembrane} implements L{IPushProducer}.
N)r4   r   r  r   r+   )rE   rv  membranes   &  rG   test_interfaceTLSProducerTests.test_interface  s)     #$$X.]H=>rJ   c                8   \        4       w  r#R Vn         ! R R4      pVP                  \        \        4       4      4       V! 4       pVP	                  VR4       V P                  VP                  P                  4       V P                  VP                  4       R# )z
If a producer is registered after the transport has disconnected, the
producer is not used, and its stopProducing method is called.
c                6    V P                  \        \        4      # rB   )r>  r   r&   r}   s   &rG   r   FTLSProducerTests.registerProducerAfterConnectionLost.<locals>.<lambda>  s    v{{>8
rJ   c                  &    ] tR tRtRtR tR tRtR# )FTLSProducerTests.registerProducerAfterConnectionLost.<locals>.Produceri  Fc                	    ^^ ,          # r  rc   rk   s   &rG   rl  VTLSProducerTests.registerProducerAfterConnectionLost.<locals>.Producer.resumeProducing  s    1urJ   c                	    R V n         R# r   r  rk   s   &rG   rp  TTLSProducerTests.registerProducerAfterConnectionLost.<locals>.Producer.stopProducing  s	    #rJ   r  N)r\   r]   r^   r_   r  rl  rp  rb   rc   rJ   rG   Producerr    s    G$rJ   r  FN)
r   r~   r8   r%   rs  r  rs   rv  r  r  )rE   rt  r   r   r  rv  s   &&    rG   #registerProducerAfterConnectionLost4TLSProducerTests.registerProducerAfterConnectionLost  s    
 '7&8#)
%	$ 	$ 	""7>+;#<= :$$Xu5+//889(()rJ   c                (    V P                  R4       R# )z
If a streaming producer is registered after the transport has
disconnected, the producer is not used, and its stopProducing method
is called.
TNr  rk   s   &rG   )test_streamingProducerAfterConnectionLost:TLSProducerTests.test_streamingProducerAfterConnectionLost  s     	006rJ   c                (    V P                  R4       R# )z
If a non-streaming producer is registered after the transport has
disconnected, the producer is not used, and its stopProducing method
is called.
FNr  rk   s   &rG   ,test_nonStreamingProducerAfterConnectionLost=TLSProducerTests.test_nonStreamingProducerAfterConnectionLost  s     	007rJ   rc   )F)NNFN)r\   r]   r^   r_   r`   r^  rw  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rb   rc   rJ   rG   rY  rY  i  st    (%:NC$?@ ?$>0
?:	:0Nd65FHP<@?*:78rJ   rY  c                  V    ] tR tRtRtR tR tR tR tR t	R t
R	 tR
 tR tR tRtR# )NonStreamingProducerTestsi  zH
Non-streaming producers can be adapted into being streaming producers.
c                   a aa \        S4      p\        VS4      oSP                  SR4       SP                  3V3R llpVSn        VP                  pVV V3R lpVP                  V4       SP                  4        V# )zL
Verify the consumer writes out all its data, but is not called after
that.
Tc                6   < V ! 4        SP                  4        R # rB   stopStreamingorigr  s   &rG   
unregister<NonStreamingProducerTests.streamUntilEnd.<locals>.unregister      F++-rJ   c                   < SP                  SP                  4       R 4       SP                  SP                  4       SP	                  SP
                  4       R# )s
   0123456789N)r   r  r  rv  r  rC   )r1  r  rE   r  s   &rG   doneStreaming?NonStreamingProducerTests.streamUntilEnd.<locals>.doneStreaming%  sA    X^^-}=h//0OO-778rJ   )r3   r   rs  r  r  rC  startStreaming)rE   r  
nsProducerr	  r  r  r  s   ff    @rG   streamUntilEnd(NonStreamingProducerTests.streamUntilEnd  sz    
 *(3
'
H=!!"3T: %77 	. '1#  	9 	' 	((*rJ   c                8    \        4       pV P                  V4      # )z{
When converted to a streaming producer, the non-streaming producer
writes out all its data, but is not called after that.
r4   r  )rE   r  s   & rG   test_writeUntilDone-NonStreamingProducerTests.test_writeUntilDone2  s    
 #$""8,,rJ   c                0  a a  ! R R\         4      pV! 4       p\        V4      p\        W24      oVP                  SR4       V 3R lpVP                  P                  V4       VP                  pV V3R lpVP                  V4       SP                  4        V# )ze
When the streaming producer is paused, the underlying producer stops
getting resumeProducing calls.
c                  &    ] tR tRt^ tR tR tRtR# )DNonStreamingProducerTests.test_pause.<locals>.PausingStringTransporti@  c                	P    \         P                  ! V 4       \        4       V n        R # rB   )r4   rH   r#   r  rk   s   &rG   rH   MNonStreamingProducerTests.test_pause.<locals>.PausingStringTransport.__init__C  s    ((.&jrJ   c                	    V ;P                   ^,          un         \        P                  ! W4       V P                   ^8X  d<   V P                  P	                  4        V P
                  pV =VP                  R4       R# R# r  )writesr4   r   rv  rh  r  rQ   )rE   rv   r  s   && rG   r   JNonStreamingProducerTests.test_pause.<locals>.PausingStringTransport.writeG  sY    q %%d1;;!#MM002AJJt$	 $rJ   )r  N)r\   r]   r^   r_   r  rH   r   rb   rc   rJ   rG   r  r  @  s    F)%rJ   r  Tc                *   < SP                  R 4       R# )z$BUG: The producer should not finish!N)fail)r  rE   s   &rG   shouldNotBeCalled?NonStreamingProducerTests.test_pause.<locals>.shouldNotBeCalledV  s    II<=rJ   c                T   < SP                  SP                  P                  ^4       R# r  )r   	_coopTask_pauseCount)r  rE   r  s   &rG   r  4NonStreamingProducerTests.test_pause.<locals>.paused]  s     .88DDaHrJ   )r4   r3   r   rs  r  rC  r  r  )rE   r  r  r  r!  r  r  r  s   f      @rG   
test_pause$NonStreamingProducerTests.test_pause:  s    	%_ 	%  *+)(3
'
=!!"3T:	> 	%%&78	I 	  	((*rJ   c                P     ! R R\         4      pV! 4       pV P                  V4      # )z
When the streaming producer is paused and then resumed, the underlying
producer starts getting resumeProducing calls again after the resume.

The test will never finish (or rather, time out) if the resume
producing call is not working.
c                       ] tR tRt^ tR tRtR# )ENonStreamingProducerTests.test_resume.<locals>.PausingStringTransportip  c                	    V ;P                   ^,          un         \        P                  ! W4       V P                   ^8X  d7   V P                  P	                  4        V P                  P                  4        R# R# r  )r  r4   r   rv  rh  rl  ru   s   &&rG   r   KNonStreamingProducerTests.test_resume.<locals>.PausingStringTransport.writes  sO    q %%d1;;!#MM002MM113 $rJ   rc   Nr\   r]   r^   r_   r  r   rb   rc   rJ   rG   r  r+  p  s    F4rJ   r  r  )rE   r  r  s   &  rG   test_resume%NonStreamingProducerTests.test_resumeg  s)    	4_ 	4 *+""8,,rJ   c                   a aaa  ! R R\         4      pV! 4       o\        S4      o\        SS4      oSP                  SR4       SP                  pVVV V3R lpVP                  V4       SP                  4        V# )zw
When the streaming producer is stopped by the consumer, the underlying
producer is stopped, and streaming is stopped.
c                       ] tR tRt^ tR tRtR# )MNonStreamingProducerTests.test_stopProducing.<locals>.StoppingStringTransporti  c                	    V ;P                   ^,          un         \        P                  ! W4       V P                   ^8X  d   V P                  P	                  4        R# R# r  )r  r4   r   rv  rp  ru   s   &&rG   r   SNonStreamingProducerTests.test_stopProducing.<locals>.StoppingStringTransport.write  s?    q %%d1;;!#MM//1 $rJ   rc   Nr.  rc   rJ   rG   StoppingStringTransportr3    s    F2rJ   r6  Tc                   < SP                  SP                  4       R 4       SP                  SP                  4       SP                  SP                  4       R# )s   012N)r   r  r  r  rC   )r1  r  r  rE   r  s   &rG   r  CNonStreamingProducerTests.test_stopProducing.<locals>.doneStreaming  s?    X^^-v6OOJ../OO-778rJ   )r4   r3   r   rs  r  rC  r  )rE   r6  r  r  r  r  r  s   f   @@@rG   test_stopProducing,NonStreamingProducerTests.test_stopProducing}  sy    	2o 	2 +,)(3
'
H=!!"3T:  	9 	9 	' 	((*rJ   c                  a aaaa	  ! R R\         4      pV! S4      p\        VS4      o	SP                  S	R4       . o\        P                  ! SP
                  4       S P                  \        P                  SP
                  4       SP                  3V	3R llpVSn        S	P                  4        S	P                  P                  4       pVP                  R 4       VVVV V	3R lpVP                  V4       V# )zw
Common implementation for tests where the underlying producer throws
an exception when its resumeProducing is called.
c                      ] tR tRtR tRtR# )INonStreamingProducerTests.resumeProducingRaises.<locals>.ThrowingProduceri  c                	f    V P                   ^8X  d
   ^^ ,          # \        P                  ! V 4       R# r  )counterr3   rl  rk   s   &rG   rl  YNonStreamingProducerTests.resumeProducingRaises.<locals>.ThrowingProducer.resumeProducing  s%    <<1$q5L(88>rJ   rc   N)r\   r]   r^   r_   rl  rb   rc   rJ   rG   ThrowingProducerr=    s    ?rJ   rA  Tc                6   < V ! 4        SP                  4        R # rB   r  r  s   &rG   r	  CNonStreamingProducerTests.resumeProducingRaises.<locals>.unregister  r  rJ   c                ,    V P                  \        4      # rB   )r>  r2   r  s   &rG   r   ANonStreamingProducerTests.resumeProducingRaises.<locals>.<lambda>  s    v{{;'?rJ   c                  < S	P                  SP                  4       R 4       S	P                  4       pS	P                  \        V4      \        S4      4       \	        VSS4       FA  w  pw  r4pS	P                  VP                  V4      4       S	P                  WER,          4       KC  	  S	P                  S
P                  4       R# )s   01whyN)	r   r  r  rr   zipr  rz   assertInrC   )r  errorsfexpectedmsglogMsgr  expectedExceptions
loggedMsgsrE   r  s   &     rG   r  @NonStreamingProducerTests.resumeProducingRaises.<locals>.stopped  s    X^^-u5++-FS[#.@*AB.1*J/*?HF  12c%=1	/ OO-778rJ   )r3   r   rs  r7   r   ro   r   r   r  r  r$  whenDone
addErrbackrC  )
rE   r  rO  rA  r  r	  r  r  rP  r  s
   fff     @@rG   resumeProducingRaises/NonStreamingProducerTests.resumeProducingRaises  s    	?3 	? &h/
'
H=!!"3T: 

))***J,=,=> %77 	. '1# 	((* **335?@	9 	9 	!rJ   c                   a a \        4       oS P                  S\        R3.4      pVV 3R lpVP                  V4       V# )z
If the underlying producer raises an exception when resumeProducing is
called, the streaming wrapper should log the error, unregister from
the consumer and stop streaming.
z while calling resumeProducing onc                >   < SP                  SP                  4       R # rB   )r  rv  )r  r  rE   s   &rG   cleanShutdownKNonStreamingProducerTests.test_resumeProducingRaises.<locals>.cleanShutdown  s    h//0rJ   )r4   rT  ZeroDivisionErrorrC  )rE   r  rX  r  s   f  @rG   test_resumeProducingRaises4NonStreamingProducerTests.test_resumeProducingRaises  sF     #$)))+MNO
	1 	'rJ   c                h    \        4       pR pW!n        V P                  V\        R3\        R3.4      # )z
If the underlying producer raises an exception when resumeProducing is
called, the streaming wrapper should log the error, unregister from
the consumer and stop streaming even if the unregisterProducer call
also raise.
c                     \        4       hrB   )r  rc   rJ   rG   raiser^NonStreamingProducerTests.test_resumeProducingRaiseAndUnregisterProducerRaises.<locals>.raiser  s
    . rJ   zwhile calling resumeProducingz while calling unregisterProducer)r4   r  rT  rZ  r  )rE   r  r_  s   &  rG   4test_resumeProducingRaiseAndUnregisterProducerRaisesNNonStreamingProducerTests.test_resumeProducingRaiseAndUnregisterProducerRaises  sF     #$	! '-#))"$CDAB
 	
rJ   c                    \        4       p\        V4      p\        W!4      pVP                  4        VP	                  4        VP	                  4        V P                  VP                  4       R# )zk
stopStreaming() can be called more than once without blowing
up. This is useful for error-handling paths.
N)r4   r3   r   r  r  r  rC   rE   r  r  r  s   &   rG   test_stopStreamingTwice1NonStreamingProducerTests.test_stopStreamingTwice  sX    
 #$)(3
'
=((*'')''))334rJ   c                    \        4       p\        V4      p\        W!4      pV P                  \	        \
        V4      4       R# )z-
L{_PullToPush} implements L{IPushProducer}.
N)r4   r3   r   r  r   r+   rd  s   &   rG   r  (NonStreamingProducerTests.test_interface  s5     #$)(3
'
=]4EFGrJ   rc   N)r\   r]   r^   r_   r`   r  r  r'  r/  r9  rT  r[  ra  re  r  rb   rc   rJ   rG   r  r    s>     D-+Z-,!F1f$
*5HrJ   r  c                  &    ] tR tRtRtR tR tRtR# )ClientNegotiationFactoryi  zU
A L{ClientFactory} that has a set of acceptable protocols for NPN/ALPN
negotiation.
c                    Wn         R# )z
Create a L{ClientNegotiationFactory}.

@param acceptableProtocols: The protocols the client will accept
    speaking after the TLS handshake is complete.
@type acceptableProtocols: L{list} of L{bytes}
N_acceptableProtocolsrE   acceptableProtocolss   &&rG   rH   !ClientNegotiationFactory.__init__  
     %8!rJ   c                    V P                   # z
Returns a list of protocols that can be spoken by the connection
factory in the form of ALPN tokens, as laid out in the IANA registry
for ALPN tokens.

@return: a list of ALPN tokens in order of preference.
@rtype: L{list} of L{bytes}
rl  rk   s   &rG   ro  ,ClientNegotiationFactory.acceptableProtocols"       (((rJ   rl  Nr\   r]   r^   r_   r`   rH   ro  rb   rc   rJ   rG   rj  rj        
8	)rJ   rj  c                  &    ] tR tRtRtR tR tRtR# )ServerNegotiationFactoryi.  zU
A L{ServerFactory} that has a set of acceptable protocols for NPN/ALPN
negotiation.
c                    Wn         R# )z
Create a L{ServerNegotiationFactory}.

@param acceptableProtocols: The protocols the server will accept
    speaking after the TLS handshake is complete.
@type acceptableProtocols: L{list} of L{bytes}
Nrl  rn  s   &&rG   rH   !ServerNegotiationFactory.__init__5  rq  rJ   c                    V P                   # rs  rl  rk   s   &rG   ro  ,ServerNegotiationFactory.acceptableProtocols?  ru  rJ   rl  Nrv  rc   rJ   rG   ry  ry  .  rw  rJ   ry  c                      ] tR tRtRt]! ]P                  ! ]P                  ! ]P                  ! 4       ]P                  ! ^RR7      P                  R 4      4      RR7      4      R R	 l4       tR
tR# )_AggregateSmallWritesTestsiK  z$Tests for ``_AggregateSmallWrites``.r  )	min_value	max_valuec                	6    R V ^,          ^,           ,          RV  # )s   0123456789ABCDEFGHIJNrc   )lengths   &rG   r   #_AggregateSmallWritesTests.<lambda>]  s    $;"PQ?Q$R$rJ   i  )max_sizec                    V ^8  d   QhRRRR/# )r  r  zlist[Union[bytes, None]]returnNonerc   )formats   "rG   __annotate__'_AggregateSmallWritesTests.__annotate__e  s     2 21I 2d 2rJ   c                   . p\        4       p\        VP                  V4      pV F+  pVf   VP                  ^ 4       K  VP	                  V4       K-  	  VP                  4        V P                  RP                  V4      RP                  R V 4       4      4       VR,          pV F  p\        V4      pV'       d   V^ ,          f   VP                  ^ 4       K&  ^ p	V'       g   K@  VP                  ^ 4      p
V
f   V P                  W4       Kh  V	\        V
4      ,          p	WP                  8  g   KV  V P                  W4       K  	  R# )a)  
A L{_AggregateSmallWrites} correctly aggregates data for the given
sequence of writes (indicated by bytes) and increments in the clock
(indicated by C{None}).

If multiple writes happen in between reactor iterations, they should
get written in a batch at the start of the next reactor iteration.
NrJ   c              3  0   "   T F  qf   K  Vx  K  	  R # 5irB   rc   )r=  r  s   & rG   r@  H_AggregateSmallWritesTests.test_writes_get_aggregated.<locals>.<genexpr>  s     &V&uu&s   
:NNN)r   r   ro   r  r   r   r   r   rr   popMAX_BUFFER_SIZE)rE   r  r  r   	aggregater  small_writeschunkcombined_lengthsmall_writes_lengthnext_original_maybe_writes   &&         rG   test_writes_get_aggregated5_AggregateSmallWritesTests.test_writes_get_aggregatedS  s   : !)&--?	E}a &	  	 	HHVchh&V&&VV	
 ayE!%jO<?#:  #"#,,8,<,<Q,?),4$$_J'3/H+II'*-F-FF((N rJ   rc   N)r\   r]   r^   r_   r`   r   stlistsone_ofnoneintegersrq   r  rb   rc   rJ   rG   r  r  K  sd    . 
II	 a7;?? 	
$2%$2rJ   r  )FNNN)NF)gr`   
__future__r   rB  typingr   zope.interfacer   r   r   zope.interface.verifyr   
hypothesisr   r	   r  twisted.internetr
   twisted.internet.taskr   r   twisted.python.compatr   OpenSSLr   OpenSSL.SSLr   r   r   r   r   r   r   r   r   twisted.protocols.tlsr   r   r   r   r   twisted.internet.sslr   r   twisted.test.ssl_helpersr   r    r!   twisted.test.test_sslverifyr"   ImportErrorskiptwisted.internet.deferr#   r$   twisted.internet.errorr%   r&   twisted.internet.interfacesr'   r(   r)   r*   r+   r,   r-   twisted.internet.protocolr.   r/   r0   r1   r2   twisted.internet.testingr3   r4   twisted.protocols.loopbackr5   r6   twisted.pythonr7   twisted.python.failurer8   twisted.python.filepathr9   twisted.test.iosimr:   twisted.test.test_tcpr<   twisted.trial.unittestr=   r>   r@   re   r   r   r   r   r  rY  r  rj  ry  r  rc   rJ   rG   <module>r     s   # 	  C C . . $ 3 +N
 
 
  MUUM : A   V U - J J  * , 7 A @( (V8 6''T.Ax .Ab> B4M%8 4MnB< B<J_8x _8DCH CHL ())} ) *)8 ())} ) *)8L!4 LA9  GHDBFFJFFGs    *E; ;FF