Ë ÏªÍf(ãó—dZddlZddlZddlZddlZddlmZmZmZmZddl m Z m Z m Z m Z m Z ddlmZ ddl mZmZdZdd lmZdd lmZdd lmZmZdd lmZdd lmZddlm Z ddl!m"Z"ddl#m$Z$e"jJ«r ddl m&Z&dZ'ndZ' ddl(m)Z)m*Z*m+Z+m,Z,dZ-dZ.Gd„d«Z/d„Z0Gd„de1«Z2Gd„de«Z3d„Z4ee-e.«Gd„de$««Z5ee-e.«Gd„d e$««Z6y#e$rdZYŒ½wxYw#e$rdZ-dZ.YŒmwxYw)!z& Tests for L{twisted.python.sendmsg}. éN)ÚcloseÚpathsepÚpipeÚread)ÚAF_INETÚAF_INET6Ú SOL_SOCKETÚerrorÚsocket)Úpack)ÚAF_UNIXÚ socketpairFT)ÚskipIf)Úreactor)ÚDeferredÚinlineCallbacks)Ú ProcessDone)ÚProcessProtocol)ÚFilePath)Úplatform)ÚTestCase)Ú MSG_DONTWAIT)Ú SCM_RIGHTSÚgetSocketFamilyÚrecvmsgÚsendmsgÚz!Platform doesn't support sendmsg.có4—eZdZdZd„Zd„Zd„Zd„Zd„Zd„Z y) Ú _FDHolderzP A wrapper around a FD that will remember if it has been closed or not. có—||_y©N©Ú_fd)ÚselfÚfds úB/usr/lib/python3/dist-packages/twisted/python/test/test_sendmsg.pyÚ__init__z_FDHolder.__init__:s €Øˆócó—|jS)z/ Return the fileno of this FD. r"©r$s r&Úfilenoz_FDHolder.fileno=s €ðx‰xˆr(cóV—|jrt|j«d|_yy)zH Close the FD. If it's already been closed, do nothing. N)r#rr*s r&rz_FDHolder.closeCs"€ð 8Š8Ü $—(‘(ŒO؈DHð r(cóŽ—|jr9tjd|j›dt«|j «yy)z> If C{self._fd} is unclosed, raise a warning. zFD z was not closed!N)r#ÚwarningsÚwarnÚResourceWarningrr*s r&Ú__del__z_FDHolder.__del__Ks5€ð 8Š8Ü M‰M˜C §¡˜zÐ)9Ð:¼OÔ LØ J‰JLð r(có—|Sr!©r*s r&Ú __enter__z_FDHolder.__enter__Ss€Øˆ r(có$—|j«yr!)r)r$Úexc_typeÚ exc_valueÚ tracebacks r&Ú__exit__z_FDHolder.__exit__Vs €Ø ‰ r(N) Ú__name__Ú __module__Ú __qualname__Ú__doc__r'r+rr1r4r9r3r(r&rr5s%„ñòòò òòór(rcóH—t«\}}t|«t|«fS)zI Create a pipe, and return the two FDs wrapped in L{_FDHolders}. )rr)ÚrÚws r&Ú _makePiperAZs"€ô ‹6D€A€qÜ a‹Lœ) A›,Ð 'Ð'r(có—eZdZdZdefd„Zy)ÚExitedWithStderrz, A process exited with some stderr. Úreturncóh—djdgt|j«z«}t|«S)zY Dump the errors in a pretty way in the event of a subprocess traceback. ó r()ÚjoinÚlistÚargsÚrepr©r$Úresults r&Ú__str__zExitedWithStderr.__str__gs+€ð—‘˜S˜E¤D¨¯©£OÑ3Ó4ˆÜF‹|Ðr(N)r:r;r<r=ÚstrrMr3r(r&rCrCbs„ñð˜ôr(rCcó.—eZdZdZd„Zd„Zd„Zd„Zd„Zy)ÚStartStopProcessProtocolaø An L{IProcessProtocol} with a Deferred for events where the subprocess starts and stops. @ivar started: A L{Deferred} which fires with this protocol's L{IProcessTransport} provider when it is connected to one. @ivar stopped: A L{Deferred} which fires with the process output or a failure if the process produces output on standard error. @ivar output: A C{str} used to accumulate standard output. @ivar errors: A C{str} used to accumulate standard error. có\—t«|_t«|_d|_d|_y)Nr()rÚstartedÚstoppedÚoutputÚerrorsr*s r&r'z!StartStopProcessProtocol.__init__s"€Ü“zˆŒ Ü“zˆŒ ؈Œ ؈ r(cóN—|jj|j«yr!)rRÚcallbackÚ transportr*s r&ÚconnectionMadez'StartStopProcessProtocol.connectionMade…s€Ø ‰ ×јdŸn™nÕ-r(có.—|xj|z c_yr!)rT©r$Údatas r&Ú outReceivedz$StartStopProcessProtocol.outReceivedˆó€Ø Š tÑŽ r(có.—|xj|z c_yr!)rUr[s r&Ú errReceivedz$StartStopProcessProtocol.errReceived‹r^r(cóì—|jt«r&|jj|j«y|jj t |j|j««yr!)ÚcheckrrSrWrTÚerrbackrCrU)r$Úreasons r&Ú processEndedz%StartStopProcessProtocol.processEndedŽsF€Ø <‰<œ Ô $Ø L‰L× !Ñ ! $§+¡+Õ .à L‰L× Ñ Ô!1°$·+±+¸t¿{¹{Ó!KÕ Lr(N) r:r;r<r=r'rYr]r`rer3r(r&rPrPos!„ñ òò .òòóMr(rPc óî—ttj«j«j}t t j«}ttjtj««j«j|d<t«}tj|||tt«j|dz«j«jdg|ddd|dœ¬«|S)zñ Start a script that is a peer of this test as a subprocess. @param script: the module name of the script in this directory (no package prefix, no '.py') @type script: C{str} @rtype: L{StartStopProcessProtocol} Ú PYTHONPATHz.pys17r@r?)rééé)ÚenvÚchildFDs)rÚsysÚ executableÚ asTextModeÚpathÚdictÚosÚenvironrrGrPrÚ spawnProcessÚ__file__Úsibling)ÚscriptÚoutputFDÚpyExerkÚsspps r&Ú_spawnr{•s¿€ô ”S—^‘^Ó $× /Ñ /Ó 1× 6Ñ 6€EÜ Œrz‰zÓ €CÜ ¤§¡¬c¯h©hÓ!7Ó8×CÑCÓE×JÑJ€Cˆ ÑÜ #Ó %€DÜ ×ÑØ Ø à Ü ”XÓ × &Ñ & v°¡~Ó 6× AÑ AÓ C× HÑ HØ ð ð Ø˜S S¨hÑ7õ ð €Kr(cóh—eZdZdZd„Zd„Zd„Zd„Zd„Zd„Z d„Z e e d «d „«Z ed „«Zy ) Ú SendmsgTestszB Tests for the Python2/3 compatible L{sendmsg} interface. có<—tt«\|_|_y)z0 Create a pair of UNIX sockets. N)rr ÚinputrTr*s r&ÚsetUpzSendmsgTests.setUp·s€ô#-¬WÓ"5шŒ D•Kr(cól—|jj«|jj«y)z4 Close the sockets opened by setUp. N)rrrTr*s r&ÚtearDownzSendmsgTests.tearDown½s$€ð ‰ ×ÑÔØ ‰ ×ÑÕr(cóÞ—|jj«|jtt|jd«}|j |j dtj«y)z— If the underlying C{sendmsg} call fails, L{send1msg} raises L{socket.error} with its errno set to the underlying errno value. ó hello, worldrN© rrÚ assertRaisesr rÚ assertEqualrIÚerrnoÚEBADF©r$Úexcs r&Útest_syscallErrorzSendmsgTests.test_syscallErrorÄsJ€ð ‰ ×ÑÔØ×Ѥ¤w°· ± ¸OÓLˆØ ×јŸ™ !™¤e§k¡kÕ2r(cóä—|jj«|jtt|jddgd«}|j |j dtj«y)z The behavior when the underlying C{sendmsg} call fails is the same whether L{sendmsg} is passed ancillary data or not. r„)rrs0123rNr…rŠs r&Ú#test_syscallErrorWithControlMessagez0SendmsgTests.test_syscallErrorWithControlMessageÍsV€ð ‰ ×ÑÔØ×ÑÜ ”7˜DŸJ™J¨¸/Ð9JÈAó ˆð ×јŸ™ !™¤e§k¡kÕ2r(có8—d}|jt|«t|j|««t |j «}|j|j d«|j|jd«|j|jg«y)zI L{recvmsg} will retrieve a message sent via L{sendmsg}. ó hello, world!rN) r‡ÚlenrrrrTr\ÚflagsÚ ancillary)r$ÚmessagerLs r&Útest_roundtripzSendmsgTests.test_roundtripØsu€ð#ˆØ ×Ñœ˜W›¤w¨t¯z©z¸7Ó'CÔD䘟™Ó%ˆØ ×јŸ™Ð&6Ô7Ø ×јŸ™ qÔ)Ø ×ј×)Ñ)¨2Õ.r(có*—ddzdz}|jjd«t|j|«}|j|t |«k«t |j t |««}|jt |d«|«y)zS L{sendmsg} returns the number of bytes which it was able to send. óxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxééFrN)rÚ setblockingrÚ assertTruer‘rrTr‡)r$r”ÚsentÚreceiveds r&Útest_shortsendzSendmsgTests.test_shortsendäsy€ð Ñ$ rÑ)ˆØ ‰ ×јuÔ%Üt—z‘z 7Ó+ˆð ‰˜œs 7›|Ñ+Ô,ܘ4Ÿ;™;¬¨G« Ó5ˆØ ×Ñœ˜X a™[Ó)¨4Õ0r(cóˆ—t|jdgd«t|j«}|j |dgdf«y)z™ L{sendmsg} treats an empty ancillary data list the same way it treats receiving no argument for the ancillary parameter at all. rrN)rrrrTr‡rKs r&Útest_roundtripEmptyAncillaryz)SendmsgTests.test_roundtripEmptyAncillaryós=€ô — ‘ Ð,¨b°!Ô4䘟™Ó%ˆØ ×јÐ"2°B¸Ð!:Õ;r(z7MSG_DONTWAIT is only known to work as intended on Linuxcó—td«D]} t|jdt¬«Œ!|jd«y#t$r8}|j |j dtj«Yd}~yd}~wwxYw)z­ The C{flags} argument to L{sendmsg} is passed on to the underlying C{sendmsg} call, to affect it in whatever way is defined by those flags. i r—)r’rNzHFailed to fill up the send buffer, or maybe send1msg blocked for a while) ÚrangerrrÚOSErrorr‡rIrˆÚEAGAINÚfail)r$ÚiÚes r&Ú test_flagszSendmsgTests.test_flagsýsp€ôx“ò ˆAð ܘŸ ™  K´|ÖDð ð I‰Ið8õ øô ò Ø× Ñ  §¡¨¡¬E¯L©LÔ9Ýûð úsAÁ BÁ -A<Á<Bc #ó^K—td|jj««}|j–—t «\}}|j |j «|j |j «|5t|jdtttd|j««fg«ddd«|j–—|jt|j«d«d«|jt|j«d«d«y#1swYŒlxYw­w)zî Calling L{sendmsg} with SOL_SOCKET, SCM_RIGHTS, and a platform-endian packed file descriptor number should send that file descriptor to a different process, where it can be retrieved by using L{recv1msg}. Úpullpipesblonkr¦Nr˜sTest fixture data: blonk. r()r{rTr+rRrAÚ addCleanuprrrr rr rSr‡r)r$rzÚpipeOutÚpipeIns r&Útest_sendSubProcessFDz"SendmsgTests.test_sendSubProcessFDsâèø€ôj $§+¡+×"4Ñ"4Ó"6Ó7ˆØl‰lÒÜ#›+‰ˆØ ‰˜Ÿ ™ Ô&Ø ‰˜Ÿ ™ Ô%à ñ Ü Ø— ‘ ØÜœj¬$¨s°F·M±M³OÓ*DÐEÐFô ÷ ðl‰lÒØ ×Ñœ˜gŸn™nÓ.°Ó5Ð7UÔVà ×Ñœ˜gŸn™nÓ.°Ó5°sÕ;÷ ð üs‚A8D-Á:rÌs2ðñó Û Û Ûß)Ó)ß?Õ?Ýðß*ð€Kåå$ß<Ý.Ý5Ý,Ý+Ý+à€8×ÑÔÝ#àLð€LðßTÓTð €LØÐ÷"ñ"òJ(ô yô ô#M˜ô#MòLñ8ˆ Ð&Ó'ôx<8óx<ó(ðx<ñvˆ Ð&Ó'ô#J˜8ó#Jó(ñ#JøðyòØ‚Kðûð6ò;Ø€LØ:Òð;ús#´C2 C?Ã2C<Ã;C<Ã? D Ä D