ó
    ×›‘h$! ã                   óV  • 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r SSKrSSK	r
\
r	\rSSKJr  SSKJr  SSKJr  SSKJr  SSKJrJrJr  SSK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K%J&r&  SSK'J(r(  SSK)J*r*J+r+J,r,  SSK-J.r.  SSK/J0r0  SSK1J2r2  SSK3J*r4J5r5  SSK6J7r7  SSK8J9r9  SSK:J;r;  SSK<J=r=  SSK>J?r?  SSK@JArA  \7" S5      rB\B(       a
  SSKCJDrDJErEJFrF  \7" S5      rG\7" S5      rH\7" S5      rI\7" S5      rJS  rK " S! S"5      rL " S# S$\Rš                  5      rN " S% S&\=Rž                  5      rP " S' S(\A5      rQ\" \B(       + S)5       " S* S+\A5      5       rR " S, S-\A5      rS " S. S/5      rT " S0 S1\Rª                  5      rV " S2 S3\A5      rW\" \B(       + S)5       " S4 S5\A5      5       rX\" \B(       + S)5       " S6 S7\A5      5       rY\" \B(       + S)5       " S8 S9\A5      5       rZ " S: S;5      r[\" \#5       " S< S=\[5      5       r\ " S> S?5      r] " S@ SA\A5      r^SB r_SC r` " SD SE\A5      ra\" \B(       + S)5       " SF SG\A5      5       rb\" \B(       + SH5       " SI SJ\A5      5       rc\" \$5       " SK SL\(5      5       rd " SM SN\=Rž                  5      reSO rf " SP SQ\A5      rgg! \ a    Sr	Sr GNf = f)RzE
Tests for L{twisted.application.app} and L{twisted.scripts.twistd}.
é    N)ÚStringIO)ÚskipIf)Úimplementer)ÚverifyObject)ÚinternetÚloggerÚplugin)ÚappÚreactorsÚservice)ÚIServiceMaker)ÚReactorBase)ÚDeferred)ÚIReactorDaemonizeÚ_ISupportsExitSignalCapturing)ÚAlternateReactor)ÚMemoryReactor)ÚILogObserverÚglobalLogBeginnerÚglobalLogPublisher)Úutil)ÚComponentized)ÚUserDatabase)r   ÚtextFromEventDict)ÚrequireModule)ÚplatformType)Ú
UsageError)Útwistd)ÚMockOS)ÚTestCaseztwisted.scripts._twistd_unix)ÚUnixApplicationRunnerÚUnixAppLoggerÚcheckPIDztwisted.python.syslogÚprofileÚpstatsÚcProfilec           	      óÆ  ^^^• [         R                  [        R                  " 5       5      n[        R                  [        R                  " 5       5      m[        5       nUR                  XR                  UTUR                  UR                  UR                  5        UUU4S jnU " [         SUR                  5        U " [        SU5        U " [         SUR                  5        g)a=  
Patch L{pwd.getpwnam} so that it behaves as though only one user exists
and patch L{grp.getgrnam} so that it behaves as though only one group
exists.

@param patch: A function like L{TestCase.patch} which will be used to
    install the fake implementations.

@type user: C{str}
@param user: The name of the single user which will exist.

@type uid: C{int}
@param uid: The UID of the single user which will exist.

@type group: C{str}
@param group: The name of the single user which will exist.

@type gid: C{int}
@param gid: The GID of the single group which will exist.
c                 ó²   >• [        T5      nTXR                  TR                  5      '   TXR                  TR                  5      '   [	        U5      nTU0U    $ ©N)ÚlistÚindexÚgr_nameÚgr_gidÚtuple)ÚnameÚresultÚgidÚgrentÚgroups     €€€Ú\C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/test/test_twistd.pyÚgetgrnamÚ#patchUserDatabase.<locals>.getgrnamd   sN   ø€ Ü�e“ˆØ.3ˆ�|‰|˜EŸM™MÓ*Ñ+Ø-0ˆ�|‰|˜EŸL™LÓ)Ñ*Ü�v“ˆØ�vˆ˜tÑ$Ð$ó    Úgetpwnamr5   ÚgetpwuidN)Úpwdr9   ÚosÚgetuidÚgrpÚgetgrgidÚgetgidr   ÚaddUserÚ	pw_passwdÚpw_gecosÚpw_dirÚpw_shellr8   )	ÚpatchÚuserÚuidr3   r1   ÚpwentÚdatabaser5   r2   s	      ``   @r4   ÚpatchUserDatabaserJ   C   s–   ú€ ô2 �L‰LœŸš›Ó%€EÜ�L‰LœŸš›Ó%€Eä‹~€HØ×ÑØ�o‰o˜s C¨¯©¸¿¹ÀuÇ~Á~ô÷%ñ 
Œ#ˆz˜8×,Ñ,Ô-Ù	Œ#ˆz˜8Ô$Ù	Œ#ˆz˜8×,Ñ,Õ-r7   c                   ó"   • \ rS rSrSrSrS rSrg)ÚMockServiceMakerép   zG
A non-implementation of L{twisted.application.service.IServiceMaker}.
Úueoac                 óZ   • Xl         [        R                  " 5       U l        U R                  $ )zM
Take a L{usage.Options} instance and return a
L{service.IService} provider.
)Úoptionsr   ÚService©ÚselfrP   s     r4   ÚmakeServiceÚMockServiceMaker.makeServicew   s!   € ð
 ŒÜ—’Ó(ˆŒØ�|‰|Ðr7   )rP   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚtapnamerT   Ú__static_attributes__© r7   r4   rL   rL   p   s   † ñð €Gõr7   rL   c                   ó   • \ rS rSrSrS rSrg)ÚCrippledAppLoggeré�   z"
@see: CrippledApplicationRunner.
c                 ó   • g r)   r]   ©rS   Úapplications     r4   ÚstartÚCrippledAppLogger.start†   ó   € Ør7   r]   N)rV   rW   rX   rY   rZ   rd   r\   r]   r7   r4   r_   r_   �   s   † ñõr7   r_   c                   ó(   • \ rS rSrSr\rS rS rSr	g)ÚCrippledApplicationRunneréŠ   z³
An application runner that cripples the platform-specific runner and
nasty side-effect-having code so that we can use it without actually
running any environment-affecting code.
c                 ó   • g r)   r]   ©rS   s    r4   ÚpreApplicationÚ(CrippledApplicationRunner.preApplication“   rf   r7   c                 ó   • g r)   r]   rk   s    r4   ÚpostApplicationÚ)CrippledApplicationRunner.postApplication–   rf   r7   r]   N)
rV   rW   rX   rY   rZ   r_   ÚloggerFactoryrl   ro   r\   r]   r7   r4   rh   rh   Š   s   † ñð &€Mòõr7   rh   c                   óÆ   • \ rS rSrSrS rS rS rS rS r	\
" \(       + S5      S	 5       r\
" \(       + S5      S
 5       r\
" \(       + S5      S 5       rS rS rS rS rSrg)ÚServerOptionsTestséš   zL
Non-platform-specific tests for the platform-specific ServerOptions class.
c                 ó(  ^ ^^^^•  " S S5      nU" S5      mU" S5      mU" S5      mU" S5      mUUUUU 4S jn[         R                  " 5       nT R                  UR                  [        R
                  5        X#l        UR                  nTTTT/n[        XE5       Hs  u  pgUu  p‰p«T R                  X‡R                  5        T R                  U	5        T R                  U
" 5       UR                  5      4  T R                  X·R                  5        Mu     g)	zP
subCommands is built from IServiceMaker plugins, and is sorted
alphabetically.
c                   ó    • \ rS rSrS rS rSrg)Ú7ServerOptionsTests.test_subCommands.<locals>.FakePluginé¥   c                 ó8   • Xl         SU-   U l        SU-   U l        g )Nzoptions for údescription of )r[   Ú_optionsÚdescription©rS   r/   s     r4   Ú__init__Ú@ServerOptionsTests.test_subCommands.<locals>.FakePlugin.__init__¦   s    € Ø#”Ø .°Ñ 5�”Ø#4°tÑ#;�Õ r7   c                 ó   • U R                   $ r)   )r{   rk   s    r4   rP   Ú?ServerOptionsTests.test_subCommands.<locals>.FakePlugin.options«   s   € Ø—}‘}Ð$r7   )r{   r|   r[   N)rV   rW   rX   rY   r~   rP   r\   r]   r7   r4   Ú
FakePluginrw   ¥   s   † ò<õ
%r7   r‚   ÚappleÚbananaÚcoconutÚdonutc              3   óZ   >#   • TR                  U [        5        Tv •  Tv •  Tv •  Tv •  g 7fr)   )ÚassertEqualr   )Ú	interfacerƒ   r„   r…   r†   rS   s    €€€€€r4   Ú
getPluginsÚ7ServerOptionsTests.test_subCommands.<locals>.getPlugins³   s*   øé € Ø×Ñ˜Y¬Ô6ØŠMØŠLØŠKØ‹Kùs   ƒ(+N)r   ÚServerOptionsrˆ   Ú_getPluginsr	   rŠ   ÚsubCommandsÚzipr[   ÚassertIsNoner{   r|   )rS   r‚   rŠ   ÚconfigrŽ   ÚexpectedOrderÚ
subCommandÚexpectedCommandr/   ÚshortcutÚparserClassÚdocumentationrƒ   r„   r…   r†   s   `           @@@@r4   Útest_subCommandsÚ#ServerOptionsTests.test_subCommandsŸ   sü   ü€ ÷	%ñ 	%ñ ˜7Ó#ˆÙ˜HÓ%ˆÙ˜YÓ'ˆÙ˜7Ó#ˆ÷	ñ 	ô ×%Ò%Ó'ˆØ×Ñ˜×+Ñ+¬V×->Ñ->Ô?Ø'Ôð ×(Ñ(ˆØ ¨°Ð7ˆä+.¨{Ö+JÑ'ˆJØ9CÑ6ˆD˜KØ×Ñ˜T×#:Ñ#:Ô;Ø×Ñ˜hÔ'Ø×Ñ™[›]¨O×,DÑ,DÓEÑFØ×Ñ˜]×,GÑ,GÖHò ,Kr7   c                 ód  ^ ^^^^	^
^•  " S S5      nU" S5      mU" S5      mU" S5      mU" S5      m	UUUU	4S jn[         R                  " 5       nT R                  UR                  [        R
                  5        X#l        [        5       Ul        T R                  [        UR                  S/5        UR                  R                  5       m
/ mTTTT	4 H/  nU
UU 4S	 jnU" UR                  5        U" UR                  5        M1     T R                  T[        T5      S
R                  T
5      5        g)z@
Reactor names are listed alphabetically by I{--help-reactors}.
c                   ó   • \ rS rSrS rSrg)ÚGServerOptionsTests.test_sortedReactorHelp.<locals>.FakeReactorInstalleréÏ   c                 ó:   • SU-   U l         SU-   U l        SU l        g )Nzname of rz   ztwisted.internet.default)Ú	shortNamer|   Ú
moduleNamer}   s     r4   r~   ÚPServerOptionsTests.test_sortedReactorHelp.<locals>.FakeReactorInstaller.__init__Ð   s"   € Ø!+¨dÑ!2�”Ø#4°tÑ#;�Ô Ø"<�•r7   )r|   r    rŸ   N)rV   rW   rX   rY   r~   r\   r]   r7   r4   ÚFakeReactorInstallerrœ   Ï   s   † õ=r7   r¢   rƒ   r„   r…   r†   c               3   ó.   >#   • Tv •  Tv •  Tv •  T v •  g 7fr)   r]   )rƒ   r„   r…   r†   s   €€€€r4   ÚgetReactorTypesÚBServerOptionsTests.test_sortedReactorHelp.<locals>.getReactorTypesÚ   s   øé € ØŠMØŠLØŠKØ‹Kùs   ƒz--help-reactorsc                 ój   >• TR                  U T5        TR                  TR                  U 5      5        g r)   )ÚassertInÚappendr+   )ÚsÚ
helpOutputÚindexesrS   s    €€€r4   ÚgetIndexÚ;ServerOptionsTests.test_sortedReactorHelp.<locals>.getIndexê   s(   ø€ Ø—‘˜a Ô,Ø—‘˜z×/Ñ/°Ó2Õ3r7   z9reactor descriptions were not in alphabetical order: {!r}N)r   rŒ   rˆ   Ú_getReactorTypesr   r¤   r   ÚmessageOutputÚassertRaisesÚ
SystemExitÚparseOptionsÚgetvaluerŸ   r|   ÚsortedÚformat)rS   r¢   r¤   r‘   Úreactorr¬   rƒ   r„   r…   r†   rª   r«   s   `     @@@@@@r4   Útest_sortedReactorHelpÚ)ServerOptionsTests.test_sortedReactorHelpÊ   s  þ€ ÷
	=ñ 	=ñ % WÓ-ˆÙ% hÓ/ˆÙ& yÓ1ˆÙ$ WÓ-ˆ÷	ð 	ô ×%Ò%Ó'ˆØ×Ñ˜×0Ñ0´(×2JÑ2JÔKØ"1ÔÜ'›zˆÔà×Ñœ* f×&9Ñ&9Ð<MÐ;NÔOØ×)Ñ)×2Ñ2Ó4ˆ
ØˆØ˜f g¨uÓ4ˆG÷4ñ �W×&Ñ&Ô'Ù�W×(Ñ(Ö)ñ 5ð 	×ÑØÜ�7‹OØG×NÑNØóõ	
r7   c                 ó„   • [         R                  " 5       nSUl        UR                  5         U R	                  US   5        g)zC
postOptions should set no_save to True when a subcommand is used.
rN   Úno_saveN)r   rŒ   r“   ÚpostOptionsÚ
assertTrue©rS   r‘   s     r4   Ú&test_postOptionsSubCommandCausesNoSaveÚ9ServerOptionsTests.test_postOptionsSubCommandCausesNoSaveù   s7   € ô ×%Ò%Ó'ˆØ"ˆÔØ×ÑÔØ�‰˜˜yÑ)Õ*r7   c                 óv   • [         R                  " 5       nUR                  5         U R                  US   5        g)zB
If no sub command is used, postOptions should not touch no_save.
rº   N)r   rŒ   r»   ÚassertFalser½   s     r4   Ú(test_postOptionsNoSubCommandSavesAsUsualÚ;ServerOptionsTests.test_postOptionsNoSubCommandSavesAsUsual  s1   € ô ×%Ò%Ó'ˆØ×ÑÔØ×Ñ˜ 	Ñ*Õ+r7   c                 ó¨   • [         R                  " 5       n[        U5      n[        R                  R
                   H  nU R                  X25        M     g)zY
All the profilers that can be used in L{app.AppProfiler} are listed in
the help output.
N)r   rŒ   Ústrr
   ÚAppProfilerÚ	profilersr§   )rS   r‘   rª   Úprofilers       r4   Útest_listAllProfilersÚ(ServerOptionsTests.test_listAllProfilers
  s;   € ô
 ×%Ò%Ó'ˆÜ˜“[ˆ
ÜŸ™×1Ô1ˆHØ�M‰M˜(Ö/ò 2r7   útwistd unix not availablec                 óV   • [         R                  " 5       nU R                  US   5        g)z7
The default value for the C{umask} option is L{None}.
ÚumaskN)r   rŒ   r�   r½   s     r4   Útest_defaultUmaskÚ$ServerOptionsTests.test_defaultUmask  s$   € ô
 ×%Ò%Ó'ˆØ×Ñ˜& ™/Õ*r7   c                 óÎ   • [         R                  " 5       nUR                  SS/5        U R                  US   S5        UR                  SS/5        U R                  US   S5        g)zP
The value given for the C{umask} option is parsed as an octal integer
literal.
ú--umaskÚ123rÍ   éS   Ú0123N)r   rŒ   r²   rˆ   r½   s     r4   Ú
test_umaskÚServerOptionsTests.test_umask  s`   € ô ×%Ò%Ó'ˆØ×Ñ˜Y¨Ð.Ô/Ø×Ñ˜ ™¨"Ô-Ø×Ñ˜Y¨Ð/Ô0Ø×Ñ˜ ™¨"Õ-r7   c                 ót   • [         R                  " 5       nU R                  [        UR                  SS/5        g)z�
If a value is given for the C{umask} option which cannot be parsed as
an integer, L{UsageError} is raised by L{ServerOptions.parseOptions}.
rÑ   ÚabcdefN)r   rŒ   r°   r   r²   r½   s     r4   Útest_invalidUmaskÚ$ServerOptionsTests.test_invalidUmask(  s/   € ô ×%Ò%Ó'ˆØ×Ñœ* f×&9Ñ&9¸IÀxÐ;PÕQr7   c                 ó  • [         R                  " 5       nU R                  [        UR                  SS/5      nU R                  UR                  S   R                  S5      5        U R                  SUR                  S   5        g)zA
C{--logger} with an unimportable module raises a L{UsageError}.
ú--loggerzno.such.module.I.hoper   zeLogger 'no.such.module.I.hope' could not be imported: 'no.such.module.I.hope' does not name an objectÚ
N©	r   rŒ   r°   r   r²   r¼   ÚargsÚ
startswithÚassertNotIn©rS   r‘   Úes      r4   Ú&test_unimportableConfiguredLogObserverÚ9ServerOptionsTests.test_unimportableConfiguredLogObserver1  sy   € ô ×%Ò%Ó'ˆØ×ÑÜ˜×+Ñ+¨jÐ:QÐ-Ró
ˆð 	�‰Ø�F‰F�1‰I× Ñ ðBóô	
ð 	×Ñ˜˜qŸv™v a™yÕ)r7   c                 ó  • [         R                  " 5       nU R                  [        UR                  SS/5      nU R                  UR                  S   R                  S5      5        U R                  SUR                  S   5        g)z@
C{--logger} with a non-existent object raises a L{UsageError}.
rÜ   ztwisted.test.test_twistd.FOOBARr   z{Logger 'twisted.test.test_twistd.FOOBAR' could not be imported: module 'twisted.test.test_twistd' has no attribute 'FOOBAR'rÝ   NrÞ   râ   s      r4   Ú*test_badAttributeWithConfiguredLogObserverÚ=ServerOptionsTests.test_badAttributeWithConfiguredLogObserverA  sz   € ô ×%Ò%Ó'ˆØ×ÑÜØ×ÑØÐ:Ð;ó
ˆð
 	�‰Ø�F‰F�1‰I× Ñ ð,óô	
ð 	×Ñ˜˜qŸv™v a™yÕ)r7   c                 ór  • SSK Jn  [        S:X  a  SnOSnSR                  X!R                  UR                  5      n[        5       n[        R                  " US9nU R                  [        UR                  S/5      nU R                  UR                  S	5        U R                  UR                  5       U5        g	)
z"
C{--version} prints the version.
r   )Ú	copyrightÚwin32z(the Twisted Windows runner)z(the Twisted daemon)ztwistd {} {}
{}
©Ústdoutz	--versionN)Útwistedrê   r   rµ   Úversionr   r   rŒ   r°   r±   r²   ÚassertIsÚcoderˆ   r³   )rS   rê   r/   ÚexpectedOutputrí   r‘   rã   s          r4   Útest_versionÚServerOptionsTests.test_versionT  s˜   € õ 	&ä˜7Ó"Ø1‰Dà)ˆDØ-×4Ñ4Ø×#Ñ# Y×%8Ñ%8ó
ˆô “ˆÜ×%Ò%¨VÑ4ˆØ×Ñœj¨&×*=Ñ*=À¸}ÓMˆØ�‰�a—f‘f˜dÔ#Ø×Ñ˜Ÿ™Ó*¨NÕ;r7   c                 ó„   • [        5       n[        R                  " US9nU R                  [        UR
                  S/5        g)z9
