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


=Nc@sdZddlZddlZddlZyddlZWnek
rSdZnXddlmZddl	m
Z
ddlmZdej
fdYZd	ej
fd
YZdS(s&
Tests for L{twisted.internet.fdesc}.
iNsnot supported on this platform(tfdesc(tuntilConcludes(tunittesttReadWriteTestCasecBszeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZRS(
s6
    Tests for fdesc.readFromFD, fdesc.writeToFD.
    cCs<tj\|_|_tj|jtj|jdS(sJ
        Create two non-blocking pipes that can be used in tests.
        N(tostpipetrtwRtsetNonBlocking(tself((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pytsetUpscCsTytj|jWntk
r'nXytj|jWntk
rOnXdS(s
        Close pipes.
        N(RtcloseRtOSErrorR(R	((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyttearDown$s

cCstj|j|S(s)
        Write data to the pipe.
        (Rt	writeToFDR(R	td((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pytwrite2scCsGg}tj|j|j}|dkr?|r8|dSdSn|SdS(s*
        Read data from the pipe.
        itN(Rt
readFromFDRtappendtNone(R	tltres((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pytread9scCs\|jd}|j|dk|j}|jt|||jd| |dS(s
        Test that the number of bytes L{fdesc.writeToFD} reports as written
        with its return value are seen by L{fdesc.readFromFD}.
        thelloiN(Rt
failUnlessRtassertEqualtlen(R	tnts((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyttest_writeAndReadHs
cCsdd}|j|}|j|dkg}d}d}xM||ksY|dkr|j|j|t|d7}|d7}qAWdj|}|jt|||j|| |dS(	s}
        Similar to L{test_writeAndRead}, but use a much larger string to verify
        the behavior for that case.
        t
0123456879i'ii2iiRN(RRRRRtjoinR(R	torigtwrittentresulttresultlengthti((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyttest_writeAndReadLargeTs
cCsBg}tj|j|j}|j|g|j|ddS(s
        Verify that reading from a file descriptor with no data does not raise
        an exception and does not result in the callback function being called.
        N(RRRRRR(R	RR#((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyttest_readFromEmptyiscCs-tj|j|j|jtjdS(s
        Test that using L{fdesc.readFromFD} on a cleanly closed file descriptor
        returns a connection done indicator.
        N(RRRRRRtCONNECTION_DONE(R	((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyttest_readFromCleanClosetscCs0tj|j|j|jdtjdS(s
        Verify that writing with L{fdesc.writeToFD} when the read end is closed
        results in a connection lost indicator.
        RN(RRRRRRtCONNECTION_LOST(R	((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyttest_writeToClosed}scCs-tj|j|j|jtjdS(s
        Verify that reading with L{fdesc.readFromFD} when the read end is
        closed results in a connection lost indicator.
        N(RRRRRRR*(R	((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyttest_readFromInvalidscCs0tj|j|j|jdtjdS(s
        Verify that writing with L{fdesc.writeToFD} when the write end is
        closed results in a connection lost indicator.
        RN(RRRRRRR*(R	((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyttest_writeToInvalidscCstj}d}|t_z|j|jddWd|t_Xd}|t_z|j|jddWd|t_XdS(s8
        Test error path for L{fdesc.writeTod}.
        cSst}tj|_|dS(N(RterrnotEAGAIN(tfdtdataterr((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyteagainWrites	RiNcSst}tj|_|dS(N(RR.tEINTR(R0R1R2((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyt
eintrWrites	(RRR(R	t
oldOsWriteR3R5((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyttest_writeErrorss			
		(t__name__t
__module__t__doc__R
R
RRRR&R'R)R+R,R-R7(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyRs																tCloseOnExecTestscBs/eZdZdZdZdZdZRS(sL
    Tests for L{fdesc._setCloseOnExec} and L{fdesc._unsetCloseOnExec}.
    s
import os, errno
try:
    os.write(%d, 'lul')
except OSError, e:
    if e.errno == errno.EBADF:
        os._exit(0)
    os._exit(5)
except:
    os._exit(10)
else:
    os._exit(20)
cCstj}|dkr{y3tjtjtjd|j|jfgWqddl}|jtj	dqXnt
tj|ddSdS(Nis-ciii(Rtforktexecvtsyst
executabletprogramtfilenot	tracebackt	print_exct_exitRtwaitpid(R	tfObjtpidRB((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyt_execWithFileDescriptors3
cCsjt|jd}tj|j|j|}|jtj||j	tj
|ddS(s
        A file descriptor passed to L{fdesc._setCloseOnExec} is not inherited
        by a new process image created with one of the exec family of
        functions.
        RiN(tfiletmktempRt_setCloseOnExecRARHt
assertTrueRt	WIFEXITEDRtWEXITSTATUS(R	RFtstatus((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyttest_setCloseOnExecs
cCs}t|jd}tj|jtj|j|j|}|jtj	||j
tj|ddS(s
        A file descriptor passed to L{fdesc._unsetCloseOnExec} is inherited by
        a new process image created with one of the exec family of functions.
        RiN(RIRJRRKRAt_unsetCloseOnExecRHRLRRMRRN(R	RFRO((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyttest_unsetCloseOnExecs(R8R9R:R@RHRPRR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyR;s

		
(R:RR>R.tfcntltImportErrortskipttwisted.internetRttwisted.python.utilRt
twisted.trialRtTestCaseRR;(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_fdesc.pyt<module>s