Ϫf~tfdZddlmZddlmZddlmZmZddlm Z m Z m Z m Z ddl mZmZddlmZddlmZmZdd lmZmZmZmZdd lmZmZdd lmZmZmZdd l m!Z!dd l"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2ddl3m4Z4m5Z5m6Z6ddl7m8Z8ddl9m:Z:ddl;mGddej~Z@Gdde8jZBGddZCee0e&e)GddZDGddeDZEGd d!eZFee'Gd"d#ZGee%Gd$d%ZHee*e.e-e/e,e+Gd&d'ZIeeID] ZJeeJeI Gd(d)eIe2ZKee.e-e/e,Gd*d+ZLGd,d-ZMd.ZNee4Gd/d0e e5ZOy1)2zJ Assorted functionality which is commonly useful when writing unit tests. ) annotations)BytesIO)AF_INETAF_INET6)CallableIteratorSequenceoverload) implementedBy implementer) verifyClass) ParamSpecSelf)addresserrorprotocoltask)_dataMustBeBytes isIPv6Address) IPv4Address IPv6Address UNIXAddress)Deferred)UnsupportedAddressFamily) IConnector IConsumerIListeningPort IProtocol IPushProducer IReactorCore IReactorFDSetIReactorSocket IReactorSSL IReactorTCP IReactorUNIX ITransport)Clock) ILogObserverLogEvent LogPublisher)basic)failure)TestCase)AccumulatingProtocolLineSendingProtocolFakeDatagramTransportStringTransport StringTransportWithDisconnectionStringIOWithoutClosing_FakeConnector _FakePort MemoryReactorMemoryReactorClockRaisingMemoryReactorNonStreamingProducerwaitUntilAllDisconnectedEventLoggingObserver_Pc:eZdZdZdxZZdZdZdZdZ dZ dZ dZ y)r.ad L{AccumulatingProtocol} is an L{IProtocol} implementation which collects the data delivered to it and can fire a Deferred when it is connected or disconnected. @ivar made: A flag indicating whether C{connectionMade} has been called. @ivar data: Bytes giving all the data passed to C{dataReceived}. @ivar closed: A flag indicated whether C{connectionLost} has been called. @ivar closedReason: The value of the I{reason} parameter passed to C{connectionLost}. @ivar closedDeferred: If set to a L{Deferred}, this will be fired when C{connectionLost} is called. rNcd|_|jP|jj9|jj}d|j_|j|yyyN)madefactoryprotocolConnectionMadecallbackselfds :/usr/lib/python3/dist-packages/twisted/internet/testing.pyconnectionMadez#AccumulatingProtocol.connectionMadeXsR << # (K(K(W 33A26DLL / JJt )X #r>c.|xj|z c_yN)datarGrMs rI dataReceivedz!AccumulatingProtocol.dataReceived_s T r>cd|_||_|j&|jdc}|_|jdyyr@)closed closedReasonclosedDeferredrE)rGreasonrHs rIconnectionLostz#AccumulatingProtocol.connectionLostbsC "    *%)%8%8$ "At" JJt  +r>) __name__ __module__ __qualname____doc__rBrQrRrSrMrCrJrOrUr>rIr.r.@s6 D6LN DGr>r.c*eZdZdZddZdZdZdZy)r/Fc4|dd|_g|_||_yrL)linesresponsestart)rGr]r_s rI__init__zLineSendingProtocol.__init__ms1X   r>cb|jr#|jD]}|j|yyrL)r_r]sendLinerGlines rIrJz"LineSendingProtocol.connectionMaders- ::  $ d# $ r>c|js)|jD]}|j|g|_|jj |yrL)r_r]rbr^appendrcs rI lineReceivedz LineSendingProtocol.lineReceivedwsAzz  $ d# $DJ T"r>cd|_yNT)lostConn)rGrTs rIrUz"LineSendingProtocol.connectionLost~s  r>N)T)rVrWrXrjr`rJrgrUrZr>rIr/r/jsH $ #r>r/c*eZdZeZdZefdZy)r0cg|_yrL)writtenrGs rIr`zFakeDatagramTransport.__init__s  r>c>|jj||fyrL)rmrf)rGpacketaddrs rIwritezFakeDatagramTransport.writes VTN+r>N)rVrWrXobjectnoAddrr`rrrZr>rIr0r0s XF"(,r>r0ceZdZdZdZdZdZdZdZdZ dZ ddZ dZ dZ dZd Zd Zd Zd Zd ZdZdZdZdZdZdZy)r1a A transport implementation which buffers data in memory and keeps track of its other state without providing any behavior. L{StringTransport} has a number of attributes which are not part of any of the interfaces it claims to implement. These attributes are provided for testing purposes. Implementation code should not use any of these attributes; they are not provided by other transports. @ivar disconnecting: A C{bool} which is C{False} until L{loseConnection} is called, then C{True}. @ivar disconnected: A C{bool} which is C{False} until L{abortConnection} is called, then C{True}. @ivar producer: If a producer is currently registered, C{producer} is a reference to it. Otherwise, L{None}. @ivar streaming: If a producer is currently registered, C{streaming} refers to the value of the second parameter passed to C{registerProducer}. @ivar hostAddr: L{None} or an object which will be returned as the host address of this transport. If L{None}, a nasty tuple will be returned instead. @ivar peerAddr: L{None} or an object which will be returned as the peer address of this transport. If L{None}, a nasty tuple will be returned instead. @ivar producerState: The state of this L{StringTransport} in its capacity as an L{IPushProducer}. One of C{'producing'}, C{'paused'}, or C{'stopped'}. @ivar io: A L{io.BytesIO} which holds the data which has been written to this transport since the last call to L{clear}. Use L{value} instead of accessing this directly. @ivar _lenient: By default L{StringTransport} enforces that L{resumeProducing} is not called after the connection is lost. This is to ensure that any code that does call L{resumeProducing} after the connection is lost is not blindly expecting L{resumeProducing} to have any impact. However, if your test case is calling L{resumeProducing} after connection close on purpose, and you know it won't block expecting further data to show up, this flag may safely be set to L{True}. Defaults to L{False}. @type lenient: L{bool} FN producingcd|j|||_|||_d|_||_yri)clearhostAddrpeerAddr connected_lenient)rG hostAddress peerAddresslenients rIr`zStringTransport.__init__s3  "'DM  "'DM r>c"t|_y)z Discard all data written to this transport so far. This is not a transport method. It is intended for tests. Do not use it in implementation code. N)riorns rIrxzStringTransport.clears )r>c6|jjS)aN Retrieve all data which has been buffered by this transport. This is not a transport method. It is intended for tests. Do not use it in implementation code. @return: A C{bytes} giving all data written to this transport since the last call to L{clear}. @rtype: C{bytes} )rgetvaluerns rIvaluezStringTransport.valuesww!!r>cPt||jj|yrL)rrrrrNs rIrrzStringTransport.writes  dr>cX|jjdj|y)Nr>)rrrjoinrNs rI writeSequencezStringTransport.writeSequences  chhtn%r>cd|_y)z~ Close the connection. Does nothing besides toggle the C{disconnecting} instance variable to C{True}. TN) disconnectingrns rIloseConnectionzStringTransport.loseConnections "r>c2d|_|jy)z Abort the connection. Same as C{loseConnection}, but also toggles the C{aborted} instance variable to C{True}. TN) disconnectedrrns rIabortConnectionzStringTransport.abortConnections ! r>c`|jtjdddS|jS)NTCPz 192.168.1.1i1)rzrrrns rIgetPeerzStringTransport.getPeers+ == &&umUC C}}r>c`|jtjdddS|jS)Nrz10.0.0.1i90)ryrrrns rIgetHostzStringTransport.getHosts+ == &&uj%@ @}}r>cN|j td||_||_y)NzCannot register two producersproducer RuntimeError streaming)rGrrs rIregisterProducerz StringTransport.registerProducer s& == $>? ?  "r>cN|j tdd|_d|_y)Nz5Cannot unregister a producer unless one is registeredrrns rIunregisterProducerz"StringTransport.unregisterProducers& == VW W r>c~|jr|js td|jdk(r tdy)Nz,Cannot resume producing after loseConnectionstoppedz Cannot resume a stopped producer)rr|r producerStaterns rI _checkStatezStringTransport._checkStates<   dmmMN N    *AB B +r>c2|jd|_y)Npausedrrrns rIpauseProducingzStringTransport.pauseProducing s %r>cd|_y)Nr)rrns rI stopProducingzStringTransport.stopProducing$s &r>c2|jd|_y)Nrvrrns rIresumeProducingzStringTransport.resumeProducing's (r>)NNF)rVrWrXrYrrrrryrzrr`rxrrrrrrrrrrrrrrrZr>rIr1r1sy1fMLHIHHM  "&"  # C &')r>r1c"eZdZUdZded<dZy)r2zt A L{StringTransport} which on disconnection will trigger the connection lost on the attached protocol. rrc|jrId|_|jjtjt j dyy)NFzBye.)r{rrUr,FailurerConnectionDonerns rIrz/StringTransportWithDisconnection.loseConnection4s; >>"DN MM ( (9M9Mf9U)V W r>N)rVrWrXrY__annotations__rrZr>rIr2r2,s Xr>r2ceZdZdZdZy)r3z) A BytesIO that can't be closed. cy)z Do nothing. NrZrns rIclosezStringIOWithoutClosing.close?r>N)rVrWrXrYrrZr>rIr3r3:s  r>r3c(eZdZdZdZdZdZdZy)r5z A fake L{IListeningPort} to be used in tests. @ivar _hostAddress: The L{IAddress} this L{IListeningPort} is pretending to be listening on. c||_y)zz @param hostAddress: An L{IAddress} this L{IListeningPort} should pretend to be listening on. N _hostAddress)rGr}s rIr`z_FakePort.__init__Ns (r>cy)zQ Fake L{IListeningPort.startListening} that doesn't do anything. NrZrns rIstartListeningz_FakePort.startListeningUrr>cy)zP Fake L{IListeningPort.stopListening} that doesn't do anything. NrZrns rI stopListeningz_FakePort.stopListeningZrr>c|jS)zN Fake L{IListeningPort.getHost} that returns our L{IAddress}. rrns rIrz_FakePort.getHost_s   r>N)rVrWrXrYr`rrrrZr>rIr5r5Es(  !r>r5c6eZdZdZdZdZdZdZdZdZ dZ y) r4a' A fake L{IConnector} that allows us to inspect if it has been told to stop connecting. @ivar stoppedConnecting: has this connector's L{_FakeConnector.stopConnecting} method been invoked yet? @ivar _address: An L{IAddress} provider that represents our destination. Fc||_y)zs @param address: An L{IAddress} provider that represents this connector's destination. N_address)rGrs rIr`z_FakeConnector.__init__us   r>cd|_y)zw Implement L{IConnector.stopConnecting} and set L{_FakeConnector.stoppedConnecting} to C{True} TN)stoppedConnectingrns rIstopConnectingz_FakeConnector.stopConnecting|s "&r>cd|_y)z@ Implement L{IConnector.disconnect} as a no-op. TN) _disconnectedrns rI disconnectz_FakeConnector.disconnects "r>cy)z= Implement L{IConnector.connect} as a no-op. NrZrns rIconnectz_FakeConnector.connectrr>c|jS)zp Implement L{IConnector.getDestination} to return the C{address} passed to C{__init__}. rrns rIgetDestinationz_FakeConnector.getDestinations }}r>N) rVrWrXrYrrr`rrrrrZr>rIr4r4fs-M &"  r>r4ceZdZdZdZdZddZdZdZdZ ddZ d Z d d Z d Z d!d Zd ZdZd"dZd#dZd$dZd#dZ d$dZd%dZd&dZdZdZdZdZdZdZdZy)'r6a: A fake reactor to be used in tests. This reactor doesn't actually do much that's useful yet. It accepts TCP connection setup attempts, but they will never succeed. @ivar hasInstalled: Keeps track of whether this reactor has been installed. @type hasInstalled: L{bool} @ivar running: Keeps track of whether this reactor is running. @type running: L{bool} @ivar hasStopped: Keeps track of whether this reactor has been stopped. @type hasStopped: L{bool} @ivar hasCrashed: Keeps track of whether this reactor has crashed. @type hasCrashed: L{bool} @ivar whenRunningHooks: Keeps track of hooks registered with C{callWhenRunning}. @type whenRunningHooks: L{list} @ivar triggers: Keeps track of hooks registered with C{addSystemEventTrigger}. @type triggers: L{dict} @ivar tcpClients: Keeps track of connection attempts (ie, calls to C{connectTCP}). @type tcpClients: L{list} @ivar tcpServers: Keeps track of server listen attempts (ie, calls to C{listenTCP}). @type tcpServers: L{list} @ivar sslClients: Keeps track of connection attempts (ie, calls to C{connectSSL}). @type sslClients: L{list} @ivar sslServers: Keeps track of server listen attempts (ie, calls to C{listenSSL}). @type sslServers: L{list} @ivar unixClients: Keeps track of connection attempts (ie, calls to C{connectUNIX}). @type unixClients: L{list} @ivar unixServers: Keeps track of server listen attempts (ie, calls to C{listenUNIX}). @type unixServers: L{list} @ivar adoptedPorts: Keeps track of server listen attempts (ie, calls to C{adoptStreamPort}). @ivar adoptedStreamConnections: Keeps track of stream-oriented connections added using C{adoptStreamConnection}. c d|_d|_d|_d|_d|_g|_i|_g|_g|_g|_ g|_ g|_ g|_ g|_ g|_g|_t!|_t!|_y)z0 Initialize the tracking lists. FTN) hasInstalledrunninghasRun hasStopped hasCrashedwhenRunningHookstriggers tcpClients tcpServers sslClients sslServers unixClients unixServers adoptedPortsadoptedStreamConnections connectorssetreaderswritersrns rIr`zMemoryReactor.__init__s"   " (*%u u r>cd|_y)zO Fake install callable to emulate reactor module installation. TN)rrns rIinstallzMemoryReactor.installs !r>ctzA Not implemented; raises L{NotImplementedError}. NotImplementedError)rGnametimeouts rIresolvezMemoryReactor.resolve "##r>c|jdusJd|_d|_|jD]\}}}||i||jy)a Fake L{IReactorCore.run}. Sets C{self.running} to L{True}, runs all of the hooks passed to C{self.callWhenRunning}, then calls C{self.stop} to simulate a request to stop the reactor. Sets C{self.hasRun} to L{True}. FTN)rrrstop)rGfargskwargss rIrunzMemoryReactor.runsW||u$$$  #44 OAtV t v   r>c d|_d|_y)z Fake L{IReactorCore.run}. Sets C{self.running} to L{False}. Sets C{self.hasStopped} to L{True}. FTN)rrrns rIrzMemoryReactor.stop s  r>c d|_d|_y)z Fake L{IReactorCore.crash}. Sets C{self.running} to L{None}, because that feels crashy. Sets C{self.hasCrashed} to L{True}. NT)rrrns rIcrashzMemoryReactor.crashs  r>ctrr)rGdelays rIiteratezMemoryReactor.iteraterr>ctrr)rG eventTypes rIfireSystemEventzMemoryReactor.fireSystemEvent#rr>c|jj|i}|j|g}|j|||fy)z Fake L{IReactorCore.run}. Keep track of trigger by appending it to self.triggers[phase][eventType]. N)r setdefaultrf)rGphasercallablerkw phaseTriggerseventTypeTriggerss rIaddSystemEventTriggerz#MemoryReactor.addSystemEventTrigger)sB 00; )44YC  (D"!56r>ctrr)rG triggerIDs rIremoveSystemEventTriggerz&MemoryReactor.removeSystemEventTrigger:rr>c@|jj|||fy)z Fake L{IReactorCore.callWhenRunning}. Keeps a list of invocations to make in C{self.whenRunningHooks}. N)rrf)rGrrrs rIcallWhenRunningzMemoryReactor.callWhenRunning@s $$hb%9:r>c|tk(rtddd}n!|tk(rtddd}n t |j j |||ft|S)zv Fake L{IReactorSocket.adoptStreamPort}, that logs the call and returns an L{IListeningPort}. r0.0.0.0::rrrrrrrfr5)rGfileno addressFamilyrCrqs rIadoptStreamPortzMemoryReactor.adoptStreamPortIs^ G #ui6D h &udD1D*, ,   &-!ABr>c@|jj|||fy)z Record the given stream connection in C{adoptedStreamConnections}. @see: L{twisted.internet.interfaces.IReactorSocket.adoptStreamConnection} N)rrfrGfileDescriptorr rCs rIadoptStreamConnectionz#MemoryReactor.adoptStreamConnectionXs %%,,nmW-UVr>c|tk(rtddd}n!|tk(rtddd}n t |j j ||||ft|S)z Fake L{IReactorSocket.adoptDatagramPort}, that logs the call and returns a fake L{IListeningPort}. @see: L{twisted.internet.interfaces.IReactorSocket.adoptDatagramPort} UDPrrrr)rGrr r maxPacketSizerqs rIadoptDatagramPortzMemoryReactor.adoptDatagramPortas` G #ui6D h &udD1D*, ,   &-=!QRr>c|jj||||ft|rtd||}t |St dd|}t |S)zm Fake L{IReactorTCP.listenTCP}, that logs the call and returns an L{IListeningPort}. rr)rrfrrrr5)rGportrCbacklog interfacers rI listenTCPzMemoryReactor.listenTCPrs] gw BC  #!%D9G!!"%D9G!!r>Nc|jj|||||ft|rtt d||}ntt d||}|j ||jj||S)zj Fake L{IReactorTCP.connectTCP}, that logs the call and returns an L{IConnector}. r)rrfrr4rrstartedConnectingr)rGhostrrCr bindAddressconns rI connectTCPzMemoryReactor.connectTCP~st dGWkJK  !+eT4"@AD!+eT4"@AD!!$' t$ r>cn|jj|||||fttdd|S)zm Fake L{IReactorSSL.listenSSL}, that logs the call and returns an L{IListeningPort}. rr)rrfr5rrGrrCcontextFactoryrrs rI listenSSLzMemoryReactor.listenSSLs5 g~w RSUIt<==r>c|jj||||||fttd||}|j ||j j||S)zj Fake L{IReactorSSL.connectSSL}, that logs the call and returns an L{IConnector}. r)rrfr4rrr)rGrrrCr rrrs rI connectSSLzMemoryReactor.connectSSLs`  4.'; G k%t<=!!$' t$ r>cj|jj|||||ftt|S)zo Fake L{IReactorUNIX.listenUNIX}, that logs the call and returns an L{IListeningPort}. )rrfr5rrGrrCrmodewantPIDs rI listenUNIXzMemoryReactor.listenUNIXs3 '7D' JKW-..r>c|jj||||ftt|}|j ||j j||S)zl Fake L{IReactorUNIX.connectUNIX}, that logs the call and returns an L{IConnector}. )rrfr4rrr)rGrrCrcheckPIDrs rI connectUNIXzMemoryReactor.connectUNIXsU '7H EFk'23!!$' t$ r>c:|jj|y)zW Fake L{IReactorFDSet.addReader} which adds the reader to a local set. N)raddrGreaders rI addReaderzMemoryReactor.addReader  r>c:|jj|y)zg Fake L{IReactorFDSet.removeReader} which removes the reader from a local set. N)rdiscardr.s rI removeReaderzMemoryReactor.removeReader V$r>c:|jj|y)zW Fake L{IReactorFDSet.addWriter} which adds the writer to a local set. N)rr-rGwriters rI addWriterzMemoryReactor.addWriterr1r>c:|jj|y)zg Fake L{IReactorFDSet.removeWriter} which removes the writer from a local set. N)rr3r7s rI removeWriterzMemoryReactor.removeWriterr5r>c,t|jS)zn Fake L{IReactorFDSet.getReaders} which returns a list of readers from the local set. )listrrns rI getReaderszMemoryReactor.getReaders DLL!!r>c,t|jS)zn Fake L{IReactorFDSet.getWriters} which returns a list of writers from the local set. )r=rrns rI getWriterszMemoryReactor.getWritersr?r>cl|jj|jjy)zt Fake L{IReactorFDSet.removeAll} which removed all readers and writers from the local sets. N)rrxrrns rI removeAllzMemoryReactor.removeAlls$  r>) )r) rstrrrErCallable[_P, object]r_P.argsr _P.kwargsreturnNone)rrFrrGrrHrIrJ)i 2NrLirrOr)rVrWrXrYr`rrrrrrrrrrr rrrrr!r#r(r+r0r4r9r;r>rArCrZr>rIr6r6s6p6! $ $$ $ 777' 7  7  7 7"$ ;,;5<;DM; ; W" " >LP / ! %! %""r>r6ceZdZdZy)r7cXtj|tj|yrL)r6r`r'rns rIr`zMemoryReactorClock.__init__st$ tr>N)rVrWrXr`rZr>rIr7r7sr>r7c\eZdZdZd dZdZddZddZddZ ddZ dd Z dd Z d Z d Z y)r8z A fake reactor to be used in tests. It accepts TCP connection setup attempts, but they will fail. @ivar _listenException: An instance of an L{Exception} @ivar _connectException: An instance of an L{Exception} Nc ||_||_y)z @param listenException: An instance of an L{Exception} to raise when any C{listen} method is called. @param connectException: An instance of an L{Exception} to raise when any C{connect} method is called. N)_listenException_connectException)rGlistenExceptionconnectExceptions rIr`zRaisingMemoryReactor.__init__s!0!1r>c|j)zb Fake L{IReactorSocket.adoptStreamPort}, that raises L{_listenException}. rV)rGrr rCs rIr z$RaisingMemoryReactor.adoptStreamPorts ###r>c|j)zQ Fake L{IReactorTCP.listenTCP}, that raises L{_listenException}. r[)rGrrCrrs rIrzRaisingMemoryReactor.listenTCP ###r>c|j)zS Fake L{IReactorTCP.connectTCP}, that raises L{_connectException}. rW)rGrrrCrrs rIrzRaisingMemoryReactor.connectTCP$$$r>c|j)zQ Fake L{IReactorSSL.listenSSL}, that raises L{_listenException}. r[rs rIr!zRaisingMemoryReactor.listenSSLr]r>c|j)zS Fake L{IReactorSSL.connectSSL}, that raises L{_connectException}. r_)rGrrrCr rrs rIr#zRaisingMemoryReactor.connectSSLs $$$r>c|j)zS Fake L{IReactorUNIX.listenUNIX}, that raises L{_listenException}. r[r%s rIr(zRaisingMemoryReactor.listenUNIX'r]r>c|j)zU Fake L{IReactorUNIX.connectUNIX}, that raises L{_connectException}. r_)rGrrCrr*s rIr+z RaisingMemoryReactor.connectUNIX-r`r>c|j)ze Fake L{IReactorSocket.adoptDatagramPort}, that raises L{_connectException}. r_)rGr r rrs rIrz&RaisingMemoryReactor.adoptDatagramPort3 $$$r>c|j)zi Fake L{IReactorSocket.adoptStreamConnection}, that raises L{_connectException}. r_r s rIrz*RaisingMemoryReactor.adoptStreamConnection:rfr>)NNrKrNrPrQ)rVrWrXrYr`r rrr!r#r(r+rrrZr>rIr8r8s@ 2$$ % $LP%$ % %%r>r8c6eZdZdZdZdZdZdZdZdZ dZ y ) r9z5 A pull producer which writes 10 times only. rFc0||_t|_yrL)consumerrresult)rGrjs rIr`zNonStreamingProducer.__init__Js  j r>c@|j|jdk\r td|jjd|jfz|xjdz c_|jdk(r+|jj |j yy)z/ Write the counter value once. NrDz"BUG: resume after unregister/stop.s%drA)rjcounterrrrr_donerns rIrz$NonStreamingProducer.resumeProducingNsz == DLLB$6CD D MM   7 8 LLA L||r! 002 "r>ctd)z An implementation of C{IPushProducer.pauseProducing}. This should never be called on a pull producer, so this just raises an error. z"BUG: pause should never be called.)rrns rIrz#NonStreamingProducer.pauseProducing[s ?@@r>cPd|_|j}|`|jdy)zQ Fire a L{Deferred} so that users can wait for this to complete. N)rjrkrErFs rIrnzNonStreamingProducer._donebs% KK K 4r>c2d|_|jy)z& Stop all production. TN)rrnrns rIrz"NonStreamingProducer.stopProducingks  r>N) rVrWrXrYrmrr`rrrnrrZr>rIr9r9Bs-GG! Ar>r9ctdfd}tj||_jddS)a Take a list of disconnecting protocols, callback a L{Deferred} when they're all done. This is a hack to make some older tests less flaky, as L{ITransport.loseConnection} is not atomic on all reactors (for example, the CoreFoundation, which sometimes takes a reactor turn for CFSocket to realise). New tests should either not use real sockets in testing, or take the advice in I{https://jml.io/pages/how-to-disconnect-in-twisted-really.html} to heart. @param reactor: The reactor to schedule the checks on. @type reactor: L{IReactorTime} @param protocols: The protocols to wait for disconnecting. @type protocols: A L{list} of L{IProtocol}s. Nc~dDcgc]}|jjc}vrjyycc}wri) transportr{r)xlc protocolss rI_checkz(waitUntilAllDisconnected.._checks2 yA! --A A GGI BAs:g{Gz?T)now)r LoopingCallclockr_)reactorrwrxrvs ` @rIr:r:ss;$ B   & !BBH 88Dd8 ##r>cneZdZdZd dZd dZed dZeddZddZddZddZ e dd Z y )r;a L{ILogObserver} That stores its events in a list for later inspection. This class is similar to L{LimitedHistoryLogObserver} save that the internal buffer is public and intended for external inspection. The observer implements the sequence protocol to ease iteration of the events. @ivar _events: The events captured by this observer @type _events: L{list} cg|_yrL_eventsrns rIr`zEventLoggingObserver.__init__s ') r>c,t|jSrL)lenrrns rI__len__zEventLoggingObserver.__len__s4<<  r>cyrLrZrGindexs rI __getitem__z EventLoggingObserver.__getitem__ r>cyrLrZrs rIrz EventLoggingObserver.__getitem__rr>c |j|SrLrrs rIrz EventLoggingObserver.__getitem__s||E""r>c,t|jSrL)iterrrns rI__iter__zEventLoggingObserver.__iter__sDLL!!r>c:|jj|y)z' @see: L{ILogObserver} N)rrf)rGevents rI__call__zEventLoggingObserver.__call__s E"r>cd|j|jfdS)a- Create an L{EventLoggingObserver} instance that observes the provided publisher and will be cleaned up with addCleanup(). @param testInstance: Test instance in which this logger is used. @type testInstance: L{twisted.trial.unittest.TestCase} @param publisher: Log publisher to observe. @type publisher: twisted.logger.LogPublisher @return: An EventLoggingObserver configured to observe the provided publisher. @rtype: L{twisted.test.proto_helpers.EventLoggingObserver} c&jSrL)removeObserver)obs publishersrIz8EventLoggingObserver.createWithCleanup..s (@(@(Er>) addObserver addCleanup)cls testInstancerrs `@rIcreateWithCleanupz&EventLoggingObserver.createWithCleanups. ec" EF r>N)rIrJ)rIint)rrrIr))rslicerIzSequence[LogEvent])rz int | slicerIzLogEvent | Sequence[LogEvent])rIzIterator[LogEvent])rr)rIrJ)rr-rr*rIr) rVrWrXrYr`rr rrr classmethodrrZr>rIr;r;s\*!    #"# r>r;N)PrY __future__rrrsocketrrtypingrrr r zope.interfacer r zope.interface.verifyr rrtwisted.internetrrrrtwisted.internet.abstractrrtwisted.internet.addressrrrtwisted.internet.deferrtwisted.internet.errorrtwisted.internet.interfacesrrrrrr r!r"r#r$r%r&twisted.internet.taskr'twisted.loggerr(r)r*twisted.protocolsr+twisted.pythonr,twisted.trial.unittestr-__all__r<Protocolr. LineReceiverr/r0r1r2r3r5r4r6ifacer7r8r9r:r;rZr>rIrs #$995-";;EJJ+;    (??#"+ "t_'8,,'T%,,0,, ZM2\)\)3\)~ X X W  ^!!!@ Z,,,^ +{L.-KKK\ = )&E}%&  [+|^DM%M%EM%`..b$: \88H-88r>