Command is printed when an invalid option is requested.
rì   z	web --fooN)r   r   rŒ   r°   r   r²   )rS   rí   r‘   s      r4   Ú!test_printSubCommandForUsageErrorÚ4ServerOptionsTests.test_printSubCommandForUsageErrorh  s5   € ô “ˆÜ×%Ò%¨VÑ4ˆà×Ñœ* f×&9Ñ&9¸K¸=ÕIr7   r]   N)rV   rW   rX   rY   rZ   r˜   r·   r¾   rÂ   rÉ   r   Ú_twistd_unixrÎ   rÕ   rÙ   rä   rç   ró   rö   r\   r]   r7   r4   rs   rs   š   s—   † ñò)IòV-
ò^+ò,ò0ñ �ÔÐ9Ó:ñ+ó ;ð+ñ �ÔÐ9Ó:ñ	.ó ;ð	.ñ �ÔÐ9Ó:ñRó ;ðRò*ò *ò&<õ(Jr7   rs   rË   c                   ó6   • \ rS rSrSrS rS rS rS rS r	Sr
g	)
ÚCheckPIDTestsir  z
Tests for L{checkPID}.
c                 ó^   • U R                  [        R                  SS 5        [        S5        g)z'
Nonexistent PID file is not an error.
Úexistsc                 ó   • g©NFr]   )Ú_s    r4   Ú<lambda>Ú.CheckPIDTests.test_notExists.<locals>.<lambda>|  s   € °r7   znon-existent PID fileN)rE   r;   Úpathr#   rk   s    r4   Útest_notExistsÚCheckPIDTests.test_notExistsx  s!   € ð 	�
‰
”2—7‘7˜H¡oÔ6ÜÐ(Õ)r7   c                 ó   • U R                  5       n[        US5       nUR                  S5        SSS5        U R                  [        [
        U5      nU R                  SUR                  5        g! , (       d  f       NF= f)z9
Non-numeric content in a PID file causes a system exit.
Úwznon-numericNznon-numeric value)ÚmktempÚopenÚwriter°   r±   r#   r§   rñ   )rS   ÚpidfileÚfrã   s       r4   Útest_nonNumericÚCheckPIDTests.test_nonNumeric  s\   € ð —+‘+“-ˆÜ�'˜3Ô 1Ø�G‰G�MÔ"÷  à×Ñœj¬(°GÓ<ˆØ�‰Ð)¨1¯6©6Õ2÷  Õús   �A/Á/
A=c                 ó4  • U R                  5       n[        US5       nUR                  S5        SSS5        S nU R                  [        SU5        U R                  [        [        U5      nU R                  SUR                  5        g! , (       d  f       N`= f)z5
Another running twistd server causes a system exit.
r  Ú42Nc                 ó   • g r)   r]   ©ÚpidÚsigs     r4   ÚkillÚ/CheckPIDTests.test_anotherRunning.<locals>.kill‘  s   € Ør7   r  zAnother twistd server)
r  r  r	  rE   r;   r°   r±   r#   r§   rñ   ©rS   r
  r  r  rã   s        r4   Útest_anotherRunningÚ!CheckPIDTests.test_anotherRunning‰  sr   € ð —+‘+“-ˆÜ�'˜3Ô 1Ø�G‰G�DŒM÷  ò	ð 	�
‰
”2�v˜tÔ$Ø×Ñœj¬(°GÓ<ˆØ�‰Ð-¨q¯v©vÕ6÷  Õús   �B	Â	
Bc                 óv  • U R                  5       n[        US5       nUR                  [        [        R
                  " 5       S-   5      5        SSS5        S nU R                  [        SU5        [        U5        U R                  [        R                  R                  U5      5        g! , (       d  f       Nb= f)z:
Stale PID file is removed without causing a system exit.
r  é   Nc                 ó6   • [        [        R                  S5      e©NÚfake)ÚOSErrorÚerrnoÚESRCHr  s     r4   r  Ú&CheckPIDTests.test_stale.<locals>.kill   ó   € Üœ%Ÿ+™+ vÓ.Ð.r7   r  )r  r  r	  rÅ   r;   ÚgetpidrE   r#   rÁ   r  rü   )rS   r
  r  r  s       r4   Ú
test_staleÚCheckPIDTests.test_stale˜  s~   € ð —+‘+“-ˆÜ�'˜3Ô 1Ø�G‰G”CœŸ	š	› a™Ó(Ô)÷  ò	/ð 	�
‰
”2�v˜tÔ$Ü�ÔØ×ÑœŸ™Ÿ™¨Ó0Õ1÷  Õús   �1B*Â*
B8c                 óŽ  • U R                  5       n[        US5       nUR                  S5        SSS5        S nU R                  [        SU5        U R                  [        [        U5      nU R                  UR                  S5        U R                  UR                  S   R                  S5      5        g! , (       d  f       N�= f)zx
An unexpected L{OSError} when checking the validity of a
PID in a C{pidfile} terminates the process via L{SystemExit}.
r  Ú3581Nc                 ó6   • [        [        R                  S5      er  ©r  r  ÚEBADFr  s     r4   r  Ú2CheckPIDTests.test_unexpectedOSError.<locals>.kill°  r"  r7   r  r   zCan't check status of PID)r  r  r	  rE   r;   r°   r±   r#   ÚassertIsNotrñ   r¼   rß   rà   r  s        r4   Útest_unexpectedOSErrorÚ$CheckPIDTests.test_unexpectedOSError§  s“   € ð
 —+‘+“-ˆÜ�'˜3Ô 1Ø�G‰G�FŒO÷  ò	/ð 	�
‰
”2�v˜tÔ$Ø×Ñœj¬(°GÓ<ˆØ×Ñ˜Ÿ™ Ô&Ø�‰˜Ÿ™˜q™	×,Ñ,Ð-HÓIÕJ÷  Õús   �B6Â6
Cr]   N)rV   rW   rX   rY   rZ   r  r  r  r$  r-  r\   r]   r7   r4   rú   rú   r  s!   † ñò*ò3ò7ò2õKr7   rú   c                   ó$   • \ rS rSrSrS rS rSrg)ÚTapFileTestsi¹  zE
Test twistd-related functionality that requires a tap file on disk.
c                 óä   • U R                  5       U l        [        U R                  S5       n[        R                  " [
        R                  " S5      U5        SSS5        g! , (       d  f       g= f)z@
Create a trivial Application and put it in a tap file on disk.
ÚwbúHi!N)r  Útapfiler  ÚpickleÚdumpr   ÚApplication)rS   r  s     r4   ÚsetUpÚTapFileTests.setUp¾  sF   € ð —{‘{“}ˆŒÜ�$—,‘, Ô%¨Ü�KŠKœ×+Ò+¨EÓ2°AÔ6÷ &×%Ö%ús   ¬,A!Á!
A/c                 óú   • [         R                  " 5       nUR                  SU R                  /5        [	        U5      R                  5       nU R                  [        R                  " U5      R                  S5        g)zv
Ensure that the createOrGetApplication call that 'twistd -f foo.tap'
makes will load the Application out of foo.tap.
z-fr3  N)
r   rŒ   r²   r4  rh   ÚcreateOrGetApplicationrˆ   r   ÚIServicer/   )rS   r‘   rc   s      r4   Ú&test_createOrGetApplicationWithTapFileÚ3TapFileTests.test_createOrGetApplicationWithTapFileÆ  s]   € ô
 ×%Ò%Ó'ˆØ×Ñ˜T 4§<¡<Ð0Ô1Ü/°Ó7×NÑNÓPˆØ×Ñœ×)Ò)¨+Ó6×;Ñ;¸UÕCr7   )r4  N)rV   rW   rX   rY   rZ   r8  r=  r\   r]   r7   r4   r0  r0  ¹  s   † ñò7õDr7   r0  c                   ó*   • \ rS rSrSrS rS rS rSrg)ÚTestLoggerFactoryiÑ  z0
A logger factory for L{TestApplicationRunner}.
c                 ó   • Xl         g r)   ©Úrunner)rS   rC  s     r4   r~   ÚTestLoggerFactory.__init__Ö  s   € Ø�r7   c                 ó˜   • U R                   R                  R                  S5        [        U R                   S5      U R                   l        g)z3
Save the logging start on the C{runner} instance.
Úlogrc   N)rC  Úorderr¨   ÚhasattrÚhadApplicationLogObserverrb   s     r4   rd   ÚTestLoggerFactory.startÙ  s3   € ð 	�‰×Ñ× Ñ  Ô'Ü07¸¿¹À]Ó0Sˆ�‰Õ-r7   c                 ó   • g)z
Don't log anything.
Nr]   rk   s    r4   ÚstopÚTestLoggerFactory.stopà  ó   � r7   rB  N)	rV   rW   rX   rY   rZ   r~   rd   rL  r\   r]   r7   r4   r@  r@  Ñ  s   † ñòòTõr7   r@  c                   ó*   • \ rS rSrSrS rS rS rSrg)ÚTestApplicationRunneriæ  zT
An ApplicationRunner which tracks the environment in which its methods are
called.
c                 óp   • [         R                  R                  X5        / U l        [	        U 5      U l        g r)   )r
   ÚApplicationRunnerr~   rG  r@  r   rR   s     r4   r~   ÚTestApplicationRunner.__init__ì  s)   € Ü×Ñ×&Ñ& tÔ5ØˆŒ
Ü'¨Ó-ˆ�r7   c                 ó\   • U R                   R                  S5        [        U S5      U l        g )NÚprerc   )rG  r¨   rH  ÚhadApplicationPreApplicationrk   s    r4   rl   Ú$TestApplicationRunner.preApplicationñ  s#   € Ø�
‰
×Ñ˜%Ô Ü,3°D¸-Ó,HˆÕ)r7   c                 ó\   • U R                   R                  S5        [        U S5      U l        g )NÚpostrc   )rG  r¨   rH  ÚhadApplicationPostApplicationrk   s    r4   ro   Ú%TestApplicationRunner.postApplicationõ  s#   € Ø�
‰
×Ñ˜&Ô!Ü-4°T¸=Ó-IˆÕ*r7   )rZ  rV  r   rG  N)	rV   rW   rX   rY   rZ   r~   rl   ro   r\   r]   r7   r4   rP  rP  æ  s   † ñò
.ò
IõJr7   rP  c                   ó¸   • \ rS rSrSrS rS rS rS r\	" \
" \SS5      (       + S	5      S
 5       r\	" \
" \SS5      (       + S	5      S 5       rS rS rS rS rSrg)ÚApplicationRunnerTestsiú  zJ
Non-platform-specific tests for the platform-specific ApplicationRunner.
c                 óª   • [         R                  " 5       n[        5       U l        SU R                  0Ul        [        5       Ul        SUl        Xl        g )NÚtest_command)	r   rŒ   rL   ÚserviceMakerÚloadedPluginsÚobjectÚ
subOptionsr“   r‘   r½   s     r4   r8  ÚApplicationRunnerTests.setUpÿ  sE   € Ü×%Ò%Ó'ˆÜ,Ó.ˆÔà .°×0AÑ0AÐBˆÔÜ"›HˆÔØ*ˆÔØ�r7   c                 óh  • [        U R                  5      nUR                  5         U R                  U R                  R
                  U R                  R                  S5        U R                  U R                  R                  [        R                  " UR                  5      R                  S   S5        g)z—
Ensure that a twistd plugin gets used in appropriate ways: it
is passed its Options instance, and the service it returns is
added to the application.
zKServiceMaker.makeService needs to be passed the correct sub Command object.r   zPServiceMaker.makeService's result needs to be set as a child of the Application.N)rh   r‘   Úrunrð   r`  rP   rc  r   r<  rc   Úservices)rS   Úarunners     r4   Ú,test_applicationRunnerGetsCorrectApplicationÚCApplicationRunnerTests.test_applicationRunnerGetsCorrectApplication  s‰   € ô ,¨D¯K©KÓ8ˆØ�‰Œà�‰Ø×Ñ×%Ñ%Ø�K‰K×"Ñ"ð"ô	
ð 	�‰Ø×Ñ×%Ñ%Ü×Ò˜W×0Ñ0Ó1×:Ñ:¸1Ñ=ð"õ	
r7   c                 ó,  • [        U R                  5      nUR                  5         U R                  UR                  5        U R                  UR                  5        U R                  UR                  5        U R                  UR                  / SQ5        g)zn
Test thet preApplication and postApplication methods are
called by ApplicationRunner.run() when appropriate.
)rU  rF  rY  N)
rP  r‘   rf  rÁ   rV  r¼   rZ  rI  rˆ   rG  )rS   r©   s     r4   Útest_preAndPostApplicationÚ1ApplicationRunnerTests.test_preAndPostApplication  sh   € ô
 " $§+¡+Ó.ˆØ	�‰ŒØ×Ñ˜×7Ñ7Ô8Ø�‰˜×7Ñ7Ô8Ø�‰˜×3Ñ3Ô4Ø×Ñ˜Ÿ™Ò"8Õ9r7   c           	      ó  ^• U R                   R                  U5        / m " U4S jS[        R                  5      n[	        [
        R                  [
        R                  5       " U4S jS5      5       nU" 5       n[        [
        R                  U5        [        [
        R                  U5        U" U R                   5      nUR                  5         Xgl
        UR                  5         U R                  TSSSSX#4S	S
/5        g)zþ
Assert that given a particular command line, an application is started
as a particular UID/GID.

@param argv: A list of strings giving the options to parse.
@param uid: An integer giving the expected UID.
@param gid: An integer giving the expected GID.
c                   ó@   >• \ rS rSrU 4S jrU 4S jrU 4S jrS rSrg)Ú\ApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeUnixApplicationRunneri7  c                 ó(   >• TR                  S5        g )NÚenvironment©r¨   )rS   ÚchrootÚrundirÚnodaemonrÍ   r
  Úeventss         €r4   ÚsetupEnvironmentÚmApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeUnixApplicationRunner.setupEnvironment8  s   ø€ Ø—‘˜mÕ,r7   c                 ó.   >• TR                  SXU45        g )NÚ
privilegesrs  )rS   ÚeuidrG   r1   rw  s       €r4   ÚshedPrivilegesÚkApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeUnixApplicationRunner.shedPrivileges;  s   ø€ Ø—‘˜|¨T¸Ð<Õ=r7   c                 ó(   >• TR                  S5        g )Nr¶   rs  )rS   r¶   Ú	oldstdoutÚ	oldstderrrw  s       €r4   ÚstartReactorÚiApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeUnixApplicationRunner.startReactor>  s   ø€ Ø—‘˜iÕ(r7   c                 ó   • g r)   r]   )rS   r
  s     r4   Ú	removePIDÚfApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeUnixApplicationRunner.removePIDA  ó   € Ør7   r]   N)	rV   rW   rX   rY   rx  r}  r‚  r…  r\   ©rw  s   €r4   ÚFakeUnixApplicationRunnerrp  7  s   ø† õ-õ>õ)õr7   r‰  c                   ó^   >• \ rS rSrSrSrSrSrSrSr	S r
