ó
    ×›‘h@5  ã                   óÊ   • S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	J
r
JrJr  SSKJr  SSKJr  SSKJr  SSKJrJr   " S	 S
\5      r " S S\5      r " S S\5      rg)zD
Test running processes with the APIs in L{twisted.internet.utils}.
é    N)ÚskipIf)ÚerrorÚ
interfacesÚreactorÚutils)ÚDeferred)Úplatform)ÚSuppressedWarningsTests)ÚSynchronousTestCaseÚTestCasec                   óú   • \ rS rSrSr\R                  " \S5      c  SrSr	Sr
\R                  rS rS rS rS rS	 rS
 r\" \R,                  " 5       S5      S 5       rS rS rS rS rS rS rS rS rS r Sr!g)ÚProcessUtilsTestsé   zh
Test running a process using L{getProcessOutput}, L{getProcessValue}, and
L{getProcessOutputAndValue}.
Nz)reactor doesn't implement IReactorProcessc                 ó*  • U R                  5       n[        US5       nUR                  [        R                  R                  U5      [        R                  -   5        SSS5        [        R                  R                  U5      $ ! , (       d  f       N-= f)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       Ú\C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/test/test_iutils.pyÚmakeSourceFileÚ ProcessUtilsTests.makeSourceFile$   s`   € ð
 —‘“ˆÜ�&˜$Ô :Ø×ÑœRŸZ™ZŸ_™_¨[Ó9¼B¿J¹JÑFÔG÷  ä�w‰w�‰˜vÓ&Ð&÷  Õús   �A BÂ
Bc                 ó¦   • U R                  / SQ5      n[        R                  " U R                  SU/5      nUR	                  U R
                  S5      $ )z�
L{getProcessOutput} returns a L{Deferred} which fires with the complete
output of the process it runs after that process exits.
)ú
import syszfor s in b'hello world\n':z    s = bytes([s])z    sys.stdout.buffer.write(s)z    sys.stdout.flush()ú-us   hello world
©r   r   ÚgetProcessOutputÚexeÚaddCallbackÚassertEqual©r   r   Úds      r   Útest_outputÚProcessUtilsTests.test_output.   sN   € ð
 ×(Ñ(òó
ˆ
ô ×"Ò" 4§8¡8¨d°JÐ-?Ó@ˆØ�}‰}˜T×-Ñ-Ð/?Ó@Ð@ó    c                 óÎ   ^ • T R                  SS/5      n[        R                  " T R                  SU/5      nT R	                  U[
        5      nU 4S jnUR                  U5        U$ )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   >• TR                  U R                  [        R                  5      $ ©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&   r1   ÚIOErrorr'   )r   r   r*   r5   s   `   r   Útest_outputWithErrorIgnoredÚ-ProcessUtilsTests.test_outputWithErrorIgnored?   sf   ø€ ð ×(Ñ(ØÐ?Ð@ó
ˆ
ô ×"Ò" 4§8¡8¨d°JÐ-?Ó@ˆØ×Ñ˜q¤'Ó*ˆõ	Kð 	
�‰�hÔØˆr-   c                 ó¤   • U R                  / SQ5      n[        R                  " U R                  SU/SS9nUR	                  U R
                  S5      $ )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"   zsys.stdout.write("foo")úsys.stdout.flush()zsys.stderr.write("foo")úsys.stderr.flush()r#   T)Úerrortoos   foofoor$   r)   s      r   Útest_outputWithErrorCollectedÚ/ProcessUtilsTests.test_outputWithErrorCollectedR   sO   € ð ×(Ñ(òó

ˆ
ô ×"Ò" 4§8¡8¨d°JÐ-?È$ÑOˆØ�}‰}˜T×-Ñ-¨yÓ9Ð9r-   c                 ó¤   • U R                  S/5      n[        R                  " U R                  SU/5      nUR	                  U R
                  S5      $ )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                 óž   ^ • T R                  / SQ5      nU 4S jn[        R                  " T R                  SU/5      nUR	                  U5      $ )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.
)r"   z*sys.stdout.buffer.write(b'hello world!\n')z,sys.stderr.buffer.write(b'goodbye world!\n')zsys.exit(1)c                 ó|   >• U u  pnTR                  US5        TR                  US5        TR                  US5        g )Ns   hello world!
s   goodbye world!
rA   ©r(   )Úout_err_codeÚoutr4   Úcoder   s       €r   ÚgotOutputAndValueÚ@ProcessUtilsTests.test_outputAndValue.<locals>.gotOutputAndValue�   s>   ø€ Ø)‰NˆC�dØ×Ñ˜SÐ"3Ô4Ø×Ñ˜SÐ"5Ô6Ø×Ñ˜T 1Õ%r-   r#   ©r   r   ÚgetProcessOutputAndValuer&   r'   ©r   r   rK   r*   s   `   r   Útest_outputAndValueÚ%ProcessUtilsTests.test_outputAndValueq   sL   ø€ ð ×(Ñ(òó
ˆ
õ	&ô ×*Ò*¨4¯8©8°d¸JÐ5GÓHˆØ�}‰}Ð.Ó/Ð/r-   z"Windows doesn't have real signals.c                 óÊ   ^ • T R                  / SQ5      nU 4S jn[        R                  " T R                  SU/5      nT R	                  U[
        5      nUR                  U5      $ )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.
)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)c                 ó˜   >• U u  pnTR                  US5        TR                  US5        TR                  U[        R                  5        g )Ns   stdout bytes
s   stderr bytes
)r(   ÚsignalÚSIGKILL)Úout_err_sigrI   r4   Úsigr   s       €r   rK   Ú>ProcessUtilsTests.test_outputSignal.<locals>.gotOutputAndValue    sB   ø€ Ø'‰MˆC�cØ×Ñ˜SÐ"3Ô4Ø×Ñ˜SÐ"3Ô4Ø×Ñ˜S¤&§.¡.Õ1r-   r#   )r   r   rN   r&   r1   Útupler'   rO   s   `   r   Útest_outputSignalÚ#ProcessUtilsTests.test_outputSignalŠ   s^   ø€ ð ×(Ñ(òó	
ˆ
õ	2ô ×*Ò*¨4¯8©8°d¸JÐ5GÓHˆØ×Ñ˜q¤%Ó(ˆØ�}‰}Ð.Ó/Ð/r-   c                 ó@  • [         R                  R                  U R                  5       5      n[         R                  " U5        U R                  SS/5      nU" U R                  SU/US9nUR                  X#R                  [        R                  " 5       5      5        U$ )Nú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   • U R                  [        R                  U R                  5      $ )zg
L{getProcessOutput} runs the given command with the working directory
given by the C{path} parameter.
)re   r   r%   r(   ©r   s    r   Útest_getProcessOutputPathÚ+ProcessUtilsTests.test_getProcessOutputPath´   s!   € ð
 �~‰~œe×4Ñ4°d×6FÑ6FÓGÐGr-   c                 óP   ^ • U 4S jnT R                  [        R                  U5      $ )zf
L{getProcessValue} runs the given command with the working directory
given by the C{path} parameter.
c                 ó*   >• TR                  U S5        g ©Nr   rG   ©ÚresultÚignoredr   s     €r   rc   Ú9ProcessUtilsTests.test_getProcessValuePath.<locals>.checkÁ   ó   ø€ Ø×Ñ˜V QÕ'r-   )re   r   rB   ©r   rc   s   ` r   Útest_getProcessValuePathÚ*ProcessUtilsTests.test_getProcessValuePath»   s!   ø€ õ	(ð �~‰~œe×3Ñ3°UÓ;Ð;r-   c                 óP   ^ • U 4S jnT R                  [        R                  U5      $ )zo
L{getProcessOutputAndValue} runs the given command with the working
directory given by the C{path} parameter.
c                 óV   >• U u  p#nTR                  X!5        TR                  US5        g rm   rG   ©Úout_err_statusrd   rI   r4   Ústatusr   s        €r   rc   ÚBProcessUtilsTests.test_getProcessOutputAndValuePath.<locals>.checkÌ   ó+   ø€ Ø-ÑˆC�fØ×Ñ˜SÔ&Ø×Ñ˜V QÕ'r-   )re   r   rN   rs   s   ` r   Ú!test_getProcessOutputAndValuePathÚ3ProcessUtilsTests.test_getProcessOutputAndValuePathÆ   s!   ø€ õ	(ð
 �~‰~œe×<Ñ<¸eÓDÐDr-   c                 óè  • [         R                  R                  U R                  5       5      n[         R                  " U5        U R                  / SQ5      nU R                  [         R                  [         R                  " 5       5        [         R                  " U5        [        R                  " [         R                  " S5      R                  5      n[         R                  " U[        R                  [        R                  -  5        U R                  [         R                  X55        U" U R                  SU/5      nUR!                  X#R#                  [$        R&                  " 5       5      5        U$ )N)r]   zcdir = os.getcwd()zsys.stdout.write(cdir)Ú.r#   )r   r   r   r   r^   r   Ú
addCleanupÚchdirÚgetcwdÚstatÚS_IMODEÚst_modeÚchmodÚS_IXUSRÚS_IRUSRr&   r'   r_   r`   ra   )r   rb   rc   rd   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   • U R                  [        R                  U R                  5      $ )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(   rh   s    r   Ú test_getProcessOutputDefaultPathÚ2ProcessUtilsTests.test_getProcessOutputDefaultPathñ   s#   € ð ×$Ñ$¤U×%;Ñ%;¸T×=MÑ=MÓNÐNr-   c                 óP   ^ • U 4S jnT R                  [        R                  U5      $ )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                 ó*   >• TR                  U S5        g rm   rG   rn   s     €r   rc   Ú@ProcessUtilsTests.test_getProcessValueDefaultPath.<locals>.check  rr   r-   )r‹   r   rB   rs   s   ` r   Útest_getProcessValueDefaultPathÚ1ProcessUtilsTests.test_getProcessValueDefaultPathú   s#   ø€ õ	(ð ×$Ñ$¤U×%:Ñ%:¸EÓBÐBr-   c                 óP   ^ • U 4S jnT R                  [        R                  U5      $ )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                 óV   >• U u  p#nTR                  X!5        TR                  US5        g rm   rG   rx   s        €r   rc   ÚIProcessUtilsTests.test_getProcessOutputAndValueDefaultPath.<locals>.check  r|   r-   )r‹   r   rN   rs   s   ` r   Ú(test_getProcessOutputAndValueDefaultPathÚ:ProcessUtilsTests.test_getProcessOutputAndValueDefaultPath  s#   ø€ õ	(ð
 ×$Ñ$¤U×%CÑ%CÀUÓKÐKr-   c                 ó¨   ^ ^• T R                  SS/5      nSm[        R                  " T R                  SU/TS9nU U4S jnUR	                  U5        U$ )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                 óX   >• U u  pnTR                  TU5        TR                  SU5        g rm   )ÚassertInr(   )rH   rI   r4   rJ   r   r›   s       €€r   rK   ÚPProcessUtilsTests.test_get_processOutputAndValueStdin.<locals>.gotOutputAndValue(  s,   ø€ Ø)‰NˆC�dð �M‰M˜* cÔ*Ø×Ñ˜Q Õ%r-   rM   )r   r   r*   rK   r›   s   `   @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+   r8   r>   rC   rP   r   r	   Ú	isWindowsrZ   re   ri   rt   r}   r‹   rŽ   r“   r˜   rŸ   Ú__static_attributes__r¡   r-   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                   ó   • \ rS rSrSrS rSrg)ÚSuppressWarningsTestsi4  z&
Tests for L{utils.suppressWarnings}.
c                 ó\  ^• / mU4S jnU R                  [        SU5        S n[        R                  " US[	        SS945      nU" S5        U R                  [        T5      S5        U" S5        U R                  [        T5      S5        U" S	5        U R                  [        T5      S
5        g)z[
L{utils.suppressWarnings} decorates a function so that the given
warnings are suppressed.
c                 ó*   >• TR                  X45        g r0   )Úappend)r   ÚaÚkwro   s      €r   ÚshowwarningÚ@SuppressWarningsTests.test_suppressWarnings.<locals>.showwarning@  s   ø€ Ø�M‰M˜1˜'Õ"r-   rµ   c                 ó0   • [         R                  " U 5        g r0   )ÚwarningsÚwarn)Úmsgs    r   ÚfÚ6SuppressWarningsTests.test_suppressWarnings.<locals>.fE  s   € Ü�MŠM˜#Õr-   )ÚignorezThis is message)ÚmessagezSanity check messagerA   zUnignored messageé   N)Úpatchr¸   r   ÚsuppressWarningsÚdictr(   Úlen)r   rµ   r»   Úgro   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-   r   r¯   r¯   4  s   † ñõ)r-   r¯   c                   óH   • \ rS rSrSr\" \R                  5      rS rS r	Sr
g)ÚDeferredSuppressedWarningsTestsiZ  zT
Tests for L{utils.runWithWarningsSuppressed}, the version that supports
Deferreds.
c                 óB  ^• S0 4S0 4/n[        5       mU R                  UU4S j5        [        R                  " S5        TR	                  S5        [        R                  " S5        U R                  S/U R                  5        Vs/ s H  o"S   PM	     sn5        gs  snf )	z’
If the function called by L{utils.runWithWarningsSuppressed} returns a
C{Deferred}, the warning filters aren't removed until the Deferred
fires.
©r½   z.*foo.*©r½   z.*bar.*c                  ó   >• T $ r0   r¡   ©ro   s   €r   Ú<lambda>ÚGDeferredSuppressedWarningsTests.test_deferredCallback.<locals>.<lambda>l  s   ø€ ¹r-   ú
ignore fooé   úignore foo 2r¾   N)r   ÚrunWithWarningsSuppressedr¸   r¹   Úcallbackr(   ÚflushWarnings)r   ÚfiltersÚwro   s      @r   Útest_deferredCallbackÚ5DeferredSuppressedWarningsTests.test_deferredCallbackd  s‡   ø€ ð *¨2Ð.Ð1FÈÐ0KÐLˆÜ“ˆØ×&Ñ& w´Ô?Ü�Š�lÔ#Ø�‰˜ÔÜ�Š�nÔ%Ø×Ñ˜.Ð)À$×BTÑBTÔBVÓ+WÒBV¸Q¨i¬LÑBVÑ+WÕXùÒ+Ws   ÂB
c                 óv  ^• S0 4S0 4/n[        5       mU R                  UU4S j5      n[        R                  " S5        TR	                  [        5       5        UR                  S 5        [        R                  " S5        U R                  S/U R                  5        Vs/ s H  o3S   PM	     sn5        gs  snf )	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.
rÊ   rË   c                  ó   >• T $ r0   r¡   rÍ   s   €r   rÎ   ÚFDeferredSuppressedWarningsTests.test_deferredErrback.<locals>.<lambda>z  s   ø€ ¹Fr-   rÐ   c                 ó,   • U R                  [        5      $ r0   )ÚtrapÚZeroDivisionError)r»   s    r   rÎ   rÜ   }  s   € ˜qŸv™vÔ&7Ô8r-   rÒ   r¾   N)	r   rÓ   r¸   r¹   Úerrbackrß   Ú
addErrbackr(   rÕ   )r   rÖ   r*   r×   ro   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ÑBVÑ+WÕXùÒ+Ws   Â B6
r¡   N)r¢   r£   r¤   r¥   r¦   Ústaticmethodr   rÓ   rØ   râ   r­   r¡   r-   r   rÈ   rÈ   Z  s&   † ññ !-¨U×-LÑ-LÓ MÐòYõYr-   rÈ   )r¦   r   rT   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-   