+
    üÐj@5  ã                   óÌ   € R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIH	t	H
t
HtHt ^ RIHt ^ RIHt ^ RIHt ^ RIHtHt  ! R R	]4      t ! R
 R]4      t ! R R]4      tR# )zD
Test running processes with the APIs in L{twisted.internet.utils}.
N)ÚskipIf)ÚerrorÚ
interfacesÚreactorÚutils)ÚDeferred)Úplatform)ÚSuppressedWarningsTests)ÚSynchronousTestCaseÚTestCasec                   ó  a € ] tR t^t o Rt]P                  ! ]R4      f   RtRt	Rt
]P                  tR tR tR tR tR tR	 t]! ]P,                  ! 4       R
4      R 4       tR tR tR tR tR tR tR tR tR t Rt!V t"R# )ÚProcessUtilsTestszh
Test running a process using L{getProcessOutput}, L{getProcessValue}, and
L{getProcessOutputAndValue}.
Nz)reactor doesn't implement IReactorProcessc                óF  € V P                  4       p\        VR4      ;_uu_ 4       pVP                  \        P                  P                  V4      \        P                  ,           4       RRR4       \        P                  P                  V4      #   + '       g   i     L/; i)zR
Write the given list of lines to a text file and return the absolute
path to it.
ÚwtN)ÚmktempÚopenÚwriteÚosÚlinesepÚjoinÚpathÚabspath)ÚselfÚsourceLinesÚscriptÚ
scriptFiles   &&  Ú:/usr/lib/python3/dist-packages/twisted/test/test_iutils.pyÚmakeSourceFileÚ ProcessUtilsTests.makeSourceFile$   sc   € ð
 —‘“ˆÜ�&˜$×Ô :Ø×ÑœRŸZ™ZŸ_™_¨[Ó9¼B¿J¹JÕFÔG÷  ä�w‰w�‰˜vÓ&Ð&÷  ×ús   ¥ABÂB 	c                ó¦   € V P                  . RO4      p\        P                  ! V P                  RV.4      pVP	                  V P
                  R4      # )z�
L{getProcessOutput} returns a L{Deferred} which fires with the complete
output of the process it runs after that process exits.
ú-us   hello world
)ú
import syszfor s in b'hello world\n':z    s = bytes([s])z    sys.stdout.buffer.write(s)z    sys.stdout.flush()©r   r   ÚgetProcessOutputÚexeÚaddCallbackÚassertEqual©r   r   Úds   &  r   Útest_outputÚProcessUtilsTests.test_output.   sN   € ð
 ×(Ñ(òó
ˆ
ô ×"Ò" 4§8¡8¨d°JÐ-?Ó@ˆØ�}‰}˜T×-Ñ-Ð/?Ó@Ð@ó    c                óÎ   a € S P                  RR.4      p\        P                  ! S P                  RV.4      pS P	                  V\
        4      pV 3R lpVP                  V4       V# )z
The L{Deferred} returned by L{getProcessOutput} is fired with an
L{IOError} L{Failure} if the child process writes to stderr.
r!   z!sys.stderr.write("hello world\n")r    c                 óX   <€ SP                  V P                  \        P                  4      # ©N)ÚassertFailureÚprocessEndedr   ÚProcessDone)Úerrr   s   &€r   ÚcbFailedÚ?ProcessUtilsTests.test_outputWithErrorIgnored.<locals>.cbFailedL   s"   ø€ Ø×%Ñ% c×&6Ñ&6¼×8IÑ8IÓJÐJr+   )r   r   r#   r$   r/   ÚIOErrorr%   )r   r   r(   r3   s   f   r   Útest_outputWithErrorIgnoredÚ-ProcessUtilsTests.test_outputWithErrorIgnored?   sf   ø€ ð ×(Ñ(ØÐ?Ð@ó
ˆ
ô ×"Ò" 4§8¡8¨d°JÐ-?Ó@ˆØ×Ñ˜q¤'Ó*ˆõ	Kð 	
�‰�hÔØˆr+   c                óª   € V P                  . RO4      p\        P                  ! V P                  RV.RR7      pVP	                  V P
                  R4      # )z²