S rS rU 4S jrU 4S jrS rS	rg)
ÚNApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeServiceiD  Nc                 ó   • g r)   r]   r}   s     r4   ÚsetNameÚVApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeService.setNameM  r‡  r7   c                 ó   • g r)   r]   )rS   Úparents     r4   ÚsetServiceParentÚ_ApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeService.setServiceParentP  r‡  r7   c                 ó   • g r)   r]   rk   s    r4   ÚdisownServiceParentÚbApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeService.disownServiceParentS  r‡  r7   c                 ó(   >• TR                  S5        g )NÚprivilegedStartServicers  ©rS   rw  s    €r4   r—  ÚeApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeService.privilegedStartServiceV  s   ø€ Ø—‘Ð6Õ7r7   c                 ó(   >• TR                  S5        g )NÚstartServicers  r˜  s    €r4   r›  Ú[ApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeService.startServiceY  s   ø€ Ø—‘˜nÕ-r7   c                 ó   • g r)   r]   rk   s    r4   ÚstopServiceÚZApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeService.stopService\  r‡  r7   r]   )rV   rW   rX   rY   r�  Úrunningr/   ÚprocessNamerG   r1   r�  r‘  r”  r—  r›  rž  r\   rˆ  s   €r4   ÚFakeServicer‹  D  s?   ø† àˆFØˆGØˆDØˆKØˆCØˆCòòòõ8õ.õr7   r¢  rr  r—  r{  Fr›  r¶   N)r‘   r²   r   Ú_SomeApplicationRunnerr   r   r<  ÚIProcessr   rl   rc   ro   rˆ   )	rS   ÚargvrG   r1   r‰  r¢  rc   rC  rw  s	           @r4   Ú"_applicationStartsWithConfiguredIDÚ9ApplicationRunnerTests._applicationStartsWithConfiguredID*  sÛ   ø€ ð 	�‰× Ñ  Ô&àˆ÷	¬×(EÑ(Eô 	ô 
”W×%Ñ%¤w×'7Ñ'7Ó	8÷	ó 	ó 
9ð	ñ4 "“mˆÜ”W×%Ñ% {Ô3Ü”W×%Ñ% {Ô3á*¨4¯;©;Ó7ˆØ×ÑÔØ(ÔØ×ÑÔ à×ÑØàØ(Ø˜u cÐ/ØØðõ		
r7   ÚsetuidNz5Platform does not support --uid/--gid twistd options.c                 ó\   • SnSnU R                  S[        U5      S[        U5      /X5        g)zà
L{postApplication} should change the UID and GID to the values
specified as numeric strings by the configuration after running
L{service.IService.privilegedStartService} and before running
L{service.IService.startService}.
éÒ  éá  ú--uidú--gidN)r¦  rÅ   )rS   rG   r1   s      r4   Ú.test_applicationStartsWithConfiguredNumericIDsÚEApplicationRunnerTests.test_applicationStartsWithConfiguredNumericIDss  s2   € ð ˆØˆØ×/Ñ/Ø”c˜#“h ¬¨S«Ð2°Cõ	
r7   c                 ón   • SnSnSnSn[        U R                  XX45        U R                  SUSU/X$5        g)zå
L{postApplication} should change the UID and GID to the values
specified as user and group names by the configuration after running
L{service.IService.privilegedStartService} and before running
L{service.IService.startService}.
Úfoorª  Úbarr«  r¬  r­  N)rJ   rE   r¦  )rS   rF   rG   r3   r1   s        r4   Ú+test_applicationStartsWithConfiguredNameIDsÚBApplicationRunnerTests.test_applicationStartsWithConfiguredNameIDs„  sD   € ð ˆØˆØˆØˆÜ˜$Ÿ*™* d°Ô<Ø×/Ñ/Ø�d˜G UÐ+¨Sõ	
r7   c                 óª   • [        5       n[        R                  " SSSS.5      nUR                  USS5        U R	                  UR
                  S5        g)z'
L{startReactor} calls L{reactor.run}.
Fr$   ©r$   rÈ   ÚdebugNz'startReactor did not call reactor.run())ÚDummyReactorr
   rR  r‚  r¼   Úcalled©rS   r¶   rC  s      r4   Útest_startReactorRunsTheReactorÚ6ApplicationRunnerTests.test_startReactorRunsTheReactor˜  sL   € ô “.ˆÜ×&Ò&Ø¨9¸uÑEó
ˆð 	×Ñ˜G T¨4Ô0Ø�‰˜Ÿ™Ð(QÕRr7   c                 óÖ   • [        5       nU R                  [        SU5        [        R                  " SSSS.5      nUR                  SSS5        U R                  UR                  5        g)z>
L{ApplicationRunner} chooses a reactor if none is specified.
r¶   Fr$   r¶  N)r¸  rE   r   r
   rR  r‚  r¼   r¹  rº  s      r4   Ú*test_applicationRunnerChoosesReactorIfNoneÚAApplicationRunnerTests.test_applicationRunnerChoosesReactorIfNone£  sY   € ô “.ˆØ�
‰
”8˜Y¨Ô0Ü×&Ò&Ø¨9¸uÑEó
ˆð 	×Ñ˜D $¨Ô-Ø�‰˜Ÿ™Õ'r7   c                 óÂ   •  " S S[         5      nU" 5       n[        R                  " SSSS.5      nUR                  USS5        U R	                  SUR
                  5        g)zO
If the reactor exits with a signal, the application runner caches
the signal.
c                   ó$   • \ rS rSrSrS rS rSrg)Ú[ApplicationRunnerTests.test_applicationRunnerCapturesSignal.<locals>.DummyReactorWithSignaliµ  úg
A dummy reactor, providing a C{run} method, and setting the
_exitSignal attribute to a nonzero value.
c                 ó   • g©z
Dummy method, does nothing.
Nr]   rk   s    r4   ÚinstallWakerÚhApplicationRunnerTests.test_applicationRunnerCapturesSignal.<locals>.DummyReactorWithSignal.installWaker»  rN  r7   c                 ó   • SU l         g)z:
A fake run method setting _exitSignal to a nonzero value
é   N©Ú_exitSignalrk   s    r4   rf  Ú_ApplicationRunnerTests.test_applicationRunnerCapturesSignal.<locals>.DummyReactorWithSignal.runÀ  s   € ð $%�Õ r7   rÊ  N©rV   rW   rX   rY   rZ   rÆ  rf  r\   r]   r7   r4   ÚDummyReactorWithSignalrÂ  µ  s   † ñò
õ
%r7   rÎ  Fr$   r¶  NrÉ  )r   r
   rR  r‚  ÚassertEqualsrË  )rS   rÎ  r¶   rC  s       r4   Ú$test_applicationRunnerCapturesSignalÚ;ApplicationRunnerTests.test_applicationRunnerCapturesSignal¯  s\   € ô	%¤[ô 	%ñ" )Ó*ˆÜ×&Ò&Ø¨9¸uÑEó
ˆð 	×Ñ˜G T¨4Ô0Ø×Ñ˜!˜V×/Ñ/Õ0r7   c                 ó¸   •  " S S5      nU" 5       n[         R                  " SSSS.5      nUR                  USS5        U R                  SUR                  5        g)z€
The runner sets its _exitSignal instance attribute to None if
the reactor does not implement L{_ISupportsExitSignalCapturing}.
c                   ó$   • \ rS rSrSrS rS rSrg)ÚiApplicationRunnerTests.test_applicationRunnerIgnoresNoSignal.<locals>.DummyReactorWithExitSignalAttributeiÓ  rÃ  c                 ó   • grÅ  r]   rk   s    r4   rÆ  ÚvApplicationRunnerTests.test_applicationRunnerIgnoresNoSignal.<locals>.DummyReactorWithExitSignalAttribute.installWakerÙ  rN  r7   c                 ó   • SU l         g)zR
A fake run method setting _exitSignal to a nonzero value
that should be ignored.
rÉ  NrÊ  rk   s    r4   rf  ÚmApplicationRunnerTests.test_applicationRunnerIgnoresNoSignal.<locals>.DummyReactorWithExitSignalAttribute.runÞ  s   € ð
 $%�Õ r7   rÊ  NrÍ  r]   r7   r4   Ú#DummyReactorWithExitSignalAttributerÔ  Ó  s   † ñò
õ
%r7   rÙ  Fr$   r¶  N)r
   rR  r‚  rÏ  rË  )rS   rÙ  r¶   rC  s       r4   Ú%test_applicationRunnerIgnoresNoSignalÚ<ApplicationRunnerTests.test_applicationRunnerIgnoresNoSignalÍ  sZ   € ÷	%ñ 	%ñ$ 6Ó7ˆÜ×&Ò&Ø¨9¸uÑEó
ˆð 	×Ñ˜G T¨4Ô0Ø×Ñ˜$ × 2Ñ 2Õ3r7   )r‘   r`  )rV   rW   rX   rY   rZ   r8  ri  rl  r¦  r   Úgetattrr;   r®  r³  r»  r¾  rÐ  rÚ  r\   r]   r7   r4   r]  r]  ú  sˆ   † ñòò
ò,
:òG
ñR Ù�B˜ $Ó'Ô'Ø?óñ
ó	ð
ñ Ù�B˜ $Ó'Ô'Ø?óñ
ó	ð
ò 	Sò
(ò1õ<4r7   r]  c                   ón   • \ rS rSrSr\" 5       rS rS rS r	S r
S rS rS	 rS
 rS rS rS rS rSrg)Ú*UnixApplicationRunnerSetupEnvironmentTestsií  a‚  
Tests for L{UnixApplicationRunner.setupEnvironment}.

@ivar root: The root of the filesystem, or C{unset} if none has been
    specified with a call to L{os.chroot} (patched for this TestCase with
    L{UnixApplicationRunnerSetupEnvironmentTests.chroot}).

@ivar cwd: The current working directory of the process, or C{unset} if
    none has been specified with a call to L{os.chdir} (patched for this
    TestCase with L{UnixApplicationRunnerSetupEnvironmentTests.chdir}).

@ivar mask: The current file creation mask of the process, or C{unset} if
    none has been specified with a call to L{os.umask} (patched for this
    TestCase with L{UnixApplicationRunnerSetupEnvironmentTests.umask}).

@ivar daemon: A boolean indicating whether daemonization has been performed
    by a call to L{_twistd_unix.daemonize} (patched for this TestCase with
    L{UnixApplicationRunnerSetupEnvironmentTests}.
c                 óÌ  ^ • T R                   T l        T R                   T l        T R                   T l        ST l        [
        R                  " 5       T l        T R                  [
        SU 4S j5        T R                  [
        SU 4S j5        T R                  [
        SU 4S j5        [        [        R                  " 5       5      T l        T R                  T R                  l        g )NFrt  c                 ó   >• [        TSU 5      $ )NÚroot©Úsetattr©r  rS   s    €r4   r   ÚBUnixApplicationRunnerSetupEnvironmentTests.setUp.<locals>.<lambda>  s   ø€ ¬g°d¸FÀDÔ.Ir7   Úchdirc                 ó   >• [        TSU 5      $ )NÚcwdrâ  rä  s    €r4   r   rå    s   ø€ ¬W°T¸5À$Ô-Gr7   rÍ   c                 ó   >• [        TSU 5      $ )NÚmaskrâ  )rê  rS   s    €r4   r   rå    s   ø€ ¬W°T¸6À4Ô-Hr7   )Úunsetrá  rè  rê  Údaemonr;   r#  r  rE   r!   r   rŒ   rC  Ú	daemonizerk   s   `r4   r8  Ú0UnixApplicationRunnerSetupEnvironmentTests.setUp  s�   ø€ Ø—J‘JˆŒ	Ø—:‘:ˆŒØ—J‘JˆŒ	ØˆŒÜ—9’9“;ˆŒØ�
‰
”2�xÔ!IÔJØ�
‰
”2�wÔ GÔHØ�
‰
”2�wÔ HÔIÜ+¬F×,@Ò,@Ó,BÓCˆŒØ $§¡ˆ�‰Õr7   c                 óJ   ^ • ST l         T R                  [        SU 4S j5        g)z�
Indicate that daemonization has happened and change the PID so that the
value written to the pidfile can be tested in the daemonization case.
Tr#  c                  ó"   >• T R                   S-   $ ©Nr  )r  rk   s   €r4   r   ÚFUnixApplicationRunnerSetupEnvironmentTests.daemonize.<locals>.<lambda>  s   ø€ ¨¯©°Aªr7   N)rì  rE   r;   ©rS   r¶   s   ` r4   rí  Ú4UnixApplicationRunnerSetupEnvironmentTests.daemonize  s   ø€ ð
 ˆŒØ�
‰
”2�xÔ!5Õ6r7   c                 óz   • U R                   R                  SSSSS5        U R                  U R                  S5        g)z‰
L{UnixApplicationRunner.setupEnvironment} changes the root of the
filesystem if passed a non-L{None} value for the C{chroot} parameter.
ú/foo/barÚ.TN)rC  rx  rˆ   rá  rk   s    r4   Útest_chrootÚ6UnixApplicationRunnerSetupEnvironmentTests.test_chroot  s2   € ð
 	�‰×$Ñ$ Z°°d¸DÀ$ÔGØ×Ñ˜Ÿ™ JÕ/r7   c                 óŽ   • U R                   R                  SSSSS5        U R                  U R                  U R                  5        g)z…
L{UnixApplicationRunner.setupEnvironment} does not change the root of
the filesystem if passed L{None} for the C{chroot} parameter.
Nr÷  T)rC  rx  rð   rá  rë  rk   s    r4   Útest_noChrootÚ8UnixApplicationRunnerSetupEnvironmentTests.test_noChroot!  s4   € ð
 	�‰×$Ñ$ T¨3°°d¸DÔAØ�‰�d—i‘i §¡Õ,r7   c                 óz   • U R                   R                  SSSSS5        U R                  U R                  S5        g)z‡
