ó O)|Pc@`sCdZddlmZmZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZddlmZmZmZmZdd lmZdd lmZdd lmZmZdd lmZdd lmZdd„Zdejfd„ƒYZ dej!fd„ƒYZ"de#fd„ƒYZ$de$ej!fd„ƒYZ%de$ej&fd„ƒYZ'de j(fd„ƒYZ)d„Z*de j(fd„ƒYZ+dej,fd„ƒYZ-d e'fd!„ƒYZ.d"e j(fd#„ƒYZ/d$e j(fd%„ƒYZ0d&ej&fd'„ƒYZ1d(e j(fd)„ƒYZ2d*ejfd+„ƒYZ3d,ejfd-„ƒYZ4d.ej&fd/„ƒYZ5d0e j(fd1„ƒYZ6d2ejfd3„ƒYZ7d4ejfd5„ƒYZ8d6ejfd7„ƒYZ9d8e9fd9„ƒYZ:d:dad;„ƒYZ;d<e j(e;fd=„ƒYZ<d>ej=fd?„ƒYZ>d@ej?fdA„ƒYZ@dBe j(fdC„ƒYZAdDejfdE„ƒYZBdFejfdG„ƒYZCdHej&fdI„ƒYZDdJej=fdK„ƒYZEdLej?fdM„ƒYZFdNe j(fdO„ƒYZGe eƒdPefdQ„ƒYƒZHdRej!fdS„ƒYZIdTe j(fdU„ƒYZJdVe j(fdW„ƒYZKdXe j(fdY„ƒYZLdZe j(fd[„ƒYZMd\e j(fd]„ƒYZNd^e j(fd_„ƒYZOyddlPZPWneQk rn$XePjRePjSƒdd`ZTeTe<_UdS(bs. Tests for implementations of L{IReactorTCP}. i(tdivisiontabsolute_importN(twraps(t implementer(tunittest(tmsg(tprotocoltreactortdefert interfaces(terror(t IPv4Address(tIHalfCloseableProtocolt IPullProducer(tpolicies(tAccumulatingProtocolc`s|ddlm}tjƒ‰‡‡fd†}|j|ƒ‰‡fd†}ˆj|ƒˆj|ƒ}|jˆjƒˆS(sš Poor excuse for an event notification helper. This polls a condition and calls back a Deferred when it is seen to be true. Do not use this function. i(ttaskc`s#ˆƒ}|rˆj|ƒndS(N(tcallback(tres(tdt predicate(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcheck#s c`sˆjƒ|S(N(tstop(tresult(tcall(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR(s ( ttwisted.internetRRtDeferredt LoopingCallt addCallbacktstartt addErrbackterrback(RtintervalRRRtd2((RRRs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt loopUntils  tClosingProtocolcB`seZd„Zd„ZRS(cC`stdƒ|jjƒdS(NsClosingProtocol.connectionMade(Rt transporttloseConnection(tself((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytconnectionMade4s cC`stdƒ|jtjƒdS(NsClosingProtocol.connectionLost(RttrapR tConnectionDone(R&treason((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytconnectionLost8s (t__name__t __module__R'R+(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR#2s tClosingFactorycB`s&eZdZdZd„Zd„ZRS(s/ Factory that closes port immediately. cC`s|jjƒ|_tƒS(N(tportt stopListeningt _cleanerUpperR#(R&tconn((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt buildProtocolEscC`s#|jdkr|jjƒS|jS(sL Clean-up for tests to wait for the port to stop listening. N(R1tNoneR/R0(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcleanUpJs N(R,R-t__doc__R4R1R3R5(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR.>s tMyProtocolFactoryMixincB`s>eZdZeZdZdZdZdZ d„Z d„Z RS(s  Mixin for factories which create L{AccumulatingProtocol} instances. @type protocolFactory: no-argument callable @ivar protocolFactory: Factory for protocols - takes the place of the typical C{protocol} attribute of factories (but that name is used by this class for something else). @type protocolConnectionMade: L{NoneType} or L{defer.Deferred} @ivar protocolConnectionMade: When an instance of L{AccumulatingProtocol} is connected, if this is not C{None}, the L{Deferred} will be called back with the protocol instance and the attribute set to C{None}. @type protocolConnectionLost: L{NoneType} or L{defer.Deferred} @ivar protocolConnectionLost: When an instance of L{AccumulatingProtocol} is created, this will be set as its C{closedDeferred} attribute and then this attribute will be set to C{None} so the L{defer.Deferred} is not used by more than one protocol. @ivar protocol: The most recently created L{AccumulatingProtocol} instance which was returned from C{buildProtocol}. @type called: C{int} @ivar called: A counter which is incremented each time C{buildProtocol} is called. @ivar peerAddresses: A C{list} of the addresses passed to C{buildProtocol}. icC`s g|_dS(N(t peerAddresses(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt__init__xscC`sV|jj|ƒ|jd7_|jƒ}||_|j|_d|_||_|S(si Create a L{AccumulatingProtocol} and set it up to be able to perform callbacks. iN( R8tappendtcalledtprotocolFactorytfactorytprotocolConnectionLosttclosedDeferredR4R(R&taddrtp((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR3|s     N( R,R-R6RR<R4tprotocolConnectionMadeR>RR;R9R3(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR7Ts tMyServerFactorycB`seZdZRS(sI Server factory which creates L{AccumulatingProtocol} instances. (R,R-R6(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRCŒstMyClientFactorycB`s>eZdZdZdZd„Zd„Zd„Zd„ZRS(sI Client factory which creates L{AccumulatingProtocol} instances. icC`s/tj|ƒtjƒ|_tjƒ|_dS(N(R7R9RRtdeferredt failDeferred(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR9šs cC`s&d|_||_|jjdƒdS(Ni(tfailedR*RFRR4(R&t connectorR*((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytclientConnectionFailedŸs  cC`s||_|jjdƒdS(N(t lostReasonRERR4(R&RHR*((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytclientConnectionLost€s cC`s d|_dS(Ni(tstopped(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt stopFactoryšs( R,R-R6RGRLR9RIRKRM(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRD“s   tListeningTestCasecB`sbeZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z RS( cC`sNtƒ}tjd|ddƒ}|j|jƒ|jtjj|ƒƒdS(sf L{IReactorTCP.listenTCP} returns an object which provides L{IListeningPort}. it interfaces 127.0.0.1N( RCRt listenTCPt addCleanupR0t failUnlessR tIListeningPortt providedBy(R&tftp1((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt test_listen¯s c`setƒ‰tjdˆddƒ}|jƒj‰‡‡fd†}tj|jƒ}|j|ƒ|S(s The L{IListeningPort} returned by L{IReactorTCP.listenTCP} can be stopped with its C{stopListening} method. After the L{Deferred} it (optionally) returns has been called back, the port number can be bound to a new server. iROs 127.0.0.1c`s"tjˆˆddƒ}|jƒS(NROs 127.0.0.1(RRPR0(tignoredR/(RUtn(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcbStopListeningÅs( RCRRPtgetHostR/Rt maybeDeferredR0R(R&R/RZR((RURYs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttestStopListeningºs  cC`s+tƒ}tjd|ddƒ}|jƒS(NiROs 127.0.0.1(RCRRPR0(R&RURV((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttestNumberedInterfaceÏs c`s†tƒ}tjd|ƒ‰tˆjƒjƒ‰ˆjtˆƒjˆƒdkƒ‡‡‡fd†}t j ˆj ƒ}|j |ƒS(Niiÿÿÿÿc`s&ˆjtˆƒjˆƒdkƒdS(Niÿÿÿÿ(tfailIftreprtfind(tign(RAtportNoR&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytstoppedListeningÚs( RCRRPtstrR[R/R_R`RaRR\R0R(R&RURdR((RARcR&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt testPortReprÕs "c`s¶tƒ}tjƒ}|_tjd|ƒ‰ˆjˆjƒtƒ}tjƒ}|_tj dˆj ƒj |ƒ}ˆj|j ƒ‡‡fd†}tj ||gƒj|ƒS(s Check that the repr string of the server transport get the good port number if the server listens on 0. is 127.0.0.1c`sY|\}}ˆjƒj}ˆjt|jƒd|fƒ|jjƒ|jjƒdS(Ns(R[R/t assertEqualR`R$R%(Rt serverProtot clientProtot portNumber(R/R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRïs   (RCRRRBRRPRQR0RDt connectTCPR[R/t disconnectt gatherResultsR(R&tservertserverConnMadetclienttclientConnMadeRHR((R/R&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_serverRepràs   c`sutƒ‰tjdˆddƒ‰ˆjˆjƒ‡‡‡‡fd†}d„‰tjˆjƒ}|j|ƒ|S(sŽ Stop and then try to restart a L{tcp.Port}: after a restart, the server should be able to handle client connections. iROs 127.0.0.1c`sˆjƒtƒ}tjƒˆ_tjƒ|_tjdˆjƒj|ƒ}ˆj |j ƒtj ˆj|jgƒj ˆƒS(Ns 127.0.0.1( tstartListeningRDRRRBRRkR[R/RQRlRmR(RXRpRH(tcloseR/R&t serverFactory(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRZs    cS`s*|\}}|jjƒ|jjƒdS(N(R$R%(RRhRi((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRts  (RCRRPRQR0RR\R(R&RZR((RtR/R&Rus9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_restartListeningûs   cC`sItƒ}d„}||_tjd|ddƒ}|j|jƒtƒS(s» If the server factory raises an exception in C{stopFactory}, the deferred returned by L{tcp.Port.stopListening} should fail with the corresponding error. cS`stdƒ‚dS(NsAn error(t RuntimeError(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytraiseException"siROs 127.0.0.1(RCRMRRPt assertFailureR0Rw(R&RuRxR/((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_exceptInStops    c`sƒtƒ‰d„}|ˆ_tjdˆddƒ‰ˆjˆjƒ‡‡‡‡fd†}d„‰ˆjˆjƒtƒj|ƒS(s¹ Even if the server factory raise an exception in C{stopFactory}, the corresponding C{tcp.Port} instance should be in a sane state and can be restarted. cS`stdƒ‚dS(NsAn error(Rw(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRx1siROs 127.0.0.1c`s‡ˆ`ˆjƒtƒ}tjƒˆ_tjƒ|_tjdˆjƒj |ƒ}ˆj |j ƒtj ˆj|jgƒj ˆƒS(Ns 127.0.0.1(RMRsRDRRRBRRkR[R/RQRlRmR(RXRpRH(RtR/R&Ru(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRZ7s    cS`s*|\}}|jjƒ|jjƒdS(N(R$R%(RRhRi((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRtEs  ( RCRMRRPRQR0RyRwR(R&RxRZ((RtR/R&Rus9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_restartAfterExcept*s    c`s–tƒ}tjd|ddƒ}|jƒj}|jdƒtƒ‰tj ƒ|_ tj ƒˆ_ tj d|ˆƒ‡fd†}ˆj j |ƒS(së If C{connectionLost} is called directly on a port object, it succeeds (and doesn't expect the presence of a C{deferred} attribute). C{connectionLost} is called by L{reactor.disconnectAll} at shutdown. iROs 127.0.0.1c`sˆjjtjƒdS(N(R*R(R tConnectionRefusedError(Rb(Rp(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR^sN(RCRRPR[R/R+R4RDRRRBRkRFR(R&RuR/RjR((Rps9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_directConnectionLostCallNs   cC`sMtƒ}d„}||_tjd|ddƒ}|jt|jdƒdS(s If C{connectionLost} is called directory on a port object and that the server factory raises an exception in C{stopFactory}, the exception is passed through to the caller. C{connectionLost} is called by L{reactor.disconnectAll} at shutdown. cS`stdƒ‚dS(NsAn error(Rw(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRxlsiROs 127.0.0.1N(RCRMRRPt assertRaisesRwR+R4(R&RuRxR/((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_exceptInConnectionLostCallcs    ( R,R-RWR]R^RfRrRvRzR{R}R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRN­s     $ cC`sIddlm}ddl}|j|ƒz |ƒWd|jdƒXdS(Ni(tspewerWithLinenums(ttwisted.python.utilR€tsystsettraceR4(RUtspewerR‚((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt callWithSpewts    tLoopbackTestCasecB`s_eZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z RS( s$ Test loopback connections. c`sŠtƒ}tjd|ddƒ‰ˆ|_ˆj|jƒˆjƒj}tƒ‰tjd|ˆƒ‡‡‡fd†}ˆj j |ƒS(sz A port created with L{IReactorTCP.listenTCP} can be connected to with L{IReactorTCP.connectTCP}. iROs 127.0.0.1c`s:ˆjˆjjƒˆjˆjƒˆjjtjƒdS(N(t assertTrueRtmadet disconnectedRJR(R R)(tx(tclientFR/R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs( R.RRPR/RQR5R[RDRkRER(R&RURjR((R‹R/R&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_closePortInProtocolFactorys   cC`s t|dd„ƒtjƒdS(NR(cS`sdS(N(R4(RŠ((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt”s(tgetattrR R)(R&tobj((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt _trapCnxDone“sc `s»tƒ}tjƒ}||_tjd|ddƒ}|j|jƒ|jƒj }t ƒ}tjƒ}||_tj d||ƒtj ||gƒ}‡fd†} |j | ƒ|S(s‰ Invoke the given callback with a client protocol and a server protocol which have been connected to each other. iROs 127.0.0.1c`s7|\}}ˆ||ƒ|jjƒ|jjƒdS(N(R$R%(RtserverProtocoltclientProtocol(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt connected©s   (RCRRRBRRPRQR0R[R/RDRkRmR( R&RRuRoR/RjR‹Rqt connsMadeR“((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt_connectedClientAndServerTest—s       c`s‡fd†}ˆj|ƒS(s The transport of a protocol connected with L{IReactorTCP.connectTCP} or L{IReactor.TCP.listenTCP} can have its I{TCP_NODELAY} state inspected and manipulated with L{ITCPTransport.getTcpNoDelay} and L{ITCPTransport.setTcpNoDelay}. c`s€xy||gD]k}|j}ˆj|jƒdƒ|jdƒˆj|jƒdƒ|jdƒˆj|jƒdƒq WdS(Nii(R$Rgt getTcpNoDelayt setTcpNoDelay(R‘R’RAR$(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR¹s   (R•(R&R((R&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_tcpNoDelay²sc`s‡fd†}ˆj|ƒS(s The transport of a protocol connected with L{IReactorTCP.connectTCP} or L{IReactor.TCP.listenTCP} can have its I{SO_KEEPALIVE} state inspected and manipulated with L{ITCPTransport.getTcpKeepAlive} and L{ITCPTransport.setTcpKeepAlive}. c`s€xy||gD]k}|j}ˆj|jƒdƒ|jdƒˆj|jƒdƒ|jdƒˆj|jƒdƒq WdS(Nii(R$RgtgetTcpKeepAlivetsetTcpKeepAlive(R‘R’RAR$(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRËs   (R•(R&R((R&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_tcpKeepAliveÄsc`sAtƒ‰tjddˆddƒ‡fd†}ˆjj|ƒS(Ns 127.0.0.1iEttimeoutic`sˆjjtjƒdS(N(R*R(R R|(RX(R‹(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRÚs(RDRRkRFR(R&R((R‹s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt testFailingÖs c`sâg‰xGtdƒD]9}tjƒ}|jdƒ|jdƒˆj|ƒqWtjˆƒtjt tj ƒ‰‡‡‡‡fd†‰ˆƒ}ˆj |t j ƒ‡fd†}|j|ƒ‡fd†}|j|ƒ|S( sŽ Assert that the error number of the ConnectionRefusedError is ECONNREFUSED, and not some other socket related error. i s 127.0.0.1iic`s`‡‡‡fd†}ˆjƒ}|jƒ\}}|jƒˆj||ƒ}|j|ƒ|S(Nc`s+|jjƒˆrˆƒSˆjdƒdS(s\ Darn. Kill it and try again, if there are any tries left. s?Could not fail to connect - could not test errno for that case.N(R$R%tfail(tproto(R&t serverSocketsttryConnectFailure(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR“s (tpopt getsocknameRtRkR(R“t serverSockett serverHostt serverPorttconnectDeferred(t clientCreatorR&R R¡(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR¡s   c`sˆj|jtjƒdS(N(RgtosErrorterrnot ECONNREFUSED(texc(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt connRefusedsc`s!xˆrˆjƒjƒqW|S(N(R¢Rt(t passthrough(R (s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcleanups (s 127.0.0.1i(trangetsockettbindtlistenR:trandomtshuffleRt ClientCreatorRtProtocolRyR R|RtaddBoth(R&tiR€trefusedDeferredR­R¯((RšR&R R¡s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt!test_connectionRefusedErrorNumberßs        cC`s&|jtjtjddtƒƒdS(su Connecting to a named service which does not exist raises L{error.ServiceNameUnknownError}. s 127.0.0.1tthisbetternotexistN(R~R tServiceNameUnknownErrorRRkRD(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_connectByServiceFail!sc`sàtƒ‰tjƒ}|ˆ_tjdˆddƒ}ˆj|jƒ|jƒj ‰t ƒ}tjƒ}||_‡fd†}ˆj t d|ƒtj dd|ƒtj||gƒ}‡‡fd†}|j|ƒ|S(s× L{IReactorTCP.connectTCP} accepts the name of a service instead of a port number and connects to the port number associated with that service, as defined by L{socket.getservbyname}. iROs 127.0.0.1c`s |dkr|dkrˆSdS(Nthttpttcpi ((t serviceNamet protocolName(Rj(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytfakeGetServicePortByName<st getservbynameR¿c`s=|\}}ˆjˆjdƒ|jjƒ|jjƒdS(Ns7Server factory was not called upon to build a protocol.(R‡R;R$R%(RR‘R’(R&Ru(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR“Es   (RCRRRBRRPRQR0R[R/RDtpatchR±RkRmR(R&RoR/t clientFactoryRqRÃtconnMadeR“((RjR&Rus9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_connectByService,s        ( R,R-R6RŒRR•R˜R›RR»RŸRÈ(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR†}s      B tStartStopFactorycB`s&eZdZdZd„Zd„ZRS(icC`s(|js|jrt‚nd|_dS(Ni(tstartedRLRw(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt startFactoryUs cC`s)|j s|jrt‚nd|_dS(Ni(RÊRLRw(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRMZs (R,R-RÊRLRËRM(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRÉPs tClientStartStopFactorycB`s/eZdZdZd„Zd„Zd„ZRS(icO`s&tj|||Žtjƒ|_dS(N(RDR9RRt whenStopped(R&tatkw((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR9escC`s(|js|jrt‚nd|_dS(Ni(RÊRLRw(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRËis cC`s9|j s|jrt‚nd|_|jjtƒdS(Ni(RÊRLRwRÍRtTrue(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRMns  (R,R-RÊRLR9RËRM(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRÌ`s   tFactoryTestCasecB`s eZdZd„Zd„ZRS(sTests for factories.c`stƒ‰tjdˆddƒ}ˆj|jƒˆjˆjˆjfdƒtjdˆddƒ}tjdˆddƒ‰ˆjˆjˆjfdƒtj |jƒ}tj |jƒ}tj ||gƒ}‡‡‡fd†}|j |ƒ‡‡fd†}|j |ƒ|S( s The factory passed to L{IReactorTCP.listenTCP} should be started only when it transitions from being used on no ports to being used on one port and should be stopped only when it transitions from being used on one port to being used on no ports. iROs 127.0.0.1ic`s&ˆjˆjˆjfdƒˆjƒS(Nii(ii(RgRÊRLR0(RX(RUtp3R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcbClosed—sc`s ˆjˆjˆjfdƒdS(Ni(ii(RgRÊRL(RX(RUR&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt cbClosedAlls(ii(ii( RÉRRPRQR0RgRÊRLRR\RmR(R&RVtp2td1R!R?RÓRÔ((RURÒR&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_serverStartStopxs   c`sˆtƒ}tjd|ddƒ}||_|j|jƒ|jƒj}tƒ‰tjd|ˆƒ|j ˆj ƒt ‡fd†ƒS(s› The factory passed to L{IReactorTCP.connectTCP} should be started when the connection attempt starts and stopped when it is over. iROs 127.0.0.1c`sˆjS(N(RL((R=(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR±s( R.RRPR/RQR5R[RÌRkR‡RÊR"(R&RURARj((R=s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_clientStartStop£s   (R,R-R6R×RØ(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRÑus +tCannotBindTestCasecB`s)eZdZd„Zd„Zd„ZRS(s] Tests for correct behavior when a reactor cannot bind to the required TCP port. cC`s«tƒ}tjd|ddƒ}|j|jƒ|jƒj}|jƒ}|j|jdƒ|j|j dƒ|j|j|ƒ|j t j tj||ddƒdS(sƒ L{IReactorTCP.listenTCP} raises L{error.CannotListenError} if the address to listen on is already in use. iROs 127.0.0.1tTCPN( RCRRPRQR0R[R/RgttypethostR~R tCannotListenError(R&RURVRYtdest((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_cannotBind»s   c`s"tˆƒ‡‡fd†ƒ}|S(sGReturns closure that when called calls f and then callbacks d. c`s ˆ||Ž}ˆjdƒ|S(Nt(R(targsRÏtrtn(RRU(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytnewfÓs (R(R&RRURã((RRUs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt_fireWhenDoneFuncÐsc`sçtjƒ}tƒ}ˆj||jƒ|_tjd|ddƒ‰ˆjˆjƒ‡‡‡fd†}‡‡fd†‰‡‡‡‡‡fd†‰‡fd†‰‡fd†‰‡‡fd †‰‡fd †‰|j |ƒ|S( s³ L{IReactorTCP.connectTCP} calls C{Factory.clientConnectionFailed} with L{error.ConnectBindError} if the bind address specified is already in use. iROs 127.0.0.1c`sctjƒ}tƒ}ˆj||jƒ|_tjdˆjƒj|ddƒ|j ˆ|ƒ|S(Ns 127.0.0.1t bindAddressi(s 127.0.0.1i( RRRDRäR3RRkR[R/R(tresultsRtcf1(t_conmadeRAR&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt _connect1çs  c`s>tjƒ}ˆj||jjƒ|j_|jˆ|ƒ|S(N(RRRäRR'R(RæRçR(t_check1connect2R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRèðs  c`söˆj|jjdƒtjƒ}tjƒ}|jjjƒj}tƒ}ˆj ||j ƒ|_ ˆj ||j ƒ|_ t j dˆjƒj|dd|fƒ|jˆ||ƒ|jˆ||ƒtj||gƒ}|jˆ||ƒ|S(Nis 127.0.0.1Rå(RgRRˆRRR$R[R/RDRäRIRMRRkRt DeferredList(RæRçRÖR!R/tcf2tdl(t _check2failedt_check2stoppedt_stopRAR&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRê÷s    c`sFˆj|jdƒ|jjtjƒˆj|jjtjƒƒ|S(Ni(RgRGR*R(R tConnectBindErrorR‡R(RæRçRì(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRî sc`sˆj|jdƒ|S(Ni(RgRL(RæRçRì(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRïsc`sHtjƒ}|jˆ|ƒˆj||jƒ|_|jjjƒ|S(N(RRRRäRMRR$R%(RæRçRìR(t_check1cleanupR&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRðs  c`sˆj|jdƒdS(Ni(RgRL(RæRç(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRòs( RRRCRäRËRRPRQR0R(R&t theDeferredtsfRé((RòRêRîRïRèRðRAR&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_clientBindÛs    (R,R-R6RßRäRõ(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRÙµs  tMyOtherClientFactorycB`seZd„ZRS(cC`s||_tƒ|_|jS(N(taddressRR(R&R÷((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR3#s  (R,R-R3(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRö"stLocalRemoteAddressTestCasecB`seZdZd„ZRS(so Tests for correct getHost/getPeer values and that the correct address is passed to buildProtocol. c`sÎtƒ}tjƒ|_|j‰tjd|ddƒ‰ˆjˆjƒˆjƒj }t ƒ‰tjƒ}ˆ_ tj d|ˆƒ‰‡‡‡fd†}|j |ƒ‡‡fd†}|j |ƒ|S(s L{IListeningPort.getHost} returns the same address as a client connection's L{ITCPTransport.getPeer}. iROs 127.0.0.1c`sBˆjˆjƒgˆjƒˆjˆjƒˆjjjƒƒdS(N(RgR[R8RR$tgetPeer(RX(RÆR/R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR?sc`sˆjƒˆS(N(Rl(RX(RHtserverConnectionLost(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR¯Es (RCRRR>RRPRQR0R[R/RDRBRkR(R&RuRYt onConnectionRR¯((RÆRHR/R&Rús9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_hostAddress/s     (R,R-R6Rü(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRø*stWriterProtocolcB`seZd„ZRS(cC`sË|jjdƒddddg}|jj|ƒ|jjƒ}|jdkrptd|fƒd|j_n|jjƒ}|jdkr®td |fƒd|j_nd|j_ |jj ƒdS( NsHello Cleveland! tGoodbyes cruels worlds RÚs#getPeer returned non-TCP socket: %sis#getHost returned non-TCP socket: %s( R$twritet writeSequenceRùRÛRR=tproblemR[tdoneR%(R&tseqtpeertus((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR'Rs (R,R-R'(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRýQstReaderProtocolcB`seZd„Zd„ZRS(cC`s|jj|7_dS(N(R=tdata(R&R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt dataReceivedhscC`sd|j_dS(Ni(R=R(R&R*((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR+js(R,R-RR+(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRgs tWriterClientFactorycB`seZd„Zd„ZRS(cC`sd|_d|_dS(NiRà(RR(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR9ns cC`stƒ}||_||_|S(N(RR=R(R&R@RA((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR3qs   (R,R-R9R3(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR ms tWriteDataTestCasecB`s eZdZd„Zd„ZRS(sw Test that connected TCP sockets can actually write data. Try to exercise the entire ITransport interface. c`sÏtjƒ‰tˆ_dˆ_dˆ_tˆƒ}tjd|ddƒ}ˆj|j ƒ|j ƒj }t ƒ‰tˆƒ}tj d||ƒ‡‡‡fd†}tj|j|jgƒ}|j|ƒS(s‚ L{ITCPTransport.write} and L{ITCPTransport.writeSequence} send bytes to the other end of the connection. iROs 127.0.0.1c`szˆjˆjdƒˆjˆjdkdƒˆjˆjdƒdjdddd d gƒ}ˆjˆj|kd ƒdS( Ns&writer didn't finish, it probably diediswriter indicated an errors$client didn't see connection droppedRàsHello Cleveland! Rþs cruels worlds s.client didn't receive all the data it expected(RRRRtjoinR(RXtexpected(R‹RUR&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRŽs  (RtFactoryRýRRt WiredFactoryRRPRQR0R[R/R RkRRmt onDisconnectR(R&twrappedFRARYtwrappedClientFRR((R‹RUR&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt test_writer}s        c`s™tjjdkr$tjdƒ‚ntjjdkrHtjdƒ‚ntjƒ‰tjƒ‰dtjf‡‡fd†ƒY}tj ƒ}||_tj d|dd ƒ}|j |j ƒ|j ƒ}ttƒd tfd „ƒYƒ‰d tjf‡‡‡fd †ƒY}tƒ‰|ˆ_ˆj}‡fd†}|j|ƒtd|j|jfƒtj|j|jˆƒtdƒ|j|tjƒS(s$ A TCP transport which is written to after the connection has been shut down should notify its protocol that the connection has been lost, even if the TCP transport is not actively being monitored for read events (ie, pauseProducing was called on it). t IOCPReactors'iocpreactor does not, in fact, stop reading immediately after pauseProducing is called. This results in a bonus disconnection notification. Under some circumstances, it might be possible to not receive this notifications (specifically, pauseProducing, deliver some data, proceed with this test).t GtkReactorsŸgtkreactor does not implement unclean disconnection notification correctly. This might more properly be a todo, but due to technical limitations it cannot be.t Disconnecterc`s,eZdZ‡fd†Z‡fd†ZRS(sØ Protocol for the server side of the connection which disconnects itself in a callback on clientPaused and publishes notification when its connection is actually lost. c`s*tdƒ‡fd†}ˆj|ƒdS(s[ Set up a callback on clientPaused to lose the connection. sDisconnector.connectionMadec`s%tdƒˆjjƒtdƒdS(Ns&Disconnector.connectionMade disconnectsloseConnection called(RR$R%(RX(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRlÒs  N(RR(R&Rl(t clientPaused(R&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR'Ís c`s%tdƒˆjdƒtdƒdS(st Notify observers that the server side of the connection has ended. sDisconnecter.connectionLostsserverLost called backN(RRR4(R&R*(t serverLost(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR+Øs  (R,R-R6R'R+((RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRÇs iROs 127.0.0.1tInfinitecB`s)eZdZd„Zd„Zd„ZRS(s¿ A producer which will write to its consumer as long as resumeProducing is called. @ivar consumer: The L{IConsumer} which will be written to. cS`s ||_dS(N(tconsumer(R&R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR9ñscS`s(tdƒ|jjdƒtdƒdS(NsInfinite.resumeProducingRŠs*Infinite.resumeProducing wrote to consumer(RRRÿ(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytresumeProducingôs cS`stdƒdS(NsInfinite.stopProducing(R(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt stopProducingùs(R,R-R6R9RR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRès  tUnreadingWriterc`s#eZdZ‡‡‡fd†ZRS(s Trivial protocol which pauses its transport immediately and then writes some bytes to it. c`sQtdƒˆjjƒˆjdƒtdƒ‡‡fd†}ˆj|ƒdS(NsUnreadingWriter.connectionMadesclientPaused called backc`sDtdƒˆˆjƒ}tdƒˆjj|tƒtdƒdS(Ns$UnreadingWriter.connectionMade writes5UnreadingWriter.connectionMade write created producers8UnreadingWriter.connectionMade write registered producer(RR$tregisterProducertFalse(RXtproducer(RR&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRÿs   (RR$tpauseProducingRR4R(R&Rÿ(RRR(R&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR's     (R,R-R6R'((RRR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRýsc`stdƒˆjS(Nt cbClientLost(RRJ(RX(Rp(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR!s sConnecting to %s:%ssReturning Deferred(Rt __class__R,RtSkipTestRRRR·t ServerFactoryRPRQR0R[RR tobjectRDR<RERRRÜR/RkRyR tConnectionLost(R&RRnR/R@RRKR!((RRpRRs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt%test_writeAfterShutdownWithoutReadingœs4   "    %     (R,R-R6RR'(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR ws tConnectionLosingProtocolcB`seZd„ZRS(cC`sD|jjdƒ|jjƒ|jjƒ|jjj|jƒdS(Nt1(R$RÿR%tmastert_connectionMadetportsR:(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR'-s  (R,R-R'(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR(,st NoopProtocolcB`seZd„Zd„ZRS(cC`s)tjƒ|_|jjj|jƒdS(N(RRRR*t serverConnsR:(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR'6scC`s|jjtƒdS(N(RRRÐ(R&R*((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR+:s(R,R-R'R+(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR-5s tConnectionLostNotifyingProtocolcB`s eZdZd„Zd„ZRS(sc Protocol which fires a Deferred which was previously passed to its initializer when the connection is lost. @ivar onConnectionLost: The L{Deferred} which will be fired in C{connectionLost}. @ivar lostConnectionReason: C{None} until the connection is lost, then a reference to the reason passed to C{connectionLost}. cC`sd|_||_dS(N(R4tlostConnectionReasontonConnectionLost(R&R1((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR9Js cC`s||_|jj|ƒdS(N(R0R1R(R&R*((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR+Os (R,R-R6R9R+(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR/?s  tHandleSavingProtocolcB`seZdZd„ZRS(s• Protocol which grabs the platform-specific socket handle and saves it as an attribute on itself when the connection is established. cC`s"|jƒ|_tjj||ƒS(s\ Save the platform-specific socket handle for future introspection. (t getHandlethandleRR·tmakeConnection(R&R$((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR5[s(R,R-R6R5(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR2UstProperlyCloseFilesMixincB`s;eZdZd„Zd„Zd„Zd„Zd„ZRS(sA Tests for platform resources properly being cleaned up. cC`s tƒ‚dS(s Bind a server port to which connections will be made. The server should use the given protocol factory. @return: The L{IListeningPort} for the server created. N(tNotImplementedError(R&R÷RjR=((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt createServeriscC`s tƒ‚dS(sà Establish a connection to the given address using the given L{ClientCreator} instance. @return: A Deferred which will fire with the connected protocol instance. N(R7(R&R÷RjRš((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt connectClientsscC`s tƒ‚dS(s… Return the exception class which will be raised when an operation is attempted on a closed platform handle. N(R7(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytgetHandleExceptionType}scC`stjS(sn Return the errno expected to result from writing to a closed platform socket handle. (RªtEBADF(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytgetHandleErrorCode…s c`sètjƒ‰tjƒ}‡fd†|_ˆjdd|ƒ‰tjƒ‰ˆjƒ}tjt‡fd†ƒ}ˆj|j |j |ƒ}‡‡fd†}|j |ƒ‡fd†}|j |ƒ‡fd†}|j |ƒ|S(sp Test that lost connections properly have their underlying socket resources cleaned up. c`s tˆƒS(N(R/((tonServerConnectionLost(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR˜ss 127.0.0.1ic`s tˆƒS(N(R2((tonClientConnectionLost(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRŸsc`s0|jjdƒ|jjƒtjˆˆgƒS(sŠ Disconnect the client. Return a Deferred which fires when both the client and the server have received disconnect notification. s0some bytes to make sure the connection is set up(R$RÿR%RRm(Rp(R>R=(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytclientConnected£s   c`sz|\}}|jjtjƒ|jjtjƒˆjƒ}ˆjˆjƒ|jjdƒ}ˆj |j d|ƒdS(sl Verify that the underlying platform socket handle has been cleaned up. tbytesiN( R0R(R tConnectionClosedR<R~R:R4tsendRgRá(RRpRntexpectedErrorCodeterr(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytclientDisconnected¯s  c`s,tjˆjƒ}|j‡fd†ƒ|S(sx Shut down the server port. Return a Deferred which fires when this has completed. c`sˆS(N((Rb(R®(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRÃs(RR\R0R(R®R(RŠ(R®s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR¯œs( RRRR$R8R[R¶RR9RÜR/RRž(R&Rut serverAddrRštclientDeferredR?RER¯((R>R=R&RŠs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_properlyCloseFiles‘s"       (R,R-R6R8R9R:R<RH(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6es   tProperlyCloseFilesTestCasecB`s)eZdZd„Zd„Zd„ZRS(s Test that the sockets created by L{IReactorTCP.connectTCP} are cleaned up when the connection they are associated with is closed. cC`stj||d|ƒS(sE Create a TCP server using L{IReactorTCP.listenTCP}. RO(RRP(R&R÷RjR=((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR8ÐscC`s|j||ƒS(sF Create a TCP client using L{IReactorTCP.connectTCP}. (Rk(R&R÷RjRš((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR9×scC`stjS(s¬ Return L{socket.error} as the expected error type which will be raised by a write to the low-level socket object after it has been closed. (R±R (R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR:Þs(R,R-R6R8R9R:(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRIËs  tWiredForDeferredscB`s#eZd„Zd„Zd„ZRS(cC`stjj|||ƒdS(N(RtProtocolWrapperR9(R&R=twrappedProtocol((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR9éscC`s'tjj|ƒ|jjjdƒdS(N(RRKR'R=t onConnectRR4(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR'ìscC`s*tjj||ƒ|jjjdƒdS(N(RRKR+R=RRR4(R&R*((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR+ðs(R,R-R9R'R+(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRJès  RcB`seZeZd„ZRS(cC`s5tjj||ƒtjƒ|_tjƒ|_dS(N(RtWrappingFactoryR9RRRMR(R&twrappedFactory((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR9ùs(R,R-RJRR9(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRöstAddressTestCasecB`s)eZdZd„Zd„Zd„ZRS(sR Tests for address-related interactions with client and server protocols. cC`s#dtjfd„ƒY}tƒ|_tjƒ|_|j_tjƒ|_|j_ ||jƒ|_ t ƒ|_ tjƒ|_ |j _tjƒ|_|j _ ||j ƒ|_tjd|j ddƒ|_tj|jjƒj|jjƒj|jƒ|_tj|j|j gƒS(s9 Create a port and connected client/server pair which can be used to test factory behavior related to addresses. @return: A L{defer.Deferred} which will be called back when both the client and server protocols have received their connection made callback. tRememberingWrappercB`s eZdZd„Zd„ZRS(s„ Simple wrapper factory which records the addresses which are passed to its L{buildProtocol} method and delegates actual protocol creation to another factory. @ivar addresses: A list of the objects passed to buildProtocol. @ivar factory: The wrapped factory to which protocol creation is delegated. cS`sg|_||_dS(N(t addressesR=(R&R=((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR9s cS`s |jj|ƒ|jj|ƒS(sˆ Append the given address to C{self.addresses} and forward the call to C{self.factory}. (RRR:R=R3(R&R@((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR3s(R,R-R6R9R3(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRQ s  iROs 127.0.0.1(Rt ClientFactoryRCRnRRRoRBtserverConnLostR>t serverWrapperRDRpRqtclientConnLostt clientWrapperRRPR/RkR[RÜRHRm(R&RQ((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytsetUps   -cC`s8|jjƒtj|j|jtj|jjƒgƒS(sf Disconnect the client/server pair and shutdown the port created in L{setUp}. ( RHRlRRmRTRVR\R/R0(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttearDown=s  cC`s„|jjjjƒ}|jjjjƒ}|j|jjt d|j |j ƒgƒ|j|jjt d|j |j ƒgƒdS(se L{ClientFactory.buildProtocol} should be invoked with the address of the server to which a connection has been established, which should be the same as the address reported by the C{getHost} method of the transport of the server protocol and as the C{getPeer} method of the transport of the client protocol. RÚN( RnRR$R[RpRùRgRWRRR RÜR/(R&R¥t clientPeer((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_buildProtocolClientHs  (R,R-R6RXRYR[(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRPs 9 tLargeBufferWriterProtocolcB`seZd„ZRS(cC`s7|jjd|jjƒd|j_|jjƒdS(NtXi(R$RÿR=tlenRR%(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR'as (R,R-R'(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR\\stLargeBufferReaderProtocolcB`seZd„Zd„ZRS(cC`s|jjt|ƒ7_dS(N(R=R^(R&R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRhscC`sd|j_dS(Ni(R=R(R&R*((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR+js(R,R-RR+(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR_gs tLargeBufferReaderClientFactorycB`seZd„Zd„ZRS(cC`sd|_d|_dS(Ni(RR^(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR9ns cC`stƒ}||_||_|S(N(R_R=R(R&R@RA((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR3qs   (R,R-R9R3(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR`ms t FireOnClosecB`seZdZd„ZRS(saA wrapper around a protocol that makes it fire a deferred when connectionLost is called. cC`s*tjj||ƒ|jjjdƒdS(N(RRKR+R=RERR4(R&R*((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR+|s(R,R-R6R+(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRaxstFireOnCloseFactorycB`seZeZd„ZRS(cC`s&tjj||ƒtjƒ|_dS(N(RRNR9RRRE(R&RO((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR9„s(R,R-RaRR9(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRbstLargeBufferTestCasecB`seZdZdZd„ZRS(s5Test that buffering large amounts of data works. i<ic`sÛtjƒ‰tˆ_dˆ_dˆ_ˆjˆ_tˆƒ}tj d|ddƒ}ˆj |j ƒ|j ƒj }tƒ‰tˆƒ}tjd||ƒtj|j|jgƒ}‡‡‡fd†}|j|ƒS(NiROs 127.0.0.1c`sVˆjˆjdƒˆjˆjˆjkdˆjˆjfƒˆjˆjdƒdS(Ns&writer didn't finish, it probably dieds9client didn't receive all the data it expected (%d != %d)s$client didn't see connection dropped(RRRR^tdatalen(RX(R‹RUR&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs  (RR R\RRRdR^RbRRPRQR0R[R/R`RkRRmRER(R&RRARYRRR((R‹RUR&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt testWriterŽs        iðiÀ(R,R-R6RdRe(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRc‰st MyHCProtocolcB`s&eZeZeZd„Zd„ZRS(cC`s&t|_|jr"|jdƒndS(N(RÐtreadHalfClosedtwriteHalfClosedR+R4(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytreadConnectionLost®s  cC`s&t|_|jr"|jdƒndS(N(RÐRhRgR+R4(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytwriteConnectionLostŽs  (R,R-RRgRhRiRj(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRf§s t MyHCFactorycB`seZdZdZd„ZRS(icC`s.|jd7_tƒ}||_||_|S(Ni(R;RfR=R(R&R@RA((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR3Às    N(R,R-R;R4RBR3(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRk»stHalfCloseTestCasecB`sDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(sTest half-closing connections.c`s–tƒˆ_}tjd|ddƒˆ_‰ˆjˆjƒt‡fd†ƒ}tj tt ƒˆ_ |j ‡‡fd†ƒ|j ˆj ƒ|S(NiROs 127.0.0.1c`sˆjS(N(R“((RA(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRÏsc`s%ˆjjˆjƒjˆjƒjƒS(N(tcfRkR[RÜR/(t_(RAR&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRÓs(RkRURRPRARQR0R"RR¶RfRmRt_setUp(R&RUR((RAR&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRXËsc`sN|ˆ_tjƒˆ_ˆj_ˆjˆjjjdƒt‡fd†ƒS(Nic`stˆjddƒdk S(NR(RŽRUR4((R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRÝs( RpRRtclientProtoConnectionLostR?RgR$R“R"(R&Rp((R&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRoØs c`seˆjˆjjdƒˆjjjƒtjˆjjƒ}|j ‡fd†ƒ|j ˆj ƒ|S(Nic`sˆjS(N(Rp(Rb(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRãs( RgRptclosedR$R%RR\RAR0Rt _tearDown(R&R((R&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRYßs c`s‰ˆjˆjjdƒˆjˆjjjdƒtjƒ‰‡‡fd†}|ˆjj_ˆjjjj ƒˆj ‡fd†ƒˆS(Niic`s dˆjj_ˆjdƒdS(Ni(RURRqRR4(R*(RR&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt_connectionLostísc`sˆjˆjjjdƒS(Ni(RgRURRq(RŠ(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRòs( RgRpRqRURRRR+R$R%R(R&RXRs((RR&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRrçs c`s•ˆj‰ˆj‰ˆj‰ˆjdƒt‡fd†ƒ}‡fd†}‡‡‡fd†}‡‡‡fd†}|j|ƒj|ƒj|ƒS(Nthelloc`stˆjƒdkS(Ni(R^t_tempDataBuffer((tt(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRûsc`sˆjƒt‡fd†ƒS(Nc`sˆjS(N(t_writeDisconnected((Rv(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRþs(tloseWriteConnectionR"(RX(Rv(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt loseWriteüs c`sLˆjˆjtƒˆjˆjtƒˆjˆjtƒt‡fd†ƒS(Nc`s ˆjjS(N(RRg((RU(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs(RgRqRRhRÐRgR"(RX(RpRUR&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRÿsc`s‚ˆjj}|dƒ|dƒˆjdtˆjjƒƒˆjˆjjdƒˆjˆjjtƒˆjˆjj t ƒdS(Ns worldslalala fooled youiRt( R$RÿRgR^RuRRRqRRgRÐ(RXtw(RpRUR&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRÿs   (RpRUR$RÿR"R(R&RRyRRÿ((RpRUR&Rvs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttestCloseWriteCloserõs    c`siˆj‰ˆjjjƒtjt‡fd†ƒt‡fd†ƒgƒ}|j‡‡fd†ƒ|S(Nc`s ˆjjS(N(RRh((RU(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRsc`s ˆjjS(N(RpRg((R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRsc`sˆjˆjjtƒS(N(RgRRgR(Rn(RUR&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs(RURR$RxRRmR"R(R&R((RUR&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttestWriteCloseNotifications ( R,R-R6RXRoRYRrR{R|(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRlÈs    tHalfClose2TestCasecB`s5eZd„Zd„Zd„Zd„Zd„ZRS(cC`s…tƒ|_}tjƒ|j_tjd|ddƒ|_}tj tt ƒj |j ƒj |j ƒjƒ}|j|jƒ|S(NiROs 127.0.0.1(RCRURRRBRRPRARR¶RRkR[RÜR/Rt _gotClient(R&RURAR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRXscC`s||_|jjS(N(RpRURB(R&Rp((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR~'s cC`s|jjjƒ|jjƒS(N(RpR$R%RAR0(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRY.sc`s‘ˆjjjdƒˆjjjƒtjƒˆjj_}tjƒˆj_}|j ‡fd†ƒ|j ‡fd†ƒtj ||gƒS(só TCP protocols support half-close connections, but not all of them support being notified of write closes. In this case, test that half-closing the connection causes the peer's connection to be closed. Rtc`sˆjˆjjjdƒS(NRt(RgRURR(RŠ(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR=sc`sˆjˆjjjtƒS(N(RgRURRqRÐ(RŠ(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR?s( RpR$RÿRxRRRURR?RRm(R&RR!((R&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttestNoNotification2sc`sŽˆjjjjƒˆjjjdƒˆjjjƒtjƒˆjj_ }tjƒˆj_ }|j ‡fd†ƒtj ||gƒS(sx If the other side has already closed its connection, loseWriteConnection should pass silently. R]c`sˆjˆjjjtƒS(N(RgRURRqRÐ(RŠ(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRLs( RURR$R%RpRÿRxRRR?RRm(R&RR!((R&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttestShutdownExceptionBs(R,R-RXR~RYRR€(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR}s    tHalfCloseBuggyApplicationTestscB`s;eZdZd„Zd„Zd„Zd„Zd„ZRS(sI Test half-closing connections where notification code has bugs. c`sœtƒˆ_tjƒˆj_tjdˆjddƒˆ_ˆjˆjj ƒˆjj ƒ}t j tt ƒ}|j|j|jƒ}‡fd†}|j|ƒtjˆjj|gƒS(s| Set up a server and connect a client to it. Return a Deferred which only fires once this is done. iROs 127.0.0.1c`s |ˆ_dS(N(R’(R’(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt setClientcs(RkRuRRRBRRPR/RQR0R[RR¶RfRkRÜRRm(R&R@tcreatorRGR‚((R&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRXVs   cG`stdƒ‚dS(s` Fake implementation of a callback which illegally raises an exception. sONO I AM BUGGY CODEN(Rw(R&Rá((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytaBugksc`sFtjƒ}ˆj_ˆjjjƒ‡fd†}|j|ƒ|S(s~ Helper for testing that an exception is logged by the time the client protocol loses its connection. c`s)ˆjtƒ}ˆjt|ƒdƒdS(Ni(tflushLoggedErrorsRwRgR^(RXterrors(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRzs(RRR’R?R$RxR(R&RqR((R&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt_notificationRaisesTestss  cC`s|j|jj_|jƒS(sã If C{readConnectionLost} raises an exception when the transport calls it to notify the protocol of that event, the exception should be logged and the protocol should be disconnected completely. (R„RuRRiR‡(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_readNotificationRaisesscC`s|j|j_|jƒS(sä If C{writeConnectionLost} raises an exception when the transport calls it to notify the protocol of that event, the exception should be logged and the protocol should be disconnected completely. (R„R’RjR‡(R&((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_writeNotificationRaises‹s(R,R-R6RXR„R‡RˆR‰(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRQs     t LogTestCasecB`seZdZd„ZRS(s4 Test logging facility of TCP base classes. c`s¿tƒ}tƒ}tjƒ|_tjd|ddƒ}ˆj|jƒtj |j ƒj |j ƒj |ƒ‰ˆjˆj ƒˆjˆjjdƒ‡‡fd†}|jj|ƒ|jS(sx Check that the log customization of the client transport happens once the client is connected. iROs 127.0.0.1t Uninitializedc`sˆjˆjjdƒdS(NsAccumulatingProtocol,client(RgR$tlogstr(Rb(RHR&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcb°s(RCRDRRRBRRPRQR0RkR[RÜR/RlRgR$RŒR(R&RnRpR/R((RHR&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_logstrClientSetup›s  !(R,R-R6RŽ(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRŠ–stPauseProducingTestCasecB`s5eZdZd„Zejjeƒs3de_nRS(sG Test some behaviors of pausing the production of a transport. c`sžtƒ}tƒ}tjƒ|_tjd|ddƒ}ˆj|jƒtj |j ƒj |j ƒj |ƒ}ˆj|j ƒ‡‡fd†}‡fd†‰|jj|ƒ|jS(s˜ In C{connectionMade} of a client protocol, C{pauseProducing} used to be ignored: this test is here to ensure it's not ignored. iROs 127.0.0.1c`s‰|j}ˆj|tjƒtjƒƒ|jjƒˆj|tjƒtjƒƒtjƒ}|j ˆƒtj d|j |ƒ|S(Ni( R$tassertInRt getReaderst getWritersR t assertNotInRRRt callLaterR(RŸttrR(tcheckAfterConnectionMadeR&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcheckInConnectionMadeÎs    c`s-|j}ˆj|tjƒtjƒƒdS(N(R$R“RR‘R’(RŸR•(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR–Ús (RCRDRRRBRRPRQR0RkR[RÜR/RlR(R&RnRpR/RHR—((R–R&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt#test_pauseProducingInConnectionMadeœs  ! s#Reactor not providing IReactorFDSet( R,R-R6R˜R t IReactorFDSetRTRtskip(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRžs %tCallBackOrderTestCasecB`seZdZd„ZRS(s- Test the order of reactor callbacks c `s*tƒ}tjƒj‡fd†ƒ|_tƒ‰tjƒˆ_tjƒˆ_‡fd†}ˆjj|ƒtjd|ddƒ}ˆj |j ƒtj |j ƒj |j ƒjˆƒ}ˆj |jƒd„}d„}‡fd†}tjˆjj|ƒˆjj|ƒgƒ}|j|ƒS( sl Check that Protocol.connectionLost is called before factory's clientConnectionLost c`sˆj|jjƒS(N(RQR$R%(RŸ(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRósc`stjdˆjjjƒdS(s: protocol.connectionMade callback iN(RR”RR$R%(R(Rp(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt_cbCMúsiROs 127.0.0.1cS`sdS(s? factory.clientConnectionLost callback tCCL((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt_cbCCL scS`sdS(s: protocol.connectionLost callback tCL((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt_cbCLsc`sˆj|ddgƒdS(NRŸR(Rg(R(R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt _cbGathers(RCRRRRBRDR>RRPRQR0RkR[RÜR/RlRmRE( R&RnRœR/RHRžR R¡R((RpR&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_loseOrderìs(   !  (R,R-R6R¢(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR›çsi ((VR6t __future__RRR±RŽRªt functoolsRtzope.interfaceRt twisted.trialRttwisted.python.logRRRRRR R ttwisted.internet.addressR ttwisted.internet.interfacesR R ttwisted.protocolsRttwisted.test.proto_helpersRR"R·R#R$R.R%R7RCRSRDtTestCaseRNR…R†R RÉRÌRÑRÙRöRøRýRR R R(R-R/R2R6RIRKRJRNRRPR\R_R`RaRbRcRfRkRlR}RRŠRR›tresourcet ImportErrort getrlimitt RLIMIT_NOFILEt numRoundst numberRounds(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytsz$"  8Ç Ó@m' µ  f \     R7E"/8