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


=Nc@sidZddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZmZm
Z
ddlmZddlmZddlmZmZde	jfdYZd	ejfd
YZde	jfdYZd
e	jfdYZdejfdYZejedsGde_ nej!edsede_ ndS(sK
Tests for implementations of L{IReactorUNIX} and L{IReactorUNIXDatagram}.
iN(t
interfacestreactortprotocolterrortaddresstdefertutils(tlockfile(tunittest(tMyServerFactorytMyClientFactorytFailedConnectionClientFactorycBseZdZdZRS(cCs
||_dS(N(tonFail(tselfR((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyt__init__scCs|jj|dS(N(Rterrback(R
t	connectortreason((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pytclientConnectionFaileds(t__name__t
__module__RR(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRs	tUnixSocketTestCasecBsheZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZRS(s
    Test unix sockets.
    csj}jttj}_tj|}j|jt	j	t	j
t	j}j|j|j
|j|fd}|j||S(s
        The address passed to the server factory's C{buildProtocol} method and
        the address returned by the connected protocol's transport's C{getPeer}
        method match the address the client socket is bound to.
        csBtj}jj|gj|jj|dS(N(RtUNIXAddresstassertEqualt
peerAddressest	transporttgetPeer(tprototexpected(R
tpeernamet
serverFactory(s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyt
cbConnMade/s(tmktempR	RtDeferredtprotocolConnectionMadeRt
listenUNIXt
addCleanupt
stopListeningtsockettAF_UNIXtSOCK_STREAMtclosetbindtconnecttaddCallback(R
tfilenametconnMadetunixPortt
unixSocketR((R
RRs:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyt
test_peerBinds	


csjt}tj}||_tj|}j|jt	tj}|_tj
}tj||g}fd}|j||S(s
        L{IReactorUNIX.connectUNIX} can be used to connect a client to a server
        started with L{IReactorUNIX.listenUNIX}.
        csI|\}}jjtjg|jj|jjdS(N(RRRRRtloseConnection(t.0tserverProtocoltclientProtocol(R
R-t
clientFactory(s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pytallConnectedGs
	
(
R R	RR!R"RR#R$R%R
tconnectUNIXt
gatherResultsR,(R
RtserverConnMadeR/tclientConnMadetctdR7((R
R-R6s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyttest_dumber7s					
csjt}tj}||_tj|dtjt	j
dttj}|_tjdd}tj
||g}fd}|j|fd}|j||S(s
        A lockfile is created and locked when L{IReactorUNIX.listenUNIX} is
        called and released when the Deferred returned by the L{IListeningPort}
        provider's C{stopListening} method is called back.
        twantPIDs.locktcheckPIDicsO|\}}jjtjg|jj|jjjS(N(RRRRRR2R%(R3R4tclientProto(R/R
R-R6(s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyt
_portStuffjs	

cs!jtjdddS(Ns.locktlocked(tfailIfRtisLocked(tignored(R
R-(s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyt_checkvs(R R	RR!R"RR#tTruet
assertTrueRRER
R8R9R,(R
RR:R;R<R=RBRG((R
R-R6R/s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyttest_pidFileTs 				


cst|jttjdt}|jtjtjdtfd}|jj	|S(s
        L{IReactorUNIX.listenUNIX} raises L{error.CannotListenError} if passed
        the name of a file on which a server is already listening.
        R?cs"tjdt}|jS(NR?(RR#RHR%(tignR/(R-R(s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pytstoppedListenings(
R R	RR#RHtassertRaisesRtCannotListenErrorR%R,(R
R/RL((R-Rs:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyttest_socketLocking|s	cCsp|j|_d|jf}itjjtjd6}tjtj	dd|fd|}|j
||S(Nsnfrom twisted.internet import protocol, reactor
reactor.listenUNIX(%r, protocol.ServerFactory(), wantPID=True)
t
PYTHONPATHs-us-ctenv(R R-tostpathseptjointsystpathRtgetProcessValuet
executableR,(R
tcallbacktsourceRQR=((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyt_uncleanSocketTests
$
csfd}j|S(s"
        If passed C{True} for the C{wantPID} parameter, a server can be started
        listening with L{IReactorUNIX.listenUNIX} when passed the name of a
        file on which a previous server which has not exited cleanly has been
        listening using the C{wantPID} option.
        cs(tjjtdt}|jS(NR?(RR#R-R	RHR%(RKtp(R
(s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pytranStupidChilds(R[(R
R]((R
s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyttest_uncleanServerSocketLockingscsfd}j|S(s
        If passed C{True} for the C{checkPID} parameter, a client connection
        attempt made with L{IReactorUNIX.connectUNIX} fails with
        L{error.BadFileError}.
        csFtj}t|}tjj|dt}j|tj	S(NR@(
RR!RRR8R-RHt
assertFailureRtBadFileError(RKR=tfR<(R
(s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyR]s(R[(R
R]((R
s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyttest_connectToUncleanServerscsj}tj||d|f}jt|jt|tjj}fd}|j	||S(s~
        Test the C{__str__} and C{__repr__} implementations of a UNIX port when
        used with the given factory.
        s
<%s on %r>cs=df}jt|jt|dS(Ns<%s (not listening)>(Rtreprtstr(RKtunconnectedString(R
tfactoryNameR/(s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRLs
(
R RR#RRcRdRt
maybeDeferredR%R,(R
RRfR-tconnectedStringR=RL((R
RfR/s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyt	_reprTests
cCs9dddY}|j|tj|j|dS(s
        The two string representations of the L{IListeningPort} returned by
        L{IReactorUNIX.listenUNIX} contains the name of the classic factory
        class being used and the filename on which the port is listening or
        indicates that the port is not listening.
        tClassicFactorycBseZdZdZRS(cSsdS(N((R
((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pytdoStartscSsdS(N((R
((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pytdoStops(RRRkRl(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRjs	s%twisted.test.test_unix.ClassicFactory((tassertIsInstancettypest	ClassTypeRi(R
Rj((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyttest_reprWithClassicFactoryscCs9dtfdY}|j|t|j|dS(s!
        The two string representations of the L{IListeningPort} returned by
        L{IReactorUNIX.listenUNIX} contains the name of the new-style factory
        class being used and the filename on which the port is listening or
        indicates that the port is not listening.
        tNewStyleFactorycBseZdZdZRS(cSsdS(N((R
((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRkscSsdS(N((R
((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRls(RRRkRl(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRqs	s&twisted.test.test_unix.NewStyleFactory(tobjectRmttypeRi(R
Rq((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyttest_reprWithNewStyleFactorys(
RRt__doc__R1R>RJROR[R^RbRiRpRt(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRs			(						tClientProtocBs<eZeZZdZdZdZdZ	dZ
RS(cCs"tj|_tj|_dS(N(RR!tdeferredStartedtdeferredGotBack(R
((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRscCs
t|_dS(N(RHtstopped(R
((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pytstopProtocolscCst|_|jjddS(N(RHtstartedRwRYtNone(R
((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyt
startProtocols	cCs||_|jjddS(N(tgotbackRxRYR|(R
tdata((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pytdatagramReceiveds	N(RRtFalseR{RyR|R~RRzR}R(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRvs
			tServerProtocBs@eZeZZdZZdZdZ	dZ
dZRS(cCs"tj|_tj|_dS(N(RR!RwtdeferredGotWhat(R
((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRscCs
t|_dS(N(RHRy(R
((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRzscCst|_|jjddS(N(RHR{RwRYR|(R
((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyR}s	cCs9||_|jjd|||_|jjddS(Nshi back(tgotfromRtwritetgotwhatRRYR|(R
Rtaddr((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRs		N(RRRR{RyR|RRRRzR}R(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyR
s

			tDatagramUnixSocketTestCasecBs;eZdZdZdZdZdZdZRS(s%
    Test datagram UNIX sockets.
    csjj}tttj|}j|jtj|d}j|jtj	j
j
g}fd}fd}|j||j||S(sf
        Test that a datagram can be sent to and received by a server and vice
        versa.
        tbindAddresscs)jjdtjjjgS(Nthi(RRRR9RRx(RF(tcptsp(s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyR4scs=jdjjjjdjdS(NRshi back(RRRR~(RF(RR
Rt
clientaddr(s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyt_cbTestExchange9s(R RRvRtlistenUNIXDatagramR$R%tconnectUNIXDatagramRR9RwR,(R
t
serveraddrtsR<R=RR((RR
RRs:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyt
test_exchange%s		

cCs^|j}t}tj||}|jtjtj|||jtj	|dS(s
        L{IReactorUNIXDatagram.listenUNIXDatagram} raises
        L{error.CannotListenError} if the unix socket specified is already in
        use.
        N(
R RRRtfailUnlessRaisesRRNR%RRtunlink(R
RR\R((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyttest_cannotListenCs	
csj}tj||d|f}jt|jt|tjj}fd}|j	||S(s
        Test the C{__str__} and C{__repr__} implementations of a UNIX datagram
        port when used with the given protocol.
        s
<%s on %r>cs=df}jt|jt|dS(Ns<%s (not listening)>(RRcRd(RKRe(R
tprotocolNameR/(s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRL_s
(
R RRRRcRdRRgR%R,(R
tserverProtoRR-RhtstopDeferredRL((R
R/Rs:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRiRs
cCs9dddY}|j|tj|j|dS(s0
        The two string representations of the L{IListeningPort} returned by
        L{IReactorUNIXDatagram.listenUNIXDatagram} contains the name of the
        classic protocol class being used and the filename on which the port is
        listening or indicates that the port is not listening.
        tClassicProtocolcBseZdZdZRS(cSsdS(N((R
R((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pytmakeConnectionoscSsdS(N((R
((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRlrs(RRRRl(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRns	s&twisted.test.test_unix.ClassicProtocol((RmRnRoRi(R
R((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyttest_reprWithClassicProtocolgscCs9dtfdY}|j|t|j|dS(s2
        The two string representations of the L{IListeningPort} returned by
        L{IReactorUNIXDatagram.listenUNIXDatagram} contains the name of the
        new-style protocol class being used and the filename on which the port
        is listening or indicates that the port is not listening.
        tNewStyleProtocolcBseZdZdZRS(cSsdS(N((R
R((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRscSsdS(N((R
((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRls(RRRRl(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyRs	s'twisted.test.test_unix.NewStyleProtocol(RrRmRsRi(R
R((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyttest_reprWithNewStyleProtocol|s(RRRuRRRiRR(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyR!s				s1This reactor does not support UNIX domain socketss3This reactor does not support UNIX datagram sockets("RutstatRRRURnR&ttwisted.internetRRRRRRRttwisted.pythonRt
twisted.trialRttwisted.test.test_tcpR	R
t
ClientFactoryRtTestCaseRtConnectedDatagramProtocolRvtDatagramProtocolRRtIReactorUNIXR|tskiptIReactorUNIXDatagram(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_unix.pyt<module>s04	q