L{UnixApplicationRunner.setupEnvironment} changes the working directory
of the process to the path given for the C{rundir} parameter.
Nrö  T)rC  rx  rˆ   rè  rk   s    r4   Útest_changeWorkingDirectoryÚFUnixApplicationRunnerSetupEnvironmentTests.test_changeWorkingDirectory)  s2   € ð
 	�‰×$Ñ$ T¨:°t¸TÀ4ÔHØ×Ñ˜Ÿ™ :Õ.r7   c                 óÒ   • [        [        5       5         U R                  R                  SSSSS5        SSS5        U R	                  U R
                  5        g! , (       d  f       N*= f)zw
L{UnixApplicationRunner.setupEnvironment} daemonizes the process if
C{False} is passed for the C{nodaemon} parameter.
Nr÷  F)r   ÚFakeDaemonizingReactorrC  rx  r¼   rì  rk   s    r4   Útest_daemonizeÚ9UnixApplicationRunnerSetupEnvironmentTests.test_daemonize1  sH   € ô
 Ô4Ó6Õ7Ø�K‰K×(Ñ(¨¨s°E¸4ÀÔF÷ 8à�‰˜Ÿ™Õ$÷ 8Õ7ús   ” AÁ
A&c                 óx   • U R                   R                  SSSSS5        U R                  U R                  5        g)z~
L{UnixApplicationRunner.setupEnvironment} does not daemonize the
process if C{True} is passed for the C{nodaemon} parameter.
Nr÷  T)rC  rx  rÁ   rì  rk   s    r4   Útest_noDaemonizeÚ;UnixApplicationRunnerSetupEnvironmentTests.test_noDaemonize:  s0   € ð
 	�‰×$Ñ$ T¨3°°d¸DÔAØ×Ñ˜Ÿ™Õ%r7   c                 ó  • U R                  5       nU R                  R                  SSSSU5        [        US5       n[	        UR                  5       5      nSSS5        U R                  WU R                  5        g! , (       d  f       N+= f)zw
L{UnixApplicationRunner.setupEnvironment} writes the process's PID to
the file specified by the C{pidfile} parameter.
Nr÷  TÚrb)r  rC  rx  r  ÚintÚreadrˆ   r  ©rS   r
  r  r  s       r4   Útest_nonDaemonPIDFileÚ@UnixApplicationRunnerSetupEnvironmentTests.test_nonDaemonPIDFileB  sf   € ð
 —+‘+“-ˆØ�‰×$Ñ$ T¨3°°d¸GÔDÜ�'˜4Ô  AÜ�a—f‘f“h“-ˆC÷ !à×Ñ˜˜dŸh™hÕ'÷ !Õ ús   ¼A;Á;
B	c                 óx  • U R                  5       n[        [        5       5         U R                  R	                  SSSSU5        SSS5        [        US5       n[        UR                  5       5      nSSS5        U R                  WU R                  S-   5        g! , (       d  f       N\= f! , (       d  f       N?= f)z�
L{UnixApplicationRunner.setupEnvironment} writes the daemonized
process's PID to the file specified by the C{pidfile} parameter if
C{nodaemon} is C{False}.
Nr÷  Fr  r  )
r  r   r  rC  rx  r  r	  r
  rˆ   r  r  s       r4   Útest_daemonPIDFileÚ=UnixApplicationRunnerSetupEnvironmentTests.test_daemonPIDFileM  s‚   € ð —+‘+“-ˆÜÔ4Ó6Õ7Ø�K‰K×(Ñ(¨¨s°E¸4ÀÔI÷ 8ä�'˜4Ô  AÜ�a—f‘f“h“-ˆC÷ !à×Ñ˜˜dŸh™h¨™lÕ+÷	 8Õ7úç Õ ús   ¤ BÁB+Â
B(Â+
B9c                 óÔ   • [        [        5       5         U R                  R                  SSSSS5        SSS5        U R	                  U R
                  S5        g! , (       d  f       N+= f)zw
L{UnixApplicationRunner.setupEnvironment} changes the process umask to
the value specified by the C{umask} parameter.
Nr÷  Fé{   ©r   r  rC  rx  rˆ   rê  rk   s    r4   rÕ   Ú5UnixApplicationRunnerSetupEnvironmentTests.test_umaskZ  sL   € ô
 Ô4Ó6Õ7Ø�K‰K×(Ñ(¨¨s°E¸3ÀÔE÷ 8à×Ñ˜Ÿ™ CÕ(÷ 8Õ7úó   ” AÁ
A'c                 óŽ   • U R                   R                  SSSSS5        U R                  U R                  U R                  5        g)z±
L{UnixApplicationRunner.setupEnvironment} doesn't change the process
umask if L{None} is passed for the C{umask} parameter and C{True} is
passed for the C{nodaemon} parameter.
Nr÷  T)rC  rx  rð   rê  rë  rk   s    r4   Útest_noDaemonizeNoUmaskÚBUnixApplicationRunnerSetupEnvironmentTests.test_noDaemonizeNoUmaskc  s4   € ð 	�‰×$Ñ$ T¨3°°d¸DÔAØ�‰�d—i‘i §¡Õ,r7   c                 óÔ   • [        [        5       5         U R                  R                  SSSSS5        SSS5        U R	                  U R
                  S5        g! , (       d  f       N+= f)z¶
L{UnixApplicationRunner.setupEnvironment} changes the process umask to
C{0077} if L{None} is passed for the C{umask} parameter and C{False} is
passed for the C{nodaemon} parameter.
Nr÷  Fé?   r  rk   s    r4   Útest_daemonizedNoUmaskÚAUnixApplicationRunnerSetupEnvironmentTests.test_daemonizedNoUmaskl  sL   € ô Ô4Ó6Õ7Ø�K‰K×(Ñ(¨¨s°E¸4ÀÔF÷ 8à×Ñ˜Ÿ™ EÕ*÷ 8Õ7úr  )rè  rì  rê  r  rá  rC  N)rV   rW   rX   rY   rZ   rb  rë  r8  rí  rø  rû  rþ  r  r  r  r  rÕ   r  r  r\   r]   r7   r4   rÞ  rÞ  í  sL   † ññ( ‹H€Eò
/ò7ò0ò-ò/ò%ò&ò	(ò,ò)ò-õ+r7   rÞ  c                   ó<   • \ rS rSrSrS rS rS rS rS r	S r
S	rg
)Ú*UnixApplicationRunnerStartApplicationTestsiw  z6
Tests for L{UnixApplicationRunner.startApplication}.
c                 óª  ^• [         R                  " 5       nUR                  / SQ5        [        R                  " S5      n[        U5      U l        / mU4S jn[        R                  " U R                  R                  5      R                  n[        R                  " U5      R                  nUR                  5       nUR                  S5        U R                  XE5        U R                  [
        SU5        U R                  [
        SS 5        U R                  [        SS	 5        U R                  R!                  U5        U R                  T/ S
Q5        g)zË
L{UnixApplicationRunner.startApplication} calls
L{UnixApplicationRunner.setupEnvironment} with the chroot, rundir,
nodaemon, umask, and pidfile parameters from the configuration it is
constructed with.
)	ú
--nodaemonrÑ   Ú0070z--chrootú/foo/chrootz--rundirú/foo/rundirú	--pidfileú/foo/pidfileÚtest_setupEnvironmentc                 ó.   >• TR                  XX4U45        g r)   )Úextend)rS   rt  ru  rv  rÍ   r
  rß   s         €r4   ÚfakeSetupEnvironmentÚ^UnixApplicationRunnerStartApplicationTests.test_setupEnvironment.<locals>.fakeSetupEnvironment—  s   ø€ Ø�K‰K˜¨¸'ÐBÕCr7   rS   rx  r}  c                  ó   • g r)   r]   ©ÚaÚkws     r4   r   ÚRUnixApplicationRunnerStartApplicationTests.test_setupEnvironment.<locals>.<lambda>«  s   € ÈTr7   ÚstartApplicationc                  ó   • g r)   r]   r,  s     r4   r   r/  ¬  s   € ¸Tr7   )r"  r#  Té8   r%  N)r   rŒ   r²   r   r7  r!   rC  ÚinspectÚ	signaturerx  Ú
parametersÚcopyÚpoprˆ   rE   r
   r0  )rS   rP   rc   r)  ÚsetupEnvironmentParametersÚfakeSetupEnvironmentParametersrß   s         @r4   r&  Ú@UnixApplicationRunnerStartApplicationTests.test_setupEnvironment}  s  ø€ ô ×&Ò&Ó(ˆØ×Ñò
ô	
ô ×)Ò)Ð*AÓBˆÜ+¨GÓ4ˆŒàˆõ	Dô &-×%6Ò%6Ø�K‰K×(Ñ(ó&
ç
‰*ð 	#ô *1×):Ò):Ø ó*
ç
‰*ð 	'ð *H×)LÑ)LÓ)NÐ&Ø&×*Ñ*¨6Ô2à×ÑÐ3ÔTà�
‰
Ô(Ð*<Ð>RÔSØ�
‰
Ô(Ð*:Ñ<QÔRØ�
‰
”3Ð*Ñ,AÔBØ�‰×$Ñ$ [Ô1à×Ñ˜ÒWÕXr7   c                 ó|   ^ • U 4S jnT R                  [        SU5        [        0 5      nUR                  SSS5        g)zN
L{UnixApplicationRunner.shedPrivileges} switches the user ID
of the process.
c                 ór   >• TR                  U S5        TR                  US5        TR                  US5        g )NéÈ   é6   é#   ©rˆ   )rG   r1   r|  rS   s      €r4   ÚswitchUIDPassÚUUnixApplicationRunnerStartApplicationTests.test_shedPrivileges.<locals>.switchUIDPass·  s3   ø€ Ø×Ñ˜S #Ô&Ø×Ñ˜S "Ô%Ø×Ñ˜T 2Õ&r7   Ú	switchUIDr?  r=  r>  N)rE   rø   r!   r}  )rS   rA  rC  s   `  r4   Útest_shedPrivilegesÚ>UnixApplicationRunnerStartApplicationTests.test_shedPrivileges±  s6   ø€ õ	'ð
 	�
‰
”< ¨mÔ<Ü& rÓ*ˆØ×Ñ˜b # rÕ*r7   c                 óÌ   • S n[        0 5      nU R                  [        SU5        U R                  [        UR
                  SSS5      nU R                  UR                  S5        g)z€
An unexpected L{OSError} when calling
L{twisted.scripts._twistd_unix.shedPrivileges}
terminates the process via L{SystemExit}.
c                 ó6   • [        [        R                  S5      er  r)  )rG   r1   r|  s      r4   ÚswitchUIDFailÚZUnixApplicationRunnerStartApplicationTests.test_shedPrivilegesError.<locals>.switchUIDFailÇ  r"  r7   rC  r?  r=  Nr  )r!   rE   rø   r°   r±   r}  rˆ   rñ   )rS   rH  rC  Úexcs       r4   Útest_shedPrivilegesErrorÚCUnixApplicationRunnerStartApplicationTests.test_shedPrivilegesErrorÀ  sU   € ò	/ô ' rÓ*ˆØ�
‰
”< ¨mÔ<Ø×Ñ¤
¨F×,AÑ,AÀ2ÀsÈDÓQˆØ×Ñ˜Ÿ™ 1Õ%r7   c                 óÞ  ^ ^^• [        T R                  UTUT5        U UU4S jnU U4S jnU U4S jnT R                  [        SU5        T R                  [        SU5        T R                  [        SU5        [        R
                  " 5       n	U	R                  SS[        T5      S	U/5        [        R                  " S
5      n
[        U	5      T l        [        U	5      nUR                  U
5        g)zR
Common code for tests which try to pass the the UID to
L{UnixApplicationRunner}.
c                 óN   >• TR                  U T5        TR                  UT5        g r)   r@  )rG   r1   rS   Ú	wantedGidÚ	wantedUids     €€€r4   Ú
initgroupsÚFUnixApplicationRunnerStartApplicationTests._setUID.<locals>.initgroupsÖ  s#   ø€ Ø×Ñ˜S )Ô,Ø×Ñ˜S )Õ,r7   c                 ó*   >• TR                  U T5        g r)   r@  )rG   rS   rP  s    €€r4   r¨  ÚBUnixApplicationRunnerStartApplicationTests._setUID.<locals>.setuidÚ  ó   ø€ Ø×Ñ˜S )Õ,r7   c                 ó*   >• TR                  U T5        g r)   r@  )r1   rS   rO  s    €€r4   ÚsetgidÚBUnixApplicationRunnerStartApplicationTests._setUID.<locals>.setgidÝ  rU  r7   rQ  r¨  rW  r   r¬  r$  r&  N)rJ   rE   r   r;   r   rŒ   r²   rÅ   r   r7  r!   rC  r0  )rS   Ú
wantedUserrP  ÚwantedGrouprO  ÚpidFilerQ  r¨  rW  rP   rc   rC  s   ` ` `       r4   Ú_setUIDÚ2UnixApplicationRunnerStartApplicationTests._setUIDÏ  s¿   ú€ ô
 	˜$Ÿ*™* j°)¸[È)ÔT÷	-ö	-ö	-ð 	�
‰
”4˜ zÔ2Ø�
‰
”2�x Ô(Ø�
‰
”2�x Ô(ä×&Ò&Ó(ˆØ×ÑØ˜7¤C¨	£N°KÀÐIô	
ô ×)Ò)Ð*AÓBˆÜ+¨GÓ4ˆŒÜ& wÓ/ˆØ×Ñ Õ,r7   c                 óP   • U R                  SSSSU R                  5       S-   5        g)z�
Starting an application with L{UnixApplicationRunner} configured
with a UID and no GUID will result in the GUID being
set to the default GUID for that UID.
r±  i  r²  i’  z_test_setUidWithoutGid.pidN)r\  r  rk   s    r4   Útest_setUidWithoutGidÚ@UnixApplicationRunnerStartApplicationTests.test_setUidWithoutGidí  s'   € ð 	�‰Ø�4˜  d§k¡k£mÐ6RÑ&Rõ	
r7   c                 ó   • [         R                  " 5       nU R                  SUSSS5        U R                  5       nSR	                  X5      nU R                  X2S   S   5        U R                  S[        U5      U5        g	)
zb
If the specified UID is the same as the current UID of the process,
then a warning is displayed.
ÚmorefooÚmorebari÷  ztest_setUidSameAsCurrentUid.pidz\tried to drop privileges and setuid {} but uid is already {}; should we be root? Continuing.r   Úmessager  N)r;   r<   r\  ÚflushWarningsrµ   rˆ   Úlen)rS   Ú
currentUidÚwarningsShownÚexpectedWarnings       r4   Útest_setUidSameAsCurrentUidÚFUnixApplicationRunnerStartApplicationTests.test_setUidSameAsCurrentUid÷  s|   € ô
 —Y’Y“[ˆ
Ø�‰Ø�z 9¨dÐ4Uô	
ð ×*Ñ*Ó,ˆð-ß-3©V°JÓ-Kð 	ð 	×Ñ˜¸Ñ*:¸9Ñ*EÔFØ×Ñ˜œC Ó.°Õ>r7   rB  N)rV   rW   rX   rY   rZ   r&  rD  rK  r\  r_  rj  r\   r]   r7   r4   r  r  w  s'   † ñò2Yòh+ò&ò-ò<
õ?r7   r  c                   ó$   • \ rS rSrSrS rS rSrg)Ú#UnixApplicationRunnerRemovePIDTestsi
  z/
Tests for L{UnixApplicationRunner.removePID}.
c                 óX  • [        0 5      nU R                  5       n[        R                  " U5        [        R                  R                  US5      n[        US5      R                  5         UR                  U5        U R                  [        R                  R                  U5      5        g)zX
L{UnixApplicationRunner.removePID} deletes the file the name of
which is passed to it.
zfoo.pidr  N)r!   r  r;   Úmakedirsr  Újoinr  Úcloser…  rÁ   rü   )rS   rC  r  r
  s       r4   Útest_removePIDÚ2UnixApplicationRunnerRemovePIDTests.test_removePID  su   € ô
 ' rÓ*ˆØ�{‰{‹}ˆÜ
�Š�DÔÜ—'‘'—,‘,˜t YÓ/ˆÜˆW�cÓ× Ñ Ô"Ø×Ñ˜Ô!Ø×ÑœŸ™Ÿ™¨Ó0Õ1r7   c                 ó
  • [        0 5      nUR                  S5        U R                  [        5      nU R	                  [        U5      S5        U R	                  US   R                  R                  [        R                  5        g)zZ
Calling L{UnixApplicationRunner.removePID} with a non-existent filename
logs an OSError.
Úfakepidr  r   N)	r!   r…  ÚflushLoggedErrorsr  rˆ   rf  Úvaluer  ÚENOENT)rS   rC  Úerrorss      r4   Útest_removePIDErrorsÚ8UnixApplicationRunnerRemovePIDTests.test_removePIDErrors  sb   € ô
 ' rÓ*ˆØ×Ñ˜Ô#Ø×'Ñ'¬Ó0ˆØ×Ñœ˜V› aÔ(Ø×Ñ˜ ™Ÿ™×.Ñ.´·±Õ=r7   r]   N)rV   rW   rX   rY   rZ   rr  rz  r\   r]   r7   r4   rm  rm  
  s   † ñò2õ	>r7   rm  c                   ó0   • \ rS rSrSrS rS rS rS rSr	g)	ÚFakeNonDaemonizingReactori)  a{  
A dummy reactor, providing C{beforeDaemonize} and C{afterDaemonize}
methods, but not announcing this, and logging whether the methods have been
called.

@ivar _beforeDaemonizeCalled: if C{beforeDaemonize} has been called or not.
@type _beforeDaemonizeCalled: C{bool}
@ivar _afterDaemonizeCalled: if C{afterDaemonize} has been called or not.
@type _afterDaemonizeCalled: C{bool}
c                 ó    • SU l         SU l        g rþ   )Ú_beforeDaemonizeCalledÚ_afterDaemonizeCalledrk   s    r4   r~   Ú"FakeNonDaemonizingReactor.__init__5  s   € Ø&+ˆÔ#Ø%*ˆÕ"r7   c                 ó   • SU l         g ©NT)r  rk   s    r4   ÚbeforeDaemonizeÚ)FakeNonDaemonizingReactor.beforeDaemonize9  s
   € Ø&*ˆÕ#r7   c                 ó   • SU l         g rƒ  )r€  rk   s    r4   ÚafterDaemonizeÚ(FakeNonDaemonizingReactor.afterDaemonize<  s
   € Ø%)ˆÕ"r7   c                 ó   • g)z
Skip event registration.
Nr]   )rS   rß   r.  s      r4   ÚaddSystemEventTriggerÚ/FakeNonDaemonizingReactor.addSystemEventTrigger?  rN  r7   )r€  r  N)
rV   rW   rX   rY   rZ   r~   r„  r‡  rŠ  r\   r]   r7   r4   r}  r}  )  s   † ñ	ò+ò+ò*õr7   r}  c                   ó   • \ rS rSrSrSrg)r  iE  z‘
A dummy reactor, providing C{beforeDaemonize} and C{afterDaemonize}
methods, announcing this, and logging whether the methods have been called.
r]   N)rV   rW   rX   rY   rZ   r\   r]   r7   r4   r  r  E  s   † ôr7   r  c                   ó"   • \ rS rSrSrSrS rSrg)r¸  iM  zž
A dummy reactor, only providing a C{run} method and checking that it
has been called.

@ivar called: if C{run} has been called or not.
@type called: C{bool}
Fc                 óJ   • U R                   (       a  [        S5      eSU l         g)zF
A fake run method, checking that it's been called one and only time.
zAlready calledTN)r¹  ÚRuntimeErrorrk   s    r4   rf  ÚDummyReactor.runX  s   € ð �;�;ÜÐ/Ó0Ð0Øˆ�r7   )r¹  N)rV   rW   rX   rY   rZ   r¹  rf  r\   r]   r7   r4   r¸  r¸  M  s   † ñð €Fõr7   r¸  c                   ó  • \ rS rSrSr\" \(       + S5      S 5       rS r\" \(       + S5      S 5       r	S r
\" \(       + S5      S 5       r\" \(       + S	5      S
 5       r\" \(       + S	5      S 5       rS rS rS rS rSrg)ÚAppProfilingTestsia  z
Tests for L{app.AppProfiler}.
zprofile module not availablec                 ó®  • [         R                  " 5       nU R                  5       US'   SUS'   [        R                  " U5      n[        5       nUR                  U5        U R                  UR                  5        [        US   5       nUR                  5       nSSS5        U R                  SW5        U R                  SU5        g! , (       d  f       N3= f)zt
L{app.ProfileRunner.run} should call the C{run} method of the reactor
and save profile data in the specified file.
r$   rÈ   NzDummyReactor.runúfunction calls©r   rŒ   r  r
   rÆ   r¸  rf  r¼   r¹  r  r
  r§   ©rS   r‘   rÈ   r¶   r  Údatas         r4   Útest_profileÚAppProfilingTests.test_profilef  s£   € ô ×%Ò%Ó'ˆØ ŸK™K›MˆˆyÑØ&ˆˆzÑÜ—?’? 6Ó*ˆÜ“.ˆà�‰�WÔà�‰˜Ÿ™Ô'Ü�&˜Ñ#Ô$¨Ø—6‘6“8ˆD÷ %à�‰Ð(¨$Ô/Ø�‰Ð&¨Õ-÷ %Õ$úó   ÂCÃ
Cc                 óþ   • [        5       nU R                  [        SU5      nU" U5      nUR                  5         UR	                  5         UR                  5       nU R                  SU5        U R                  SU5        g )Nrí   r”  z(run))r   rE   ÚsysÚprint_statsÚrestorer³   r§   )rS   Ú
statsClassr$   Úoutrí   Ústatsr—  s          r4   Ú
_testStatsÚAppProfilingTests._testStatsz  sg   € Ü‹jˆð —‘œC ¨3Ó/ˆñ ˜7Ó#ˆØ×ÑÔØ�‰Ôà�|‰|‹~ˆØ�‰Ð&¨Ô-Ø�‰�g˜tÕ$r7   c                 óF  • [         R                  " 5       nU R                  5       US'   SUS'   SUS'   [        R                  " U5      n[        5       nUR                  U5        U R                  UR                  5        U R                  [        R                  US   5        g)z€
With the C{savestats} option specified, L{app.ProfileRunner.run}
should save the raw stats object instead of a summary output.
r$   rÈ   TÚ	savestatsN©r   rŒ   r  r
   rÆ   r¸  rf  r¼   r¹  r¢  r%   ÚStats©rS   r‘   rÈ   r¶   s       r4   Útest_profileSaveStatsÚ'AppProfilingTests.test_profileSaveStats‹  s~   € ô ×%Ò%Ó'ˆØ ŸK™K›MˆˆyÑØ&ˆˆzÑØ"ˆˆ{ÑÜ—?’? 6Ó*ˆÜ“.ˆà�‰�WÔà�‰˜Ÿ™Ô'Ø�‰œŸ™ f¨YÑ&7Õ8r7   c                 ó  • [         R                  R                  5       n[        R                  " 5       nSUS'   [
        R                  " U5      nS[         R                  S'    U R                  [        UR                  S5        [         R                  R                  5         [         R                  R                  U5        g! [         R                  R                  5         [         R                  R                  U5        f = f)zn
When the C{profile} module is not present, L{app.ProfilerRunner.run}
should raise a C{SystemExit} exception.
r$   rÈ   N©rœ  Úmodulesr6  r   rŒ   r
   rÆ   r°   r±   rf  ÚclearÚupdate©rS   ÚsavedModulesr‘   rÈ   s       r4   Útest_withoutProfileÚ%AppProfilingTests.test_withoutProfile�  s­   € ô
 —{‘{×'Ñ'Ó)ˆä×%Ò%Ó'ˆØ&ˆˆzÑÜ—?’? 6Ó*ˆà!%Œ�‰�IÑð	-Ø×Ñœj¨(¯,©,¸Ô=ä�K‰K×ÑÔÜ�K‰K×Ñ˜|Õ,øô �K‰K×ÑÔÜ�K‰K×Ñ˜|Õ,úó   Á#!C Ã?Dc                 ó   •  " S S[         R                  5      nU R                  [         SU5        [        R                  " 5       nU R                  5       US'   SUS'   [        R                  " U5      n[        5       n[        R                  nU R                  [        UR                  U5        U R                  [        R                  U5        g)zm
When an error happens during the print of the stats, C{sys.stdout}
should be restored to its initial value.
c                   ó   • \ rS rSrS rSrg)ÚGAppProfilingTests.test_profilePrintStatsError.<locals>.ErroneousProfilei¶  c                 ó   • [        S5      e)NÚBoom©r�  rk   s    r4   r�  ÚSAppProfilingTests.test_profilePrintStatsError.<locals>.ErroneousProfile.print_stats·  s   € Ü" 6Ó*Ð*r7   r]   N)rV   rW   rX   rY   r�  r\   r]   r7   r4   ÚErroneousProfiler·  ¶  s   † õ+r7   r¼  ÚProfiler$   rÈ   N)r$   r½  rE   r   rŒ   r  r
   rÆ   r¸  rœ  rí   r°   r�  rf  rð   )rS   r¼  r‘   rÈ   r¶   Ú	oldStdouts         r4   Útest_profilePrintStatsErrorÚ-AppProfilingTests.test_profilePrintStatsError¯  s“   € ô	+œwŸ™ô 	+ð 	�
‰
”7˜IÐ'7Ô8ä×%Ò%Ó'ˆØ ŸK™K›MˆˆyÑØ&ˆˆzÑÜ—?’? 6Ó*ˆÜ“.ˆä—J‘Jˆ	Ø×Ñœ,¨¯©°gÔ>Ø�‰”c—j‘j )Õ,r7   zcProfile module not availablec                 ó®  • [         R                  " 5       nU R                  5       US'   SUS'   [        R                  " U5      n[        5       nUR                  U5        U R                  UR                  5        [        US   5       nUR                  5       nSSS5        U R                  SW5        U R                  SU5        g! , (       d  f       N3= f)zu
L{app.CProfileRunner.run} should call the C{run} method of the
reactor and save profile data in the specified file.
r$   r&   rÈ   Nrf  r”  r•  r–  s         r4   Útest_cProfileÚAppProfilingTests.test_cProfileÆ  s¢   € ô ×%Ò%Ó'ˆØ ŸK™K›MˆˆyÑØ'ˆˆzÑÜ—?’? 6Ó*ˆÜ“.ˆà�‰�WÔà�‰˜Ÿ™Ô'Ü�&˜Ñ#Ô$¨Ø—6‘6“8ˆD÷ %à�‰�e˜TÔ"Ø�‰Ð&¨Õ-÷ %Õ$úrš  c                 óF  • [         R                  " 5       nU R                  5       US'   SUS'   SUS'   [        R                  " U5      n[        5       nUR                  U5        U R                  UR                  5        U R                  [        R                  US   5        g)z�
With the C{savestats} option specified,
L{app.CProfileRunner.run} should save the raw stats object
instead of a summary output.
r$   r&   rÈ   Tr¥  Nr¦  r¨  s       r4   Útest_cProfileSaveStatsÚ(AppProfilingTests.test_cProfileSaveStatsÚ  s~   € ô ×%Ò%Ó'ˆØ ŸK™K›MˆˆyÑØ'ˆˆzÑØ"ˆˆ{ÑÜ—?’? 6Ó*ˆÜ“.ˆà�‰�WÔà�‰˜Ÿ™Ô'Ø�‰œŸ™ f¨YÑ&7Õ8r7   c                 ó  • [         R                  R                  5       nS[         R                  S'   [        R                  " 5       nSUS'   [
        R                  " U5      n U R                  [        UR                  S5        [         R                  R                  5         [         R                  R                  U5        g! [         R                  R                  5         [         R                  R                  U5        f = f)zŠ
When the C{cProfile} module is not present,
L{app.CProfileRunner.run} should raise a C{SystemExit}
exception and log the C{ImportError}.
Nr&   rÈ   r¬  r°  s       r4   Útest_withoutCProfileÚ&AppProfilingTests.test_withoutCProfileí  s­   € ô —{‘{×'Ñ'Ó)ˆØ"&Œ�‰�JÑä×%Ò%Ó'ˆØ'ˆˆzÑÜ—?’? 6Ó*ˆð	-Ø×Ñœj¨(¯,©,¸Ô=ä�K‰K×ÑÔÜ�K‰K×Ñ˜|Õ,øô �K‰K×ÑÔÜ�K‰K×Ñ˜|Õ,úr´  c                 óÞ   • [         R                  " 5       nU R                  5       US'   SUS'   U R                  [        [
        R                  U5      nU R                  [        U5      S5        g)zY
Check that L{app.AppProfiler} raises L{SystemExit} when given an
unknown profiler name.
r$   ÚfoobarrÈ   z!Unsupported profiler name: foobarN)	r   rŒ   r  r°   r±   r
   rÆ   rˆ   rÅ   )rS   r‘   Úerrors      r4   Útest_unknownProfilerÚ&AppProfilingTests.test_unknownProfilerÿ  sY   € ô
 ×%Ò%Ó'ˆØ ŸK™K›MˆˆyÑØ%ˆˆzÑà×!Ñ!¤*¬c¯o©o¸vÓFˆØ×Ñœ˜U›Ð%HÕIr7   c                 óh   • [         R                  " 0 5      nU R                  UR                  S5        g)zE
L{app.Profiler} defaults to the cprofile profiler if not specified.
ÚcprofileN©r
   rÆ   rˆ   rÈ   ©rS   rÈ   s     r4   Útest_defaultProfilerÚ&AppProfilingTests.test_defaultProfiler  s(   € ô —?’? 2Ó&ˆØ×Ñ˜×*Ñ*¨JÕ7r7   c                 ól   • [         R                  " SS05      nU R                  UR                  S5        g)zM
The case of the profiler name passed to L{app.AppProfiler} is not
relevant.
rÈ   ÚCprOfilerÐ  NrÑ  rÒ  s     r4   Útest_profilerNameCaseInsentiveÚ0AppProfilingTests.test_profilerNameCaseInsentive  s-   € ô
 —?’? J°
Ð#;Ó<ˆØ×Ñ˜×*Ñ*¨JÕ7r7   r]   N)rV   rW   rX   rY   rZ   r   r$   r˜  r¢  r©  r²  r¿  r&   rÂ  rÅ  rÈ  rÍ  rÓ  r×  r\   r]   r7   r4   r’  r’  a  s¼   † ññ �ŒKÐ7Ó8ñ.ó 9ð.ò&%ñ" �ŒKÐ7Ó8ñ9ó 9ð9ò"-ñ$ �ŒKÐ7Ó8ñ-ó 9ð-ñ, �ŒLÐ9Ó:ñ.ó ;ð.ñ& �ŒLÐ9Ó:ñ9ó ;ð9ò$-ò$
Jò8õ8r7   r’  c                 óX   ^^• / m[         R                  mUU4S jnU " [         SU5        T$ )zû
Patch L{logger.textFileLogObserver} to record every call and keep a
reference to the passed log file for tests.

@param patch: a callback for patching (usually L{TestCase.patch}).

@return: the list that keeps track of the log files.
@rtype: C{list}
c                 ó>   >• TR                  U 5        T" U /UQ70 UD6$ r)   rs  )ÚlogFilerß   ÚkwargsÚlogFilesÚoldFileLogObservers      €€r4   ÚobserverÚ+_patchTextFileLogObserver.<locals>.observer(  s$   ø€ Ø�‰˜Ô Ù! 'Ð;¨DÒ;°FÑ;Ð;r7   ÚtextFileLogObserver)r   rá  )rE   rß  rÝ  rÞ  s     @@r4   Ú_patchTextFileLogObserverrâ    s/   ù€ ð €HÜ×3Ñ3Ðö<ñ 
Œ&Ð'¨Ô2Ø€Or7   c                 óT   ^• / m " U4S jS5      nU R                  [        SU5        T$ )zi
Make fake syslog, and return list to which prefix and then log
messages will be appended if it is used.
c                   ó.   >• \ rS rSrU 4S jrU 4S jrSrg)Ú(_setupSyslog.<locals>.fakesyslogobserveri7  c                 ó(   >• TR                  U5        g r)   rs  )rS   ÚprefixÚlogMessagess     €r4   r~   Ú1_setupSyslog.<locals>.fakesyslogobserver.__init__8  s   ø€ Ø×Ñ˜vÕ&r7   c                 ó(   >• TR                  U5        g r)   rs  )rS   Ú	eventDictrè  s     €r4   ÚemitÚ-_setupSyslog.<locals>.fakesyslogobserver.emit;  s   ø€ Ø×Ñ˜yÕ)r7   r]   N)rV   rW   rX   rY   r~   rì  r\   )rè  s   €r4   Úfakesyslogobserverrå  7  s   ø† õ	'÷	*ð 	*r7   rî  ÚSyslogObserver)rE   Úsyslog)ÚtestCaserî  rè  s     @r4   Ú_setupSyslogrò  0  s.   ø€ ð
 €K÷*ô *ð ‡N�N”6Ð+Ð-?Ô@ØÐr7   c                   óä   • \ rS rSrSrS rS rS rS rS r	S r
0 \R                  4S	 jrS
 rS rS rS r\" \(       + S5      \" \(       + S5      S 5       5       rS rS rS rS rS rS rSrg)ÚAppLoggerTestsiB  zv
Tests for L{app.AppLogger}.

@ivar observers: list of observers installed during the tests.
@type observers: C{list}
c                 óN   ^ • / T l         U 4S jnT R                  [        SU5        g)zp
Override L{globaLogBeginner.beginLoggingTo} so that we can trace the
observers installed in C{self.observers}.
c                 óz   >• U  H4  nTR                   R                  U5        [        R                  " U5        M6     g r)   )Ú	observersr¨   r   ÚaddObserver)r÷  rß  rS   s     €r4   ÚbeginLoggingToÚ,AppLoggerTests.setUp.<locals>.beginLoggingToQ  s-   ø€ Û%�Ø—‘×%Ñ% hÔ/Ü"×.Ò.¨xÖ8ò &r7   rù  N)r÷  rE   r   )rS   rù  s   ` r4   r8  ÚAppLoggerTests.setUpJ  s%   ø€ ð
 ˆŒõ	9ð
 	�
‰
Ô$Ð&6¸ÕGr7   c                 óV   • U R                    H  n[        R                  " U5        M     g)z!
Remove all installed observers.
N)r÷  r   ÚremoveObserver©rS   rß  s     r4   ÚtearDownÚAppLoggerTests.tearDownX  s    € ð ŸœˆHÜ×-Ò-¨hÖ7ò 'r7   c                 óH   • [        [        5       " S S5      5       nU" 5       $ )z¢
Make a new observer which captures all logs sent to it.

@return: An observer that stores all logs sent to it.
@rtype: Callable that implements L{ILogObserver}.
c                   ó   • \ rS rSr/ rS rSrg)Ú2AppLoggerTests._makeObserver.<locals>.TestObserverig  c                 ó:   • U R                   R                  U5        g r)   )Ú_logsr¨   )rS   Úevents     r4   Ú__call__Ú;AppLoggerTests._makeObserver.<locals>.TestObserver.__call__k  s   € Ø—
‘
×!Ñ! %Õ(r7   r]   N)rV   rW   rX   rY   r  r  r\   r]   r7   r4   ÚTestObserverr  g  s   † àˆEõ)r7   r	  )r   r   )rS   r	  s     r4   Ú_makeObserverÚAppLoggerTests._makeObserver_  s*   € ô 
”\Ó	"÷	)ð 	)ó 
#ð	)ñ ‹~Ðr7   c                 óÆ   • U R                  U R                  U/5        U R                  SUR                  S   S   5        U R                  SUR                  S   S   5        g)zw
Ensure that initial C{twistd} logs are written to logs.

@param observer: The observer made by L{self._makeObserver).
ústarting upr   Ú
log_formatzreactor classr  N)rˆ   r÷  r§   r  rþ  s     r4   Ú_checkObserverÚAppLoggerTests._checkObserverp  sR   € ð 	×Ñ˜Ÿ™¨(¨Ô4Ø�‰�m X§^¡^°AÑ%6°|Ñ%DÔEØ�‰�o x§~¡~°aÑ'8¸Ñ'FÕGr7   c                 ó¾   ^• [         R                  " 0 5      nU R                  5       mU4S jUl        UR                  " [        5       5        U R                  T5        g)z|
L{app.AppLogger.start} calls L{globalLogBeginner.addObserver}, and then
writes some messages about twistd and the reactor.
c                  ó   >• T $ r)   r]   ©rß  s   €r4   r   Ú+AppLoggerTests.test_start.<locals>.<lambda>�  s   ø€ ©r7   N)r
   Ú	AppLoggerr
  Ú_getLogObserverrd   r   r  )rS   r   rß  s     @r4   Ú
test_startÚAppLoggerTests.test_startz  sE   ø€ ô
 —’˜rÓ"ˆØ×%Ñ%Ó'ˆÜ!1ˆÔØ�Š”]“_Ô%Ø×Ñ˜HÕ%r7   c                 óÖ   • [        5       nU R                  5       nUR                  [        U5        [        R
                  " 0 5      nUR                  " U5        U R                  U5        g)z•
When the L{ILogObserver} component is available on the application,
that object will be used as the log observer instead of constructing a
new one.
N)r   r
  ÚsetComponentr   r
   r  rd   r  )rS   rc   rß  r   s       r4   Ú$test_startUsesApplicationLogObserverÚ3AppLoggerTests.test_startUsesApplicationLogObserver…  sQ   € ô $“oˆØ×%Ñ%Ó'ˆØ× Ñ ¤¨xÔ8Ü—’˜rÓ"ˆØ�Š�[Ô!Ø×Ñ˜HÕ%r7   c                 óŽ   ^• U R                  5       mSU4S j0nUR                  U5        U" U5      nUR                  " U5        T$ )aÄ  
Set up an AppLogger which exercises the C{logger} configuration option.

@type application: L{Componentized}
@param application: The L{Application} object to pass to
    L{app.AppLogger.start}.
@type extraLogArgs: C{dict}
@param extraLogArgs: extra values to pass to AppLogger.
@type appLogger: L{AppLogger} class, or a subclass
@param appLogger: factory for L{AppLogger} instances.

@rtype: C{list}
@return: The logs accumulated by the log observer.
r   c                  ó   >• T $ r)   r]   r  s   €r4   r   Ú7AppLoggerTests._setupConfiguredLogger.<locals>.<lambda>¤  s   ø€ ¡Xr7   )r
  r¯  rd   )rS   rc   ÚextraLogArgsÚ	appLoggerÚlogArgsr   rß  s         @r4   Ú_setupConfiguredLoggerÚ%AppLoggerTests._setupConfiguredLogger’  sE   ø€ ð" ×%Ñ%Ó'ˆØÔ-Ð.ˆØ�‰�|Ô$Ù˜7Ó#ˆØ�Š�[Ô!Øˆr7   c                 óX   • [        5       nU R                  U R                  U5      5        g)zè
When the C{logger} key is specified in the configuration dictionary
(i.e., when C{--logger} is passed to twistd), the initial log observer
will be the log observer returned from the callable which the value
refers to in FQPN form.
N)r   r  r#  rb   s     r4   Ú#test_startUsesConfiguredLogObserverÚ2AppLoggerTests.test_startUsesConfiguredLogObserverª  s$   € ô $“oˆØ×Ñ˜D×7Ñ7¸ÓDÕEr7   c                 óÜ   • U R                  5       n[        5       nUR                  [        U5        U R	                  U R                  U5      5        U R                  UR                  / 5        g)zS
C{--logger} takes precedence over a L{ILogObserver} component set on
Application.
N)r
  r   r  r   r  r#  rˆ   r  )rS   rß  rc   s      r4   Ú(test_configuredLogObserverBeatsComponentÚ7AppLoggerTests.test_configuredLogObserverBeatsComponent´  sV   € ð
 ×%Ñ%Ó'ˆÜ#“oˆØ× Ñ ¤¨xÔ8Ø×Ñ˜D×7Ñ7¸ÓDÔEØ×Ñ˜Ÿ™¨Õ,r7   c                 óÀ   • / n[        5       nUR                  [        UR                  5        U R	                  U R                  U5      5        U R                  U/ 5        g)zY
