ϪfdZddlZddlZddlZ ddlZddlmZddl m Z ddl m Z Gdde jZGd d e jZGd d e jZy#e$rdZYUwxYw) z& Tests for L{twisted.internet.fdesc}. N)fdescznot supported on this platform)untilConcludes)unittestceZdZdZdZdZy)NonBlockingTestszE Tests for L{fdesc.setNonBlocking} and L{fdesc.setBlocking}. ctj\}}|jtj||jtj||j t j |t j tjztj||jt j |t j tjzy)zR L{fdesc.setNonBlocking} sets a file description to non-blocking. N) ospipe addCleanupclose assertFalsefcntlF_GETFL O_NONBLOCKrsetNonBlocking assertTrueselfrws 9/usr/lib/python3/dist-packages/twisted/test/test_fdesc.pytest_setNonBlockingz$NonBlockingTests.test_setNonBlockingswwy1 !$ !$ Q 6FG Q  Au}}5 EFctj\}}|jtj||jtj|t j |t j ||jtj|tjtjzy)zK L{fdesc.setBlocking} sets a file description to blocking. N) r r r r rr setBlockingr rrrrs rtest_setBlockingz!NonBlockingTests.test_setBlocking'sywwy1 !$ !$ Q ! Q 6FGrN)__name__ __module__ __qualname____doc__rrrrrrs G HrrcXeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd Zy)ReadWriteTestsz< Tests for L{fdesc.readFromFD}, L{fdesc.writeToFD}. ctj\|_|_t j |jt j |jy)zG Create a non-blocking pipe that can be used in tests. N)r r rrrrrs rsetUpzReadWriteTests.setUp8s; TVV$ TVV$rc tj|j tj|jy#t$rY,wxYw#t$rYywxYw)z Close pipes. N)r r rOSErrorrr%s rtearDownzReadWriteTests.tearDown@sS  HHTVV   HHTVV       s"AA A A AAcBtj|j|S)z) Write data to the pipe. )r writeToFDr)rds rwritezReadWriteTests.writeMstvvq))rcrg}tj|j|j}||r|dSy|S)z* Read data from the pipe. rr)r readFromFDrappend)rlress rreadzReadWriteTests.readSs< tvvqxx0 ;t Jrc|jd}|j|dkD|j}|jt |||jdd||y)z Test that the number of bytes L{fdesc.writeToFD} reports as written with its return value are seen by L{fdesc.readFromFD}. shellorN)r-rr3 assertEquallen)rnss rtest_writeAndReadz ReadWriteTests.test_writeAndReadasW JJx  A IIK Q# "1q)rc|ddz}|j|}|j|dkDg}d}d}||ks|dkrA|j|j|t |dz }|dz }||kr;|dkrAdj |}|j t |||j |d||y) z} Similar to L{test_writeAndRead}, but use a much larger string to verify the behavior for that case. s 0123456879i'r2rN)r-rr0r3r6joinr5)rorigwrittenresult resultlengthis rtest_writeAndReadLargez%ReadWriteTests.test_writeAndReadLargels u$**T" ! $ W$B MM$))+ & Cr O +L FA W$B &! Vg. hw0rcg}tj|j|j}|j |g|j |y)z 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)rr/rr0r5 assertIsNone)rr1rAs rtest_readFromEmptyz!ReadWriteTests.test_readFromEmptysA !!$&&!((3 B &!rctj|j|j|j t j y)z Test that using L{fdesc.readFromFD} on a cleanly closed file descriptor returns a connection done indicator. N)r r rr5r3rCONNECTION_DONEr%s rtest_readFromCleanClosez&ReadWriteTests.test_readFromCleanClose0  e&;&;.eagainWrites)C CIIrrMrcDt}tj|_|rW)r(rXEINTRrZs r eintrWritez3ReadWriteTests.test_writeErrors..eintrWrites)C CIIrN)r r-r5)r oldOsWriter^ras rtest_writeErrorszReadWriteTests.test_writeErrorssXX    "   TZZ-q 1!BH   "   TZZ-q 1!BH"BH"BHs!B!B B B%N)rrrr r&r)r-r3r9rDrGrJrOrRrTrcr!rrr#r#3sE% *  *1("=B=B"rr#c&eZdZdZdZdZdZdZy)CloseOnExecTestszL Tests for L{fdesc._setCloseOnExec} and L{fdesc._unsetCloseOnExec}. z import os, errno try: os.write(%d, b'lul') except OSError as e: if e.errno == errno.EBADF: os._exit(0) os._exit(5) except BaseException: os._exit(10) else: os._exit(20) ctj}|dk(rS tjtjtjd|j |j fzgyttj|ddS#t$r,ddl}|jtjdYywxYw)Nrz-cr=) r forkexecvsys executableprogramfileno BaseException traceback print_exc_exitrwaitpid)rfObjpidros r_execWithFileDescriptorz(CloseOnExecTests._execWithFileDescriptorsggi !8 NN^^T4<<4;;=:J+JK""**c15a8 8!  ##%  sAB 2C?Cc\t|jd5}tj|j |j |}|j tj||jtj|ddddy#1swYyxYw)z 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. wbrN) openmktempr_setCloseOnExecrmrurr WIFEXITEDr5 WEXITSTATUSrrsstatuss rtest_setCloseOnExecz$CloseOnExecTests.test_setCloseOnExecs} $++- & 8$  ! !$++- 011$7F OOBLL0 1   R^^F3Q 7  8 8 8s A>B""B+ct|jd5}tj|j tj |j |j |}|jtj||jtj|ddddy#1swYyxYw)z A file descriptor passed to L{fdesc._unsetCloseOnExec} is inherited by a new process image created with one of the exec family of functions. rwN) rxryrrzrm_unsetCloseOnExecrurr r{r5r|r}s rtest_unsetCloseOnExecz&CloseOnExecTests.test_unsetCloseOnExecs $++- & 9$  ! !$++- 0  # #DKKM 211$7F OOBLL0 1   R^^F3R 8  9 9 9s B!CCN)rrrr rlrurrr!rrreres G9$ 8 9rre)r rXr rjrtwisted.internetr ImportErrorskiptwisted.python.utilr twisted.trialrSynchronousTestCaserr#rer!rrrsz ''."Hx33H8Q"X11Q"h;9x33;9s, +D,sA&&A0/A0