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_endpoints.pyc


+Nc@sdZddlmZddlmZddlmZddlmZm	Z	ddlm
Z
ddlmZm
Z
ddlmZmZdd	lmZmZdd
lmZddlmZddlmZdd
lmZedjjdZeejjdZ e
j!ej"Z#e
j!e j"Z$yvddl%m&Z&ddl'm(Z(m)Z)m*Z*m+Z+ddl,m-Z-e)j.ej/Z0e+j.ej/Z1e2Z3Wne4k
rdZ3nXdefdYZ5de5fdYZ6defdYZ7dej8fdYZ9de:fdYZ;de;ej8fd YZ<d!e;ej8fd"YZ=d#e;ej8fd$YZ>d%ej8fd&YZ?d'ej8fd(YZ@d)d*ZAd+ej8fd,YZBd-ej8fd.YZCd/S(0s
Test the C{I...Endpoint} implementations that wrap the L{IReactorTCP},
L{IReactorSSL}, and L{IReactorUNIX} interfaces found in
L{twisted.internet.endpoints}.
i(tEPERM(t
implements(tunittest(terrort
interfaces(t	endpoints(tIPv4AddresstUNIXAddress(t
ClientFactorytProtocol(t
MemoryReactortRaisingMemoryReactor(tFailure(tplugins(t	getModule(tFilePathstwisted.tests
server.pemtfake_CAs(tmakeCertificate(tCertificateOptionstCertificatetKeyPairtPrivateCertificate(tContextTypes.OpenSSL is required to construct SSL EndpointstTestProtocolcBs;eZdZdZdZdZdZdZRS(sx
    Protocol whose only function is to callback deferreds on the
    factory when it is connected or disconnected.
    cCsg|_g|_d|_dS(Ni(tdatatconnectionsLosttconnectionMadeCalls(tself((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt__init__0s		cCsdS(NsA Test Protocol((R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt	logPrefix6scCs|jd7_dS(Ni(R(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pytconnectionMade:scCs|jj|dS(N(Rtappend(RR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pytdataReceived>scCs|jj|dS(N(RR(Rtreason((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pytconnectionLostBs(t__name__t
__module__t__doc__RRRR R"(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyR*s				tTestHalfCloseableProtocolcBs6eZdZeejdZdZdZRS(s
    A Protocol that implements L{IHalfCloseableProtocol} and records that
    its C{readConnectionLost} and {writeConnectionLost} methods.
    cCs#tj|t|_t|_dS(N(RRtFalsetreadLostt	writeLost(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRNs
	cCs
t|_dS(N(tTrueR((R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pytreadConnectionLostTscCs
t|_dS(N(R*R)(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pytwriteConnectionLostXs(	R#R$R%RRtIHalfCloseableProtocolRR+R,(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyR&Gs

		tTestFactorycBseZdZeZRS(s
    Simple factory to be used both when connecting and listening. It contains
    two deferreds which are called back when my protocol connects and
    disconnects.
    (R#R$R%Rtprotocol(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyR.]stWrappingFactoryTestscBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZRS(sS
    Test the behaviour of our ugly implementation detail C{_WrappingFactory}.
    cCs<t}tj|d}|j|jd|jdS(s
        L{_WrappingFactory.doStart} passes through to the wrapped factory's
        C{doStart} method, allowing application-specific setup and logging.
        iN(RRt_WrappingFactorytNonetdoStarttassertEqualtnumPorts(Rtfactorytwf((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_doStartls	
cCsEt}d|_tj|d}|j|jd|jdS(s
        L{_WrappingFactory.doStop} passes through to the wrapped factory's
        C{doStop} method, allowing application-specific cleanup and logging.
        iiN(RR5RR1R2tdoStopR4(RR6R7((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_doStopws
		
csgdtfdY}tj|d}|jdj|jt}|jfd|S(s
        An exception raised in C{buildProtocol} of our wrappedFactory
        results in our C{onConnection} errback being fired.
        tBogusFactorycBseZdZdZRS(sZ
            A one off factory whose C{buildProtocol} raises an C{Exception}.
            cSstddS(NsMy protocol is poorly defined.(t
ValueError(Rtaddr((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt
buildProtocols(R#R$R%R>(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyR;scsj|jdS(NsMy protocol is poorly defined.(sMy protocol is poorly defined.(R4targs(te(R(sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt<lambda>sN(	RRR1R2R>t
assertFailuret
_onConnectionR<taddCallback(RR;R7td((RsH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_failedBuildProtocols	
cCs>tjtd}|jd}|j|jddS(s
        If the wrapped protocol provides L{ILoggingContext}, whatever is
        returned from the wrapped C{logPrefix} method is returned from
        L{_WrappingProtocol.logPrefix}.
        sA Test ProtocolN(RR1R.R2R>R4R(RR7twp((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_logPrefixPassthroughscCscdtfdY}t}||_tj|d}|jd}|j|jddS(s
        If the wrapped protocol does not provide L{ILoggingContext}, the wrapped
        protocol's class name is returned from L{_WrappingProtocol.logPrefix}.
        t
NoProtocolcBseZRS((R#R$(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRIsN(	tobjectR.R/RR1R2R>R4R(RRIR6R7RG((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_logPrefixDefaults		cCstjtd}|jd}|jd|jd|j|jj	dg|jd|j|jj	ddgdS(s
        The wrapped C{Protocol}'s C{dataReceived} will get called when our
        C{_WrappingProtocol}'s C{dataReceived} gets called.
        tfootbarN(
RR1R.R2R>tmakeConnectionR R4t_wrappedProtocolR(RR7tp((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt test_wrappedProtocolDataReceiveds


cCsgtjtd}|jd}t}|j||j|j||j|j	j|dS(so
        Our transport is properly hooked up to the wrappedProtocol when a
        connection is made.
        N(
RR1R.R2R>RJRNR4t	transportRO(RR7RPtdummyTransport((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_wrappedProtocolTransports	
cCsTt}tj|d}|jd}|jd|j|jjdgdS(s
        Our wrappedProtocol's connectionLost method is called when
        L{_WrappingProtocol.connectionLost} is called.
        tfailN(	R.RR1R2R>R"R4ROR(RttfR7RP((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt"test_wrappedProtocolConnectionLosts
	
csytjtd}ttjdd}|jd|gfd}|jj	||j
|gdS(s
        Calls to L{_WrappingFactory.clientConnectionLost} should errback the
        L{_WrappingFactory._onConnection} L{Deferred}
        tstringRUcsj|dS(N(R(tf(terrors(sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pytgotErrorsN(RR1R.R2RRtConnectErrortclientConnectionFailedRCt
addErrbackR4(RR7texpectedFailureR[((RZsH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_clientConnectionFailedscCsDt}t}tj||}|jtjj|tdS(sx
        Our  L{_WrappingProtocol} should be an L{IHalfCloseableProtocol} if
        the C{wrappedProtocol} is.
        N(	RJR&Rt_WrappingProtocolR4RR-t
providedByR*(RtcdthcpRP((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt"test_wrappingProtocolHalfCloseables
		cCs;t}tjd|}|jtjj|tdS(s
        Our L{_WrappingProtocol} should not provide L{IHalfCloseableProtocol}
        if the C{WrappedProtocol} doesn't.
        N(	RRRaR2R4RR-RbR'(RttpRP((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt%test_wrappingProtocolNotHalfCloseables	cCs<t}tjd|}|j|j|jtdS(s~
        L{_WrappingProtocol.readConnectionLost} should proxy to the wrapped
        protocol's C{readConnectionLost}
        N(R&RRaR2R+R4R(R*(RRdRP((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt&test_wrappedProtocolReadConnectionLosts	
cCs<t}tjd|}|j|j|jtdS(s
        L{_WrappingProtocol.writeConnectionLost} should proxy to the wrapped
        protocol's C{writeConnectionLost}
        N(R&RRaR2R,R4R)R*(RRdRP((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt'test_wrappedProtocolWriteConnectionLosts	
(R#R$R%R8R:RFRHRKRQRTRWR`ReRgRhRi(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyR0hs												tEndpointTestCaseMixincBsVeZdZdZdZdZdZdZdZdZ	dZ
RS(	sJ
    Generic test methods to be mixed into all endpoint test classes.
    cCs|j|ddS(s
        Retrieve a single factory that has connected using the given reactor.
        (This behavior is valid for TCP and SSL but needs to be overridden for
        UNIX.)

        @param reactor: a L{MemoryReactor}
        ii(texpectedClients(Rtreactor((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pytretrieveConnectedFactory.scst}t}t}|j||\}}}|j|}gfd}|j||j|}	|	jj||j|g|j	|}
|jt
|
d|j|
d|dS(s}
        A client endpoint can connect and returns a deferred who gets called
        back with a protocol instance.
        csj|dS(N(R(RP(treceivedProtos(sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt
checkProtoJsiiN(RJR
tcreateClientEndpointtconnectRDRmRCtcallbackR4RktlentassertConnectArgs(Rtprototmreactort
clientFactoryteptexpectedArgstignoredDestRERoR6Rk((RnsH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_endpointConnectSuccess9s			
c	stjdd}td|}t}|j||\}}}|j|}gfd}|j||j|gdS(st
        If an endpoint tries to connect to a non-listening port it gets
        a C{ConnectError} failure.
        RXsConnection FailedtconnectExceptioncsj|jdS(N(Rtvalue(RY(treceivedExceptions(sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pytcheckFailureksN(RR\RRJRpRqR^R4(	Rt
expectedErrorRvRwRxtignoredArgsRzRER((R~sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_endpointConnectFailureYs	
c	st}t}|j||\}}}|j|}gfd}|j||j|jtdd}|j|j	t
j|j|j	j|dS(s
        Calling L{Deferred.cancel} on the L{Deferred} returned from
        L{IStreamClientEndpoint.connect} is errbacked with an expected
        L{ConnectingCancelledError} exception.
        csj|dS(N(R(RY(treceivedFailures(sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRsiiN(
R
RJRpRqR^tcancelR4RstassertIsInstanceR}RtConnectingCancelledErrortaddress(	RRvRwRxRRRERtfailure((RsH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt test_endpointConnectingCancelledss		


cst}t}|j||\}}}|j|}gfd}|j||j|g|j|j||gdS(ss
        An endpoint can listen and returns a deferred that gets called back
        with a port instance.
        csj|jdS(N(RtgetHost(tport(t
receivedHosts(sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pytcheckPortAndServersN(R
RJtcreateServerEndpointtlistenRDR4texpectedServers(RRvR6RxRytexpectedHostRER((RsH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_endpointListenSuccesss		
c	st}tjdd|}td|}|j||\}}}|jt}gfd}|j||j|gdS(s
        When an endpoint tries to listen on an already listening port, a
        C{CannotListenError} failure is errbacked.
        tiPtlistenExceptioncsj|jdS(N(RR}(RY(R~(sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRsN(RJRtCannotListenErrorRRRR^R4(	RR6t	exceptionRvRxRRzRER((R~sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_endpointListenFailures	
cCst}t}|j|||j\}}}|j||j|}|jt|d|j|d|dS(sn
        The endpoint should pass it's connectArgs parameter to the reactor's
        listen methods.
        iiN(	RJR
RptconnectArgsRqRkR4RsRt(RR6RvRxRytignoredHostRk((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt"test_endpointConnectNonDefaultArgss		
cCsit}t}|j|||j\}}}|j||j|}|j||gdS(sm
        The endpoint should pass it's listenArgs parameter to the reactor's
        listen methods.
        N(RJR
Rt
listenArgsRRR4(RR6RvRxRyRR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt!test_endpointListenNonDefaultArgss		
(R#R$R%RmR{RRRRRR(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRj)s		 		 			tTCP4EndpointsTestCasecBsMeZdZdZdZdZdZdZdZdZ	RS(s"
    Tests for TCP Endpoints.
    cCs|jS(sD
        @return: List of calls to L{IReactorTCP.listenTCP}
        (t
tcpServers(RRl((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRscCs|jS(sE
        @return: List of calls to L{IReactorTCP.connectTCP}
        (t
tcpClients(RRl((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRksc
Csn|\}}}}}|\}}	}
}}|j|||j||	|j|||j||dS(s]
        Compare host, port, timeout, and bindAddress in C{receivedArgs}
        to C{expectedArgs}.  We ignore the factory because we don't
        only care what protocol comes out of the
        C{IStreamClientEndpoint.connect} call.

        @param receivedArgs: C{tuple} of (C{host}, C{port}, C{factory},
            C{timeout}, C{bindAddress}) that was passed to
            L{IReactorTCP.connectTCP}.
        @param expectedArgs: C{tuple} of (C{host}, C{port}, C{factory},
            C{timeout}, C{bindAddress}) that we expect to have been passed
            to L{IReactorTCP.connectTCP}.
        N(R4(
RtreceivedArgsRythostRtignoredFactoryttimeouttbindAddressRtexpectedPortt_ignoredFactorytexpectedTimeouttexpectedBindAddress((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRtscCsidd6dd6S(sK
        @return: C{dict} of keyword arguments to pass to connect.
        i
Rt	localhostiR(Ri((R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRscCsidd6dd6S(sI
        @return: C{dict} of keyword arguments to pass to listen
        idtbacklogs	127.0.0.1t	interface((R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyR!scKsmtddd}|dkr'i}ntj||j||j||jdd|jddf|fS(	s
        Create an L{TCP4ServerEndpoint} and return the values needed to verify
        its behaviour.

        @param reactor: A fake L{IReactorTCP} that L{TCP4ServerEndpoint} can
            call L{IReactorTCP.listenTCP} on.
        @param factory: The thing that we expect to be passed to our
            L{IStreamServerEndpoint.listen} implementation.
        @param listenArgs: Optional dictionary of arguments to
            L{IReactorTCP.listenTCP}.
        tTCPs0.0.0.0iRi2RRN(RR2RtTCP4ServerEndpointRtget(RRlR6RR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyR(s			cKsdtddd}tj||j|j||j|j||jdd|jddf|fS(s
        Create an L{TCP4ClientEndpoint} and return the values needed to verify
        its behavior.

        @param reactor: A fake L{IReactorTCP} that L{TCP4ClientEndpoint} can
            call L{IReactorTCP.connectTCP} on.
        @param clientFactory: The thing that we expect to be passed to our
            L{IStreamClientEndpoint.connect} implementation.
        @param connectArgs: Optional dictionary of arguments to
            L{IReactorTCP.connectTCP}
        RRiPRiRN(RRtTCP4ClientEndpointRRRR2(RRlRwRR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRpBs	(
R#R$R%RRkRtRRRRp(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRs						tSSL4EndpointsTestCasecBseeZdZereZndZdZdZdZdZ	dZ
dZdZRS(	s"
    Tests for SSL Endpoints.
    cCs|jS(sD
        @return: List of calls to L{IReactorSSL.listenSSL}
        (t
sslServers(RRl((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRcscCs|jS(sE
        @return: List of calls to L{IReactorSSL.connectSSL}
        (t
sslClients(RRl((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRkjscCs|\}}}}}}|\}	}
}}}
}|j||	|j||
|j|||j||
|j||dS(s
        Compare host, port, contextFactory, timeout, and bindAddress in
        C{receivedArgs} to C{expectedArgs}.  We ignore the factory because we
        don't only care what protocol comes out of the
        C{IStreamClientEndpoint.connect} call.

        @param receivedArgs: C{tuple} of (C{host}, C{port}, C{factory},
            C{contextFactory}, C{timeout}, C{bindAddress}) that was passed to
            L{IReactorSSL.connectSSL}.
        @param expectedArgs: C{tuple} of (C{host}, C{port}, C{factory},
            C{contextFactory}, C{timeout}, C{bindAddress}) that we expect to
            have been passed to L{IReactorSSL.connectSSL}.
        N(R4(RRRyRRRtcontextFactoryRRRRRtexpectedContextFactoryRR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRtqscCsidd6dd6S(sK
        @return: C{dict} of keyword arguments to pass to connect.
        i
RRiR(s	localhosti((R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRscCsidd6dd6S(sI
        @return: C{dict} of keyword arguments to pass to listen
        idRs	127.0.0.1R((R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRscCs|tdddd\|_|_tdddd\|_|_td|jd|jd	t|_td	t|_d
S(sF
        Set up client and server SSL contexts for use later.
        tOsServer Test CertificatetCNtserversClient Test Certificatetclientt
privateKeytcertificatetrequireCertificateN(	RtsKeytsCerttcKeytcCertRR'tserverSSLContexttclientSSLContext(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pytsetUps		cKsdtddd}tj||j|j||j||j|jdd|jddf|fS(s
        Create an L{SSL4ServerEndpoint} and return the tools to verify its
        behaviour.

        @param factory: The thing that we expect to be passed to our
            L{IStreamServerEndpoint.listen} implementation.
        @param reactor: A fake L{IReactorSSL} that L{SSL4ServerEndpoint} can
            call L{IReactorSSL.listenSSL} on.
        @param listenArgs: Optional dictionary of arguments to
            L{IReactorSSL.listenSSL}.
        Rs0.0.0.0iRi2RR(RRtSSL4ServerEndpointRRR(RRlR6RR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRs	c	Kstddd}|dkr'i}ntj||j|j|j||j|j||j|jdd|jddf|fS(s
        Create an L{SSL4ClientEndpoint} and return the values needed to verify
        its behaviour.

        @param reactor: A fake L{IReactorSSL} that L{SSL4ClientEndpoint} can
            call L{IReactorSSL.connectSSL} on.
        @param clientFactory: The thing that we expect to be passed to our
            L{IStreamClientEndpoint.connect} implementation.
        @param connectArgs: Optional dictionary of arguments to
            L{IReactorSSL.connectSSL}
        RRiPRiRN(RR2RtSSL4ClientEndpointRRRR(RRlRwRR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRps		(
R#R$R%tskipSSLtskipRRkRtRRRRRp(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyR[s								tUNIXEndpointsTestCasecBsVeZdZdZdZdZdZdZdZdZ	dZ
RS(	s)
    Tests for UnixSocket Endpoints.
    cCs|j|ddS(s
        Override L{EndpointTestCaseMixin.retrieveConnectedFactory} to account
        for different index of 'factory' in C{connectUNIX} args.
        ii(Rk(RRl((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRmscCs|jS(sF
        @return: List of calls to L{IReactorUNIX.listenUNIX}
        (tunixServers(RRl((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRscCs|jS(sG
        @return: List of calls to L{IReactorUNIX.connectUNIX}
        (tunixClients(RRl((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRkscCsX|\}}}}|\}}}	}
|j|||j||	|j||
dS(s
        Compare path, timeout, checkPID in C{receivedArgs} to C{expectedArgs}.
        We ignore the factory because we don't only care what protocol comes
        out of the C{IStreamClientEndpoint.connect} call.

        @param receivedArgs: C{tuple} of (C{path}, C{timeout}, C{checkPID})
            that was passed to L{IReactorUNIX.connectUNIX}.
        @param expectedArgs: C{tuple} of (C{path}, C{timeout}, C{checkPID})
            that we expect to have been passed to L{IReactorUNIX.connectUNIX}.
        N(R4(RRRytpathRRtcheckPIDtexpectedPathRRtexpectedCheckPID((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRts
cCsidd6dd6S(sK
        @return: C{dict} of keyword arguments to pass to connect.
        i
RiR((R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRscCsidd6dd6dd6S(sI
        @return: C{dict} of keyword arguments to pass to listen
        idRitmodeitwantPID((R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRscKsgt|j}tj||j||j||jdd|jdd|jddf|fS(s
        Create an L{UNIXServerEndpoint} and return the tools to verify its
        behaviour.

        @param reactor: A fake L{IReactorUNIX} that L{UNIXServerEndpoint} can
            call L{IReactorUNIX.listenUNIX} on.
        @param factory: The thing that we expect to be passed to our
            L{IStreamServerEndpoint.listen} implementation.
        @param listenArgs: Optional dictionary of arguments to
            L{IReactorUNIX.listenUNIX}.
        Ri2RiRi(RtmktempRtUNIXServerEndpointtnameR(RRlR6RR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyR!s	cKsXt|j}tj||j||j||jdd|jddf|fS(s
        Create an L{UNIXClientEndpoint} and return the values needed to verify
        its behaviour.

        @param reactor: A fake L{IReactorUNIX} that L{UNIXClientEndpoint} can
            call L{IReactorUNIX.connectUNIX} on.
        @param clientFactory: The thing that we expect to be passed to our
            L{IStreamClientEndpoint.connect} implementation.
        @param connectArgs: Optional dictionary of arguments to
            L{IReactorUNIX.connectUNIX}
        RiRi(RRRtUNIXClientEndpointRR(RRlRwRR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRp8s	(R#R$R%RmRRkRtRRRRp(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRs							tParserTestCasecBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZRS(sK
    Tests for L{endpoints._parseServer}, the low-level parsing logic.
    tFactorycOstj||S(sT
        Provide a hook for test_strports to substitute the deprecated API.
        (Rt_parseServer(Rtatkw((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pytparseVscCsC|j|jd|jdd|jfidd6dd6fdS(	sN
        Simple strings with a 'tcp:' prefix should be parsed as TCP.
        stcp:80RiPRRi2RN(R4RRY(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_simpleTCP]scCsC|j|jd|jdd|jfidd6dd6fdS(	sU
        TCP port descriptions parse their 'interface' argument as a string.
        stcp:80:interface=127.0.0.1RiPs	127.0.0.1Ri2RN(R4RRY(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_interfaceTCPescCsC|j|jd|jdd|jfidd6dd6fdS(	sU
        TCP port descriptions parse their 'backlog' argument as an integer.
        stcp:80:backlog=6RiPRRiRN(R4RRY(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_backlogTCPnscCsJ|j|jd|jdd|jfidd6dd6td6fd	S(
s
        L{endpoints._parseServer} returns a C{'UNIX'} port description with
        defaults for C{'mode'}, C{'backlog'}, and C{'wantPID'} when passed a
        string with the C{'unix:'} prefix and no other parameter values.
        sunix:/var/run/fingertUNIXs/var/run/fingeriRi2RRN(R4RRYR*(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_simpleUNIXwscCsJ|j|jd|jdd|jfidd6dd6td6fd	S(
sK
        C{mode} can be set by including C{"mode=<some integer>"}.
        sunix:/var/run/finger:mode=0660Rs/var/run/fingeriRi2RRN(R4RRYR*(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt
test_modeUNIXscCsJ|j|jd|jdd|jfidd6dd6td6fd	S(
sM
        C{wantPID} can be set to false by included C{"lockfile=0"}.
        sunix:/var/run/finger:lockfile=0Rs/var/run/fingeriRi2RRN(R4RRYR'(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_wantPIDUNIXscCsJ|j|jd|jdd|jfidd6dd6td6fd	S(
sf
        Backslash can be used to escape colons and backslashes in port
        descriptions.
        sunix:foo\:bar\=baz\:qux\\Rsfoo:bar=baz:qux\iRi2RRN(R4RRYR*(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_escapescCs|jtjdddS(s
        L{endpoints.quoteStringArgument} should quote backslashes and colons
        for interpolation into L{endpoints.serverFromString} and
        L{endpoints.clientFactory} arguments.
        ssome : stuff \ssome \: stuff \\N(R4RtquoteStringArgument(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_quoteStringArgumentscCsJ|j|jd|jdd|jfidd6dd6td6fd	S(
s
        In strports descriptions, '=' in a parameter value does not need to be
        quoted; it will simply be parsed as part of the value.
        sunix:address=foo=barRsfoo=bariRi2RRN(R4RRYR*(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_impliedEscapescCsM|j|jd|jddd|jfidd6dd6td6fd	S(
s
        For compatibility with the old L{twisted.application.strports.parse},
        the third 'mode' argument may be specified to L{endpoints.parse} to
        indicate a default other than TCP.
        tfilenametunixRiRi2RRN(R4RRYR*(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_nonstandardDefaultscCs |jt|jd|jdS(se
        L{strports.parse} raises C{ValueError} when given an unknown endpoint
        type.
        sbogus-type:nothingN(tassertRaisesR<RRY(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_unknownTypes(R#R$R%RYRRRRRRRRRRRR(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyROs								
	
		
		tServerStringTestscBsVeZdZdZdZer0ee_ndZdZdZ	dZ
RS(sC
    Tests for L{twisted.internet.endpoints.serverFromString}.
    cCs~t}tj|d}|j|tj|j|j||j|jd|j|j	d|j|j
ddS(s
        When passed a TCP strports description, L{endpoints.serverFromString}
        returns a L{TCP4ServerEndpoint} instance initialized with the values
        from the string.
        s&tcp:1234:backlog=12:interface=10.0.0.1iis10.0.0.1N(RJRtserverFromStringRRtassertIdenticalt_reactorR4t_portt_backlogt
_interface(RRlR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_tcps	cCst}tj|dttf}|j|tj|j|j||j|j	d|j|j
d|j|jd|jj
}|j|tdS(s
        When passed an SSL strports description, L{endpoints.serverFromString}
        returns a L{SSL4ServerEndpoint} instance initialized with the values
        from the string.
        s?ssl:1234:backlog=12:privateKey=%s:certKey=%s:interface=10.0.0.1iis10.0.0.1N(RJRRtescapedPEMPathNameRRRRR4RRRt_sslContextFactoryt
getContextR(RRlRtctx((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_ssls	
cCst}tj|d}|j|tj|j|j||j|jd|j|j	d|j|j
d|j|jtdS(s
        When passed a UNIX strports description, L{endpoint.serverFromString}
        returns a L{UNIXServerEndpoint} instance initialized with the values
        from the string.
        s0unix:/var/foo/bar:backlog=7:mode=0123:lockfile=1s/var/foo/bariiSN(
RJRRRRRRR4t_addressRt_modet_wantPIDR*(RRltendpoint((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt	test_unixs		cCs5|jttjdd}|jt|ddS(s
        The older service-based API (L{twisted.internet.strports.service})
        allowed an implicit default of 'tcp' so that TCP ports could be
        specified as a simple integer, but we've since decided that's a bad
        idea, and the new API does not accept an implicit default argument; you
        have to say 'tcp:' now.  If you try passing an old implicit port number
        to the new API, you'll get a C{ValueError}.
        t4321sqUnqualified strport description passed to 'service'.Use qualified endpoint descriptions; for example, 'tcp:4321'.N(RR<RRR2R4tstr(RR}((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_implicitDefaultNotAlloweds
		cCs5|jttjdd}|jt|ddS(sq
        L{endpoints.serverFromString} raises C{ValueError} when given an
        unknown endpoint type.
        sftl:andromeda/carcosa/hali/2387sUnknown endpoint type: 'ftl'N(RR<RRR2R4R(RR}((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRs		cCst|t}tj|d}ddlm}|j|j||j|j	|ddf|j|j
tdddd	d
S(s
        L{endpoints.serverFromString} looks up plugins of type
        L{IStreamServerEndpoint} and constructs endpoints from them.
        sfake:hello:world:yes=no:up=downi(tfakethellotworldtyestnotuptdownN(t
addFakePluginRJRRttwisted.plugins.fakeendpointRRtparserR4R?tkwargstdict(RtnotAReactortfakeEndpointR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_typeFromPlugin*s
	(R#R$R%RRRRRRRR
(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRs					sfakeendpoint.pycsddljjtjfd}|j|t|j}|jt	t
jj|j
|j|tjj|jdS(s
    For the duration of C{testCase}, add a fake plugin to twisted.plugins which
    contains some sample endpoint parsers.
    iNcs+jjjjtj(dS(N(tmodulestcleartupdateR
t__path__((tsystsavedModulestsavedPluginPath(sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pytcleanupEs
(RRtcopyR
Rt
addCleanupRRtcreateDirectoryRR#tfilePathtsiblingtcopyTotchildRR(ttestCasetdropinSourceRtfp((RRRsH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyR=s	

tClientStringTestscBsDeZdZdZdZdZdZdZdZRS(sC
    Tests for L{twisted.internet.endpoints.clientFromString}.
    cCst}tj|d}|j|tj|j|j||j|jd|j|j	d|j|j
d|j|jddS(s
        When passed a TCP strports description, L{endpointClient} returns a
        L{TCP4ClientEndpoint} instance initialized with the values from the
        string.
        s=tcp:host=example.com:port=1234:timeout=7:bindAddress=10.0.0.2sexample.comiis10.0.0.2N(RJRtclientFromStringRRRRR4t_hostRt_timeoutt_bindAddress(RRlR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRWs		cCsEt}tj|d}|j|jd|j|jddS(s{
        A TCP strports description may omit I{timeout} or I{bindAddress} to
        allow the default to be used.
        stcp:host=example.com:port=1234iN(RJRR!R4R#R$R2(RRlR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_tcpDefaultsis		cCs~t}tj|d}|j|tj|j|j||j|jd|j|j	d|j|j
tdS(s
        When passed a UNIX strports description, L{endpointClient} returns a
        L{UNIXClientEndpoint} instance initialized with the values from the
        string.
        s+unix:path=/var/foo/bar:lockfile=1:timeout=9s/var/foo/bari	N(RJRR!RRRRR4t_pathR#t	_checkPIDR*(RRlR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRvs		cCs?tjtd}|j|jd|j|jtdS(sz
        A UNIX strports description may omit I{lockfile} or I{timeout} to allow
        the defaults to be used.
        sunix:path=/var/foo/bariN(RR!RJR4R#R'R'(RR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_unixDefaultsscCst|t}tj|d}ddlm}|j|j||j|j	d|j|j
tdddd	d
S(s
        L{endpoints.clientFromString} looks up plugins of type
        L{IStreamClientEndpoint} and constructs endpoints from them.
        scfake:alpha:beta:cee=dee:num=1i(t
fakeClienttalphatbetatceetdeetnumt1N(R*R+(RRJRR!RR)RRR4R?R	R
(RRtclientEndpointR)((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyR
s
	cCs5|jttjdd}|jt|ddS(sq
        L{endpoints.serverFromString} raises C{ValueError} when given an
        unknown endpoint type.
        sftl:andromeda/carcosa/hali/2387sUnknown endpoint type: 'ftl'N(RR<RR!R2R4R(RR}((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRs		(	R#R$R%RR%RR(R
R(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyR Rs		
		
	tSSLClientStringTestscBs8eZdZereZndZdZdZRS(sU
    Tests for L{twisted.internet.endpoints.clientFromString} which require SSL.
    cCst}tj|dtttf}|j|tj|j|j||j	|j
d|j	|jd|j	|jd|j	|j
d|j}|j|t|j}|j|t|j	t|jtt|j}|jt|j|j	|tgtjdtjdgD]6}|jjjdr<tj|j ^q<}|j	g|j!D]}t|^q|d	S(
s
        When passed an SSL strports description, L{clientFromString} returns a
        L{SSL4ClientEndpoint} instance initialized with the values from the
        string.
        sdssl:host=example.net:port=4321:privateKey=%s:certKey=%s:bindAddress=10.0.0.3:timeout=3:caCertsDir=%ssexample.netiis10.0.0.3s
thing1.pems
thing2.pems.pemN("RJRR!RtescapedCAsPathNameRRRRR4R"RR#R$RRRRRRttestCertificateRt_setPrivateKeyRRttestPrivateCertificatetcasPathRtbasenametlowertendswithtloadPEMt
getContenttcaCerts(RRlRtcertOptionsRtprivateCerttxt
expectedCerts((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRs6	
	"6%cCsdtfdY}tjdj}||_|jgtj|D]}t|^qJtj	tjdj
gdS(s
        If a certificate in the directory is unreadable,
        L{endpoints._loadCAsFromDir} will ignore that certificate.
        tUnreadableFilePathcBseZdZRS(cSsAtj|}|tjdjkr9ttn|SdS(Ns
thing2.pem(RR;R6RtIOErrorR(RR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyR;s(R#R$R;(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyRAstignoreds
thing1.pemN(RR6Rtparentt	clonePathR4Rt_loadCAsFromDirRR:R;(RRAtcasPathCloneR?((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_unreadableCertificates		%cCsgt}tj|d}|j}|j|t|j|jt|j	}|j|t
dS(s
        When passed an SSL strports description without any extra parameters,
        L{clientFromString} returns a simple non-verifying endpoint that will
        speak SSL.
        s%ssl:host=simple.example.org:port=4321N(RJRR!RRRR4tverifyR'RR(RRlRR=R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyttest_sslSimples		(R#R$R%RRRRHRJ(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyR1s		&	N(DR%terrnoRtzope.interfaceRt
twisted.trialRttwisted.internetRRRttwisted.internet.addressRRttwisted.internet.protocolRR	ttwisted.test.proto_helpersR
Rttwisted.python.failureRttwistedR
ttwisted.python.modulesRttwisted.python.filepathRRRtpemPathR#R6RRRR2ttwisted.test.test_sslverifyRttwisted.internet.sslRRRRtOpenSSL.SSLRR:R;R3R5R'RtImportErrorRR&R.tTestCaseR0RJRjRRRRRRR R1(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_endpoints.pyt<module>sR"


ll}q]