C{--logger} takes precedence over a L{LegacyILogObserver} component
set on Application.
N)r   r  ÚLegacyILogObserverr¨   r  r#  rˆ   )rS   Únonlogsrc   s      r4   Ú.test_configuredLogObserverBeatsLegacyComponentÚ=AppLoggerTests.test_configuredLogObserverBeatsLegacyComponent¿  sN   € ð
 ˆÜ#“oˆØ× Ñ Ô!3°W·^±^ÔDØ×Ñ˜D×7Ñ7¸ÓDÔEØ×Ñ˜ "Õ%r7   c                 ó>  • / nU R                  5       n[        5       nUR                  [        U5        UR                  [        UR
                  5        [        R                  " 0 5      nUR                  " U5        U R                  U5        U R                  U/ 5        g)z_
A L{ILogObserver} takes precedence over a L{LegacyILogObserver}
component set on Application.
N)r
  r   r  r   r,  r¨   r
   r  rd   r  rˆ   )rS   r-  rß  rc   r   s        r4   Ú.test_loggerComponentBeatsLegacyLoggerComponentÚ=AppLoggerTests.test_loggerComponentBeatsLegacyLoggerComponentÊ  s{   € ð
 ˆØ×%Ñ%Ó'ˆÜ#“oˆØ× Ñ ¤¨xÔ8Ø× Ñ Ô!3°W·^±^ÔDä—’˜rÓ"ˆØ�Š�[Ô!à×Ñ˜HÔ%Ø×Ñ˜ "Õ%r7   rË   zsyslog not availablec                 ó¢   • [        U 5      n[        5       nU R                  U R                  USS0[        5      5        U R                  U/ 5        g)zH
C{--logger} takes precedence over a C{--syslog} command line
argument.
rð  TN)rò  r   r  r#  r"   rˆ   )rS   Úlogsrc   s      r4   Ú%test_configuredLogObserverBeatsSyslogÚ4AppLoggerTests.test_configuredLogObserverBeatsSyslogÛ  sL   € ô ˜DÓ!ˆÜ#“oˆØ×ÑØ×'Ñ'¨°hÀÐ5EÄ}ÓUô	
ð 	×Ñ˜˜rÕ"r7   c                 óÚ   • [        5       nU R                  5       nU R                  U R                  USS05      5        U R	                  [
        R                  R                  U5      5        g)zI