If a C{True} value is supplied for the C{errortoo} parameter to
L{getProcessOutput}, the returned L{Deferred} fires with the child's
stderr output as well as its stdout output.
r    T)Úerrortoos   foofoo)r!   zsys.stdout.write("foo")úsys.stdout.flush()zsys.stderr.write("foo")úsys.stderr.flush()r"   r'   s   &  r   Útest_outputWithErrorCollectedÚ/ProcessUtilsTests.test_outputWithErrorCollectedR   sO   € ð ×(Ñ(òó

ˆ
ô ×"Ò" 4§8¡8¨d°JÐ-?È$ÔOˆØ�}‰}˜T×-Ñ-¨yÓ9Ð9r+   c                ó¤   € V P                  R.4      p\        P                  ! V P                  RV.4      pVP	                  V P
                  ^4      # )zd
The L{Deferred} returned by L{getProcessValue} is fired with the exit
status of the child process.
zraise SystemExit(1)r    )r   r   ÚgetProcessValuer$   r%   r&   r'   s   &  r   Ú
test_valueÚProcessUtilsTests.test_valueg   sJ   € ð
 ×(Ñ(Ð*?Ð)@ÓAˆ
ä×!Ò! $§(¡(¨T°:Ð,>Ó?ˆØ�}‰}˜T×-Ñ-¨qÓ1Ð1r+   c                óž   a € S P                  . RO4      pV 3R lp\        P                  ! S P                  RV.4      pVP	                  V4      # )zà
The L{Deferred} returned by L{getProcessOutputAndValue} fires with a
three-tuple, the elements of which give the data written to the child's
stdout, the data written to the child's stderr, and the exit status of
the child.
c                 ó~   <€ V w  rpSP                  VR 4       SP                  VR4       SP                  V^4       R# )s   hello world!
s   goodbye world!
N©r&   )Úout_err_codeÚoutr2   Úcoder   s   &   €r   ÚgotOutputAndValueÚ@ProcessUtilsTests.test_outputAndValue.<locals>.gotOutputAndValue�   s>   ø€ Ø)‰NˆC�dØ×Ñ˜SÐ"3Ô4Ø×Ñ˜SÐ"5Ô6Ø×Ñ˜T 1Ö%r+   r    )r!   z*sys.stdout.buffer.write(b'hello world!\n')z,sys.stderr.buffer.write(b'goodbye world!\n')zsys.exit(1)©r   r   ÚgetProcessOutputAndValuer$   r%   ©r   r   rH   r(   s   f   r   Útest_outputAndValueÚ%ProcessUtilsTests.test_outputAndValueq   sL   ø€ ð ×(Ñ(òó
ˆ
õ	&ô ×*Ò*¨4¯8©8°d¸JÐ5GÓHˆØ�}‰}Ð.Ó/Ð/r+   z"Windows doesn't have real signals.c                óÊ   a € S P                  . RO4      pV 3R lp\        P                  ! S P                  RV.4      pS P	                  V\
        4      pVP                  V4      # )zÖ
If the child process exits because of a signal, the L{Deferred}
returned by L{getProcessOutputAndValue} fires a L{Failure} of a tuple
containing the child's stdout, stderr, and the signal which caused
it to exit.
c                 óš   <€ V w  rpSP                  VR 4       SP                  VR4       SP                  V\        P                  4       R# )s   stdout bytes
s   stderr bytes
N)r&   ÚsignalÚSIGKILL)Úout_err_sigrF   r2   Úsigr   s   &   €r   rH   Ú>ProcessUtilsTests.test_outputSignal.<locals>.gotOutputAndValue    sB   ø€ Ø'‰MˆC�cØ×Ñ˜SÐ"3Ô4Ø×Ñ˜SÐ"3Ô4Ø×Ñ˜S¤&§.¡.Ö1r+   r    )zimport sys, os, signalz"sys.stdout.write('stdout bytes\n')z"sys.stderr.write('stderr bytes\n')r:   r;   z$os.kill(os.getpid(), signal.SIGKILL))r   r   rK   r$   r/   Útupler%   rL   s   f   r   Útest_outputSignalÚ#ProcessUtilsTests.test_outputSignalŠ   s^   ø€ ð ×(Ñ(òó	
ˆ
õ	2ô ×*Ò*¨4¯8©8°d¸JÐ5GÓHˆØ×Ñ˜q¤%Ó(ˆØ�}‰}Ð.Ó/Ð/r+   c                óF  € \         P                  P                  V P                  4       4      p\         P                  ! V4       V P                  R R.4      pV! V P                  RV.VR7      pVP                  W#P                  \        P                  ! 4       4      4       V# )úimport os, syszsys.stdout.write(os.getcwd())r    )r   )r   r   r   r   Úmakedirsr   r$   r%   ÚencodeÚsysÚgetfilesystemencoding)r   ÚutilFuncÚcheckÚdirr   r(   s   &&&   r   Ú	_pathTestÚProcessUtilsTests._pathTestª   s{   € Ü�g‰g�o‰o˜dŸk™k›mÓ,ˆÜ
�Š�CÔØ×(Ñ(ØÐ>Ð?ó
ˆ
ñ �T—X‘X  jÐ1¸Ô<ˆØ	�‰�eŸZ™Z¬×(AÒ(AÓ(CÓDÔEØˆr+   c                óV   € V P                  \        P                  V P                  4      # )zg
L{getProcessOutput} runs the given command with the working directory
given by the C{path} parameter.
)rb   r   r#   r&   ©r   s   &r   Útest_getProcessOutputPathÚ+ProcessUtilsTests.test_getProcessOutputPath´   s!   € ð
 �~‰~œe×4Ñ4°d×6FÑ6FÓGÐGr+   c                óP   a € V 3R lpS P                  \        P                  V4      # )zf
L{getProcessValue} runs the given command with the working directory
given by the C{path} parameter.
c                 ó,   <€ SP                  V ^ 4       R# ©é    NrD   ©ÚresultÚignoredr   s   &&€r   r`   Ú9ProcessUtilsTests.test_getProcessValuePath.<locals>.checkÁ   ó   ø€ Ø×Ñ˜V QÖ'r+   )rb   r   r?   ©r   r`   s   f r   Útest_getProcessValuePathÚ*ProcessUtilsTests.test_getProcessValuePath»   s!   ø€ õ	(ð �~‰~œe×3Ñ3°UÓ;Ð;r+   c                óP   a € V 3R lpS P                  \        P                  V4      # )zo
L{getProcessOutputAndValue} runs the given command with the working
directory given by the C{path} parameter.
c                 óX   <€ V w  r#pSP                  W!4       SP                  V^ 4       R# rj   rD   ©Úout_err_statusra   rF   r2   Ústatusr   s   &&   €r   r`   ÚBProcessUtilsTests.test_getProcessOutputAndValuePath.<locals>.checkÌ   ó+   ø€ Ø-ÑˆC�fØ×Ñ˜SÔ&Ø×Ñ˜V QÖ'r+   )rb   r   rK   rq   s   f r   Ú!test_getProcessOutputAndValuePathÚ3ProcessUtilsTests.test_getProcessOutputAndValuePathÆ   s!   ø€ õ	(ð
 �~‰~œe×<Ñ<¸eÓDÐDr+   c                óð  € \         P                  P                  V P                  4       4      p\         P                  ! V4       V P                  . RO4      pV P                  \         P                  \         P                  ! 4       4       \         P                  ! V4       \        P                  ! \         P                  ! R4      P                  4      p\         P                  ! V\        P                  \        P                  ,          4       V P                  \         P                  W54       V! V P                  RV.4      pVP!                  W#P#                  \$        P&                  ! 4       4      4       V# )rZ   Ú.r    )rZ   zcdir = os.getcwd()zsys.stdout.write(cdir))r   r   r   r   r[   r   Ú
addCleanupÚchdirÚgetcwdÚstatÚS_IMODEÚst_modeÚchmodÚS_IXUSRÚS_IRUSRr$   r%   r\   r]   r^   )r   r_   r`   ra   r   ÚoriginalModer(   s   &&&    r   Ú_defaultPathTestÚ"ProcessUtilsTests._defaultPathTestÓ   så   € ä�g‰g�o‰o˜dŸk™k›mÓ,ˆÜ
�Š�CÔà×(Ñ(ÚNó
ˆ
ð
 	�‰œŸ™¤"§)¢)£+Ô.Ü
�Š�Œô —|’|¤B§G¢G¨C£L×$8Ñ$8Ó9ˆô
 	�Š�”d—l‘l¤T§\¡\Õ1Ô2ð
 	�‰œŸ™ #Ô4á�T—X‘X  jÐ1Ó2ˆØ	�‰�eŸZ™Z¬×(AÒ(AÓ(CÓDÔEØˆr+   c                óV   € V P                  \        P                  V P                  4      # )zÙ
If no value is supplied for the C{path} parameter, L{getProcessOutput}
runs the given command in the same working directory as the parent
process and succeeds even if the current working directory is not
accessible.
)r‰   r   r#   r&   re   s   &r   Ú test_getProcessOutputDefaultPathÚ2ProcessUtilsTests.test_getProcessOutputDefaultPathñ   s#   € ð ×$Ñ$¤U×%;Ñ%;¸T×=MÑ=MÓNÐNr+   c                óP   a € V 3R lpS P                  \        P                  V4      # )zØ
If no value is supplied for the C{path} parameter, L{getProcessValue}
runs the given command in the same working directory as the parent
process and succeeds even if the current working directory is not
accessible.
c                 ó,   <€ SP                  V ^ 4       R# rj   rD   rl   s   &&€r   r`   Ú@ProcessUtilsTests.test_getProcessValueDefaultPath.<locals>.check  rp   r+   )r‰   r   r?   rq   s   f r   Útest_getProcessValueDefaultPathÚ1ProcessUtilsTests.test_getProcessValueDefaultPathú   s#   ø€ õ	(ð ×$Ñ$¤U×%:Ñ%:¸EÓBÐBr+   c                óP   a € V 3R lpS P                  \        P                  V4      # )zá
If no value is supplied for the C{path} parameter,
L{getProcessOutputAndValue} runs the given command in the same working
directory as the parent process and succeeds even if the current
working directory is not accessible.
c                 óX   <€ V w  r#pSP                  W!4       SP                  V^ 4       R# rj   rD   rv   s   &&   €r   r`   ÚIProcessUtilsTests.test_getProcessOutputAndValueDefaultPath.<locals>.check  rz   r+   )r‰   r   rK   rq   s   f r   Ú(test_getProcessOutputAndValueDefaultPathÚ:ProcessUtilsTests.test_getProcessOutputAndValueDefaultPath  s#   ø€ õ	(ð
 ×$Ñ$¤U×%CÑ%CÀUÓKÐKr+   c                ó®   a a€ S P                  RR.4      pRo\        P                  ! S P                  RV.SR7      pV V3R lpVP	                  V4       V# )zl
Standard input can be made available to the child process by passing
bytes for the `stdinBytes` parameter.
r!   z"sys.stdout.write(sys.stdin.read())s   These are the bytes to see.r    )Ú
stdinBytesc                 óZ   <€ V w  rpSP                  SV4       SP                  ^ V4       R# rj   )ÚassertInr&   )rE   rF   r2   rG   r   r™   s   &   €€r   rH   ÚPProcessUtilsTests.test_get_processOutputAndValueStdin.<locals>.gotOutputAndValue(  s,   ø€ Ø)‰NˆC�dð �M‰M˜* cÔ*Ø×Ñ˜Q Ö%r+   rJ   )r   r   r(   rH   r™   s   f   @r   Ú#test_get_processOutputAndValueStdinÚ5ProcessUtilsTests.test_get_processOutputAndValueStdin  sb   ù€ ð
 ×(Ñ(àØ4ðó
ˆ
ð 4ˆ
Ü×*Ò*Ø�H‰HØ�:ÐØ!ô
ˆö	&ð 	
�‰Ð'Ô(Øˆr+   © )#Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚIReactorProcessr   ÚskipÚoutputÚvaluer]   Ú
executabler$   r   r)   r6   r<   r@   rM   r   r   Ú	isWindowsrW   rb   rf   rr   r{   r‰   rŒ   r‘   r–   r�   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r   r   r      s³   ø‡ € ñð
 ×!Ò! '¨4Ó0Ò8Ø:ˆà€FØ€EØ
�.‰.€Cò'òAò"ò&:ò*2ò0ñ2 ˆH×ÒÓ Ð"FÓGñ0ó Hð0ò>òHò	<òEòò<OòCòL÷ð r+   r   c                   ó*   a € ] tR tRt o RtR tRtV tR# )ÚSuppressWarningsTestsi4  z&
Tests for L{utils.suppressWarnings}.
c                ód  a€ . oV3R lpV P                  \        RV4       R p\        P                  ! VR	\	        RR7      34      pV! R4       V P                  \        S4      ^4       V! R4       V P                  \        S4      ^4       V! R4       V P                  \        S4      ^4       R# )
z[
L{utils.suppressWarnings} decorates a function so that the given
warnings are suppressed.
c                 ó,   <€ SP                  W34       R # r.   )Úappend)r   ÚaÚkwrm   s   &*,€r   ÚshowwarningÚ@SuppressWarningsTests.test_suppressWarnings.<locals>.showwarning@  s   ø€ Ø�M‰M˜1˜'Ö"r+   r¶   c                 ó2   € \         P                  ! V 4       R # r.   )ÚwarningsÚwarn)Úmsgs   &r   ÚfÚ6SuppressWarningsTests.test_suppressWarnings.<locals>.fE  s   € Ü�MŠM˜#Ör+   zThis is message)ÚmessagezSanity check messagezUnignored messageN)Úignore)Úpatchr¹   r   ÚsuppressWarningsÚdictr&   Úlen)r   r¶   r¼   Úgrm   s   &   @r   Útest_suppressWarningsÚ+SuppressWarningsTests.test_suppressWarnings9  s¢   ø€ ð
 ˆõ	#ð 	�
‰
”8˜]¨KÔ8ò	ô ×"Ò" 1 {´DÐARÔ4SÐ&TÓUˆñ 	
Ð
 Ô!Ø×Ñœ˜V› aÔ(ñ 	
Ð
ÔØ×Ñœ˜V› aÔ(ñ 	
Ð
ÔØ×Ñœ˜V› aÖ(r+   rŸ   N)r    r¡   r¢   r£   r¤   rÅ   r«   r¬   r­   s   @r   r°   r°   4  s   ø‡ € ñ÷)ð )r+   r°   c                   óT   a € ] tR tRt o Rt]! ]P                  4      tR tR t	Rt
V tR# )ÚDeferredSuppressedWarningsTestsiZ  zT
Tests for L{utils.runWithWarningsSuppressed}, the version that supports
Deferreds.
c                óJ  a€ R/ 3R/ 3.p\        4       oV P                  VV3R l4       \        P                  ! R4       SP	                  ^4       \        P                  ! R4       T P                  R.V P                  4        Uu. uF  q"R,          NK  	  up4       R# u upi )z’
If the function called by L{utils.runWithWarningsSuppressed} returns a
C{Deferred}, the warning filters aren't removed until the Deferred
fires.
c                  ó   <€ S # r.   rŸ   ©rm   s   €r   Ú<lambda>ÚGDeferredSuppressedWarningsTests.test_deferredCallback.<locals>.<lambda>l  s   ø€ ¹r+   ú
ignore fooúignore foo 2r¾   N©r¿   z.*foo.*©r¿   z.*bar.*)r   ÚrunWithWarningsSuppressedr¹   rº   Úcallbackr&   ÚflushWarnings)r   ÚfiltersÚwrm   s   &  @r   Útest_deferredCallbackÚ5DeferredSuppressedWarningsTests.test_deferredCallbackd  s‰   ø€ ð *¨2Ð.Ð1FÈÐ0KÐLˆÜ“ˆØ×&Ñ& w´Ô?Ü�Š�lÔ#Ø�‰˜ÔÜ�Š�nÔ%Ø×Ñ˜.Ð)À$×BTÑBTÔBVÓ+WÑBV¸Q¨i¯L¨LÑBVÑ+WÖXùÒ+Ws   ÂB 
c                ó~  a€ R/ 3R/ 3.p\        4       oV P                  VV3R l4      p\        P                  ! R4       SP	                  \        4       4       VP                  R 4       \        P                  ! R4       T P                  R.V P                  4        Uu. uF  q3R,          NK  	  up4       R# u upi )	z¢
If the function called by L{utils.runWithWarningsSuppressed} returns a
C{Deferred}, the warning filters aren't removed until the Deferred
fires with an errback.
c                  ó   <€ S # r.   rŸ   rË   s   €r   rÌ   ÚFDeferredSuppressedWarningsTests.test_deferredErrback.<locals>.<lambda>z  s   ø€ ¹Fr+   rÎ   c                 ó,   € V P                  \        4      # r.   )ÚtrapÚZeroDivisionError)r¼   s   &r   rÌ   rÛ   }  s   € ˜qŸv™vÔ&7Ô8r+   rÏ   r¾   NrÐ   rÑ   )	r   rÒ   r¹   rº   ÚerrbackrÞ   Ú
addErrbackr&   rÔ   )r   rÕ   r(   rÖ   rm   s   &   @r   Útest_deferredErrbackÚ4DeferredSuppressedWarningsTests.test_deferredErrbackr  sœ   ø€ ð *¨2Ð.Ð1FÈÐ0KÐLˆÜ“ˆØ×*Ñ*¨7´NÓCˆÜ�Š�lÔ#Ø�‰Ô(Ó*Ô+Ø	�‰Ñ8Ô9Ü�Š�nÔ%Ø×Ñ˜.Ð)À$×BTÑBTÔBVÓ+WÑBV¸Q¨i¯L¨LÑBVÑ+WÖXùÒ+Ws   Â B:
rŸ   N)r    r¡   r¢   r£   r¤   Ústaticmethodr   rÒ   r×   rá   r«   r¬   r­   s   @r   rÈ   rÈ   Z  s/   ø‡ € ññ !-¨U×-LÑ-LÓ MÐòY÷Yð Yr+   rÈ   )r¤   r   rQ   r‚   r]   r¹   Úunittestr   Útwisted.internetr   r   r   r   Útwisted.internet.deferr   Útwisted.python.runtimer   Útwisted.python.test.test_utilr	   Útwisted.trial.unittestr
   r   r   r°   rÈ   rŸ   r+   r   Ú<module>rê      s\   ðñó
 
Û Û Û 
Û Ý ç >Ó >Ý +Ý +Ý Aß @ôZ˜ô Zôz#)Ð/ô #)ôL%YÐ&=ö %Yr+   