Your IP : 172.28.240.42


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


BNc@sdZeZddlZddlZddlmZddlmZddl	m
Z
ddlmZddl
mZddlmZmZdd	lmZdd
lmZmZddlmZmZddlmZmZmZmZdd
lmZddl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(m)Z)ddl*m+Z+m,Z,m-Z-ddlm.Z.m/Z/ddl*m0Z0ddl1m2Z2m3Z3ddl4m5Z5m6Z6m7Z7ddl8m9Z9ddl:m;Z;m<Z<ddl:m=Z=yddl>m?Z?Wne@k
rdZ?nXdejBdZCde,fdYZDddddYZEdeFfd YZGd!ZHd"eFfd#YZId$efd%YZJd&e-fd'YZKd(eFfd)YZLd*efd+YZMd,efd-YZNd.ee6fd/YZOd0e5fd1YZPd2ee9ePfd3YZQd4e-fd5YZRd6efd7YZSd8efd9YZTeUjVeOjWeUjVeQjWeUjVeSjWeUjVeTjWd:e-fd;YZXd<eXfd=YZYd>eXfd?YZZd@eXfdAYZ[dBe[fdCYZ\dDeXfdEYZ]dFeXfdGYZ^dHe+fdIYZ_dJe-fdKYZ`dLe`fdMYZadNe`fdOYZbdPebfdQYZcdRebfdSYZddTe-fdUYZedVe-fdWYZfdXeffdYYZgdZeefd[YZhd\ebfd]YZid^eefd_YZjd`eFfdaYZkdbeekfdcYZleUjVeljWdS(es.
Tests for implementations of L{IReactorTCP}.
iN(t
implements(tverifyObject(tplatform(tFailure(tlog(tSkipTesttTestCase(tReactorBuilder(tDNSLookupErrortConnectionLost(tConnectionDonetConnectionAborted(tILoggingContexttIResolverSimplet
IConnectort
IReactorFDSet(tIPv4Address(tDeferredtDeferredListtsucceedtfailt
maybeDeferredt
gatherResults(tTCP4ServerEndpointtTCP4ClientEndpoint(t
ServerFactoryt
ClientFactorytProtocol(t
IPushProducert
IPullProducer(t
ClientCreator(t
ConnectiontServer(tLogObserverMixintConnectionTestsMixintserverFactoryFor(tObjectModelIntegrationMixin(tMyClientFactorytMyServerFactory(tClosingProtocol(tClientContextFactorys	127.0.0.1cCsNtj}tj||}z!|j|df|jSWd|jXdS(s
    Ask the platform to allocate a free port on the specified interface,
    then release the socket and return the address which was allocated.

    @param interface: The local address to try to bind the port on.
    @type interface: C{str}

    @param type: The socket type which will use the resulting port.

    @return: A two-tuple of address and port, like that returned by
        L{socket.getsockname}.
    iN(tsockettAF_INETtbindtgetsocknametclose(t	interfacettypetfamilytprobe((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytfindFreePort-s
	tStopcBs eZdZdZdZRS(sQ
    A client factory which stops a reactor when a connection attempt fails.
    cCs
||_dS(N(treactor(tselfR4((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt__init__HscCs|jjdS(N(R4tstop(R5t	connectortreason((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytclientConnectionFailedLs(t__name__t
__module__t__doc__R6R:(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR3Ds	tFakeResolvercBs*eZdZeedZdZRS(sR
    A resolver implementation based on a C{dict} mapping names to addresses.
    cCs
||_dS(N(tnames(R5R?((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR6WscCs>yt|j|SWn"tk
r9ttd|SXdS(NsFakeResolver couldn't find (RR?tKeyErrorRR(R5tnamettimeout((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt
getHostByName[s
(R;R<R=RR
R6RC(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR>Qs
	t_SimplePullProducercBs)eZdZdZdZdZRS(s
    A pull producer which writes one byte whenever it is resumed.  For use by
    L{test_unregisterProducerAfterDisconnect}.
    cCs
||_dS(N(tconsumer(R5RE((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR6hscCsdS(N((R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt
stopProducinglscCs!tjd|jjddS(NsProducer.resumeProducingtx(RtmsgREtwrite(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytresumeProducingps
(R;R<R=R6RFRJ(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRDcs		cCsItj|r|jSd|jjkr2|jStd|fdS(sV
    Like L{IReactorFDSet.getWriters}, but with support for IOCP reactor as well.
    tIOCPsCannot find writers on %rN(Rt
providedByt
getWriterst	__class__R;thandlest	Exception(R4((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt_getWritersvs

t
FakeSocketcBsVeZdZdZdZdZdZdZdZdZ	dZ
RS(	s
    A fake for L{socket.socket} objects.

    @ivar data: A C{str} giving the data which will be returned from
        L{FakeSocket.recv}.

    @ivar sendBuffer: A C{list} of the objects passed to L{FakeSocket.send}.
    cCs||_g|_dS(N(tdatat
sendBuffer(R5RS((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR6s	cCs
||_dS(N(tblocking(R5RU((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytsetblockingscCs|jS(N(RS(R5tsize((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytrecvscCs|jj|t|S(s
        I{Send} all of C{bytes} by accumulating it into C{self.sendBuffer}.

        @return: The length of C{bytes}, indicating all the data has been
            accepted.
        (RTtappendtlen(R5tbytes((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytsendscCsdS(s
        Shutdown is not implemented.  The method is provided since real sockets
        have it and some code expects it.  No behavior of L{FakeSocket} is
        affected by a call to it.
        N((R5thow((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytshutdownscCsdS(s
        Close is not implemented.  The method is provided since real sockets
        have it and some code expects it.  No behavior of L{FakeSocket} is
        affected by a call to it.
        N((R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR-scGsdS(s
        Setsockopt is not implemented.  The method is provided since
        real sockets have it and some code expects it.  No behavior of
        L{FakeSocket} is affected by a call to it.
        N((R5targs((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt
setsockoptscCsdS(s
        Return a fake file descriptor.  If actually used, this will have no
        connection to this L{FakeSocket} and will probably cause surprising
        results.
        i((R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytfilenos(R;R<R=R6RVRXR\R^R-R`Ra(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRRs							tTestFakeSocketcBs)eZdZdZdZdZRS(sT
    Test that the FakeSocket can be used by the doRead method of L{Connection}
    cCs0td}|jd|j|jddS(NtsomeDatai(RRRVtassertEqualRU(R5tskt((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt
test_blockings
cCs)td}|j|jdddS(NRci
(RRRdRX(R5Re((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt	test_recvscCsEtd}|jd}|j|d|j|jdgdS(s
        L{FakeSocket.send} accepts the entire string passed to it, adds it to
        its send buffer, and returns its length.
        ttfooiN(RRR\RdRT(R5Retcount((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt	test_sends(R;R<R=RfRgRk(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRbs		tFakeProtocolcBseZdZdZRS(sL
    An L{IProtocol} that returns a value from its dataReceived method.
    cCsdS(sq
        Return something other than C{None} to trigger a deprecation warning for
        that behavior.
        (((R5RS((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytdataReceiveds(R;R<R=Rm(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRlst_FakeFDSetReactorcBs-eZdZeedZZZZRS(s]
    A no-op implementation of L{IReactorFDSet}, which ignores all adds and
    removes.
    cCsdS(N(tNone(R5tdesc((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt<lambda>s(	R;R<R=RRt	addReadert	addWritertremoveReadertremoveWriter(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRns
tTCPServerTestscBs;eZdZdZdZdZdZdZRS(s<
    Whitebox tests for L{twisted.internet.tcp.Server}.
    cCskt|_dtfdY}td|_t|_t|j|jd|d|j|_	dS(NtFakePortcBseZdZRS(i(R;R<t_realPortNumber(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRwsRhi(Rhi(
RnR4tobjectRRReRtprotocolR Rotserver(R5Rw((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytsetUpscCsF|jjttd|jjd|j|jjgdS(sq
        L{Server.write} discards bytes passed to it if called after it has lost
        its connection.
        sSimulated lost connectionshello worldN(R{tconnectionLostRRPRIRdReRT(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_writeAfterDisconnects	cCst|j_|jdS(s
        L{Server.write} discards bytes passed to it if called after it has lost
        its connection when the connection had started TLS.
        N(tTrueR{tTLSR~(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt test_writeAfteDisconnectAfterTLSscCsI|jjttd|jjdg|j|jjgdS(sy
        L{Server.writeSequence} discards bytes passed to it if called after it
        has lost its connection.
        sSimulated lost connectionshello worldN(R{R}RRPt
writeSequenceRdReRT(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt!test_writeSequenceAfterDisconnects	cCst|j_|jdS(s
        L{Server.writeSequence} discards bytes passed to it if called after it
        has lost its connection when the connection had started TLS.
        N(RR{RR(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt(test_writeSequenceAfteDisconnectAfterTLS&s(R;R<R=R|R~RRR(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRvs	
				tTCPConnectionTestscBsAeZdZdZdZdZedkr?de_nRS(s@
    Whitebox tests for L{twisted.internet.tcp.Connection}.
    cCstd}t}t||}|j|jtjg}|j|ddt|j|ddd|jt|ddS(s
        When an L{IProtocol} implementation that returns a value from its
        C{dataReceived} method, a deprecated warning is emitted.
        RcitcategorytmessagesReturning a value other than None from twisted.internet.test.test_tcp.FakeProtocol.dataReceived is deprecated since Twisted 11.0.0.iN(	RRRlRtdoReadt
flushWarningsRmRdtDeprecationWarningRZ(R5ReRztconntwarnings((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_doReadWarningIsRaised4s	
cCs8td}t}t||}|j|jdS(s
        The C{TLS} attribute of a L{Connection} instance is C{False} before
        L{Connection.startTLS} is called.
        RhN(RRRlRtassertFalseR(R5ReRzR((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_noTLSBeforeStartTLSGs	cCs]td}t}t||dt}t|_|jtt|j|j	dS(s}
        The C{TLS} attribute of a L{Connection} instance is C{True} after
        L{Connection.startTLS} is called.
        RhR4N(
RRRlRRnRt_tlsClientDefaulttstartTLSR(t
assertTrueR(R5ReRzR((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_tlsAfterStartTLSRs		sNo SSL support availableN(	R;R<R=RRRR(Rotskip(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR0s			tTCPClientTestsBuildercBsVeZdZdZdZdZdZdZdZdZ	dZ
RS(	sG
    Builder defining tests relating to L{IReactorTCP.connectTCP}.
    cCst|dddS(sj
        Create a L{TCP4ServerEndpoint} listening on localhost on a
        TCP/IP-selected port.
        iR.s	127.0.0.1(R(R5R4((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytserverEndpointescCst|d|jS(s
        Create a L{TCP4ClientEndpoint} which will connect to localhost
        on the port given by C{serverAddress}.

        @type serverAddress: L{IPv4Address}
        s	127.0.0.1(Rtport(R5R4t
serverAddress((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytclientEndpointmscCs>|j}|jddt}|jtt|dS(sV
        L{IReactorTCP.connectTCP} returns an object providing L{IConnector}.
        s	127.0.0.1iN(tbuildReactort
connectTCPRRRR(R5R4R8((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_interfacexscCsEt\}}|j}|j||t||j|dS(sl
        The reactor can be stopped by a client factory's
        C{clientConnectionFailed} method.
        N(R2RRR3t
runReactor(R5thostRR4((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt'test_clientConnectionFailedStopsReactorscs#t\}}|jjdttd|}|j}idd6dd6dtffdY}t}||_j	d|jj
|dd	|fjtid	d6|j
|jdtd
d	||jdtd
d	|j
dS(s
        A client's transport's C{getHost} and C{getPeer} return L{IPv4Address}
        instances which give the dotted-quad string form of the local and
        remote endpoints of the connection respectively.
        iR.RtpeertCheckAddresscseZfdZRS(cs.|jd<|jd<jdS(NRR(tgetHosttgetPeerR7(R5t	transport(t	addressesR4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytmakeConnections(R;R<R((RR4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRst	localhosttbindAddresss	127.0.0.1tTCPN(R2Rt	listenTCPR#RRRoR3RzRRtinstallResolverR>RRdR(R5RRR{RRt
clientFactory((R4RsB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_addressess(	

cs|jjdtt}gdtffdY}t}||_jd|jj|j	|j
dS(s
        This test checks that we correctly get notifications event for a
        client. This ought to prevent a regression under Windows using the GTK2
        reactor. See #3925.
        itCheckConnectioncseZfdZRS(csj|jdS(N(RYR7(R5(t	connectedR4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytconnectionMades
(R;R<R((RR4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRss	127.0.0.1N(RRR#RR3RzRRRtrunR(R5R{RR((R4RsB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_connectEvents	
cs|jjdtt}tjtjjfdgdt	ffdY}t
}||_jd|j
j||j|jdddS(sY
        If a producer is unregistered from a L{ITCPTransport} provider after the
        transport has been disconnected (by the peer) and after
        L{ITCPTransport.loseConnection} has been called, the transport is not
        re-added to the reactor as a writer as would be necessary if the
        transport were still connected.
        ics
jS(N(R7(tign(R4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRqstClientProtocolcs5eZdZdZfdZdZRS(s
            Protocol to connect, register a producer, try to lose the
            connection, wait for the server to disconnect from us, and
            then unregister the producer.
            cSs:tjd|jjt|jt|jjdS(NsClientProtocol.connectionMade(RRHRtregisterProducerRDtFalsetloseConnection(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs
	csDtjd|jj|jtkjddS(NsClientProtocol.connectionLost(RRHt
unregisterRYRRQtcallbackRo(R5R9(R4tfinishedtwriting(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR}s

cSstjd|jjdS(NsClientProtocol unregister(RRHRtunregisterProducer(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs
(R;R<R=RR}R((R4RR(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs	s	127.0.0.1s/Transport was writing after unregisterProducer.N(RRR#R'Rt
addErrbackRterrtaddCallbackRRRzRRRRR(R5RRR((R4RRsB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt&test_unregisterProducerAfterDisconnects	"		
cs|jddg}jj}||krKtjrKtdndddYjdtt}t	j
tjj
fddtffd	Y}t}||_jd
|jj||jdS(
s
        If L{ITCPTransport.loseConnection} is called while a producer
        is registered with the transport, the connection is closed
        after the producer is unregistered.
        tGlib2ReactortGtk2Reactors=A pygobject/pygtk bug disables this functionality on Windows.tProducercBseZdZRS(cSstjddS(NsProducer.resumeProducing(RRH(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRJs(R;R<RJ(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR
sics
jS(N(R7(R(R4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRqsRcsAeZdZfdZfdZfdZRS(s
            Protocol to connect, register a producer, try to lose the
            connection, unregister the producer, and wait for the connection to
            actually be lost.
            csPtjd|jjt|jjjdjd|jdS(NsClientProtocol.connectionMadei(RRHRRRRt	callLaterR(R5(RR4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs

cs@tjd|jjjdjttddS(NsClientProtocol unregisterg?sConnection was not lost(RRHRRRterrbackRRP(R5(RR4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR's


	cstjdjddS(NsClientProtocol.connectionLost(RRHRRo(R5R9(R(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR}1s
(R;R<R=RRR}((R4RR(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs

s	127.0.0.1N((RRNR;Rt	isWindowsRRR#RRRRRRRRzRRRR(R5tskippedReactorstreactorClassNameRRR((R4RRsB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_disconnectWhileProducings 	"		(R;R<R=RRRRRRRR(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRas						%		/tStreamTransportTestsMixincBs)eZdZdZdZdZRS(sR
    Mixin defining tests which apply to any port/connection based transport.
    cCsz|j}|j}dtfdY}|}|j||}|j|d}|j|f|dddS(st
        When a port starts, a message including a description of the associated
        factory is logged.
        tSomeFactorycBseZeedZRS(cSsdS(Ns
Crazy Factory((R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt	logPrefixKs(R;R<RRR(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRIs
s
Crazy FactoryiRN(tobserveRRtgetListeningPortt#getExpectedStartListeningLogMessageRd(R5tloggedMessagesR4RtfactorytptexpectedMessage((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_startedListeningLogMessageBs	csgfd|j|jt|j}tjfdfd}j|j|j|dS(s
        When a connection is lost, an informative message should be logged
        (see L{getExpectedConnectionLostLogMsg}): an address identifying
        the port and the fact that it was closed.
        csjtj|dS(N(RYRttextFromEventDict(t	eventDict(R(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytlogConnectionLostMsg\scstjjdS(N(RtremoveObserverR7(tignored(RR4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytstopReactords
cs'tjtjjdS(N(RtaddObserverRt
stopListeningR((RRR(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytdoStopListeninghs
N(	RRRtgetExpectedConnectionLostLogMsgRRtcallWhenRunningRtassertIn(R5RR((RRR4RRsB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_connectionLostLogMsgTs


cCs2|j}|j|t}|j|dS(sz
        The L{IListeningPort} object is an instance of a class with no
        classic classes in its hierarchy.
        N(RRRtassertFullyNewStyle(R5R4R((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_allNewStylers(R;R<R=RRR(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR>s		tTCPPortTestsBuildercBs_eZdZdZdZdZdZdZdZdZ	dZ
d	ZRS(
s,
    Tests for L{IReactorTCP.listenTCP}
    cCs|jd|S(s0
        Get a TCP port from a reactor.
        i(R(R5R4R((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRscCsd||jjfS(sY
        Get the message expected to be logged when a TCP port starts listening.
        s%s starting on %d(RR(R5RR((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRscCsd|jjfS(sJ
        Get the expected connection lost message for a TCP port.
        s(TCP Port %s Closed)(RR(R5R((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRscCsA|j}|jdt}|j}|j|tdS(s
        When no interface is passed to L{IReactorTCP.listenTCP}, the returned
        listening port listens on an IPv4 address.
        iN(RRRRtassertIsInstanceR(R5R4Rtaddress((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_portGetHostOnIPv4scsdtffdY}|}|jjd|d|}|jty)|j|jj|jjfWn8t	j
k
r\}}|j|tj
tjfnX|j|jS(s
        Connect C{client} to a server listening on C{interface} started with
        L{IReactorTCP.listenTCP} and return the address passed to the factory's
        C{buildProtocol} method.

        @param client: A C{SOCK_STREAM} L{socket.socket} created with an address
            family such that it will be able to connect to a server listening on
            C{interface}.

        @param interface: A C{str} giving an address for a server to listen on.
            This should almost certainly be the loopback address for some
            address family supported by L{IReactorTCP.listenTCP}.

        @return: Whatever object, probably an L{IAddress} provider, is passed to
            a server factory's C{buildProtocol} method when C{client}
            establishes a connection.
        tObserveAddresscseZfdZRS(csj||_tS(N(R7tobservedAddressR(R5R(R4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt
buildProtocols
	(R;R<R((R4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRsiR.(RRRRVRtconnectRRRR)terrorRterrnotEINPROGRESStEWOULDBLOCKRR(R5tclientR.RRRterrnumR((R4sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt_buildProtocolAddressTests	
) 
cCscd}tjtjtj}|j|j|j||}|jtd|j|dS(s
        When a connection is accepted over IPv4, an L{IPv4Address} is passed
        to the factory's C{buildProtocol} method giving the peer's address.
        s	127.0.0.1RN(	R)R*tSOCK_STREAMt
addCleanupR-RRdRR,(R5R.RR((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_buildProtocolIPv4Addresssc	sdtffdY}|jt}||_jd|d|}|jty)|j|jj	|jj
fWn8tjk
r\}}|j
|tjtjfnX|j|jS(s
        Connect C{client} to a server listening on C{interface} started with
        L{IReactorTCP.listenTCP} and return the address returned by one of the
        server transport's address lookup methods, C{getHost} or C{getPeer}.

        @param client: A C{SOCK_STREAM} L{socket.socket} created with an address
            family such that it will be able to connect to a server listening on
            C{interface}.

        @param interface: A C{str} giving an address for a server to listen on.
            This should almost certainly be the loopback address for some
            address family supported by L{IReactorTCP.listenTCP}.

        @param which: A C{str} equal to either C{"getHost"} or C{"getPeer"}
            determining which address will be returned.

        @return: Whatever object, probably an L{IAddress} provider, is returned
            from the method indicated by C{which}.
        RcseZfdZRS(cs&jt||j_dS(N(R7tgetattrRR(R5R(twhichR4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs
(R;R<R((R4R(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRsiR.(RRRRzRRVRRRRRR)RRRRRRR(	R5RR.RRRRRR((R4RsB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt_serverGetConnectionAddressTests		
) 
cCsfd}tjtjtj}|j|j|j||d}|jtd|j|dS(s
        When a connection is accepted over IPv4, the server
        L{ITransport.getHost} method returns an L{IPv4Address} giving the
        address on which the server accepted the connection.
        s	127.0.0.1RRN(	R)R*RRR-RRdRtgetpeername(R5R.RthostAddress((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_serverGetHostOnIPv4scCsfd}tjtjtj}|j|j|j||d}|jtd|j|dS(s
        When a connection is accepted over IPv4, the server
        L{ITransport.getPeer} method returns an L{IPv4Address} giving the
        address of the remote end of the connection.
        s	127.0.0.1RRN(	R)R*RRR-RRdRR,(R5R.RtpeerAddress((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_serverGetPeerOnIPv4
s(R;R<R=RRRRRRRRR(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR}s					&	
	&	tStopStartReadingProtocolcBs)eZdZdZdZdZRS(sD
    Protocol that pauses and resumes the transport a few times
    cCsd|_|jddS(NRhi(RStpauseResumeProducing(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs	cCsi|jj|jj|rC|jjjd|j|dn"|jjjd|jjj|dS(s?
        Toggle transport read state, then count down.
        iiN(	RtpauseProducingRJRR4RRtreadyR(R5tcounter((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR#s

cCsWtjdt||j|7_t|jdkrS|jjj|jndS(Nsgot dataiii@(RRHRZRSRR7R(R5RS((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRm1s(R;R<R=RRRm(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs		tTCPConnectionTestsBuildercBs eZdZdZdZRS(sP
    Builder defining tests relating to L{twisted.internet.tcp.Connection}.
    c	s#tj_ddg}jj}||kr[tjr[tdnt_	t
_t
_j
d}|jj}fd}fdtd|}t}t|_	t|j|jgj||}j|S(st
        This test verifies transport socket read state after multiple
        pause/resumeProducing calls.
        RRs.This test is broken on gtk/glib under Windows.icsj|dj|d|dd|ddf}|djjdddd	jj||jfdS(
sL
            Send several IOCPReactor's buffers' worth of data.
            iiRGiitycs
jS(N(R7(R(R4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRqYsi i (RRRIR7R(tprotosR(R4R5tsftcleanup(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytproceedPs cs[j|dddd	dtt|djjt|djjt|jgS(
s
            Make sure IOCPReactor didn't start several WSARecv operations
            that clobbered each other's results.
            RGiiRsdid not get the right dataiii i (RdRRRRR(RSRR(R5(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR[ss	127.0.0.1(RRR4RNR;RRRRRzRRR7RRRRRRRRRR(	R5RRRRRtcctcftd((R4R5RRsB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_stopStartReading=s(				*
cs|jgdtffdY}t}||_jd|}td|jj}t}t|_|j	|}d}|j
||j|jdddgd	S(
s
        Alice connects to Bob.  Alice writes some bytes and then shuts down the
        connection.  Bob receives the bytes from the connection and then pauses
        the transport object.  Shortly afterwards Bob resumes the transport
        object.  At that point, Bob is notified that the connection has been
        closed.

        This is no problem for most reactors.  The underlying event notification
        API will probably just remind them that the connection has been closed.
        It is a little tricky for win32eventreactor (MsgWaitForMultipleObjects).
        MsgWaitForMultipleObjects will only deliver the close notification once.
        The reactor needs to remember that notification until Bob resumes the
        transport.
        tPausercs;eZfdZfdZfdZRS(cs1jd|jjjd|jdS(Ntpausedi(RYRRRtresume(R5R[(teventsR4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRms

csjd|jjdS(Ntresumed(RYRRJ(R5(R(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs
csjdjdS(Ntlost(RYR7(R5R9(R4R(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR}s
(R;R<RmRR}((RR4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR
sis	127.0.0.1cSs!|jjd|jjdS(Nssome bytes for you(RRIR(R((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRsRRRN(
RRRRzRRRRRRRRRd(R5R
t
serverFactoryRR	R
tclientDeferredR((R4RsB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt'test_connectionLostAfterPausedTransportos					

(R;R<R=RR(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR9s	2tWriteSequenceTestscBsMeZdZdZdZdZdZdZdZdZ	RS(s!
    Test for L{twisted.internet.abstract.FileDescriptor.writeSequence}.

    @ivar client: the connected client factory to be used in tests.
    @type client: L{MyClientFactory}

    @ivar server: the listening server factory to be used in tests.
    @type server: L{MyServerFactory}
    cCsXt}t|_t|_||_t}t|_t|_||_dS(N(R&RtprotocolConnectionMadetprotocolConnectionLostR{R%R(R5R{R((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR|s			cCs1t|dddk	r$||_n	||_dS(s
        Set the write buffer size for the given transport, mananing possible
        differences (ie, IOCP). Bug #4322 should remove the need of that hack.
        twriteBufferSizeN(RRoRt
bufferSize(R5Rtvalue((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytsetWriteBufferSizescsjj}jjd|}j|jjd|jj}j|j	fdd}fd}j
j|}|j
j|}|j}j}	t
||||	g}
fd}|
j|jdS(sV
        C{writeSequence} sends the data even if C{write} hasn't been called.
        is	127.0.0.1cs5tjd|j|djjjdS(Nsdata received: %rsSome sequence splitted(RRHtassertEqualsRzRR(RS(R5R(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRmscSs.tjd||jjdddgdS(Nsclient connected %ssSome s	sequence tsplitted(RRHRR(tproto((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytclientConnectedscstjd||_dS(Nsserver connected %s(RRHRm(R(Rm(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytserverConnectedscsj|S(N(R7(tresult(R4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR7s
N(RR{RRRRRRRt
disconnectRRRRtaddBothR(R5R{RR8R R!td1td2td3td4RR7((R4R5RRmsB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_withoutWrites$			
csjj}}jjd|}j|jjd|jj|}j|j	fd}|j
j|}|jt
j|jfdjdS(so
        C{writeSequence} with an element in the sequence of type unicode raises
        C{TypeError}.
        is	127.0.0.1csItjd|jt|jjdg}jt|ddS(Nsserver connected %suUnicode is not koshersData must not be unicode(RRHtassertRaisest	TypeErrorRRRtstr(Rtexc(R5(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR!s
cs
jS(N(R7(R(R4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRqsN(RR{RRRRRRRR#RRRRRR(R5RR{RR8R!R((R4R5sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt,test_writeSequenceWithUnicodeRaisesExceptionscs|jjd|j}|j|jjd|jj|j}|j|j	|jj
}|jj
fd}|j||jj|jjfd}|j|fd}|j
||jdS(s
        Helper for testing producers which call C{writeSequence}.  This will set
        up a connection which a producer can use.  It returns after the
        connection is closed.

        @param clientConnected: A callback which will be invoked with a client
            protocol after a connection is setup.  This is responsible for
            setting up some sort of producer.
        is	127.0.0.1csjS(N(R(R(R R&(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR!"s
cstgS(N(R(R(R(R'(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytdidProducerActions-scsj|S(N(R7(R"(R4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR71s
N(RRR{RRRRRRR#RRRR$R(R5R RR8R%R!R/R7((R4R R'R(R&sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt
_producerTests"



cswjjdtffdY}|fd}j|jjddgdS(s{
        C{writeSequence} pauses its streaming producer if too much data is
        buffered, and then resumes it.
        tSaveActionProducercs?eZeedZdZfdZdZRS(cSs
g|_dS(N(tactions(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR6AscSs|jjddS(Ntpause(R2RY(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRDscs4|jjdjjjjjjdS(NR(R2RYRzRRR(R5(RR{(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRJGscSs|jjddS(NR7(R2RY(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRFQs(R;R<RRR6RRJRF((R{R(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR1?s

		
csn|jjtjjgj|jd|jjddgdjjdgdS(NiRGi2iR3(RRRRR2RR(R(R5tproducer(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR Vs
R3RN(RR{RyR0RR2(R5R1R ((R4R5R{RsB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_streamingProducer8s		
cs}jj}dtffdY}|fd}j|jjddgdS(s
        C{writeSequence} pauses its producer if too much data is buffered only
        if this is a streaming producer.
        R1cs6eZeedZfdZdZRS(cSs
g|_dS(N(R2(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR6oscss|jjd|jjddkr;jjjn4jjjdjjjddgddS(NRiiRGi2i(R2RYRjRzRt
stopConsumingRR(R5(ttestR(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRJrs
cSs|jjddS(NR7(R2RY(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRFzs(R;R<RRR6RJRF((RR7(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR1ms
	cs-|jjtjjdgdS(NR(RRRRR2(R(R5R4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR sRN(RR{RyR0RR2(R5R{R1R ((R4R5RR7sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_nonStreamingProduceres	
(
R;R<R=R|RR)R.R0R5R8(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs				'		2	-tAbortServerProtocolcBseZdZdZRS(s>
    Generic server protocol for abortConnection() tests.
    cCs |jjj||j`dS(N(RtdoneR(R5R9((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR}s(R;R<R=R}(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR9stServerAbortsTwicecBseZdZdZRS(s'
    Call abortConnection() twice.
    cCs|jj|jjdS(N(RtabortConnection(R5RS((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRms
(R;R<R=Rm(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR;stServerAbortsThenLosescBseZdZdZRS(s>
    Call abortConnection() followed by loseConnection().
    cCs|jj|jjdS(N(RR<R(R5RS((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRms
(R;R<R=Rm(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR=stAbortServerWritingProtocolcBseZdZdZRS(s4
    Protocol that writes data upon connection.
    cCs|jjddS(sW
        Tell the client that the connection is set up and it's time to abort.
        RN(RRI(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs(R;R<R=R(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR>stReadAbortServerProtocolcBseZdZdZRS(s
    Server that should never receive any data, except 'X's which are written
    by the other side of the connection before abortConnection, and so might
    possibly arrive.
    cCs%|jddr!tdndS(NtXRhsUnexpectedly received data.(treplaceRP(R5RS((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRms(R;R<R=Rm(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR?stNoReadServercBseZdZdZRS(s
    Stop reading immediately on connection.

    This simulates a lost connection that will cause the other side to time
    out, and therefore call abortConnection().
    cCs|jjdS(N(RtstopReading(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs(R;R<R=R(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRBstEventualNoReadServercBs>eZdZeZeZdZdZdZdZ	RS(s
    Like NoReadServer, except we Wait until some bytes have been delivered
    before stopping reading. This means TLS handshake has finished, where
    applicable.
    cCs<|js8t|_|jj|t|jjdndS(Nthello(tgotDataRRRRRI(R5RS((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRms		cCs'|jr
dSt|_|jjdS(N(tstoppedReadingRRRC(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRJs		cCsdS(N((R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRscCsdS(N((R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRFs(
R;R<R=RRFRGRmRJRRF(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRDs			tAbortServerFactorycBs eZdZdZdZRS(s5
    Server factory for abortConnection() tests.
    cCs||_||_||_dS(N(R:tserverClassR4(R5R:RIR4((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR6s		cCs"|j}||_||_|S(N(RIRR(R5taddrR((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs		(R;R<R=R6R(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRHs	tBaseAbortingClientcBs&eZdZeZdZdZRS(s/
    Base class for abort-testing clients.
    cCs||_||_dS(N(R:R4(R5R:R4((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR6s	cCs2|jrtdn|jj||`dS(Ns,BUG: connectionLost was called re-entrantly!(tinReactorMethodtRuntimeErrorR:R(R5R9((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR}s	(R;R<R=RRLR6R}(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRKs	tWritingButNotAbortingClientcBseZdZdZRS(s&
    Write data, but don't abort.
    cCs|jjddS(NRE(RRI(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR's(R;R<R=R(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRN"stAbortingClientcBs eZdZdZdZRS(s9
    Call abortConnection() after writing some data.
    cCs t|_|jt|_dS(sF
        Some data was received, so the connection is set up.
        N(RRLt
writeAndAbortR(R5RS((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRm1s	
cCs9|jjdd|jj|jjdddS(NR@i'tY(RRIR<(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRP:s
(R;R<R=RmRP(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRO,s		tAbortingTwiceClientcBseZdZdZRS(s@
    Call abortConnection() twice, after writing some data.
    cCstj||jjdS(N(RORPRR<(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRPIs
(R;R<R=RP(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRRDstAbortingThenLosingClientcBseZdZdZRS(s;
    Call abortConnection() and then loseConnection().
    cCstj||jjdS(N(RORPRR(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRPTs
(R;R<R=RP(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRSOstProducerAbortingClientcBsJeZdZeZdZdZdZdZdZ	dZ
RS(sA
    Call abortConnection from doWrite, via resumeProducing.
    cCs||_||_t|_dS(N(R:R4RtproducerStopped(R5R:R4((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR6as		cCs=|jjddt|_|jj|tt|_dS(Ntlalalai(RRIRtinRegisterProducerRR(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRIgs	cCs|jdS(N(RI(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRnscCs/t|_|js"|jjnt|_dS(N(RRLRWRR<R(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRJrs		cCs
t|_dS(N(RRU(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRFyscCsJ|jstdn|jr0tdn|jj||`dS(Ns&BUG: stopProducing() was never called.s(BUG: connectionLost called re-entrantly!(RURMRLR:R(R5R9((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR}}s		(R;R<R=RRLR6RIRRJRFR}(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRTZs					tStreamingProducerClientcBsVeZdZdZdZdZdZdZdZdZ	dZ
RS(	s
    Call abortConnection() when the other side has stopped reading.

    In particular, we want to call abortConnection() only once our local
    socket hits a state where it is no longer writeable. This helps emulate
    the most common use case for abortConnection(), closing a connection after
    a timeout, with write buffers being full.

    Since it's very difficult to know when this actually happens, we just
    write a lot of data, and assume at that point no more writes will happen.
    cCs1||_t|_||_d|_t|_dS(Ni(R:RRR4textraWritesRL(R5R:R4((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR6s
				cCs|jdS(N(RI(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRscCsB|jj|tx(tdD]}|jjddq WdS(sh
        Write large amount to transport, then wait for a while for buffers to
        fill up.
        idt
1234567890i}N(RRRtrangeRI(R5ti((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRIscCs
t|_dS(N(RR(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRJscCsdS(N((R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRFscCs0|jr
dSt|_|jjd|jdS(s&
        Called when local buffer fills up.

        The goal is to hit the point where the local file descriptor is not
        writeable (or the moral equivalent). The fact that pauseProducing has
        been called is not sufficient, since that can happen when Twisted's
        buffers fill up but OS hasn't gotten any writes yet. We want to be as
        close as possible to every buffer (including OS buffers) being full.

        So, we wait a bit more after this for Twisted to write out a few
        chunks, then abortConnection.
        Ng{Gz?(RRR4RtdoAbort(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs
		cCsB|jstjtdnt|_|jjt|_dS(Ns&BUG: We should be paused a this point.(	RRRRMRRLRR<R(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR]s
		
cCs-|jjjj|jj||`dS(N(RRRtstartReadingR:R(R5R9((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR}s(R;R<R=R6RRIRJRFRR]R}(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRXs			
				tStreamingProducerClientLatercBs eZdZdZdZRS(sX
    Call abortConnection() from dataReceived, after bytes have been
    exchanged.
    cCs|jjdt|_dS(NRE(RRIRRF(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRscCs#|jst|_|jndS(N(RFRRI(R5RS((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRms		(R;R<R=RRm(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR_s	tProducerAbortingClientLatercBs eZdZdZdZRS(s
    Call abortConnection from doWrite, via resumeProducing.

    Try to do so after some bytes have already been exchanged, so we
    don't interrupt SSL handshake.
    cCsdS(N((R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRscCs|jdS(N(RI(R5RS((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRms(R;R<R=RRm(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR`s	tDataReceivedRaisingClientcBseZdZdZRS(sN
    Call abortConnection(), and then throw exception, from dataReceived.
    cCs|jjtddS(NtONO(RR<tZeroDivisionError(R5RS((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRms
(R;R<R=Rm(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRastResumeThrowsClientcBs eZdZdZdZRS(sL
    Call abortConnection() and throw exception from resumeProducing().
    cCs)|js%|jjtdndS(Nsono!(RWRR<Rc(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRJs	
cCs|jj||`dS(N(R:R(R5R9((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyR}s(R;R<R=RJR}(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRds	tAbortConnectionMixincBs}eZdZd
dZdZdZdZdZdZ	dZ
dZd	Zd
Z
dZdZRS(s7
    Unit tests for L{ITransport.abortConnection}.
    cs"jttt|jt|}j|}fd}|j|g}g}j|jj|j|jfd|jfd|jfdfd}	|j|	|jfdfd}
|j	|
j
dd	ttf}tt
f}yd
dlm}
Wntk
rd
}
nX|
r||
jf}||
jf}nrj|djf|nj|dj|j|dj|d
S(s
        A test runner utility function, which hooks up a matched pair of client
        and server protocols.

        We then run the reactor until both sides have disconnected, and then
        verify that the right exception resulted.
        cs
|_dS(N(R(R(R{(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt	addServer1scsS(N((RG(tclientDoneDeferred(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRq9scsS(N((RG(tserverDoneDeferred(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRq:scs
jS(N(R(RG(t
serverport(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRq<scsddk	rjnjjgj}jt|dtt|dS(Ni(RotflushLoggedErrorsRdt	removeAlltgetDelayedCallsRZtmapR,(tignoretdelayedCalls(tclientConnectionLostReasonR4R5(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytverifyReactorIsClean=s
cs
jS(N(R7(R(R4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRqFscstj|jdS(N(RRR7(R(R4(sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyterrorHandlerHs
RBi
i(tSSLiN(RRRHtlistenRRRR$RYRRRR	R
tOpenSSLRstImportErrorRotErrorRR(R5tclientClassRIRptcRRftserverReasontclientReasonRqRrtclientExpectedExceptionstserverExpectedExceptionsRs((R4R5RgRpR{RhRisB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pytrunAbortTestsH			




cCs|jttS(s
        abortConnection() is called in dataReceived. The protocol should be
        disconnected, but connectionLost should not be called re-entrantly.
        (R~ROR?(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_dataReceivedAbortcscCs|jttS(s
        abortConnection() is called twice by client.

        No exception should be thrown, and the connection will be closed.
        (R~RRR?(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt test_clientAbortsConnectionTwicekscCs|jttS(s
        Client calls abortConnection(), followed by loseConnection().

        No exception should be thrown, and the connection will be closed.
        (R~RSR?(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt.test_clientAbortsConnectionThenLosesConnectionts	cCs|jttdtS(s
        abortConnection() is called twice by server.

        No exception should be thrown, and the connection will be closed.
        Rp(R~RNR;R	(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt test_serverAbortsConnectionTwice~scCs|jttdtS(s
        Server calls abortConnection(), followed by loseConnection().

        No exception should be thrown, and the connection will be closed.
        Rp(R~RNR=R	(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt.test_serverAbortsConnectionThenLosesConnections	cCs|jttdS(s
        abortConnection() is called in resumeProducing, before any bytes have
        been exchanged. The protocol should be disconnected, but
        connectionLost should not be called re-entrantly.
        N(R~RTR9(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_resumeProducingAborts	cCs|jttS(s
        abortConnection() is called in resumeProducing, after some
        bytes have been exchanged. The protocol should be disconnected.
        (R~R`R>(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_resumeProducingAbortLaters	cCs|jttdS(s{
        abortConnection() triggered by the write buffer being full.

        In particular, the server side stops reading. This is supposed
        to simulate a realistic timeout scenario where the client
        notices the server is no longer accepting data.

        The protocol should be disconnected, but connectionLost should not be
        called re-entrantly.
        N(R~RXRB(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_fullWriteBuffers	cCs|jttS(s
        abortConnection() is triggered by a write buffer being full.

        However, this buffer is filled after some bytes have been exchanged,
        allowing a TLS handshake if we're testing TLS. The connection will
        then be lost.
        (R~R_RD(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt%test_fullWriteBufferAfterByteExchanges	cCs|jttdtdS(sJ
        dataReceived calls abortConnection(), and then raises an exception.

        The connection will be lost, with the thrown exception
        (C{ZeroDivisionError}) as the reason on the client. The idea here is
        that bugs should not be masked by abortConnection, in particular
        unexpected exceptions.
        RpN(R~RaR>Rc(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_dataReceivedThrowss		cCs|jttdtdS(sM
        resumeProducing calls abortConnection(), and then raises an exception.

        The connection will be lost, with the thrown exception
        (C{ZeroDivisionError}) as the reason on the client. The idea here is
        that bugs should not be masked by abortConnection, in particular
        unexpected exceptions.
        RpN(R~RdR9Rc(R5((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyttest_resumeProducingThrowss		N(R;R<R=RoR~RRRRRRRRRRR(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyResC				
	
		
					tAbortConnectionTestCasecBs eZdZdZdZRS(s5
    TCP-specific L{AbortConnectionMixin} tests.
    cCs|jd|ddS(s9
        Listen with the given protocol factory.
        iR.s	127.0.0.1(R(R5R4R{((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRtscOs"|j|jj|jjS(sh
        Connect a client to the listening server port.  Return the resulting
        Deferred.
        (RRRR(R5t
clientcreatorRitatk((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs(R;R<R=RtR(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyRs	((mR=R/t
__metaclass__R)Rtzope.interfaceRtzope.interface.verifyRttwisted.python.runtimeRttwisted.python.failureRttwisted.pythonRttwisted.trial.unittestRRt#twisted.internet.test.reactormixinsRttwisted.internet.errorRR	R
Rttwisted.internet.interfacesRR
RRttwisted.internet.addressRttwisted.internet.deferRRRRRRttwisted.internet.endpointsRRttwisted.internet.protocolRRRRRRttwisted.internet.tcpRR t&twisted.internet.test.connectionmixinsR!R"R#ttwisted.internet.test.test_coreR$ttwisted.test.test_tcpR%R&R'ttwisted.internet.sslR(RvRoRR2R3R>RyRDRQRRRbRlRnRvRRRRRRRtglobalstupdatetmakeTestCaseClassesR9R;R=R>R?RBRDRHRKRNRORRRSRTRXR_R`RaRdReR(((sB/usr/lib/python2.7/dist-packages/twisted/internet/test/test_tcp.pyt<module>s".


	@
71?	h


#
-Q