C{--logger} takes precedence over a C{--logfile} command line
argument.
Úlogfiler  N)r   r  r  r#  rÁ   r;   r  rü   )rS   rc   r  s      r4   Ú&test_configuredLogObserverBeatsLogfileÚ5AppLoggerTests.test_configuredLogObserverBeatsLogfileé  sV   € ô
 $“oˆØ�{‰{‹}ˆØ×ÑØ×'Ñ'¨°iÀÐ5HÓIô	
ð 	×ÑœŸ™Ÿ™¨Ó-Õ.r7   c                 óÊ  • [         R                  " SS05      n[        U R                  5      nUR                  " 5         U R                  [        U5      S5        U R                  US   [        R                  5        [         R                  " SS05      nUR                  " 5         U R                  [        U5      S5        U R                  US   [        R                  5        g)zz
When logfile is empty or set to C{-}, L{app.AppLogger._getLogObserver}
returns a log observer pointing at C{sys.stdout}.
r8  Ú-r  r   Ú rÉ  N)
r
   r  râ  rE   r  rˆ   rf  rð   rœ  rí   )rS   r   rÝ  s      r4   Útest_getLogObserverStdoutÚ(AppLoggerTests.test_getLogObserverStdoutõ  s£   € ô
 —’ 	¨3Ð/Ó0ˆÜ,¨T¯Z©ZÓ8ˆà×ÒÔ à×Ñœ˜X›¨Ô*Ø�‰�h˜q‘k¤3§:¡:Ô.ä—’ 	¨2˜Ó/ˆØ×ÒÔ à×Ñœ˜X›¨Ô*Ø�‰�h˜q‘k¤3§:¡:Õ.r7   c                 ó–  • [        U R                  5      nU R                  5       n[        R                  " SU05      nUR                  5       nU R                  UR                  R                  5        U R                  [        U5      S5        U R                  US   R                  [        R                  R                  U5      5        g)z}
When passing the C{logfile} option, L{app.AppLogger._getLogObserver}
returns a log observer pointing at the specified path.
r8  r  r   N)râ  rE   r  r
   r  r  Ú
addCleanupÚ_outFilerq  rˆ   rf  r  r;   Úabspath)rS   rÝ  ÚfilenameÚsutrß  s        r4   Útest_getLogObserverFileÚ&AppLoggerTests.test_getLogObserverFile  s‘   € ô
 -¨T¯Z©ZÓ8ˆØ—;‘;“=ˆÜ�mŠm˜Y¨Ð1Ó2ˆà×&Ñ&Ó(ˆØ�‰˜×)Ñ)×/Ñ/Ô0à×Ñœ˜X›¨Ô*Ø×Ñ˜ !™×)Ñ)¬2¯7©7¯?©?¸8Ó+DÕEr7   c                 óV  ^• / m[        5       nU4S jnU R                  [        SU5        [        R                  " 0 5      nXl        UR                  " 5         U R                  TU/5        UR                  " 5         U R                  TU/5        U R                  UR
                  5        g)z 
L{app.AppLogger.stop} removes the observer created in C{start}, and
reinitialize its C{_observer} so that if C{stop} is called several
times it doesn't break.
c                 ó(   >• TR                  U 5        g r)   rs  )rß  Úremoveds    €r4   ÚremoveÚ(AppLoggerTests.test_stop.<locals>.remove   s   ø€ Ø�N‰N˜8Õ$r7   rý  N)	rb  rE   r   r
   r  Ú	_observerrL  rˆ   r�   )rS   rß  rK  r   rJ  s       @r4   Ú	test_stopÚAppLoggerTests.test_stop  sˆ   ø€ ð ˆÜ“8ˆõ	%ð 	�
‰
Ô%Ð'7¸Ô@Ü—’˜rÓ"ˆØ#ÔØ�ŠŒØ×Ñ˜ 8 *Ô-Ø�ŠŒØ×Ñ˜ 8 *Ô-Ø×Ñ˜&×*Ñ*Õ+r7   c                 ól  ^^• / m[         R                  " 0 5      n[        [        5       " U4S jS5      5       mU4S jUl        UR
                  " [        5       5        U R                  S[        TS   5      5        U R                  U R                  /5      nU R                  [        U5      SU5        g)z\
L{app.AppLogger} using a legacy logger observer still works, wrapping
it in a compat shim.
c                   ó&   >• \ rS rSrSrU 4S jrSrg)Ú;AppLoggerTests.test_legacyObservers.<locals>.LoggerObserveri4  z@
An observer which implements the legacy L{LegacyILogObserver}.
c                 ó(   >• TR                  U5        g)z
Add C{x} to the logs list.
Nrs  )rS   Úxr4  s     €r4   r  ÚDAppLoggerTests.test_legacyObservers.<locals>.LoggerObserver.__call__:  s   ø€ ð —‘˜A•r7   r]   N)rV   rW   rX   rY   rZ   r  r\   ©r4  s   €r4   ÚLoggerObserverrR  4  s   ø† ñ÷ð r7   rW  c                  ó   >• T " 5       $ r)   r]   )rW  s   €r4   r   Ú5AppLoggerTests.test_legacyObservers.<locals>.<lambda>@  s   ø€ ©.Ô*:r7   r  r   N)r
   r  r   r,  Ú_observerFactoryrd   r   r§   r   re  Útest_legacyObserversrˆ   rf  )rS   r   ÚwarningsrW  r4  s      @@r4   r[  Ú#AppLoggerTests.test_legacyObservers,  s”   ù€ ð
 ˆÜ—’˜rÓ"ˆä	Ô'Ó	(÷		ó 		ó 
)ð		ô #;ˆÔØ�Š”]“_Ô%à�‰�mÔ%6°t¸A±wÓ%?Ô@Ø×%Ñ% t×'@Ñ'@Ð&AÓBˆØ×Ñœ˜X›¨¨8Õ4r7   c                 ó\  ^• / m[         R                  " 0 5      nU4S jUl        UR                  " [	        5       5        U R                  S[        TS   5      5        U R                  U R                  /5      nU R                  US   S   S5        U R                  [        U5      SU5        g)z°
L{app.AppLogger} using a logger observer which does not implement
L{ILogObserver} or L{LegacyILogObserver} will be wrapped in a compat
shim and raise a L{DeprecationWarning}.
c                  ó   >• T R                   $ r)   rs  rV  s   €r4   r   ÚAAppLoggerTests.test_unmarkedObserversDeprecated.<locals>.<lambda>O  s	   ø€ ¨¯ªr7   r  r   rd  aZ  Passing a logger factory which makes log observers which do not implement twisted.logger.ILogObserver or twisted.python.log.ILogObserver to twisted.application.app.AppLogger was deprecated in Twisted 16.2. Please use a factory that produces twisted.logger.ILogObserver (or the legacy twisted.python.log.ILogObserver) implementing objects instead.r  N)r
   r  r  rd   r   r§   r   re  Ú test_unmarkedObserversDeprecatedrˆ   rf  )rS   r   r\  r4  s      @r4   ra  Ú/AppLoggerTests.test_unmarkedObserversDeprecatedG  s–   ø€ ð ˆÜ—’˜rÓ"ˆÜ!4ˆÔØ�Š”]“_Ô%à�‰�mÔ%6°t¸A±wÓ%?Ô@à×%Ñ% t×'LÑ'LÐ&MÓNˆØ×ÑØ�Q‰K˜	Ñ"ð0ô	
ð 	×Ñœ˜X›¨¨8Õ4r7   )r÷  N)rV   rW   rX   rY   rZ   r8  rÿ  r
  r  r  r  r
   r  r#  r&  r)  r.  r1  r   rø   rð  r5  r9  r>  rF  rN  r[  ra  r\   r]   r7   r4   rô  rô  B  sœ   † ñòHò8òò"Hò	&ò&ð )+°c·m±môò0Fò	-ò	&ò&ñ" �ÔÐ9Ó:Ù�ŒJÐ.Ó/ñ
#ó 0ó ;ð
#ò
/ò/ò&Fò,ò*5õ65r7   rô  c                   ód   • \ rS rSrSrS rS rS rS rS r	S r
\" \(       + S	5      S
 5       rSrg)ÚUnixAppLoggerTestsie  zg
Tests for L{UnixAppLogger}.

