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


BNc@sdZeZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
mZddlmZddlmZdd	lmZmZd
ZdefdYZd
efdYZejejdS(s0
Tests for implementations of L{IReactorFDSet}.
iN(t
implements(tplatform(tSkipTest(t
IReactorFDSettIReadDescriptor(tFileDescriptor(tReactorBuilder(tEINPROGRESStEWOULDBLOCKcCstj}|jd|jdztj}y||jty!|jd|jdfWn5tjk
r}|jdt	t
fkrqnX|j\}}Wn|jnXWd|jX||fS(Ns	127.0.0.1ii(s	127.0.0.1i(
tsockettbindtlistentsetblockingtFalsetconnecttgetsocknameterrortargsRRtaccepttclose(tserverSockettclienttetservertaddr((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyt
socketpairs$


!

tReactorFDSetTestsBuildercBseZdZegZdZdZdZdZdZ	dZ
dZdZd	Z
d
ZdZdZd
Zejrde_nRS(s>
    Builder defining tests relating to L{IReactorFDSet}.
    cCs9t\}}|j|j|j|j||fS(sL
        Return the two sockets which make up a new TCP connection.
        (Rt
addCleanupR(tselfRR((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyt_connectedPair6scCsC|j}|j\}}t|}|j|_|||fS(N(tbuildReactorRRtfileno(RtreactorRRtfd((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyt_simpleSetup@s
cs[|j\}fd}|_j|jd|jdS(s
        C{reactor.addReader()} accepts an L{IReadDescriptor} provider and calls
        its C{doRead} method when there may be data available on its C{fileno}.
        csjjdS(N(tremoveReadertstop((R!R (sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyt
removeAndStopRs
txN(R"tdoReadt	addReadertsendallt
runReactor(RRR%((R!R sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyttest_addReaderKs	

csj\}}}fd}||_|j||j||jd|jd|jd|jj|dS(s
        L{reactor.removeReader()} accepts an L{IReadDescriptor} provider
        previously passed to C{reactor.addReader()} and causes it to no longer
        be monitored for input events.
        csjddS(NsdoRead should not be called(tfail((R(sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyR,fsR&iN(R"R'R(R#R)t	callLaterR$R*(RR R!RR,((RsD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyttest_removeReader^s	


csN|j\}fd}|_j|jdS(s
        C{reactor.addWriter()} accepts an L{IWriteDescriptor} provider and
        calls its C{doWrite} method when it may be possible to write to its
        C{fileno}.
        csjjdS(N(tremoveWriterR$((R!R (sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyR%~s
N(R"tdoWritet	addWriterR*(RRR%((R!R sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyttest_addWritervs
	
cCs|j}t|d|d}t|d|}t|d|}|j\}}|j|||j|||||j|||j|||||j|||j||dS(s=
        Helper for getReaders and getWriters tests.
        tgettstaddtremoveN(RtgetattrRtassertNotIntassertIn(RtkindR R3R5R6RR((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyt
_getFDTests

cCs|jddS(s
        L{IReactorFDSet.getReaders} reflects the additions and removals made
        with L{IReactorFDSet.addReader} and L{IReactorFDSet.removeReader}.
        tReaderN(R;(R((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyttest_getReadersscstj\}}}fd}||_|j||j||jd|jd|jj|dS(s
        L{reactor.removeWriter()} accepts an L{IWriteDescriptor} provider
        previously passed to C{reactor.addWriter()} and causes it to no longer
        be monitored for outputability.
        csjddS(NsdoWrite should not be called(R,((R(sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyR,siN(R"R0R1R/R-R$R*(RR R!RR,((RsD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyttest_removeWriters	

cCs|jddS(s
        L{IReactorFDSet.getWriters} reflects the additions and removals made
        with L{IReactorFDSet.addWriter} and L{IReactorFDSet.removeWriter}.
        tWriterN(R;(R((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyttest_getWritersscsj}j\}}}fd|_fd|_|jd|j||j||j}|jd|jd|j	j
|j||gdS(s
        C{reactor.removeAll()} removes all registered L{IReadDescriptor}
        providers and all registered L{IWriteDescriptor} providers and returns
        them.
        cs
jdS(NsdoRead should not be called(R,((R(sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyt<lambda>scs
jdS(NsdoWrite should not be called(R,((R(sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyRAsR&iN(RR"R'R0R)R(R1t	removeAllR-R$R*tassertEqual(RR R!Rtremoved((RsD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyttest_removeAlls



cCsL|j}t|}|j|j|j||j|jgdS(s
        A descriptor's C{fileno} method should not be called after the
        descriptor has been removed from the reactor.
        N(RtRemovingDescriptortcallWhenRunningtstartR*RCtcalls(RR t
descriptor((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyttest_removedFromReactors

cs|j|j\dtffdY}|}j|jd|j|j|jddS(sp
        If L{FileDescriptor.fileno} returns C{-1}, the descriptor is removed
        from the reactor.
        tDisappearingDescriptorcsDeZjZdZdZfdZfdZRS(tcSs|jS(N(t_fileno(R((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyRscs2d|_|jjd7_jddS(Niity(RNt	_receivedtrecvtsend(R(RR(sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyR's	csjdS(N(R$(Rtreason(R (sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pytconnectionLosts(t__name__t
__module__RRNRPR'RT((R RR(sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyRLs
	R&N(RRRR(RRR*RCRP(RRLRJ((R RRsD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyttest_negativeOneFileDescriptors"


csjjj}|d	kr:td|fnj\}dtffdY}j|fd}jd|jj	t
jdS(
s
        The file descriptor underlying a FileDescriptor may be closed and
        replaced by another at some point.  Bytes which arrive on the new
        descriptor must not be delivered to the FileDescriptor which was
        originally registered with the original descriptor of the same number.

        Practically speaking, this is difficult or impossible to detect.  The
        implementation relies on C{fileno} raising an exception if the original
        descriptor has gone away.  If C{fileno} continues to return the original
        file descriptor value, the reactor may deliver events from that
        descriptor.  This is a best effort attempt to ease certain debugging
        situations.  Applications should not rely on it intentionally.
        tEPollReactort	CFReactors&%r cannot detect lost file descriptorstVictimcs5eZdZfdZdZfdZRS(s
            This L{FileDescriptor} will have its socket closed out from under it
            and another socket will take its place.  It will raise a
            socket.error from C{fileno} after this happens (because socket
            objects remember whether they have been closed), so as long as the
            reactor calls the C{fileno} method the problem will be detected.
            cs
jS(N(R(R(R(sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyR2scSstddS(Ns$Victim.doRead should never be called(t	Exception(R((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyR'5scsjdS(s
                When the problem is detected, the reactor should disconnect this
                file descriptor.  When that happens, stop the reactor so the
                test ends.
                N(R$(RRS(R (sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyRT8s(RURVt__doc__RR'RT((RR (sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyRZ*s	csOj\}}j}jtj|j||jddS(NR&(RRRtostdup2RR(tnewCtnewSR(RR(sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pytmessItUpGs

iN(RXRY(Rt	__class__RURRRR(R-R*tflushLoggedErrorsR	R(RtnameRRZRa((R RRsD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyttest_lostFileDescriptors
s*Cannot duplicate socket filenos on Windows(RURVR\RtrequiredInterfacesRR"R+R.R2R;R=R>R@RERKRWReRt	isWindowstskip(((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyR0s"		
											 	DRFcBsNeZdZeedZdZdZdZdZ	dZ
RS(s
    A read descriptor which removes itself from the reactor as soon as it
    gets a chance to do a read and keeps track of when its own C{fileno}
    method is called.

    @ivar insideReactor: A flag which is true as long as the reactor has
        this descriptor as a reader.

    @ivar calls: A list of the bottom of the call stack for any call to
        C{fileno} when C{insideReactor} is false.
    cCs4||_t|_g|_t\|_|_dS(N(R R
t
insideReactorRIRtreadtwrite(RR ((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyt__init__is			cCs-t|_|jj||jjddS(Nta(tTrueRiR R(RkRR(R((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyRHps	cCsdS(Ntfoo((R((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyt	logPrefixvscCs*|jj|t|_|jjdS(N(R R#R
RiR$(R((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyR'zs	cCs9|js,|jjtjddd n|jjS(Ntlimitii(RiRItappendt	tracebackt
extract_stackRjR(R((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyRs	#cCsdS(N((RRS((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyRTs(RURVR\RRRlRHRpR'RRT(((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyRFZs
					(R\ttypet
__metaclass__R]R	Rstzope.interfaceRttwisted.python.runtimeRttwisted.trial.unittestRttwisted.internet.interfacesRRttwisted.internet.abstractRt#twisted.internet.test.reactormixinsRttwisted.internet.tcpRRRRtobjectRFtglobalstupdatetmakeTestCaseClasses(((sD/usr/lib/python2.7/dist-packages/twisted/internet/test/test_fdset.pyt<module>s$	+0