Ϫft dZddlmZddlZddlmZddlmZmZm Z ddl m Z ddl m Z mZddlmZdd lmZmZdd lmZ dd lmZdd lmZmZmZmZmZmZm Z m!Z!m"Z"dd l#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+ddl,m-Z-m.Z.m/Z/ddl0m1Z1ddl4m5Z5m6Z6ddl7m8Z8m9Z9ddl:m;Z;mZ>m?Z?m@Z@mAZAddlBmCZCmDZDmEZEmFZFddlmGZGddlHmIZImJZJddlKmLZLmMZMddlNmOZOddlPmQZQddlRmSZSddlTmUZUddlVmWZWddlXmYZYmZZZGdd Z[Gd!d"eEZ\ d5d#Z]Gd$d%eZZ^ d6d&Z_Gd'd(eYZ`Gd)d*eZZaGd+d,eZZbGd-d.eZZce e>Gd/d0eCZde e>Gd1d2eFZeGd3d4eYZfy#e2$rdZ3dxZxZ!xZZ Y wxYw)7z% Tests for L{twisted.protocols.tls}. ) annotationsN)Union) InterfacedirectlyProvides implementer) verifyObject)given strategies)reactor)Clock deferLater) iterbytes)crypto) SSL_CB_HANDSHAKE_DONE TLS_METHOD ConnectionContextErrorTLSv1_1_METHODTLSv1_2_METHOD TLSv1_METHOD WantReadError)TLSMemoryBIOFactoryTLSMemoryBIOProtocol_AggregateSmallWrites_ProducerMembrane _PullToPush)PrivateCertificateoptionsForClientTLS)ClientTLSContextServerTLSContextcertPath)!certificatesForAuthorityAndServerz;pyOpenSSL 16.0.0 or newer required for twisted.protocol.tls)Deferred gatherResults)ConnectionDoneConnectionLost)IHandshakeListenerIOpenSSLClientConnectionCreatorIOpenSSLServerConnectionCreatorIProtocolNegotiationFactory IPushProducer ISSLTransport ISystemHandle) ClientFactoryFactoryProtocol ServerFactory) TaskStopped)NonStreamingProducerStringTransport)collapsingPumpPolicy loopbackAsync)log)Failure)FilePath)connectedServerAndClientConnectionLostNotifyingProtocol)SynchronousTestCaseTestCasec6eZdZdZefdZedZdZdZ y)HandshakeCallbackContextFactorya 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. c0t|_||_yN)r$ _finished_method)selfmethods A/usr/lib/python3/dist-packages/twisted/protocols/test/test_tls.py__init__z(HandshakeCallbackContextFactory.__init__Ts! c,|}||jfS)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. )rD)clscontextFactorys rHfactoryAndDeferredz2HandshakeCallbackContextFactory.factoryAndDeferredXs~7777rJcN|tzr|jjdyy)a 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)rrDcallback)rF connectionwhererets rH_infoz%HandshakeCallbackContextFactory._infobs$ ( ( NN # #D ) )rJcft|j}|j|j|S)zp Create and return an SSL context configured to use L{self._info} as the info callback. )rrEset_info_callbackrT)rFcontexts rH getContextz*HandshakeCallbackContextFactory.getContextls) $,,'!!$**-rJN) __name__ __module__ __qualname____doc__rrI classmethodrNrTrXrJrHrArAKs/)88*rJrAc(eZdZdZdZdZdZdZy)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||_yrC)howMany)rFrbs rHrIzAccumulatingProtocol.__init__s  rJcg|_yrC)receivedrFs rHconnectionMadez#AccumulatingProtocol.connectionMades  rJc|jj|ttt|j|j k\r|j jyyrC)rdappendsummaplenrb transportloseConnectionrFdatas rH dataReceivedz!AccumulatingProtocol.dataReceivedsE T" s3 & '4<< 7 NN ) ) + 8rJcZ|jtstj|yyrC)checkr&r8errrFreasons rHconnectionLostz#AccumulatingProtocol.connectionLosts||N+ GGFO,rJN)rYrZr[r\rIrfrprvr^rJrHr`r`vs, rJr`cf td t} fd|_r+ttt Gfdd}|}n|r t |}n t}t}t|| ||}|jd} | t}| j| | fS)a  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. lJ)cSrCr^clientProtocolsrHz"buildTLSProtocol..s^rJceZdZfdZeZy)-buildTLSProtocol..HardCodedConnectioncSrCr^)rF tlsProtocolfakeConnections rHclientConnectionForTLSzDbuildTLSProtocol..HardCodedConnection.clientConnectionForTLSs %%rJN)rYrZr[rserverConnectionForTLSrsrHHardCodedConnectionr}s &&< "rJrrGN) r`r/protocolrr*r)r!r r r buildProtocolr5makeConnection) serverrlr serverMethod clientFactoryrrMclockwrapperFactory sslProtocolrzs ` @rHbuildTLSProtocolrs*,7N!OM3M 46U V < < W < -. -\BN-/N GE(F M5N!..t4K#% y) ; &&rJc"eZdZdZdZdZdZy)TLSMemoryBIOFactoryTestsz< Ensure TLSMemoryBIOFactory logging acts correctly. cPt}g}|j}tj||j tj |t }d|_d|_t|d|}|j|j|j|gy)zs L{TLSMemoryBIOFactory.doStart} and L{TLSMemoryBIOFactory.doStop} do not log any messages. cyrCr^r^rJrHr{z5TLSMemoryBIOFactoryTests.test_quiet..rJcyrCr^r^rJrHr{z5TLSMemoryBIOFactoryTests.test_quiet..rrJFN) r!rhr8 addObserver addCleanupremoveObserverr2doStartdoStopr assertEqual)rFrMlogsloggerwrappedFactoryfactorys rH test_quietz#TLSMemoryBIOFactoryTests.test_quiets *+  **F3&!- ,%ne^L r"rJct}t|dt}|jd|j y)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. FzServerFactory (TLS)N)r!rr2r logPrefix)rFrMrs rHtest_logPrefixz'TLSMemoryBIOFactoryTests.test_logPrefixs6 *+%ne]_M .0A0A0CDrJcGdd}t}t|d|}|jd|jy)z If the wrapped factory does not provide L{ILoggingContext}, L{TLSMemoryBIOFactory.logPrefix} uses the wrapped factory's class name. c eZdZy)BTLSMemoryBIOFactoryTests.test_logPrefixFallback..NoFactoryNrYrZr[r^rJrH NoFactoryr rJrFzNoFactory (TLS)N)r!rrr)rFrrMrs rHtest_logPrefixFallbackz/TLSMemoryBIOFactoryTests.test_logPrefixFallbacks@   *+%neY[I *G,=,=,?@rJN)rYrZr[r\rrrr^rJrHrrs#(E ArJrc t\}}t}ttGfddtttGddt t t d|dtjfd|  t |jd tj fd |  t fd  fd d |\}}}|||fS)a 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:eZdZdZdZfdZfdZdZxZS)*handshakingClientAndServer..ClientFNc^t||jjyyrC)superrfrlwrite)rF __class__clientGreetingDatas rHrfz9handshakingClientAndServer..Client.connectionMades, G " $!-$$%78.rJcd|_|jj|_r|jj yyNT) handshookrlgetPeerCertificatepeerAfterHandshakeabortConnection)rFclientAbortAfterHandshakes rHhandshakeCompletedz=handshakingClientAndServer..Client.handshakeCompleteds7!DN&*nn&G&G&ID #(..0)rJcyrCr^rts rHrvz9handshakingClientAndServer..Client.connectionLost  rJ) rYrZr[rrrfrrv __classcell__)rrrs@rHClientrs ! 9  1  rJrceZdZdZdZdZy)*handshakingClientAndServer..ServerFcd|_yr) handshakedres rHrz=handshakingClientAndServer..Server.handshakeCompleteds "DOrJcyrCr^rts rHrvz9handshakingClientAndServer..Server.connectionLostrrJN)rYrZr[rrrvr^rJrHServerrs  # rJr example.com trustRootTcdSNi?Br^)rsrHr{z,handshakingClientAndServer.. rJ)isClientrrFcdSrr^)rsrHr{z,handshakingClientAndServer..!rrJc&jdSrCr)serverFsrHr{z,handshakingClientAndServer..%%%d+rJc&jdSrCr)clientFsrHr{z,handshakingClientAndServer..&rrJ)greetr) r#r rr(r`rrr/ forProtocoloptionsr2r;) rrauthCert serverCertrclientrpumprrrrs `` @@@@rHhandshakingClientAndServerrs=>Hj GE#$%%$#$%%"MX>$001GH G "$001GH G 4++ FFD 64 rJc"eZdZdZdZdZdZy)DeterministicTLSMemoryBIOTestsz 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. ct\}}}|j|jjd|j|jjd|j |j|jjd|j|jjd|j |jjdy)a 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)rrwrappedProtocolrrflush assertIsNotr)rFrrrs rHtest_handshakeNotificationz9DeterministicTLSMemoryBIOTests.test_handshakeNotification6s :; //995A //::EB  //994@ //::DA //BBDIrJctdd\}}}|j}|j|j|jgy)a 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)rrrrrdrFrrrwrappedServerProtocols rHtest_handshakeStopWritingz8DeterministicTLSMemoryBIOTests.test_handshakeStopWritingEsD ::JDQ & 6 6  .77 %T40  0078  0078rJc(Gddt}Gdd}t}t}t|d|}|}t ||t |t }|j||j|j|y)zw L{TLSMemoryBIOProtocol} instances provide the interfaces provided by the transport they wrap. c eZdZy)DTLSMemoryBIOTests.test_wrappedProtocolInterfaces..ITransportNrr^rJrH ITransportryrrJrceZdZdZy)ETLSMemoryBIOTests.test_wrappedProtocolInterfaces..MyTransportcyrCr^rns rHrzKTLSMemoryBIOTests.test_wrappedProtocolInterfaces..MyTransport.write}rJN)rYrZr[rr^rJrH MyTransportr|s rJrTN) rr/r rrrr1rrr)rFrrrrMrrlrs rHtest_wrappedProtocolInterfacesz0TLSMemoryBIOTests.test_wrappedProtocolInterfacesss{     & )+,^T=QM J/*>8:F ""9-  --k:;rJct}t}t|d|}t|t }t }|j ||j|jty)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 rrr1r5rassertIsInstance getHandler)rFrrMrrrls rHtest_getHandlez TLSMemoryBIOTests.test_getHandles\ /)+,^T7K$^XZ@#%  Y' eoo/.rJTN) r1r/rr rrr5rassertIsNotNonerlrassertIs)rFrrMrrrlrzs @rHtest_makeConnectionz%TLSMemoryBIOTests.test_makeConnections "% !7 )+,^T=Q$2248 #% ""9- ^556 119= n..  > @ ,-A4W*88>% !) /1,-A5-X*88>*+<>OP       rJc0|j\}}}}|S)zr The TLS handshake is performed when L{TLSMemoryBIOProtocol} is connected to a transport. )r)rF tlsClient tlsServerr_s rHtest_handshakez TLSMemoryBIOTests.test_handshakes$ 6:5L5L5N2 9/! rJc t t} fd|_t}t |d|}|j d}t t } fd|_ttj}tj|}|j|}t |d|}|j d} t| |} d} j|  j| t | gS)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. ctSrCr<clientConnectionLostsrHr{z9TLSMemoryBIOTests.test_handshakeFailure..)H * rJTNctSrCr<)serverConnectionLostsrHr{z9TLSMemoryBIOTests.test_handshakeFailure..rrJFcB|jjtyrC)lostConnectionReasontrapr)rs rHcbConnectionLostzATLSMemoryBIOTests.test_handshakeFailure..cbConnectionLosts  ) ) . .u 5rJ)r$r/rrArrr2r:r" getContentrloadPEMrr7 addCallbackr%)rFrrrr r certificateData certificater r r rrrs @@rHtest_handshakeFailurez'TLSMemoryBIOTests.test_handshakeFailures (z% "  ?@,-A4W*88>'z% "  #8,779(00A *22;?,-A5-X*88>*+<>OP 6 (()9:(()9: !#79K L  rJc^ t}t|_tj \}}t |d|}|j d t}t|_t}t |d|}|j d}t|  fd}|j||S)z L{TLSMemoryBIOProtocol.getPeerCertificate} returns the L{OpenSSL.crypto.X509} instance representing the peer's certificate. TNFcj}j|tjj |j ddy)Nsha256s_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:40)rrrX509rdigest)ignoredcertrFr s rH cbHandshookz>TLSMemoryBIOTests.test_getPeerCertificate..cbHandshook(sD$779D  ! !$ 4    H%8  rJ) r/r1rrArNrrr2r!r7r!) rFrrrrr r r r,r s ` @rHtest_getPeerCertificatez)TLSMemoryBIOTests.test_getPeerCertificate s& !)  , > > @ ,-A4W*88>% !) /1,-A5-X*88>'):;  %%k2  rJc d t t} fd|_tj \}}t |d|}|j d}tt t}fd|_t}t |d|}|j d}t|| fd} |j|  fd} |j| |S) 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 bytescSrCr^rysrHr{z.ArrJTNcSrCr^serverProtocolsrHr{z.LrrJFc>jjSrCrlr)r*rzr ros rHr,z?TLSMemoryBIOTests.test_writeAfterHandshake..cbHandshookUs  $ $ * *4 0& %rJc\jdjjyNrJrrrdr*rorFr4s rHcbDisconnectedzBTLSMemoryBIOTests.test_writeAfterHandshake..cbDisconnected_"   SXXn&=&=> ErJ) r1r/rrArNrrr`rkr2r!r7r!)rFrrrrr r r r r,r;rzr ror4s` @@@@rHtest_writeAfterHandshakez*TLSMemoryBIOTests.test_writeAfterHandshake7s !% !7  , > > @ ,-A4W*88>-c$i8% !7 /1,-A5-X*88>*+<>OP & %%k2 F %%n5  rJc t}||_tj\}}t |d|}|j d}t t t} fd|_t} t | d|}|j d} t| |}  fd} | j| | S)z{ Run test where client sends data before handshake, given the sending protocol and expected bytes. TNcSrCr^r3srHr{z.wrrJFc\jdjjyr8r9r:s rHcbConnectionDonezDTLSMemoryBIOTests.writeBeforeHandshakeTest..cbConnectionDoner<rJ) r/rrArNrrr`rkr2r!r7r!)rFsendingProtocolrorrrrr r r r r rAr4s` ` @rHwriteBeforeHandshakeTestz*TLSMemoryBIOTests.writeBeforeHandshakeTestfs & !0  , > > @ ,-A4W*88>-c$i8% !7 /1,-A5-X*88>*+<>OP F &&'78!!rJcNdGfddt}|j|S)r/r0ceZdZfdZy)JTLSMemoryBIOTests.test_writeBeforeHandshake..SimpleSendingProtocolc<|jjyrCr6rns rHrfzYTLSMemoryBIOTests.test_writeBeforeHandshake..SimpleSendingProtocol.connectionMades$$T*rJNrYrZr[rfrosrHSimpleSendingProtocolrFs +rJrJr1rCrFrJros @rHtest_writeBeforeHandshakez+TLSMemoryBIOTests.test_writeBeforeHandshakes,  +H +,,-BDIIrJcNdGfddt}|j|S)z Bytes written to L{TLSMemoryBIOProtocol} with C{writeSequence} are received by the protocol on the other side of the connection. r0ceZdZfdZy)CTLSMemoryBIOTests.test_writeSequence..SimpleSendingProtocolc`|jjttyrC)rl writeSequencelistrrns rHrfzRTLSMemoryBIOTests.test_writeSequence..SimpleSendingProtocol.connectionMades,,T)D/-BCrJNrHrIsrHrJrPs  DrJrJrKrLs @rHtest_writeSequencez$TLSMemoryBIOTests.test_writeSequences.  DH D,,-BDIIrJcNdGfddt}|j|S)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). r0ceZdZfdZy)NTLSMemoryBIOTests.test_writeAfterLoseConnection..SimpleSendingProtocolc|jj|jj|jjd|jjdgy)Nrworld)rlrrmrRrns rHrfz]TLSMemoryBIOTests.test_writeAfterLoseConnection..SimpleSendingProtocol.connectionMadesK$$T*--/$$X.,,hZ8rJNrHrIsrHrJrWs 9rJrJrKrLs @rHtest_writeAfterLoseConnectionz/TLSMemoryBIOTests.test_writeAfterLoseConnections,  9H 9,,-BDIIrJcdgGfddt}fdj|d}|jfd|jfd|S)zV Writing C{unicode} to L{TLSMemoryBIOProtocol} throws a C{TypeError}. helloceZdZfdZy)QTLSMemoryBIOTests.test_writeUnicodeRaisesTypeError..SimpleSendingProtocolc |jj|jjd|jjy#t$r.j d|jj YywxYw)NbytesT)rlrrm TypeErrorrhr)rFnotBytesresults rHrfz`TLSMemoryBIOTests.test_writeUnicodeRaisesTypeError..SimpleSendingProtocol.connectionMadesg5NN((2NN((2NN113 5MM$'NN2245sAA4B  B NrH)rbrcsrHrJr^s 5rJrJcljtjttdy)N)rrkflushLoggedErrorsr'raresrHflush_logged_errorszOTLSMemoryBIOTests.test_writeUnicodeRaisesTypeError..flush_logged_errorss&   S!7!7 !RSUV WrJr`c*jdgSr)r)ignrcrFs rHr{zDTLSMemoryBIOTests.test_writeUnicodeRaisesTypeError..sd..vv>rJc&ttdSNr)r r )rirgs rHr{zDTLSMemoryBIOTests.test_writeUnicodeRaisesTypeError..sj!5HIrJ)r1rCaddBoth)rFrJdrgrbrcs` @@@rH test_writeUnicodeRaisesTypeErrorz2TLSMemoryBIOTests.test_writeUnicodeRaisesTypeErrorsU 5H 5 X  ) )*? J >? IJrJc gd G fddt}t}||_t}t |d|}|j d}t ttt  t} fd|_t}t |d|}|j d}t||t} fd} | j| | S) 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. ) abcdefghiceZdZfdZy)DTLSMemoryBIOTests.test_multipleWrites..SimpleSendingProtocolcJD]}|jj|yrCr6)rFbros rHrfzSTLSMemoryBIOTests.test_multipleWrites..SimpleSendingProtocol.connectionMades$,ANN((+,rJNrHrIsrHrJrzs ,rJrJTNcSrCr^r3srHr{z7TLSMemoryBIOTests.test_multipleWrites..rrJFczjdjjdjyr8r9r:s rHrAz?TLSMemoryBIOTests.test_multipleWrites..cbConnectionDones*   SXXn&=&=> OrJ)r1r/rrArrr`rirjrkr2r!r7r6r!) rFrJrrrr r r r r rAror4s ` @@rHtest_multipleWritesz%TLSMemoryBIOTests.test_multipleWritess F ,H , & !6 >@,-A4W*88>-c#c4..AB% !7 /1,-A5-X*88>* 02F   P &&'78!!rJc d d G fddt}t}||_t|}t |d|}|j d}t t  zt}fd|_t|}t |d |}|j d} t| |} fd } | j| | S) 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. r0iceZdZfdZy):TLSMemoryBIOTests.hugeWrite..SimpleSendingProtocolcB|jjzyrCr6)rFrofactors rHrfzITLSMemoryBIOTests.hugeWrite..SimpleSendingProtocol.connectionMades$$TF]3rJNrH)rorsrHrJrs 4rJrJrTNcSrCr^r3srHr{z-TLSMemoryBIOTests.hugeWrite.. rrJFcbjdjjzyr8r9)r*rorrFr4s rHrAz5TLSMemoryBIOTests.hugeWrite..cbConnectionDones&   SXXn&=&=>v NrJ) r1r/rrArrr`rkr2r!r7r!)rFrGrJrrrr r r r r rArorr4s` @@@rH hugeWritezTLSMemoryBIOTests.hugeWrites  4H 4& !6 >fM,-A4W*88>-c$i&.@A% !7 /v>,-A5-X*88>*+<>OP O &&'78!!rJc"|jSrC)rres rHtest_hugeWritez TLSMemoryBIOTests.test_hugeWrites~~rJc.|jtS)Nr)rrres rHtest_hugeWrite_TLSv1_2z(TLSMemoryBIOTests.test_hugeWrite_TLSv1_2s~~^~44rJctt}fd|_t}t |d|}|j d}t }t|||jjd}j|S)z~ If a L{TLSMemoryBIOProtocol} loses its connection unexpectedly, this is reported to the application. ctSrCr<rsrHr{z;TLSMemoryBIOTests.test_disorderlyShutdown..'rrJTNcL|jjttyrC)rrrr'rys rHr;zATLSMemoryBIOTests.test_disorderlyShutdown..cbDisconnected8s  / / 4 4UN KrJ) r$r/rrArrr1r7rlrmr!)rFrrrr r4r;rs @rHtest_disorderlyShutdownz)TLSMemoryBIOTests.test_disorderlyShutdown s (z% "  ?@,-A4W*88>"n&78   //1 L ((8##rJc Gddt}t t}| fd|_tj \}}t |d|}|jd}t|t}fd|_t}t |d|}|jd} t| |dd z fd } |j|  fd } |j| |S) z L{TLSMemoryBIOProtocol.loseConnection} sends a TLS close alert and shuts down the underlying connection cleanly on both sides, after transmitting all buffered data. ceZdZdZdZy)NTLSMemoryBIOTests.test_loseConnectionAfterHandshake..NotifyingProtocolc>tj||g|_yrC)r=rIro)rFonConnectionLosts rHrIzWTLSMemoryBIOTests.test_loseConnectionAfterHandshake..NotifyingProtocol.__init__Fs/88?OP rJc:|jj|yrC)rorhrns rHrpz[TLSMemoryBIOTests.test_loseConnectionAfterHandshake..NotifyingProtocol.dataReceivedJs   &rJN)rYrZr[rIrpr^rJrHNotifyingProtocolrEs   'rJrcSrCr^rysrHr{zETLSMemoryBIOTests.test_loseConnectionAfterHandshake..PrrJTNcSrCr^r3srHr{zETLSMemoryBIOTests.test_loseConnectionAfterHandshake..\rrJFs 123456890順cjjjjdjjtgS)Nx)rlrrmr%)r* chunkOfBytesrrzrr4s rH cbHandshakezHTLSMemoryBIOTests.test_loseConnectionAfterHandshake..cbHandshakefsS  $ $ * *< 8  $ $ * *4 0  $ $ 3 3 5!"68L!MN NrJc|\}}|jjt|jjtjdj |j j |jjjj |jjjyr8) rrr&rrrorrlq disconnect)rcrzr4rrFs rHrAzMTLSMemoryBIOTests.test_loseConnectionAfterHandshake..cbConnectionDoneys/5 ,^^  / / 4 4^ D  / / 4 4^ D   SXXn&9&9:L I OON4466AA B OON4466AA BrJ) r=r$r/rrArNrrr2r!r7r!)rFrrrrrr r r r rrArrrzrr4s` @@@@@rH!test_loseConnectionAfterHandshakez3TLSMemoryBIOTests.test_loseConnectionAfterHandshake>s ' ? ' (z% *+?@!7  , > > @ ,-A4W*88>'z*+?@% !7 /1,-A5-X*88>'):;#f,  O O %%k2  C" %%&67  rJcHGddt}ttdt}|}t ||}t }|j ||jd|j|j|j|j|jttd|j|jjt|j!|jj"j$dy)zz The user protocol's connectionLost is only called when transport underlying TLS is disconnected. ceZdZdZdZy)TTLSMemoryBIOTests.test_connectionLostOnlyAfterUnderlyingCloses..LostProtocolNc||_yrC) disconnectedrts rHrvzcTLSMemoryBIOTests.test_connectionLostOnlyAfterUnderlyingCloses..LostProtocol.connectionLosts $*!rJ)rYrZr[rrvr^rJrH LostProtocolrs L +rJrTNono)r)r1rr r/rr5r_tlsShutdownFinishedr disconnecting assertIsNonerrvr9r'rrrvalueargs)rFrrrrrls rH,test_connectionLostOnlyAfterUnderlyingClosesz>TLSMemoryBIOTests.test_connectionLostOnlyAfterUnderlyingClosess  +8 + --=-?}W>*>8D #% ""9- ((.  //0 (//0 ""7>%+@#AB --33NCD ..44998DrJcl|j\}}}}|j|g|jffd }||_|jd|j |j |j |jdg|j |jdg|S)z If TLSMemoryBIOProtocol.loseConnection is called multiple times, all but the first call have no effect. c4jd|SNrhshutdowncallss rH _shutdownTLSz@TLSMemoryBIOTests.test_loseConnectionTwice.._shutdownTLS LLO: rJrr)rsuccessResultOfrrrmrrr)rFrrrdisconnectDeferredrrs @rHtest_loseConnectionTwicez*TLSMemoryBIOTests.test_loseConnectionTwices  # # %      ./"+"8"8 ".   "  //0 $   " $"!rJcj\}}}g|jffd }|_jd|jfd}|j ||S)zq If TLSMemoryBIOProtocol.loseConnection is called after connectionLost, it does nothing. c4jd|Srrrs rHrzNTLSMemoryBIOTests.test_loseConnectionAfterConnectionLost.._shutdownTLSrrJrcrjdgjjdgyr)rrm)rrrFrs rHrzNTLSMemoryBIOTests.test_loseConnectionAfterConnectionLost..disconnecteds5   UQC (  $ $ &   UQC (rJ)rrrrmr!)rFrrrrrrrs` @@rH&test_loseConnectionAfterConnectionLostz8TLSMemoryBIOTests.test_loseConnectionAfterConnectionLostst  # # %      "+"8"8 ".   " ) &&|4!!rJc j\ }}}|j}g}g|j|_j|_ fd}|j |fd}|j ||S)zP Unexpected disconnects get converted to ConnectionLost errors. c\jdjjyNr)rrlrmrirs rH handshakeDonez;TLSMemoryBIOTests.test_unexpectedEOF..handshakeDones! OOH %    . . 0rJc\jdjtdyrk)rrrr'rirurFs rHrz:TLSMemoryBIOTests.test_unexpectedEOF..disconnected s" OOF1IOON;VAY GrJ)rrrhrprvr!) rFrrrr4rorrrurs ` @@rHtest_unexpectedEOFz$TLSMemoryBIOTests.test_unexpectedEOFs  # # %     "22&*kk#(. % 1 %%m4 H &&|4!!rJc j\}}}gjj_Gdd}|j_fd}|j |fd}|j ||S)zN Errors while writing cause the protocols to be disconnected. ceZdZdZdZdZy)4TLSMemoryBIOTests.test_errorWriting..Wrapperc||_yrC)_wrapped)rFwrappeds rHrIz=TLSMemoryBIOTests.test_errorWriting..Wrapper.__init__s ' rJc.t|j|SrC)getattrr)rFattrs rH __getattr__z@TLSMemoryBIOTests.test_errorWriting..Wrapper.__getattr__"st}}d33rJctdg)N)z SSL routinesz this message is probably useless)r)rFrs rHsendz9TLSMemoryBIOTests.test_errorWriting..Wrapper.send%sUVWWrJN)rYrZr[rIrrr^rJrHWrapperrs ( 4 XrJrc(jdyr)rrs rHrz:TLSMemoryBIOTests.test_errorWriting..handshakeDone+s OOH %rJc\jdjtdyrk)rrrrrs rHrz9TLSMemoryBIOTests.test_errorWriting..disconnected1s" OOF1IOOE2F1I >rJ)rrhrrv_tlsConnectionr!) rFrrrrrrrurs ` @@rHtest_errorWritingz#TLSMemoryBIOTests.test_errorWritings  # # %     39== !!0 X X$+9+C+C#D   & %%m4 ? &&|4!!rJcdd}|jtjtjGddt}Gddt}|t }||}t \}}t|jdtj|}ttd|d tj|} tt ||t | ||t } ||} |j| ||j| |y ) z TLSMemoryBIOProtocol doesn't leave circular references that keep it in memory after connection is closed. cPtfdtjDS)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. c3<K|]}t|sdyw)rN) isinstance).0xtypes rH zVTLSMemoryBIOTests.test_noCircularReferences..nObjectsOfType..EsJQjD6IqJs)rigc get_objects)rs`rHnObjectsOfTypezCTLSMemoryBIOTests.test_noCircularReferences..nObjectsOfType=sJ".."2JJ JrJceZdZdZy)CTLSMemoryBIOTests.test_noCircularReferences..CloserProtocolc8|jjyrC)rlrmrns rHrpzPTLSMemoryBIOTests.test_noCircularReferences..CloserProtocol.dataReceivedKs--/rJN)rYrZr[rpr^rJrHCloserProtocolrJs 0rJrceZdZdZy)DTLSMemoryBIOTests.test_noCircularReferences..GreeterProtocolc:|jjdyrr6res rHrfzSTLSMemoryBIOTests.test_noCircularReferences..GreeterProtocol.connectionMadeOs$$X.rJNrHr^rJrHGreeterProtocolrNs /rJrFrrTN)rrenabledisabler1rr#rrr0rrr7r) rFrrr origTLSProtosorigServerProtosrrr r newTLSProtosnewServerProtoss rHtest_noCircularReferencesz+TLSMemoryBIOTests.test_noCircularReferences7s  K  "  0X 0 /h /'';< ).9@B*+    %)<)<^)L ,   B     0  0@ A 0A B &&:; (8 }5 *:;rJN)rYrZr[r\rrrrrrr$r-r=rCrMrTrZrnrrrrrrrrrrrrrr^rJrHrrds 9<.=.=( : !. `(!T-!^"B J JJ"2&"P *$"L 5$"B!"F"@%"N/.HistoryStringTransportc<tj|g|_yrC)r5rIproducerHistoryres rHrIzPTLSProducerTests.setupStreamingProducer..HistoryStringTransport.__init__s((.')$rJcd|jjdtj|y)Npause)rrhr5pauseProducingres rHrzVTLSProducerTests.setupStreamingProducer..HistoryStringTransport.pauseProducings$$$++G4..t4rJcd|jjdtj|y)Nresume)rrhr5resumeProducingres rHrzWTLSProducerTests.setupStreamingProducer..HistoryStringTransport.resumeProducings$$$++H5//5rJcd|jjdtj|y)Nstop)rrhr5 stopProducingres rHrzUTLSProducerTests.setupStreamingProducer..HistoryStringTransport.stopProducings$$$++F3--d3rJN)rYrZr[rIrrrr^rJrHHistoryStringTransportrs * 5 6 4rJr )rlrrrT)r5rrlregisterProducerr streaming) rFrlrrrr applicationProtocolrproducers rHsetupStreamingProducerz'TLSProducerTests.setupStreamingProducersq 4_ 4",<)% , ([ *+%%66xF  --778"K99rJctdD]g}|j|jd}|r|j||j|jd}|r|j||rd|rgn|j |jj d|j |jj dy)zJ Transfer bytes back and forth between two TLS protocols. TrJN)rangerrlrprr)rFrserverTLSProtocoli clientData serverDatas rHflushTwoTLSProtocolsz%TLSProducerTests.flushTwoTLSProtocolss q AK$9$94@J!..z:$5$?$?FJ((4j  ..446< *44::#>#@ ; &&557 //: 11G9=  --==>rJc|j\}}}|jjj|j |j dg|jjj |j |jd|j |j ddg|j|jjy)z When the TLS transport is not blocked on reads, it correctly calls resumeProducing on the registered producer. r producingrN) rrlr rrrrr assertFalserrrs rH)test_streamingProducerResumedInNormalModez:TLSProducerTests.test_streamingProducerResumedInNormalModes $(#>#>#@ ;&&557 11G9= &&668 //= 11GX3FG ..>>?rJch|j\}}}|jjd|jjj d|j |jd|j |jdg|j|jjy)z When the TLS transport is blocked on reads, it correctly calls pauseProducing on the registered producer. rrrrN) rrlrr_clockadvancerrrrrrrFrzrr s rH4test_streamingProducerPausedInWriteBlockedOnReadModezETLSProducerTests.test_streamingProducerPausedInWriteBlockedOnReadModes 150K0K0M- X   &&x0""**1- //: 11G9=  --==>rJc|j\}}}|jjddz|j|jdgt d\}}|j |||j|jddg|j|jj|j|jj|j|jdy) z When the TLS transport is blocked on reads, it correctly calls resumeProducing on the registered producer. s hello worldirTrrrN) rrlrrrrrr rrrr)rFrzrr r4rs rH5test_streamingProducerResumedInWriteBlockedOnReadModezFTLSProducerTests.test_streamingProducerResumedInWriteBlockedOnReadModes 150K0K0M- X   &&~'>? 11G9=-=D,I)) !!+/@A 11GX3FG ..>>? ..<<= //=rJc|j\}}}|j}t}|jt|j j |d|j|j|y)zM Registering a streaming producer twice throws an exception. TN)rrobject assertRaises RuntimeErrorrlr r)rFrzrr originalProducer producer2s rHtest_streamingProducerTwicez,TLSProducerTests.test_streamingProducerTwicesg150K0K0M- X&00H   .22CCYPT  k++-=>rJc|j\}}}|jj|j|j|j|jj y)z\ Unregistering a streaming producer removes it, reverting to initial state. NrrlunregisterProducerrrr r%s rH test_streamingProducerUnregisterz1TLSProducerTests.test_streamingProducerUnregistersY150K0K0M- X  335 +//0 +//889rJc|j\}}}|jj|jj|j|j|j|jj y)zd Unregistering a streaming producer when no producer is registered is safe. Nr2r%s rH%test_streamingProducerUnregisterTwicez6TLSProducerTests.test_streamingProducerUnregisterTwicesk 150K0K0M- X  335  335 +//0 +//889rJc|j\}}}td\}}|s|j||n |jj d|jj |j|||j |jj|j d|jv|jj d|jjddg|jjjd|jj|j|jjd |j |jj|jj d |jjd g|jjjd|j|||j!|jj|j#d j%|j&d y )zl Common code for tests involving writes by producer after loseConnection is called. Tr(sx rr rYrrJswon'tswon't!s x hello worldN)rrrrlrrmr rrrRrr#r$r3assertNotEqualrrrrrd)rFwriteBlockedOnReadrzrr r4rs rHloseConnectionWithProducerz+TLSProducerTests.loseConnectionWithProducer#s 150K0K0M- X,.PausingStringTransportFc|js-|j!d|_|jjtj||yr) _didPauser rr5rrns rHrzhTLSProducerTests.test_streamingProducerBothTransportsDecideToPause..PausingStringTransport.writens9~~$--*C%)DNMM002%%dD1rJN)rYrZr[rErr^rJrHPausingStringTransportrCks I 2rJrFc6eZdZdZdZdZdZdZdZdZ y) YTLSProducerTests.test_streamingProducerBothTransportsDecideToPause..TLSConnectioncg|_yrC)lres rHrIzbTLSProducerTests.test_streamingProducerBothTransportsDecideToPause..TLSConnection.__init__us rJc|js|dd}t|jdk(r%|jjdt|jj|t|S)Nrr)rJrkrhrrns rHrz^TLSProducerTests.test_streamingProducerBothTransportsDecideToPause..TLSConnection.sendxsVvv9Dtvv;!#FFMM(+'/) d#4y rJcyrCr^res rHset_connect_statezkTLSProducerTests.test_streamingProducerBothTransportsDecideToPause..TLSConnection.set_connect_staterrJcyrCr^res rH do_handshakezfTLSProducerTests.test_streamingProducerBothTransportsDecideToPause..TLSConnection.do_handshakerrJcyrCr^rns rH bio_writezcTLSProducerTests.test_streamingProducerBothTransportsDecideToPause..TLSConnection.bio_writerrJcy)NXr^rFsizes rHbio_readzbTLSProducerTests.test_streamingProducerBothTransportsDecideToPause..TLSConnection.bio_readsrJctrC)rrUs rHrecvz^TLSProducerTests.test_streamingProducerBothTransportsDecideToPause..TLSConnection.recvs #o%rJN) rYrZr[rIrrNrPrRrWrYr^rJrH TLSConnectionrHts%  !     &rJrZrrrrrrrN) r5rrrrlrrr#r$rr rrp)rFrFrZrlrzrr s rH1test_streamingProducerBothTransportsDecideToPausezBTLSProducerTests.test_streamingProducerBothTransportsDecideToPausedsF 2_ 2 & &>+, 040K0K mo1L1 - X //=   &&x0""**1- //: 11G9= &&668 //= 11GX3FG  * //= 11GX3FGrJc|j\}}}|jjj|j |j dy)z If the underlying transport tells its producer to stopProducing(), this is passed on to the high-level producer. stoppedN)rrlr rrrrs rH#test_streamingProducerStopProducingz4TLSProducerTests.test_streamingProducerStopProducingsG $(#>#>#@ ;&&446 //;rJc`t\}t|j|jjdjjj j tjj jj|jjjjfd}jj|td\}}j|jS)zM Non-streaming producers get wrapped as streaming producers. Fcjjjjjj j yrC)rconsumerrlr rrD)ignorer rFstreamingProducerrs rHdonez8TLSProducerTests.test_nonStreamingProducer..donesD   h// 0   k33<< = OO-77 8rJTr()rr4rlr r rrrr _consumerrr rcr!r)rFrzrdr4rr rcrs` @@@rHtest_nonStreamingProducerz*TLSProducerTests.test_nonStreamingProducers'7&8# '(@(@A   11(EB'11::DD /= *44h? *44n6N6NO  --778 9 ##D),rJc8t\}}d|_Gdd}|jtt|}|j |d|j |j j|j|jy)z If a producer is registered after the transport has disconnected, the producer is not used, and its stopProducing method is called. c6|jttSrC)rrr'rus rHr{zFTLSProducerTests.registerProducerAfterConnectionLost..sv{{ >8 rJceZdZdZdZdZy)FTLSProducerTests.registerProducerAfterConnectionLost..ProducerFc ddz S)Nrrr^res rHrzVTLSProducerTests.registerProducerAfterConnectionLost..Producer.resumeProducings 1u rJcd|_yr)r]res rHrzTTLSProducerTests.registerProducerAfterConnectionLost..Producer.stopProducings # rJN)rYrZr[r]rrr^rJrHProducerrnsG  $rJrqFN) rrvr9r&r rrlr rr])rFr rzrrqr s rH#registerProducerAfterConnectionLostz4TLSProducerTests.registerProducerAfterConnectionLosts '7&8# ) % $ $ ""7>+;#<=:$$Xu5 +//889 (()rJc&|jdy)z If a streaming producer is registered after the transport has disconnected, the producer is not used, and its stopProducing method is called. TNrrres rH)test_streamingProducerAfterConnectionLostz:TLSProducerTests.test_streamingProducerAfterConnectionLosts 006rJc&|jdy)z If a non-streaming producer is registered after the transport has disconnected, the producer is not used, and its stopProducing method is called. FNrtres rH,test_nonStreamingProducerAfterConnectionLostz=TLSProducerTests.test_nonStreamingProducerAfterConnectionLosts 007rJ)F)NNFN)rYrZr[r\rrrrr!r&r)r0r4r6r;r>r@r[r^rfrirrrurwr^rJrHrris{*OS%:NC$ ?@ ?$>0 ?: :0Nd65FHP<@?*:78rJrcLeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z y ) NonStreamingProducerTestszP Non-streaming producers can be adapted into being streaming producers. ct}t|jdjffd }|_|j}fd}|j |j |S)zd Verify the consumer writes out all its data, but is not called after that. Tc4|jyrC stopStreamingorigrcs rH unregisterz.unregister F  + + -rJcjjdjjj j y)Ns 0123456789)rrrr rrD)rrarFrcs rH doneStreamingz?NonStreamingProducerTests.streamUntilEnd..doneStreaming%sA   X^^-} =   h// 0 OO-77 8rJ)r4rr r3rcr!startStreaming)rFra nsProducerrrdrrcs`` @rHstreamUntilEndz(NonStreamingProducerTests.streamUntilEndsz *(3 ' H=!!"3T: %77 .'1#   9 ' ((* rJc8t}|j|S)z When converted to a streaming producer, the non-streaming producer writes out all its data, but is not called after that. r5r)rFras rHtest_writeUntilDonez-NonStreamingProducerTests.test_writeUntilDone2s #$""8,,rJc.Gddt}|}t|}t|||jdfd}|jj ||j }fd}|j |j|S)z} When the streaming producer is paused, the underlying producer stops getting resumeProducing calls. ceZdZdZdZdZy)DNonStreamingProducerTests.test_pause..PausingStringTransportrcLtj|t|_yrC)r5rIr$rres rHrIzMNonStreamingProducerTests.test_pause..PausingStringTransport.__init__Cs((.&j rJc|xjdz c_tj|||jdk(r:|jj |j }|`|j dyyNrr)writesr5rr rrrP)rFrorms rHrzJNonStreamingProducerTests.test_pause..PausingStringTransport.writeGs[ q %%dD1;;!#MM002 A JJt$ $rJN)rYrZr[rrIrr^rJrHrFr@sF ) %rJrFTc(jdy)Nz$BUG: The producer should not finish!)fail)rbrFs rHshouldNotBeCalledz?NonStreamingProducerTests.test_pause..shouldNotBeCalledVs II< =rJcRjjjdyr)r _coopTask _pauseCount)rbrFrcs rHrz4NonStreamingProducerTests.test_pause..paused]s   .88DDa HrJ)r5r4rr rcr!rr)rFrFrarrrdrrcs` @rH test_pausez$NonStreamingProducerTests.test_pause:s  %_ % *+)(3 ' H=!!"3T: > %%&78 I   ((* rJcPGddt}|}|j|S)a 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. ceZdZdZdZy)ENonStreamingProducerTests.test_resume..PausingStringTransportrc|xjdz c_tj|||jdk(r5|jj |jj yyr)rr5rr rrrns rHrzKNonStreamingProducerTests.test_resume..PausingStringTransport.writessQ q %%dD1;;!#MM002MM113$rJNrYrZr[rrr^rJrHrFrps F 4rJrFr)rFrFras rH test_resumez%NonStreamingProducerTests.test_resumegs) 4_ 4*+""8,,rJcGddt}|ttjdj}fd}|j |j |S)z When the streaming producer is stopped by the consumer, the underlying producer is stopped, and streaming is stopped. ceZdZdZdZy)MNonStreamingProducerTests.test_stopProducing..StoppingStringTransportrc|xjdz c_tj|||jdk(r|jj yyr)rr5rr rrns rHrzSNonStreamingProducerTests.test_stopProducing..StoppingStringTransport.writesA q %%dD1;;!#MM//1$rJNrr^rJrHStoppingStringTransportrs F 2rJrTcjjdjjjjy)Ns012)rrrr]rD)rrarrFrcs rHrzCNonStreamingProducerTests.test_stopProducing..doneStreamings?   X^^-v 6 OOJ.. / OO-77 8rJ)r5r4rr rcr!r)rFrrdrrarrcs` @@@rHtest_stopProducingz,NonStreamingProducerTests.test_stopProducing}st  2o 2+,)(3 ' H=!!"3T:   9 ' ((* rJc Gddt}|}t| j dgtjj j tjj jf fd }|_ j jj}|jd fd}|j||S)z Common implementation for tests where the underlying producer throws an exception when its resumeProducing is called. ceZdZdZy)INonStreamingProducerTests.resumeProducingRaises..ThrowingProducercV|jdk(rddz Stj|y)Nrerr)counterr4rres rHrzYNonStreamingProducerTests.resumeProducingRaises..ThrowingProducer.resumeProducings%<<1$q5L(88>rJN)rYrZr[rr^rJrHThrowingProducerrs ?rJrTc4|jyrCr|r~s rHrzCNonStreamingProducerTests.resumeProducingRaises..unregisterrrJc,|jtSrC)rr3rls rHr{zANonStreamingProducerTests.resumeProducingRaises..sv{{;'?rJc jjd j} jt|tt |D]>\}\}}} j |j | j||d@ j jy)Ns01why) rrrfrkziprrrassertInrD) rierrorsfexpectedmsglogMsgraexpectedExceptions loggedMsgsrFrcs rHr]z@NonStreamingProducerTests.resumeProducingRaises..stoppeds   X^^-u 5++-F   S[#.@*A B.1*J/ 2*?HcF 12 c6%=1  2 OO-77 8rJ)r4rr r8rrhrrr3rrwhenDone addErrbackr!) rFrarrrrrdr]rrcs ``` @@rHresumeProducingRaisesz/NonStreamingProducerTests.resumeProducingRaisess  ?3 ?&h/ ' H=!!"3T:   ))* **J,=,=>%77 .'1# ((* **335 ?@ 9 9 ! rJc~tjtdfg}fd}|j||S)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. !failed, producing will be stoppedc<jjyrC)rr )rbrarFs rH cleanShutdownzKNonStreamingProducerTests.test_resumeProducingRaises..cleanShutdowns   h// 0rJ)r5rZeroDivisionErrorr!)rFrdrras` @rHtest_resumeProducingRaisesz4NonStreamingProducerTests.test_resumeProducingRaisessF #$)) )+NOP  1 ' rJcjt}d}||_|j|tdftdfgS)a 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. ctrC)r-r^rJrHraiserz^NonStreamingProducerTests.test_resumeProducingRaiseAndUnregisterProducerRaises..raisers . rJrzfailed to unregister producer)r5r3rrr-)rFrars rH4test_resumeProducingRaiseAndUnregisterProducerRaiseszNNonStreamingProducerTests.test_resumeProducingRaiseAndUnregisterProducerRaisessH#$ !'-#)) "$GH>?   rJct}t|}t||}|j|j |j |j |j y)z stopStreaming() can be called more than once without blowing up. This is useful for error-handling paths. N)r5r4rrr}rrDrFrarrcs rHtest_stopStreamingTwicez1NonStreamingProducerTests.test_stopStreamingTwicesZ #$)(3 ' H=((*'')'') )334rJct}t|}t||}|jt t |y)z= L{_PullToPush} implements L{IPushProducer}. N)r5r4rrrr,rs rHriz(NonStreamingProducerTests.test_interfaces7#$)(3 ' H=  ]4EFGrJN)rYrZr[r\rrrrrrrrrrir^rJrHryry s> D-+Z-,!F1f$ * 5HrJryceZdZdZdZdZy)ClientNegotiationFactoryza A L{ClientFactory} that has a set of acceptable protocols for NPN/ALPN negotiation. c||_y)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_acceptableProtocolsrFacceptableProtocolss rHrIz!ClientNegotiationFactory.__init__ %8!rJc|jSa 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} rres rHrz,ClientNegotiationFactory.acceptableProtocols"(((rJNrYrZr[r\rIrr^rJrHrr 8 )rJrceZdZdZdZdZy)ServerNegotiationFactoryza A L{ServerFactory} that has a set of acceptable protocols for NPN/ALPN negotiation. c||_y)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} Nrrs rHrIz!ServerNegotiationFactory.__init__5rrJc|jSrrres rHrz,ServerNegotiationFactory.acceptableProtocols?rrJNrr^rJrHrr.rrJrc eZdZdZeej ejejejddjddd dZ y ) _AggregateSmallWritesTestsz$Tests for ``_AggregateSmallWrites``.rr) min_value max_valuecd|dzdzzd|S)Ns0123456789ABCDEFGHIJrr^)lengths rHr{z#_AggregateSmallWritesTests.]s $;" PQ?Q$R$rJi)max_sizecXg}t}t|j|}|D]'}||jd|j |)|j |j dj|djd|D|dd}|D]}t|}|r|d|jd|r|dd} |s3|jd} | |j || Y| t| z } | |jkDr|j || |rYy)aY 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. NrrJc3&K|] }|| ywrCr^)rrs rHrzH_AggregateSmallWritesTests.test_writes_get_aggregated..s&VEDUu&Vs) r rrhr$rrrrrkpopMAX_BUFFER_SIZE) rFrrcr aggregater small_writeschunkcombined_lengthsmall_writes_lengthnext_original_maybe_writes rHtest_writes_get_aggregatedz5_AggregateSmallWritesTests.test_writes_get_aggregatedSs<:!)&--?  'E} a &  '   HHV chh&V&&VV ay  E!%jO<?#:  #<?#:"# ,8,<,r?rAr`rrrrrrryrrrr^rJrHrs# CC..$3+N   MUUM:AVU-JJ*,7A@((V88EI''T.Ax.Ad8=> B4M%84MnB <B