@ivar signals: list of signal handlers installed.
@type signals: C{list}
c                 óN   ^ • / T l         U 4S jnT R                  [        SU5        g)z[
Fake C{signal.signal} for not installing the handlers but saving them
in C{self.signals}.
c                 ó>   >• TR                   R                  X45        g r)   )Úsignalsr¨   )r  r  rS   s     €r4   Ú
fakeSignalÚ,UnixAppLoggerTests.setUp.<locals>.fakeSignalu  s   ø€ Ø�L‰L×Ñ  Õ)r7   ÚsignalN)rg  rE   rj  )rS   rh  s   ` r4   r8  ÚUnixAppLoggerTests.setUpn  s#   ø€ ð
 ˆŒõ	*ð 	�
‰
”6˜8 ZÕ0r7   c                 ó¢  • [        U R                  5      n[        SSS.5      nUR                  " 5         U R	                  [        U5      S5        U R                  US   [        R                  5        [        SSS.5      nUR                  " 5         U R	                  [        U5      S5        U R                  US   [        R                  5        g)	z�
When non-daemonized and C{logfile} is empty or set to C{-},
L{UnixAppLogger._getLogObserver} returns a log observer pointing at
C{sys.stdout}.
r<  T©r8  rv  r  r   r=  rÉ  N)	râ  rE   r"   r  rˆ   rf  rð   rœ  rí   )rS   rÝ  r   s      r4   r>  Ú,UnixAppLoggerTests.test_getLogObserverStdoutz  sœ   € ô -¨T¯Z©ZÓ8ˆä¨3¸DÑAÓBˆØ×ÒÔ Ø×Ñœ˜X›¨Ô*Ø�‰�h˜q‘k¤3§:¡:Ô.ä¨2¸4Ñ@ÓAˆØ×ÒÔ Ø×Ñœ˜X›¨Ô*Ø�‰�h˜q‘k¤3§:¡:Õ.r7   c                 ó–   • [        SSS.5      nU R                  [        UR                  5      nU R	                  [        U5      S5        g)zg
When daemonized and C{logfile} is set to C{-},
L{UnixAppLogger._getLogObserver} raises C{SystemExit}.
r<  Frm  z&Daemons cannot log to stdout, exiting!N)r"   r°   r±   r  rˆ   rÅ   )rS   r   rÌ  s      r4   Útest_getLogObserverStdoutDaemonÚ2UnixAppLoggerTests.test_getLogObserverStdoutDaemonŒ  s@   € ô
 ¨3¸EÑBÓCˆØ×!Ñ!¤*¨f×.DÑ.DÓEˆØ×Ñœ˜U›Ð%MÕNr7   c                 ó–  ^• [        U R                  5      nU R                  5       n[        SU05      nUR	                  5       nU R                  UR                  R                  5        U R                  [        U5      S5        U R                  US   R                  [        R                  R                  U5      5        U R                  [        U R                  5      S5        U R                  U R                  S   S   [        R                  5        [!        5       mU4S jnXQS   l        U R                  S   S   nU" SS5        T$ )z³
When C{logfile} contains a file name, L{app.AppLogger._getLogObserver}
returns a log observer pointing at the specified path, and a signal
handler rotating the log is installed.
r8  r  r   c                  ó(   >• T R                  S 5        g r)   )Úcallback)Úds   €r4   ÚrotateÚ:UnixAppLoggerTests.test_getLogObserverFile.<locals>.rotateª  s   ø€ Ø�J‰J�tÕr7   N)râ  rE   r  r"   r  rA  rB  rq  rˆ   rf  r  r;   rC  rg  rj  ÚSIGUSR1r   rv  )rS   rÝ  rD  rE  rß  rv  Ú	rotateLogru  s          @r4   rF  Ú*UnixAppLoggerTests.test_getLogObserverFile•  s  ø€ ô -¨T¯Z©ZÓ8ˆØ—;‘;“=ˆÜ˜Y¨Ð1Ó2ˆà×&Ñ&Ó(ˆØ�‰˜×)Ñ)×/Ñ/Ô0à×Ñœ˜X›¨Ô*Ø×Ñ˜ !™×)Ñ)¬2¯7©7¯?©?¸8Ó+DÔEà×Ñœ˜TŸ\™\Ó*¨AÔ.Ø×Ñ˜Ÿ™ a™¨Ñ+¬V¯^©^Ô<ä‹Jˆõ	ð $�‰Ôà—L‘L ‘O AÑ&ˆ	Ù�$˜ÔØˆr7   c                 ó  ^ • U 4S jnT R                  [        SU5        T R                  5       n[        SU05      nUR	                  5       nT R                  UR                  R                  5        T R                  T R                  / 5        g)za
If a signal handler is already installed,
L{UnixAppLogger._getLogObserver} doesn't override it.
c                 óX   >• TR                  U [        R                  5        [        5       $ r)   )rˆ   rj  rx  rb  )r  rS   s    €r4   ÚfakeGetSignalÚVUnixAppLoggerTests.test_getLogObserverDontOverrideSignalHandler.<locals>.fakeGetSignal¹  s   ø€ Ø×Ñ˜S¤&§.¡.Ô1Ü“8ˆOr7   Ú	getsignalr8  N)
rE   rj  r  r"   r  rA  rB  rq  rˆ   rg  )rS   r}  rD  rE  rß  s   `    r4   Ú,test_getLogObserverDontOverrideSignalHandlerÚ?UnixAppLoggerTests.test_getLogObserverDontOverrideSignalHandler³  sn   ø€ õ	ð 	�
‰
”6˜;¨Ô6Ø—;‘;“=ˆÜ˜Y¨Ð1Ó2ˆà×&Ñ&Ó(ˆØ�‰˜×)Ñ)×/Ñ/Ô0à×Ñ˜Ÿ™ rÕ*r7   c                 ód  • [        U R                  5      n[        SSS.5      nUR                  " 5       nU R	                  UR
                  R                  5        U R                  [        U5      S5        U R                  US   R                  [        R                  R                  S5      5        g)z–
When daemonized and C{logfile} is empty, the observer returned by
L{UnixAppLogger._getLogObserver} points at C{twistd.log} in the current
directory.
r=  Frm  r  r   z
twistd.logN)râ  rE   r"   r  rA  rB  rq  rˆ   rf  r  r;   rC  )rS   rÝ  r   rß  s       r4   Útest_getLogObserverDefaultFileÚ1UnixAppLoggerTests.test_getLogObserverDefaultFileÆ  s‚   € ô -¨T¯Z©ZÓ8ˆÜ¨2¸5ÑAÓBˆØ×)Ò)Ó+ˆØ�‰˜×)Ñ)×/Ñ/Ô0à×Ñœ˜X›¨Ô*Ø×Ñ˜ !™×)Ñ)¬2¯7©7¯?©?¸<Ó+HÕIr7   rË   c                 ó¾   • [        U 5      n[        SSS.5      nUR                  " 5       nU R                  US/5        U" SS05        U R                  USSS0/5        g)zz
If C{syslog} is set to C{True}, L{UnixAppLogger._getLogObserver} starts
a L{syslog.SyslogObserver} with given C{prefix}.
Tztest-prefix)rð  rç  r-  ÚbN)rò  r"   r  rˆ   )rS   r4  r   rß  s       r4   Útest_getLogObserverSyslogÚ,UnixAppLoggerTests.test_getLogObserverSyslogÔ  sb   € ô ˜DÓ!ˆÜ¨$¸-ÑHÓIˆØ×)Ò)Ó+ˆØ×Ñ˜ ˜Ô/Ù�#�s�ÔØ×Ñ˜ °°S¨zÐ:Õ;r7   )rg  N)rV   rW   rX   rY   rZ   r8  r>  rp  rF  r€  rƒ  r   rø   r‡  r\   r]   r7   r4   rd  rd  e  sF   † ñò
1ò/ò$Oòò<+ò&Jñ �ÔÐ9Ó:ñ
<ó ;ó
<r7   rd  z!twistd unix support not availablec                   óx   • \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rSrg)ÚDaemonizeTestsiâ  z@
Tests for L{_twistd_unix.UnixApplicationRunner} daemonization.
c                 óÊ  • [        5       U l        [        R                  " 5       U l        U R                  [        SU R                  5        [        R                  U R                  5      U l        [        R                  " S5      U R                  l        [        R                  U R                  l        [        R                  U R                  l        S U R                  l        g )Nr;   r3  c                  ó   • g r)   r]   )rß   s    r4   r   Ú&DaemonizeTests.setUp.<locals>.<lambda>ð  s   € °r7   )r   Úmockosr   rŒ   r‘   rE   rø   r!   rC  r   r7  rc   rœ  rí   r€  Ústderrr�  r‚  rk   s    r4   r8  ÚDaemonizeTests.setUpè  sˆ   € Ü“hˆŒÜ×*Ò*Ó,ˆŒØ�
‰
”<  t§{¡{Ô3Ü"×8Ñ8¸¿¹ÓEˆŒÜ")×"5Ò"5°eÓ"<ˆ�‰ÔÜ #§
¡
ˆ�‰ÔÜ #§
¡
ˆ�‰ÔÙ#5ˆ�‰Õ r7   c                 ó2  • [        [        5       5         U R                  R                  5         SSS5        U R	                  U R
                  R                  / SQ5        U R	                  U R
                  R                  SS/5        g! , (       d  f       N_= f)z_
When double fork succeeded in C{daemonize}, the child process writes
B{0} to the status pipe.
N)©ræ  r÷  ©rÍ   r  ©ÚforkTÚsetsidr”  )r	  éþÿÿÿó   0©Úunlinkz
twistd.pidéýÿÿÿr—  )r   r  rC  ro   rˆ   rŽ  ÚactionsÚclosedrk   s    r4   Útest_successÚDaemonizeTests.test_successò  sn   € ô
 Ô4Ó6Õ7Ø�K‰K×'Ñ'Ô)÷ 8à×ÑØ�K‰K×Ñòô	
ð 	×Ñ˜Ÿ™×+Ñ+¨b°"¨XÕ6÷ 8Õ7ús   ”BÂ
Bc                 ó”  • SU R                   l        SU R                   l        [        [	        5       5         U R                  [        U R                  R                  5        SSS5        U R                  U R                   R                  / SQ5        U R                  U R                   R                  S/5        g! , (       d  f       N^= f)zp
The parent process initiating the C{daemonize} call reads data from the
status pipe and then exit the process.
Fr˜  N)r’  r“  r”  ©r
  éÿÿÿÿéd   ©Úexitr   r™  r¢  )rŽ  ÚchildÚreadDatar   r  r°   ÚSystemErrorrC  ro   rˆ   rœ  r�  rk   s    r4   Útest_successInParentÚ#DaemonizeTests.test_successInParent  sŽ   € ð
 "ˆ�‰ÔØ#ˆ�‰ÔÜÔ4Ó6Õ7Ø×Ñœk¨4¯;©;×+FÑ+FÔG÷ 8à×ÑØ�K‰K×Ñòô
	
ð 	×Ñ˜Ÿ™×+Ñ+¨b¨TÕ2÷ 8Õ7ús   ¶+B9Â9
Cc                 óŒ  ^• / mU4S jnXR                   l        [        [        5       5         U R                  R                  5         SSS5        U R                  U R                   R                  / SQ5        U R                  U R                   R                  SS/5        U R                  SS/T5        g! , (       d  f       Ns= f)zj
If the C{os.write} call to the status pipe raises an B{EINTR} error,
the process child retries to write.
c                 óz   >• TR                  X45        [        T5      S:X  a  [        [        R                  5      eg rñ  ©r¨   rf  r  r  ÚEINTR)Úfdr—  Úwrittens     €r4   ÚraisingWriteÚ6DaemonizeTests.test_successEINTR.<locals>.raisingWrite$  s1   ø€ Ø�N‰N˜B˜:Ô&Ü�7‹|˜qÓ ÜœeŸk™kÓ*Ð*ð !r7   N)r’  r“  r”  r–  r”  r™  r›  r—  )r—  r˜  )	rŽ  r	  r   r  rC  ro   rˆ   rœ  r�  )rS   r±  r°  s     @r4   Útest_successEINTRÚ DaemonizeTests.test_successEINTR  sš   ø€ ð
 ˆõ	+ð
 )�‰ÔÜÔ4Ó6Õ7Ø�K‰K×'Ñ'Ô)÷ 8à×ÑØ�K‰K×Ñòô
	
