Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/test/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyc


=Nc@s*dZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZm
Z
mZddl
mZddlmZdd	lmZmZdd
lmZddlmZdd
ZdejfdYZdejfdYZdefdYZdeejfdYZ deej!fdYZ"dej#fdYZ$dZ%dej#fdYZ&dej'fdYZ(de"fd YZ)d!ej#fd"YZ*d#ej#fd$YZ+d%ej#fd&YZ,d'ej!fd(YZ-d)ej#fd*YZ.d+ejfd,YZ/d-ejfd.YZ0d/ej!fd0YZ1d1ej#fd2YZ2d3ejfd4YZ3d5ejfd6YZ4d7ejfd8YZ5d9e5fd:YZ6d;dbd<YZ7d=ej#e7fd>YZ8d?ej9fd@YZ:dAej;fdBYZ<dCej#fdDYZ=dEejfdFYZ>dGejfdHYZ?dIej!fdJYZ@dKej9fdLYZAdMej;fdNYZBdOej#fdPYZCdQefdRYZDdSejfdTYZEdUej#fdVYZFdWej#fdXYZGdYej#fdZYZHd[ej#fd\YZId]ej#fd^YZJd_ej#fd`YZKyddlLZLWneMk
rn$XeLjNeLjOddaZPePe8_QdS(cs.
Tests for implementations of L{IReactorTCP}.
iN(t
implements(tunittest(tmsg(tprotocoltreactortdefert
interfaces(terror(tIPv4Address(tIHalfCloseableProtocolt
IPullProducer(tpolicies(tAccumulatingProtocolics|ddlm}tjfd}|j|fd}j|j|}|jjS(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(ttaskcs#}|rj|ndS(N(tcallback(tres(t	predicatetd(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcheck s	csj|S(N(tstop(tresult(tcall(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR%s
(	ttwisted.internetR
RtDeferredtLoopingCalltaddCallbacktstartt
addErrbackterrback(RtintervalR
RRtd2((RRRs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt	loopUntils
tClosingProtocolcBseZdZdZRS(cCstd|jjdS(NsClosingProtocol.connectionMade(Rt	transporttloseConnection(tself((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytconnectionMade1s
cCstd|jtjdS(NsClosingProtocol.connectionLost(RttrapRtConnectionDone(R#treason((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytconnectionLost5s
(t__name__t
__module__R$R((((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR /s	tClosingFactorycBs&eZdZdZdZdZRS(s/
    Factory that closes port immediately.
    cCs|jj|_tS(N(tportt
stopListeningt
_cleanerUpperR (R#tconn((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt
buildProtocolBscCs#|jdkr|jjS|jS(sL
        Clean-up for tests to wait for the port to stop listening.
        N(R.tNoneR,R-(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcleanUpGs
N(R)R*t__doc__R1R.R0R2(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR+;s	tMyProtocolFactoryMixincBs>eZdZeZdZdZdZdZ	dZ
dZRS(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}.
    icCs
g|_dS(N(t
peerAddresses(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt__init__uscCsV|jj||jd7_|j}||_|j|_d|_||_|S(si
        Create a L{AccumulatingProtocol} and set it up to be able to perform
        callbacks.
        iN(	R5tappendtcalledtprotocolFactorytfactorytprotocolConnectionLosttclosedDeferredR1R(R#taddrtp((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR0ys			N(R)R*R3RR9R1tprotocolConnectionMadeR;RR8R6R0(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR4Qs	tMyServerFactorycBseZdZRS(sI
    Server factory which creates L{AccumulatingProtocol} instances.
    (R)R*R3(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR@stMyClientFactorycBs>eZdZdZdZdZdZdZdZRS(sI
    Client factory which creates L{AccumulatingProtocol} instances.
    icCs/tj|tj|_tj|_dS(N(R4R6RRtdeferredtfailDeferred(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6s
cCs&d|_||_|jjddS(Ni(tfailedR'RCRR1(R#t	connectorR'((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytclientConnectionFaileds		cCs||_|jjddS(N(t
lostReasonRBRR1(R#RER'((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytclientConnectionLosts	cCs
d|_dS(Ni(tstopped(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytstopFactorys(	R)R*R3RDRIR6RFRHRJ(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRAs			tListeningTestCasecBsbeZdZdZdZdZdZdZdZdZ	dZ
d	ZRS(
cCsNt}tjd|dd}|j|j|jtjj|dS(sf
        L{IReactorTCP.listenTCP} returns an object which provides
        L{IListeningPort}.
        it	interfaces	127.0.0.1N(	R@Rt	listenTCPt
addCleanupR-t
failUnlessRtIListeningPortt
providedBy(R#tftp1((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_listens	csettjddd}|jjfd}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.
        iRLs	127.0.0.1cs"tjdd}|jS(NRLs	127.0.0.1(RRMR-(tignoredR,(tnRR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcbStopListenings(	R@RRMtgetHostR,Rt
maybeDeferredR-R(R#R,RWR((RRRVs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttestStopListenings	
cCs+t}tjd|dd}|jS(NiRLs	127.0.0.1(R@RRMR-(R#RRRS((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttestNumberedInterfaces	cst}tjd|tjjjtjdkfd}t	j
j}|j|S(Niics&jtjdkdS(Ni(tfailIftreprtfind(tign(R#tportNoR>(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytstoppedListenings(
R@RRMtstrRXR,R\R]R^RRYR-R(R#RRRaR((R`R#R>s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttestPortReprs	"cst}tj}|_tjd|jjt}tj}|_tj	dj
j|}j|jfd}tj
||gj|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.1csY|\}}jj}jt|jd|f|jj|jjdS(Ns<AccumulatingProtocol #0 on %s>(RXR,tassertEqualR]R!R"(t.0tserverPrototclientProtot
portNumber(R#R,(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs	
(R@RRR?RRMRNR-RAt
connectTCPRXR,t
disconnectt
gatherResultsR(R#tservertserverConnMadetclienttclientConnMadeRER((R#R,s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_serverReprs			csuttjdddjjfd}dtjj}|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.
        iRLs	127.0.0.1csjt}tj_tj|_tjdjj|}j	|j
tjj|jgjS(Ns	127.0.0.1(
tstartListeningRARRR?RRiRXR,RNRjRkR(RURnRE(R#t
serverFactorytcloseR,(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRWs
		cSs*|\}}|jj|jjdS(N(R!R"(ReRfRg((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs
s	
(R@RRMRNR-RRYR(R#RWR((R#RrRsR,s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_restartListenings	
	
cCsIt}d}||_tjd|dd}|j|jtS(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.
        cSstddS(NsAn error(tRuntimeError(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytraiseExceptionsiRLs	127.0.0.1(R@RJRRMt
assertFailureR-Ru(R#RrRvR,((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_exceptInStops
			cstd}|_tjdddjjfd}djjtj|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.
        cSstddS(NsAn error(Ru(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRv,siRLs	127.0.0.1cs`jt}tj_tj|_tjdjj	|}j
|jtjj|jgj
S(Ns	127.0.0.1(RJRqRARRR?RRiRXR,RNRjRkR(RURnRE(R#RrRsR,(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRW2s
		cSs*|\}}|jj|jjdS(N(R!R"(ReRfRg((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs@s	
(	R@RJRRMRNR-RwRuR(R#RvRW((R#RrRsR,s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_restartAfterExcept%s				cst}tjd|dd}|jj}|jdttj	|_
tj	_
tjd|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.
        iRLs	127.0.0.1csjjtjdS(N(R'R%RtConnectionRefusedError(R_(Rn(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRXsN(R@RRMRXR,R(R1RARRR?RiRCR(R#RrR,RhR((Rns9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_directConnectionLostCallHs	
	cCsMt}d}||_tjd|dd}|jt|jddS(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.
        cSstddS(NsAn error(Ru(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRvfsiRLs	127.0.0.1N(R@RJRRMtassertRaisesRuR(R1(R#RrRvR,((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_exceptInConnectionLostCall]s
			(R)R*RTRZR[RcRpRtRxRyR{R}(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRKs								#	cCsIddlm}ddl}|j|z|Wd|jdXdS(Ni(tspewerWithLinenums(ttwisted.python.utilR~tsystsettraceR1(RRtspewerR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcallWithSpewns
tLoopbackTestCasecBs_eZdZdZdZdZdZdZdZdZ	dZ
d	ZRS(
s$
    Test loopback connections.
    cst}tjd|dd|_j|jjj}ttjd|fd}j	j
|S(sz
        A port created with L{IReactorTCP.listenTCP} can be connected to with
        L{IReactorTCP.connectTCP}.
        iRLs	127.0.0.1cs:jjjjjjjtjdS(N(t
assertTrueRtmadetdisconnectedRGR%RR&(tx(R#R,tclientF(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs(R+RRMR,RNR2RXRARiRBR(R#RRRhR((R#R,Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_closePortInProtocolFactory{s			cCs t|ddtjdS(NR%cSsdS(N(R1(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt<lambda>s(tgetattrRR&(R#tobj((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt_trapCnxDonesc
st}tj}||_tjd|dd}|j|j|jj	}t
}tj}||_tjd||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.
        iRLs	127.0.0.1cs7|\}}|||jj|jjdS(N(R!R"(RetserverProtocoltclientProtocol(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt	connecteds	

(R@RRR?RRMRNR-RXR,RARiRkR(
R#RRrRmR,RhRRot	connsMadeR((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt_connectedClientAndServerTests				
csfd}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}.
        csxy||gD]k}|j}j|jd|jdj|jd|jdj|jdq
WdS(Nii(R!Rdt
getTcpNoDelayt
setTcpNoDelay(RRR>R!(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs	

(R(R#R((R#s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_tcpNoDelayscsfd}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}.
        csxy||gD]k}|j}j|jd|jdj|jd|jdj|jdq
WdS(Nii(R!RdtgetTcpKeepAlivetsetTcpKeepAlive(RRR>R!(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs	

(R(R#R((R#s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_tcpKeepAlivescsAttjddddfd}jj|S(Ns	127.0.0.1iEttimeouticsjjtjdS(N(R'R%RRz(RU(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs(RARRiRCR(R#R((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttestFailings	csgxGtdD]9}tj}|jd|jdj|qWtjtjt	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.1iics`fd}j}|j\}}|jj||}|j||S(Ncs+|jjrSjddS(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(ttryConnectFailuret
serverSocketsR#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs
(tpoptgetsocknameRsRiR(RtserverSockett
serverHostt
serverPorttconnectDeferred(RRt
clientCreatorR#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs	

csj|jtjdS(N(RdtosErrorterrnotECONNREFUSED(texc(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytconnRefusedscs!xrjjqW|S(N(RRs(tpassthrough(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcleanups	(s	127.0.0.1i(txrangetsockettbindtlistenR7trandomtshuffleRt
ClientCreatorRtProtocolRwRRzRtaddBoth(R#tiRtrefusedDeferredRR((RRR#Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt!test_connectionRefusedErrorNumbers 


	

cCs&|jtjtjddtdS(su
        Connecting to a named service which does not exist raises
        L{error.ServiceNameUnknownError}.
        s	127.0.0.1tthisbetternotexistN(R|RtServiceNameUnknownErrorRRiRA(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_connectByServiceFailscsttj}|_tjddd}j|j|jj	t
}tj}||_fd}jt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}.
        iRLs	127.0.0.1cs |dkr|dkrSdS(Nthttpttcpi
((tserviceNametprotocolName(Rh(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytfakeGetServicePortByName5st
getservbynameRcs=|\}}jjd|jj|jjdS(Ns7Server factory was not called upon to build a protocol.(RR8R!R"(ReRR(RrR#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR>s	
(R@RRR?RRMRNR-RXR,RAtpatchRRiRkR(R#RmR,t
clientFactoryRoRtconnMadeR((R#RrRhs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_connectByService%s 				
(R)R*R3RRRRRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRws								B	tStartStopFactorycBs&eZdZdZdZdZRS(icCs(|js|jrtnd|_dS(Ni(tstartedRIRu(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytstartFactoryMs	cCs)|js|jrtnd|_dS(Ni(RRIRu(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRJRs	(R)R*RRIRRJ(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRHs	tClientStartStopFactorycBs&eZdZdZdZdZRS(icCs(|js|jrtnd|_dS(Ni(RRIRu(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR]s	cCs)|js|jrtnd|_dS(Ni(RRIRu(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRJbs	(R)R*RRIRRJ(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRXs	tFactoryTestCasecBs eZdZdZdZRS(sTests for factories.csttjddd}j|jjjjfdtjddd}tjdddjjjfdtj	|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.
        iRLs	127.0.0.1ics&jjjfdjS(Nii(ii(RdRRIR-(RU(R#tp3RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcbClosedscs jjjfddS(Ni(ii(RdRRI(RU(R#RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcbClosedAlls(ii(ii(RRRMRNR-RdRRIRRYRkR(R#RStp2td1RR<RR((RRRR#s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_serverStartStopks
	

cst}tjd|dd}||_|j|j|jj}ttjd||j	j
tfdS(s
        The factory passed to L{IReactorTCP.connectTCP} should be started when
        the connection attempt starts and stopped when it is over.
        iRLs	127.0.0.1csjS(N(RI((R:(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs(R+RRMR,RNR2RXRRiRRR(R#RRR>Rh((R:s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_clientStartStops			(R)R*R3RR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRhs	+tConnectorTestCasecBs#eZdZdZdZRS(cs0t}tjd|dd}||_j|j|jj}ggtfd_j	_
tjd|jt
jjj}j|jdj|jdj|j|tfd}fd}|j||S(sU
        L{IReactorTCP.connectTCP} returns an object which provides
        L{IConnector}.  The destination of the connector is the address which
        was passed to C{connectTCP}.  The same connector object is passed to
        the factory's C{startedConnecting} method as to the factory's
        C{clientConnectionLost} method.
        iRLs	127.0.0.1csj|j|fS(N(R7(RER'(tseenFailurestseenConnectors(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRstTCPcsjS(N(RI((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRscs.djtjjgdS(Ni(R%RR&Rd(RU(RR#RER(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytclientFactoryStoppeds(R+RRMR,RNR2RXRRHR7tstartedConnectingRiRRt
IConnectorRQtgetDestinationRdttypethostRR(R#RrttcpPortRhtdestRR((RRR#RERs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_connectorIdentitys(			
cst}tjd|dd}j|j|jj}d}t|_tj	d|t
fd}fd}|j|S(s
        Calling L{IConnector.stopConnecting} in C{Factory.startedConnecting}
        results in C{Factory.clientConnectionFailed} being called with
        L{error.UserError} as the reason.
        iRLs	127.0.0.1cSs|jdS(N(tstopConnecting(RE((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRscsjS(N(RI((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRscs*jjdjjtjdS(Ni(RdRDR'R%Rt	UserError(RU(R#R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs(R@RRMRNR-RXR,RRRiRR(R#RrRRhRRR((R#Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt
test_userFails				cst}tjd|dd}||_j|j|jj}td}|_tj	d|t
fd}fd}|j|S(s
        Calling L{IConnector.connect} in C{Factory.clientConnectionLost} causes
        a new connection attempt to be made.
        iRLs	127.0.0.1cSs|jdS(N(tconnect(RER'((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRHscsjS(N(RD((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRscsOj}j|j|jfdjjtjjjddS(Ni(ii(	RRdRtclosedR'R%RRzRI(RUR>(R#R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytreconnectFaileds	(R+RRMR,RNR2RXRARHRiRR(R#RrRRhRHRR((R#Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_reconnects					(R)R*RRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs	&	tCannotBindTestCasecBs)eZdZdZdZdZRS(s]
    Tests for correct behavior when a reactor cannot bind to the required TCP
    port.
    cCst}tjd|dd}|j|j|jj}|j}|j|jd|j|j	d|j|j||j
tjtj||dddS(s
        L{IReactorTCP.listenTCP} raises L{error.CannotListenError} if the
        address to listen on is already in use.
        iRLs	127.0.0.1RN(
R@RRMRNR-RXR,RdRRR|RtCannotListenError(R#RRRSRVR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_cannotBinds	cs2ddlm}fd}|j|S(sGReturns closure that when called calls f and then callbacks d.
        i(tutilcs ||}jd|S(Nt(R(targstkwtrtn(RRR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytnewf$s
(ttwisted.pythonRtmergeFunctionMetadata(R#RRRttputilR((RRRs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt_fireWhenDoneFunc scstj}t}j||j|_tjd|ddjjfd}fdfdfdfdfd	fd
|j	||S(s
        L{IReactorTCP.connectTCP} calls C{Factory.clientConnectionFailed} with
        L{error.ConnectBindError} if the bind address specified is already in
        use.
        iRLs	127.0.0.1csctj}t}j||j|_tjdjj|dd|j	||S(Ns	127.0.0.1tbindAddressi(s	127.0.0.1i(
RRRARR0RRiRXR,R(tresultsRtcf1(R#R>t_conmade(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt	_connect17s	cs>tj}j||jj|j_|j||S(N(RRRRR$R(RRR(R#t_check1connect2(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR@s
csj|jjdtj}tj}|jjjj}t}j	||j
|_
j	||j|_tj
djj|dd|f|j|||j||tj||g}|j|||S(Nis	127.0.0.1R(RdRRRRR!RXR,RARRFRJRRiRtDeferredList(RRRRR,tcf2tdl(t_check2stoppedt_stopR#t
_check2failedR>(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRGs	
csFj|jd|jjtjj|jjtj|S(Ni(RdRDR'R%RtConnectBindErrorRR(RRR(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRYscsj|jd|S(Ni(RdRI(RRR(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR_scsHtj}|j|j||j|_|jjj|S(N(RRRRRJRR!R"(RRRR(R#t_check1cleanup(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRcs
csj|jddS(Ni(RdRI(RR(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRjs(
RRR@RRRRMRNR-R(R#ttheDeferredtsfR((RRR#RR>RRRs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_clientBind+s		
(R)R*R3RRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs		tMyOtherClientFactorycBseZdZRS(cCs||_t|_|jS(N(taddressRR(R#R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR0ss	(R)R*R0(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRrstLocalRemoteAddressTestCasecBseZdZdZRS(so
    Tests for correct getHost/getPeer values and that the correct address is
    passed to buildProtocol.
    cst}tj|_|jtjd|ddjjjj	}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}.
        iRLs	127.0.0.1csBjjgjjjjjjdS(N(RdRXR5RR!tgetPeer(RU(R#RR,(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRscsjS(N(Rj(RU(REtserverConnectionLost(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs
(R@RRR;RRMRNR-RXR,RAR?RiR(R#RrRVtonConnectionRR((R	R#RR,REs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_hostAddresss			

(R)R*R3R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRzstWriterProtocolcBseZdZRS(cCs|jjdddddg}|jj||jj}|jdkrhdG|GHd|j_n|jj}|jdkrd	G|GHd|j_nd|j_|jj	dS(
NsHello Cleveland!
tGoodbyes cruels worlds
Rs getPeer returned non-TCP socket:is getHost returned non-TCP socket:(
R!twritet
writeSequenceRRR:tproblemRXtdoneR"(R#tseqtpeertus((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stReaderProtocolcBseZdZdZRS(cCs|jj|7_dS(N(R:tdata(R#R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytdataReceivedscCsd|j_dS(Ni(R:R(R#R'((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR(s(R)R*RR((((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs	tWriterClientFactorycBseZdZdZRS(cCsd|_d|_dS(NiR(RR(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6s	cCst}||_||_|S(N(RR:R(R#R=R>((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR0s			(R)R*R6R0(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs	tWriteDataTestCasecBs eZdZdZdZRS(sw
    Test that connected TCP sockets can actually write data. Try to exercise
    the entire ITransport interface.
    cstjt_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.
        iRLs	127.0.0.1cszjjdjjdkdjjddjdddd	d
g}jj|kddS(Ns&writer didn't finish, it probably diediswriter indicated an errors$client didn't see connection droppedRsHello Cleveland!
R
s cruels worlds
s.client didn't receive all the data it expected(RORRtjoinR(RUtexpected(R#RRR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs	(RtFactoryRRRtWiredFactoryRRMRNR-RXR,RRiRRktonDisconnectR(R#twrappedFR>RVtwrappedClientFRR((RRR#Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_writers					cstjjdkr$tjdntjjdkrHtjdntjtjdtjffdY}tj	}||_tj
d|dd	}|j|j|j
}d
tfdYdtjffd
Y}t|_j}fd}|j|td|j|jftj|j|jtd|j|tjS(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).
        tIOCPReactors'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
GtkReactorsgtkreactor does not implement unclean disconnection notification correctly.  This might more properly be a todo, but due to technical limitations it cannot be.tDisconnectercs,eZdZfdZfdZRS(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.
            cs*tdfd}j|dS(s[
                Set up a callback on clientPaused to lose the connection.
                sDisconnector.connectionMadecs%tdjjtddS(Ns&Disconnector.connectionMade disconnectsloseConnection called(RR!R"(RU(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRj"s

N(RR(R#Rj(tclientPaused(R#s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR$s
cs%tdjdtddS(st
                Notify observers that the server side of the connection has
                ended.
                sDisconnecter.connectionLostsserverLost called backN(RRR1(R#R'(t
serverLost(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR((s

(R)R*R3R$R(((R%R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR$siRLs	127.0.0.1tInfinitecBs3eZdZeedZdZdZRS(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.
            cSs
||_dS(N(tconsumer(R#R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6AscSs(td|jjdtddS(NsInfinite.resumeProducingRs*Infinite.resumeProducing wrote to consumer(RR(R(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytresumeProducingDs
cSstddS(NsInfinite.stopProducing(R(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt
stopProducingIs(R)R*R3RR
R6R)R*(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR'8s

		tUnreadingWritercs#eZdZfdZRS(s
            Trivial protocol which pauses its transport immediately and then
            writes some bytes to it.
            csQtdjjjdtdfd}j|dS(NsUnreadingWriter.connectionMadesclientPaused called backcsDtdj}tdjj|ttddS(Ns$UnreadingWriter.connectionMade writes5UnreadingWriter.connectionMade write created producers8UnreadingWriter.connectionMade write registered producer(RR!tregisterProducertFalse(RUtproducer(R#R'(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRWs


(RR!tpauseProducingRR1R(R#R(R%R'R&(R#s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR$Rs



(R)R*R3R$((R'R%R&(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR+MscstdjS(NtcbClientLost(RRG(RU(Rn(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR0ns
sConnecting to %s:%ssReturning Deferred(Rt	__class__R)RtSkipTestRRRRt
ServerFactoryRMRNR-RXtobjectRAR9RBRRRR,RiRwRtConnectionLost(R#R$RlR,R=R+RHR0((R%RnR'R&s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt%test_writeAfterShutdownWithoutReadings2	"	%			

(R)R*R3R!R6(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs	tConnectionLosingProtocolcBseZdZRS(cCsD|jjd|jj|jj|jjj|jdS(Nt1(R!RR"tmastert_connectionMadetportsR7(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.pyR7|stNoopProtocolcBseZdZdZRS(cCs)tj|_|jjj|jdS(N(RRRR9tserverConnsR7(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR$scCs|jjtdS(N(RRtTrue(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<s	tConnectionLostNotifyingProtocolcBs eZdZdZdZRS(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}.
    cCsd|_||_dS(N(R1tlostConnectionReasontonConnectionLost(R#RA((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6s	cCs||_|jj|dS(N(R@RAR(R#R'((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR(s	(R)R*R3R6R((((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR?s
	tHandleSavingProtocolcBseZdZdZRS(s
    Protocol which grabs the platform-specific socket handle and
    saves it as an attribute on itself when the connection is
    established.
    cCs"|j|_tjj||S(s\
        Save the platform-specific socket handle for future
        introspection.
        (t	getHandlethandleRRtmakeConnection(R#R!((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyREs(R)R*R3RE(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRBstProperlyCloseFilesMixincBs;eZdZdZdZdZdZdZRS(sA
    Tests for platform resources properly being cleaned up.
    cCs
tdS(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#RRhR:((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcreateServerscCs
tdS(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(RG(R#RRhR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt
connectClientscCs
tdS(s
        Return the exception class which will be raised when an operation is
        attempted on a closed platform handle.
        N(RG(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytgetHandleExceptionTypescCstjS(sn
        Return the errno expected to result from writing to a closed
        platform socket handle.
        (RtEBADF(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytgetHandleErrorCodes	cstjtj}fd|_jdd|tjj}tjtfd}j|j	|j
|}fd}|j|fd}|j|fd}|j||S(sp
        Test that lost connections properly have their underlying socket
        resources cleaned up.
        cs
tS(N(R?((tonServerConnectionLost(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRss	127.0.0.1ics
tS(N(RB((tonClientConnectionLost(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRscs0|jjd|jjtjgS(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!RR"RRk(Rn(RNRM(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytclientConnecteds
	
csz|\}}|jjtj|jjtjj}jj|jjd}j	|j
d|dS(sl
            Verify that the underlying platform socket handle has been
            cleaned up.
            tbytesiN(R@R%RtConnectionClosedRLR|RJRDtsendRdR(ReRnRltexpectedErrorCodeterr(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytclientDisconnecteds	cs,tjj}|jfd|S(sx
            Shut down the server port.  Return a Deferred which fires when
            this has completed.
            csS(N((R_(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs(RRYR-R(RR(R(Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs(
RRRR3RHRXRRRIRR,RR(R#Rrt
serverAddrRtclientDeferredRORUR((RNR#RMRs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_properlyCloseFiless"



(R)R*R3RHRIRJRLRX(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRFs	
	
		tProperlyCloseFilesTestCasecBs)eZdZdZdZdZRS(s
    Test that the sockets created by L{IReactorTCP.connectTCP} are cleaned up
    when the connection they are associated with is closed.
    cCstj||d|S(sE
        Create a TCP server using L{IReactorTCP.listenTCP}.
        RL(RRM(R#RRhR:((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRHscCs|j||S(sF
        Create a TCP client using L{IReactorTCP.connectTCP}.
        (Ri(R#RRhR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRI&scCstjS(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.
        (RR(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRJ-s(R)R*R3RHRIRJ(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRYs		tWiredForDeferredscBs#eZdZdZdZRS(cCstjj|||dS(N(RtProtocolWrapperR6(R#R:twrappedProtocol((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR68scCs'tjj||jjjddS(N(RR[R$R:t	onConnectRR1(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR$;scCs*tjj|||jjjddS(N(RR[R(R:RRR1(R#R'((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR(?s(R)R*R6R$R((((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRZ7s		RcBseZeZdZRS(cCs5tjj||tj|_tj|_dS(N(RtWrappingFactoryR6RRR]R(R#twrappedFactory((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6Hs(R)R*RZRR6(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyREstAddressTestCasecBs)eZdZdZdZdZRS(sR
    Tests for address-related interactions with client and server protocols.
    cCs#dtjfdY}t|_tj|_|j_tj|_|j_	||j|_
t|_tj|_
|j_tj|_|j_	||j|_tjd|j
dd|_tj|jjj|jjj|j|_tj|j|j
gS(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.
        tRememberingWrappercBs eZdZdZdZRS(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.
            cSsg|_||_dS(N(t	addressesR:(R#R:((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6fs	cSs |jj||jj|S(s
                Append the given address to C{self.addresses} and forward
                the call to C{self.factory}.
                (RbR7R:R0(R#R=((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR0ms(R)R*R3R6R0(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRa\s		iRLs	127.0.0.1(Rt
ClientFactoryR@RlRRRmR?tserverConnLostR;t
serverWrapperRARnRotclientConnLostt
clientWrapperRRMR,RiRXRRERk(R#Ra((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytsetUpSs	-cCs8|jjtj|j|jtj|jjgS(sf
        Disconnect the client/server pair and shutdown the port created in
        L{setUp}.
        (	RERjRRkRdRfRYR,R-(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttearDowns
cCs|jjjj}|jjjj}|j|jjt	d|j
|jg|j|jjt	d|j
|jgdS(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.
        RN(RlRR!RXRnRRdRgRbRRR,(R#Rt
clientPeer((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_buildProtocolClients		(R)R*R3RhRiRk(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR`Os	9	tLargeBufferWriterProtocolcBseZdZRS(cCs7|jjd|jjd|j_|jjdS(NtXi(R!RR:tlenRR"(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.pyRlstLargeBufferReaderProtocolcBseZdZdZRS(cCs|jjt|7_dS(N(R:Rn(R#R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRscCsd|j_dS(Ni(R:R(R#R'((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR(s(R)R*RR((((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRos	tLargeBufferReaderClientFactorycBseZdZdZRS(cCsd|_d|_dS(Ni(RRn(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6s	cCst}||_||_|S(N(RoR:R(R#R=R>((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR0s			(R)R*R6R0(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRps	tFireOnClosecBseZdZdZRS(saA wrapper around a protocol that makes it fire a deferred when
    connectionLost is called.
    cCs*tjj|||jjjddS(N(RR[R(R:RBRR1(R#R'((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR(s(R)R*R3R((((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRqstFireOnCloseFactorycBseZeZdZRS(cCs&tjj||tj|_dS(N(RR^R6RRRB(R#R_((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6s(R)R*RqRR6(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRrstLargeBufferTestCasecBseZdZdZdZRS(s5Test that buffering large amounts of data works.
    i<icstjt_d_d_j_t}tj	d|dd}j
|j|jj
}tt}tjd||tj|j|jg}fd}|j|S(NiRLs	127.0.0.1csVjjdjjjkdjjfjjddS(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(RORRntdatalen(RU(R#RRR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs(RRRlRRRtRnRrRRMRNR-RXR,RpRiRRkRBR(R#RR>RVR RR((R#RRRs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt
testWriters				ii(R)R*R3RtRu(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRsstMyHCProtocolcBs0eZeeeZeZdZdZRS(cCs&t|_|jr"|jdndS(N(R>treadHalfClosedtwriteHalfClosedR(R1(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytreadConnectionLosts		cCs&t|_|jr"|jdndS(N(R>RxRwR(R1(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytwriteConnectionLosts		(	R)R*RR	R-RwRxRyRz(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRvs

	tMyHCFactorycBseZdZdZdZRS(icCs.|jd7_t}||_||_|S(Ni(R8RvR:R(R#R=R>((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR0s
			N(R)R*R8R1R?R0(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR{
stHalfCloseTestCasecBsDeZdZdZdZdZdZdZdZRS(sTest half-closing connections.cst_}tjd|dd_jjtfd}tj	tt
_|jfd|jj
|S(NiRLs	127.0.0.1csjS(N(R((R>(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRscs%jjjjjjS(N(tcfRiRXRR,(t_(R>R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR"s(R{RRRRMR>RNR-RRRRvR}Rt_setUp(R#RRR((R#R>s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRhscsN|_tj_j_jjjjdtfdS(Nicstjdddk	S(NR(RRRR1((R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR,s(	RnRRtclientProtoConnectionLostR<RdR!RR(R#Rn((R#s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR's	csejjjdjjjtjjj}|j	fd|j	j
|S(NicsjS(N(R(R_(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR2s(RdRnRR!R"RRYR>R-Rt	_tearDown(R#R((R#s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRi.scsjjjdjjjjdtjfd}|jj_jjjj	j
fdS(Niics djj_jddS(Ni(RRRRRR1(R'(R#R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt_connectionLost<scsjjjjdS(Ni(RdRRRR(R(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRAs(RdRnRRRRRRR(R!R"R(R#RUR((R#Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6scsjjjjdtfd}fd}fd}fd}|j|j|j|S(NthellocstjdkS(Ni(Rnt_tempDataBuffer((tt(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRJscsjtfdS(NcsjS(N(t_writeDisconnected((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRMs(tloseWriteConnectionR(RU(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt	loseWriteKs
csLjjtjjtjjttfdS(Ncs
jjS(N(RRw((RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRRs(RdRR-RxR>RwR(RU(RRR#Rn(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRNscsjj}|d|djdtjjjjjdjjjtjjj	t
dS(Ns worldslalala fooled youiR(R!RRdRnRRRRR-RwR>(RUtw(RRR#Rn(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRSs

(RnRRR!RRR(R#RRRR((RRR#RnRs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttestCloseWriteCloserDs			
csijjjjtjtfdtfdg}|jfd|S(Ncs
jjS(N(RRx((RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRbscs
jjS(N(RnRw((R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRcscsjjjtS(N(RdRRwR-(R~(R#RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRds(RRRR!RRRkRR(R#R((R#RRs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttestWriteCloseNotification]s	(	R)R*R3RhRRiRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR|s	
				tHalfClose2TestCasecBs5eZdZdZdZdZdZRS(cCst|_}tj|j_tjd|dd|_}tj	tt
j|jj
|jj}|j|j|S(NiRLs	127.0.0.1(R@RRRRR?RRMR>RRRRiRXRR,Rt
_gotClient(R#RRR>R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRhkscCs||_|jjS(N(RnRRR?(R#Rn((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRvs	cCs|jjj|jjS(N(RnR!R"R>R-(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRi}scsjjjdjjjtjjj_}tjj_}|j	fd|j	fdtj
||gS(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.
        RcsjjjjdS(NR(RdRRRR(R(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRscsjjjjtS(N(RdRRRRR>(R(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs(RnR!RRRRRRRR<RRk(R#RR((R#s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttestNoNotificationscsjjjjjjjdjjjtjjj_	}tjj_	}|j
fdtj||gS(sx
        If the other side has already closed its connection,
        loseWriteConnection should pass silently.
        RmcsjjjjtS(N(RdRRRRR>(R(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs(RRRR!R"RnRRRRR<RRk(R#RR((R#s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttestShutdownExceptions(R)R*RhRRiRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRis
				tHalfCloseBuggyApplicationTestscBs;eZdZdZdZdZdZdZRS(sI
    Test half-closing connections where notification code has bugs.
    cst_tjj_tjdjdd_jjj	jj
}tjtt
}|j|j|j}fd}|j|tjjj|gS(s|
        Set up a server and connect a client to it.  Return a Deferred which
        only fires once this is done.
        iRLs	127.0.0.1cs
|_dS(N(R(R(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt	setClients(R{RrRRR?RRMR,RNR-RXRRRvRiRRRk(R#R=tcreatorRWR((R#s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRhs
	cGstddS(s`
        Fake implementation of a callback which illegally raises an
        exception.
        sONO I AM BUGGY CODEN(Ru(R#R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytaBugscsFtj}j_jjjfd}|j||S(s~
        Helper for testing that an exception is logged by the time the
        client protocol loses its connection.
        cs)jt}jt|ddS(Ni(tflushLoggedErrorsRuRdRn(RUterrors(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs(RRRR<R!RR(R#RR((R#s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt_notificationRaisesTests

cCs|j|jj_|jS(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.
        (RRrRRyR(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_readNotificationRaisesscCs|j|j_|jS(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.
        (RRRzR(R#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_writeNotificationRaisess(R)R*R3RhRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs				
tLogTestCasecBseZdZdZRS(s4
    Test logging facility of TCP base classes.
    cst}t}tj|_tjd|dd}j|jtj	|j
j|j
j|jj
jjjdfd}|jj||jS(sx
        Check that the log customization of the client transport happens
        once the client is connected.
        iRLs	127.0.0.1t
UninitializedcsjjjddS(NsAccumulatingProtocol,client(RdR!tlogstr(R_(RER#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcbs(R@RARRR?RRMRNR-RiRXRR,RjRdR!RR(R#RlRnR,R((R#REs9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_logstrClientSetups		!(R)R*R3R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRstPauseProducingTestCasecBs5eZdZdZejjes3de_nRS(sG
    Test some behaviors of pausing the production of a transport.
    cst}t}tj|_tjd|dd}j|jtj	|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.
        iRLs	127.0.0.1cs|j}j|tjtj|jjj|tjtjtj}|j	tj
d|j||S(Ni(R!tassertInRt
getReaderst
getWritersR/tassertNotInRRRt	callLaterR(RttrR(R#tcheckAfterConnectionMade(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pytcheckInConnectionMades	

cs-|j}j|tjtjdS(N(R!RRRR(RR(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR)s	(R@RARRR?RRMRNR-RiRXRR,RjR(R#RlRnR,RER((RR#s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt#test_pauseProducingInConnectionMades		!s#Reactor not providing IReactorFDSet(	R)R*R3RRt
IReactorFDSetRQRtskip(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRs	%tCallBackOrderTestCasecBseZdZdZRS(s-
    Test the order of reactor callbacks
    c	s*t}tjjfd|_ttj_tj_fd}jj|tjd|dd}j	|j
tj|jj
|jj}j	|jd}d}fd}tjjj|jj|g}|j|S(	sl
        Check that Protocol.connectionLost is called before factory's
        clientConnectionLost
        csj|jjS(N(RNR!R"(R(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyRBscstjdjjjdS(s:
            protocol.connectionMade callback
            iN(RRRR!R"(R(Rn(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt_cbCMIsiRLs	127.0.0.1cSsdS(s?
            factory.clientConnectionLost callback
            tCCL((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt_cbCCLXscSsdS(s:
            protocol.connectionLost callback
            tCL((R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt_cbCL^scsj|ddgdS(NRR(Rd(R(R#(s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt	_cbGatherds(R@RRRR?RAR;RRMRNR-RiRXRR,RjRkRB(	R#RlRR,RERRRR((R#Rns9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyttest_loseOrder;s(		!		(R)R*R3R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyR6si
((RR3RRRtzope.interfaceRt
twisted.trialRttwisted.python.logRRRRRRRttwisted.internet.addressRttwisted.internet.interfacesR	R
ttwisted.protocolsRttwisted.test.proto_helpersRRRR R3R+R4R4R@RcRAtTestCaseRKRRRRRRRRRRRRRRR7R<R?RBRFRYR[RZR^RR`RlRoRpRqRrRsRvR{R|RRRRRtresourcetImportErrort	getrlimitt
RLIMIT_NOFILEt	numRoundstnumberRounds(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_tcp.pyt<module>sv$"8		@]m'
	
e
\	
R7E"/8