ð 	×Ñ˜Ÿ™×+Ñ+¨b°"¨XÔ6Ø×Ñ˜* jÐ1°7Õ;÷ 8Õ7ús   ­B5Â5
Cc                 óÌ  ^• / mU4S jnXR                   l        SU R                   l        [        [	        5       5         U R                  [        U R                  R                  5        SSS5        U R                  U R                   R                  / SQ5        U R                  U R                   R                  S/5        U R                  SS/T5        g! , (       d  f       Nr= f)zg
If the C{os.read} call on the status pipe raises an B{EINTR} error, the
parent child retries to read.
c                 óz   >• TR                  X45        [        T5      S:X  a  [        [        R                  5      eg)Nr  r˜  r­  )r¯  Úsizer
  s     €r4   ÚraisingReadÚ=DaemonizeTests.test_successInParentEINTR.<locals>.raisingReadA  s.   ø€ Ø�K‰K˜˜
Ô#Ü�4‹y˜A‹~ÜœeŸk™kÓ*Ð*Ør7   FN)r’  r“  r”  r¤  r™  r¢  )r¢  r£  )rŽ  r
  r¦  r   r  r°   r¨  rC  ro   rˆ   rœ  r�  )rS   r¸  r
  s     @r4   Útest_successInParentEINTRÚ(DaemonizeTests.test_successInParentEINTR:  s®   ø€ ð
 ˆõ	ð '�‰ÔØ!ˆ�‰ÔÜÔ4Ó6Õ7Ø×Ñœk¨4¯;©;×+FÑ+FÔG÷ 8à×ÑØ�K‰K×Ñòô		
ð 	×Ñ˜Ÿ™×+Ñ+¨b¨TÔ2Ø×Ñ˜) YÐ/°Õ6÷ 8Õ7ús   ¾+CÃ
C#c                 óô  ^•  " U4S jS[         R                  5      nU" 5       nUR                  U R                  R                  5        [        [        5       5         U R                  [        U R                  R                  5        SSS5        U R                  U R                  R                  SSSSSSS	U4S
/5        U R                  U R                  R                  SS	/5        g! , (       d  f       Ng= f)z–
Assert L{UnixApplicationRunner.postApplication} writes
C{reported} to its status pipe if the service raises an
exception whose message is C{raised}.
c                   ó"   >• \ rS rSrU 4S jrSrg)Ú6DaemonizeTests.assertErrorWritten.<locals>.FakeServicei_  c                 ó   >• [        T5      er)   rº  )rS   Úraiseds    €r4   r›  ÚCDaemonizeTests.assertErrorWritten.<locals>.FakeService.startService`  s   ø€ Ü" 6Ó*Ð*r7   r]   N)rV   rW   rX   rY   r›  r\   )rÀ  s   €r4   r¢  r¾  _  s   ø† ÷+ð +r7   r¢  Nr’  r“  r”  r–  r	  r—  r™  r›  )r   rQ   r‘  rC  rc   r   r  r°   r�  ro   rˆ   rŽ  rœ  r�  )rS   rÀ  Úreportedr¢  ÚerrorServices    `   r4   ÚassertErrorWrittenÚ!DaemonizeTests.assertErrorWrittenX  sÄ   ø€ ÷	+œ'Ÿ/™/ô 	+ñ #“}ˆØ×%Ñ% d§k¡k×&=Ñ&=Ô>äÔ4Ó6Õ7Ø×Ñœl¨D¯K©K×,GÑ,GÔH÷ 8à×ÑØ�K‰K×ÑàØ ØØØØ˜"˜hÐ'Ø(ðô	
ð 	×Ñ˜Ÿ™×+Ñ+¨b°"¨XÕ6÷ 8Õ7ús   Á+C)Ã)
C7c                 ó$   • U R                  SSS9  g)zl
If an error happens during daemonization, the child process writes the
exception error to the status pipe.
zSomething is wrongs"   1 RuntimeError: Something is wrong©rÀ  rÂ  N©rÄ  rk   s    r4   Ú
test_errorÚDaemonizeTests.test_errorv  s   € ð
 	×ÑØ'Ð2Wð 	 ò 	
r7   c                 ó$   • U R                  SSS9  g)z›
If an error happens during daemonization, and that error's
message is Unicode, the child encodes the message as ascii
with backslash Unicode code points.
u   â€¢s   1 RuntimeError: \u2022rÇ  NrÈ  rk   s    r4   Útest_unicodeErrorÚ DaemonizeTests.test_unicodeError  s   € ð 	×Ñ xÐ:TÐÒUr7   c                 ó  • SU R                   l        XR                   l        [        5       nU R	                  [
        SU5        [        [        5       5         U R                  [        U R                  R                  5        SSS5        U R                  UR                  5       U5        U R                  U R                   R                  U5        U R                  U R                   R                  S/5        g! , (       d  f       N|= f)zß
Make L{os.read} appear to return C{readData}, and assert that
L{UnixApplicationRunner.postApplication} writes
C{errorMessage} to standard error and executes the calls
against L{os} functions specified in C{mockOSActions}.
FÚ
__stderr__Nr¢  )rŽ  r¦  r§  r   rE   rœ  r   r  r°   r¨  rC  ro   rˆ   r³   rœ  r�  )rS   r§  ÚerrorMessageÚmockOSActionsÚerrorIOs        r4   ÚassertErrorInParentBehaviorÚ*DaemonizeTests.assertErrorInParentBehavior‡  s´   € ð "ˆ�‰ÔØ'�‰ÔÜ“*ˆØ�
‰
”3˜ gÔ.ÜÔ4Ó6Õ7Ø×Ñœk¨4¯;©;×+FÑ+FÔG÷ 8à×Ñ˜×)Ñ)Ó+¨\Ô:Ø×Ñ˜Ÿ™×,Ñ,¨mÔ<Ø×Ñ˜Ÿ™×+Ñ+¨b¨TÕ2÷	 8Õ7ús   Á+C7Ã7
Dc                 ó*   • U R                  SS/ SQS9  g)z­
When the child writes an error message to the status pipe
during daemonization, the parent writes the repr of the
message to C{stderr} and exits with non-zero status code.
s    1 Exception: An identified errorzgAn error has occurred: b'Exception: An identified error'
Please look at log file for more information.
©r’  r“  r”  r¡  )r¥  r  r™  ©r§  rÐ  rÑ  N©rÓ  rk   s    r4   Útest_errorInParentÚ!DaemonizeTests.test_errorInParent˜  s%   € ð 	×(Ñ(Ø8ðBòð 	)ò 	
r7   c                 ó*   • U R                  SS/ SQS9  g)z¸
When the child writes a non-ASCII error message to the status
pipe during daemonization, the parent writes the repr of the
message to C{stderr} and exits with a non-zero status code.
s   1 Exception: ÿzXAn error has occurred: b'Exception: \xff'
Please look at log file for more information.
rÖ  r×  NrØ  rk   s    r4   Útest_nonASCIIErrorInParentÚ)DaemonizeTests.test_nonASCIIErrorInParent®  s%   € ð 	×(Ñ(Ø)ðBòð 	)ò 	
r7   c                 ón   • SnSR                  S5      nU R                  USR                  U5      / SQS9  g)zâ
When the child writes a non-ASCII error message to the status
pipe during daemonization, and that message is too longer, the
parent writes the repr of the truncated message to C{stderr}
and exits with a non-zero status code.
ód   1 RuntimeError: \u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022zb'RuntimeError: {}'zb\\u2022\\u2022\\u2022\\u2022\\u2022\\u2022\\u2022\\u2022\\u2022\\u2022\\u2022\\u2022\\u2022\\u2022zHAn error has occurred: {}
Please look at log file for more information.
rÖ  r×  N)rµ   rÓ  )rS   ÚtruncatedMessageÚreportedMessages      r4   Ú&test_errorInParentWithTruncatedUnicodeÚ5DaemonizeTests.test_errorInParentWithTruncatedUnicodeÄ  sL   € ð AÐð 0×6Ñ6°ÓGˆØ×(Ñ(Ø%ðBßBHÁ&Ø#óCòð 	)ò 	
r7   c                 ó$   • U R                  SSS9  g)zc
If an error occurs during daemonization and its message is too
long, it's truncated by the child.
ÚÈxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsd   1 RuntimeError: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxrÇ  NrÈ  rk   s    r4   Útest_errorMessageTruncatedÚ)DaemonizeTests.test_errorMessageTruncatedá  s   € ð
 	×ÑØÐ'Fð 	 ò 	
r7   c                 ó$   • U R                  SSS9  g)zž
If an error occurs during daemonization and its message is
unicode and too long, it's truncated by the child, even if
this splits a unicode escape sequence.
uZ   â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢rß  rÇ  NrÈ  rk   s    r4   Ú!test_unicodeErrorMessageTruncatedÚ0DaemonizeTests.test_unicodeErrorMessageTruncatedê  s   € ð 	×ÑØ Ø:ð 	 ò 	
r7   c                 óº   • [        5       nU R                  R                  U5        U R                  UR                  5        U R                  UR
                  5        g)z˜
C{daemonize} indeed calls L{IReactorDaemonize.beforeDaemonize} and
L{IReactorDaemonize.afterDaemonize} if the reactor implements
L{IReactorDaemonize}.
N)r  rC  rí  r¼   r  r€  ró  s     r4   Útest_hooksCalledÚDaemonizeTests.test_hooksCalledõ  sB   € ô )Ó*ˆØ�‰×Ñ˜gÔ&Ø�‰˜×6Ñ6Ô7Ø�‰˜×5Ñ5Õ6r7   c                 óº   • [        5       nU R                  R                  U5        U R                  UR                  5        U R                  UR
                  5        g)z 
C{daemonize} does NOT call L{IReactorDaemonize.beforeDaemonize} or
L{IReactorDaemonize.afterDaemonize} if the reactor does NOT implement
L{IReactorDaemonize}.
N)r}  rC  rí  rÁ   r  r€  ró  s     r4   Útest_hooksNotCalledÚ"DaemonizeTests.test_hooksNotCalled   sF   € ô ,Ó-ˆØ�‰×Ñ˜gÔ&Ø×Ñ˜×7Ñ7Ô8Ø×Ñ˜×6Ñ6Õ7r7   )r‘   rŽ  rC  N)rV   rW   rX   rY   rZ   r8  rž  r©  r³  rº  rÄ  rÉ  rÌ  rÓ  rÙ  rÜ  râ  ræ  ré  rì  rï  r\   r]   r7   r4   rŠ  rŠ  â  sX   † ñò6ò7ò*3ò,<ò:7ò<7ò<
òVò3ò"
ò,
ò,
ò:
ò	
ò	7õ	8r7   rŠ  c                   óL   • \ rS rSrSr\S 5       r\R                  S 5       rSrg)ÚSignalCapturingMemoryReactori  z}
MemoryReactor that implements the _ISupportsExitSignalCapturing interface,
all other operations identical to MemoryReactor.
c                 ó   • U R                   $ r)   ©Ú_valrk   s    r4   rË  Ú(SignalCapturingMemoryReactor._exitSignal  s   € à�y‰yÐr7   c                 ó   • Xl         g r)   rô  )rS   Úvals     r4   rË  rö    s   € à�	r7   rô  N)	rV   rW   rX   rY   rZ   ÚpropertyrË  Úsetterr\   r]   r7   r4   rò  rò    s5   † ñð
 ñó ðð ×Ññó ór7   rò  c                   ó<   ^ • \ rS rSrSr\rU 4S jrS rS r	Sr
U =r$ )ÚStubApplicationRunnerWithSignali  zÛ
An application runner that uses a SignalCapturingMemoryReactor and
has a _signalValue attribute that it will set in the reactor.

@ivar _signalValue: The signal value to set on the reactor's _exitSignal
    attribute.
c                 ó2   >• [         TU ]  U5        S U l        g r)   )Úsuperr~   Ú_signalValue)rS   r‘   Ú	__class__s     €r4   r~   Ú(StubApplicationRunnerWithSignal.__init__'  s   ø€ Ü‰Ñ˜Ô Ø ˆÕr7   c                 ó   • g)z
Does nothing.
Nr]   rk   s    r4   rl   Ú.StubApplicationRunnerWithSignal.preApplication+  rN  r7   c                 ó˜   • [        5       nU R                  Ul        U R                  U[        R
                  [        R                  5        g)zH
Instantiate a SignalCapturingMemoryReactor and start it
in the runner.
N)rò  rÿ  rË  r‚  rœ  rí   r�  ró  s     r4   ro   Ú/StubApplicationRunnerWithSignal.postApplication0  s4   € ô
 /Ó0ˆØ"×/Ñ/ˆÔØ×Ñ˜'¤3§:¡:¬s¯z©zÕ:r7   )rÿ  )rV   rW   rX   rY   rZ   r_   rq   r~   rl   ro   r\   Ú__classcell__)r   s   @r4   rü  rü    s#   ø† ñð &€Mõ!ò÷
;ð ;r7   rü  c                 ó   ^ • U 4S jnU$ )a)  
Create a factory function to instantiate a
StubApplicationRunnerWithSignal that will report signum as the captured
signal..

@param signum: The integer signal number or None
@type signum: C{int} or C{None}

@return: A factory function to create stub runners.
@rtype: stubApplicationRunnerFactory
c                 ó,   >• [        U 5      nTUl        U$ )aw  
Create a StubApplicationRunnerWithSignal using a reactor that
implements _ISupportsExitSignalCapturing and whose _exitSignal
attribute is set to signum.

@param config: The runner configuration, platform dependent.
@type config: L{twisted.scripts.twistd.ServerOptions}

@return: A runner to use for the test.
@rtype: twisted.test.test_twistd.StubApplicationRunnerWithSignal
)rü  rÿ  )r‘   rC  Úsignums     €r4   ÚstubApplicationRunnerFactoryÚIstubApplicationRunnerFactoryCreator.<locals>.stubApplicationRunnerFactoryG  s   ø€ ô 1°Ó8ˆØ$ˆÔØˆr7   r]   )r	  r
  s   ` r4   Ú#stubApplicationRunnerFactoryCreatorr  :  s   ø€ õð  (Ð'r7   c                   ó0   • \ rS rSrSrS rS rS rS rSr	g)	ÚExitWithSignalTestsiZ  z7
Tests for L{twisted.application.app._exitWithSignal}.
c                 ó  ^ • [         R                  " 5       T l        S[        5       0T R                  l        [        5       T R                  l        ST R                  l        SS/T l        U 4S jnT R                  [        SU5        g)z=
Set up the server options and a fake for use by test cases.
r_  Nc                 óB   >• U TR                   S'   UTR                   S'   g)z”
Fake method to capture arguments passed to os.kill.

@param pid: The pid of the process being killed.

@param sig: The signal sent to the process.
r   r  N)ÚfakeKillArgs)r  r  rS   s     €r4   ÚfakeKillÚ+ExitWithSignalTests.setUp.<locals>.fakeKillj  s%   ø€ ð $'ˆD×Ñ˜aÑ Ø#&ˆD×Ñ˜aÒ r7   r  )r   rŒ   r‘   rL   ra  rb  rc  r“   r  rE   r;   )rS   r  s   ` r4   r8  ÚExitWithSignalTests.setUp`  sg   ø€ ô ×*Ò*Ó,ˆŒØ%3Ô5EÓ5GÐ$Hˆ�‰Ô!Ü!'£ˆ�‰ÔØ!/ˆ�‰ÔØ! 4˜LˆÔõ		'ð 	�
‰
”2�v˜xÕ(r7   c                 óÚ  ^• SS/mU4S jnU R                  [        SU5        [        R                  " [        R                  5        U R                  TS   [        R                  5        U R                  TS   [        R                  5        U R                  U R                  S   [        R                  " 5       5        U R                  U R                  S   [        R                  5        g)z„
exitWithSignal replaces the existing signal handler with the default
handler and sends the replaced signal to the current process.
Nc                 ó   >• U TS'   UTS'   g )Nr   r  r]   )r  ÚhandlerÚfakeSignalArgss     €r4   Úfake_signalÚ<ExitWithSignalTests.test_exitWithSignal.<locals>.fake_signal  s   ø€ Ø #ˆN˜1ÑØ 'ˆN˜1Òr7   rj  r   r  )
rE   rj  r
   Ú_exitWithSignalÚSIGINTrÏ  ÚSIG_DFLr  r;   r#  )rS   r  r  s     @r4   Útest_exitWithSignalÚ'ExitWithSignalTests.test_exitWithSignalw  s©   ø€ ð  ˜ˆõ	(ð 	�
‰
”6˜8 [Ô1Ü×ÒœFŸM™MÔ*à×Ñ˜.¨Ñ+¬V¯]©]Ô;Ø×Ñ˜.¨Ñ+¬V¯^©^Ô<Ø×Ñ˜$×+Ñ+¨AÑ.´·	²	³Ô<Ø×Ñ˜$×+Ñ+¨AÑ.´·±Õ>r7   c                 óü   • U R                  [        S[        S5      5        [        R                  " U R                  5        U R                  U R                  S   5        U R                  U R                  S   5        g)zJ
_exitWithSignal is not called if the runner does not exit with a
signal.
r£  Nr   r  )rE   r   r  ÚrunAppr‘   r�   r  rk   s    r4   Útest_normalExitÚ#ExitWithSignalTests.test_normalExit‹  sc   € ð
 	�
‰
ÜÐ,Ô.QÐRVÓ.Wô	
ô 	�Š�d—k‘kÔ"Ø×Ñ˜$×+Ñ+¨AÑ.Ô/Ø×Ñ˜$×+Ñ+¨AÑ.Õ/r7   c                 ó^  • U R                  [        S[        [        R                  5      5        [        R
                  " U R                  5        U R                  U R                  S   [        R                  " 5       5        U R                  U R                  S   [        R                  5        g)z@
_exitWithSignal is called when the runner exits with a signal.
r£  r   r  N)rE   r   r  rj  r  r!  r‘   rÏ  r  r;   r#  rk   s    r4   Útest_runnerExitsWithSignalÚ.ExitWithSignalTests.test_runnerExitsWithSignal—  st   € ð 	�
‰
ÜØ$Ü/´·±Ó>ô	
ô
 	�Š�d—k‘kÔ"Ø×Ñ˜$×+Ñ+¨AÑ.´·	²	³Ô<Ø×Ñ˜$×+Ñ+¨AÑ.´·±Õ>r7   )r‘   r  N)
rV   rW   rX   rY   rZ   r8  r  r"  r%  r\   r]   r7   r4   r  r  Z  s   † ñò)ò.?ò(
0õ?r7   r  )hrZ   r  r3  r;   r5  rj  rœ  r=   Ú_grpr:   Ú_pwdÚImportErrorÚior   Úunittestr   Úzope.interfacer   Úzope.interface.verifyr   rî   r   r   r	   Útwisted.applicationr
   r   r   Útwisted.application.servicer   Útwisted.internet.baser   Útwisted.internet.deferr   Útwisted.internet.interfacesr   r   Ú#twisted.internet.test.modulehelpersr   Útwisted.internet.testingr   Útwisted.loggerr   r   r   Útwisted.pythonr   Útwisted.python.componentsr   Útwisted.python.fakepwdr   Útwisted.python.logr,  r   Útwisted.python.reflectr   Útwisted.python.runtimer   Útwisted.python.usager   Útwisted.scriptsr   Útwisted.test.test_processr   Útwisted.trial.unittestr    rø   Útwisted.scripts._twistd_unixr!   r"   r#   rð  r$   r%   r&   rJ   rL   r  r_   r£  rh   rs   rú   r0  r@  rR  rP  r]  rÞ  r  rm  r}  r  r¸  r’  râ  rò  rô  rd  rŠ  rò  rü  r  r  r]   r7   r4   Ú<module>rA     s  ðñó
 Û Û 	Û Û Û 
ðÛÛð
 €CØ
€Cå Ý å &Ý .ç ,Ñ ,ß 6Ñ 6Ý 5Ý -Ý +ß XÝ @Ý 2ß NÑ NÝ Ý 3Ý /ß TÝ 0Ý /Ý +Ý "Ý ,Ý +áÐ;Ó<€Þ÷ñ ñ 
Ð.Ó	/€Ù
˜	Ó
"€Ù	�xÓ	 €Ù˜Ó$€ò*.÷Zñ ô"˜Ÿ™ô ô × =Ñ =ô ô UJ˜ô UJñp ˆLÔÐ5Ó6ôCK�Hó CKó 7ðCKôLD�8ô D÷0ñ ô*J˜C×1Ñ1ô Jô(p4˜Xô p4ñf ˆLÔÐ5Ó6ôF+°ó F+ó 7ðF+ñR ˆLÔÐ5Ó6ôO?°ó O?ó 7ðO?ñd ˆLÔÐ5Ó6ô>¨(ó >ó 7ð>÷<ñ ñ8 ÐÓôÐ6ó ó  ð÷ñ ô(w8˜ô w8òtò*ô$`5�Xô `5ñF	 ˆLÔÐ5Ó6ôy<˜ó y<ó 7ðy<ñx ˆLÔÐ=Ó>ôf8�Xó f8ó ?ðf8ñR	 Ð*Ó+ô =ó ó ,ðô; f×&CÑ&Cô ;ò<(ô@H?˜(õ H?øðOB ó Ø
€CØ
ƒCðús   œJ Ê
J(Ê'J(