Ë
    oj$! ã                   ó  — d Z ddlZddlZddlZddlZddlZddlZ	 ddlZddl	Z
e
Z	eZddlmZ ddlmZ ddlmZ ddlmZ ddlmZmZmZ ddlmZmZmZ dd	lmZ dd
lmZ ddl m!Z! ddl"m#Z#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z*m+Z+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m*Z4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZA  e7d«      ZBeBr
ddlCmDZDmEZEmFZF  e7d«      ZG e7d«      ZH e7d«      ZI e7d«      ZJd „ ZK G d!„ d"«      ZL G d#„ d$ejš                  «      ZN G d%„ d&e=jž                  «      ZP G d'„ d(eA«      ZQ eeB d)«       G d*„ d+eA«      «       ZR G d,„ d-eA«      ZS G d.„ d/«      ZT G d0„ d1ejª                  «      ZV G d2„ d3eA«      ZW eeB d)«       G d4„ d5eA«      «       ZX eeB d)«       G d6„ d7eA«      «       ZY eeB d)«       G d8„ d9eA«      «       ZZ G d:„ d;«      Z[ ee#«       G d<„ d=e[«      «       Z\ G d>„ d?«      Z] G d@„ dAeA«      Z^dB„ Z_dC„ Z` G dD„ dEeA«      Za eeB d)«       G dF„ dGeA«      «       Zb eeB dH«       G dI„ dJeA«      «       Zc ee$«       G dK„ dLe(«      «       Zd G dM„ dNe=jž                  «      ZedO„ Zf G dP„ dQeA«      Zgy# e$ r dZ	dZY �Œaw xY w)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           	      óÂ  ‡‡‡— t         j                  t        j                  «       «      }t        j                  t        j                  «       «      Št        «       }|j                  ||j                  |‰|j                  |j                  |j                  «       ˆˆˆfd„} | t         d|j                  «        | t        d|«        | t         d|j                  «       y)au  
    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        ‰«      }‰||j                  ‰j                  «      <   ‰||j                  ‰j                  «      <   t	        |«      }‰|i|    S ©N)ÚlistÚindexÚgr_nameÚgr_gidÚtuple)ÚnameÚresultÚgidÚgrentÚgroups     €€€ú:/usr/lib/python3/dist-packages/twisted/test/test_twistd.pyÚgetgrnamz#patchUserDatabase.<locals>.getgrnamd   sR   ø€ Ü�e“ˆØ.3ˆˆv�|‰|˜EŸM™MÓ*Ñ+Ø-0ˆˆv�|‰|˜EŸL™LÓ)Ñ*Ü�v“ˆØ�vˆ˜tÑ$Ð$ó    Úgetpwnamr5   ÚgetpwuidN)Úpwdr8   ÚosÚgetuidÚgrpÚgetgrgidÚgetgidr   ÚaddUserÚ	pw_passwdÚpw_gecosÚpw_dirÚpw_shellr7   )	ÚpatchÚuserÚuidr3   r1   ÚpwentÚdatabaser5   r2   s	      ``   @r4   ÚpatchUserDatabaserI   C   s˜   ú€ ô2 �L‰LœŸ™›Ó%€EÜ�L‰LœŸ™›Ó%€Eä‹~€HØ×ÑØˆe�o‰o˜s C¨¯©¸¿¹ÀuÇ~Á~ôö%ñ 
Œ#ˆz˜8×,Ñ,Ô-Ù	Œ#ˆz˜8Ô$Ù	Œ#ˆz˜8×,Ñ,Õ-r6   c                   ó   — e Zd ZdZdZd„ Zy)ÚMockServiceMakerzO
    A non-implementation of L{twisted.application.service.IServiceMaker}.
    Úueoac                 óZ   — || _         t        j                  «       | _        | j                  S )ze
        Take a L{usage.Options} instance and return a
        L{service.IService} provider.
        )Úoptionsr   ÚService©ÚselfrN   s     r4   ÚmakeServicezMockServiceMaker.makeServicew   s#   € ð
 ˆŒÜ—‘Ó(ˆŒØ�|‰|Ðr6   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚtapnamerR   © r6   r4   rK   rK   p   s   „ ñð €Gór6   rK   c                   ó   — e Zd ZdZd„ Zy)ÚCrippledAppLoggerz*
    @see: CrippledApplicationRunner.
    c                  ó   — y r)   rX   ©rQ   Úapplications     r4   ÚstartzCrippledAppLogger.start†   ó   € Ør6   N)rS   rT   rU   rV   r^   rX   r6   r4   rZ   rZ   �   s   „ ñór6   rZ   c                   ó    — e Zd ZdZeZd„ Zd„ Zy)ÚCrippledApplicationRunnerzÃ
    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                  ó   — y r)   rX   ©rQ   s    r4   ÚpreApplicationz(CrippledApplicationRunner.preApplication“   r_   r6   c                  ó   — y r)   rX   rc   s    r4   ÚpostApplicationz)CrippledApplicationRunner.postApplication–   r_   r6   N)rS   rT   rU   rV   rZ   ÚloggerFactoryrd   rf   rX   r6   r4   ra   ra   Š   s   „ ñð &€Mòór6   ra   c                   ó¦   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Z e	e
 d«      d„ «       Z e	e
 d«      d	„ «       Z e	e
 d«      d
„ «       Zd„ Zd„ Zd„ Zd„ Zy)ÚServerOptionsTestszT
    Non-platform-specific tests for the platform-specific ServerOptions class.
    c                 ó.  ‡ ‡‡‡‡—  G d„ d«      } |d«      Š |d«      Š |d«      Š |d«      Šˆˆˆˆˆ fd„}t        j                  «       }‰ j                  |j                  t        j
                  «       ||_        |j                  }‰‰‰‰g}t        ||«      D ]w  \  }}|\  }}	}
}‰ j                  ||j                  «       ‰ j                  |	«       ‰ j                   |
«       |j                  «      f ‰ j                  ||j                  «       Œy y)	zh
        subCommands is built from IServiceMaker plugins, and is sorted
        alphabetically.
        c                   ó   — e Zd Zd„ Zd„ Zy)ú7ServerOptionsTests.test_subCommands.<locals>.FakePluginc                 ó:   — || _         d|z   | _        d|z   | _        y )Nzoptions for údescription of )rW   Ú_optionsÚdescription©rQ   r/   s     r4   Ú__init__z@ServerOptionsTests.test_subCommands.<locals>.FakePlugin.__init__¦   s"   € Ø#�”Ø .°Ñ 5�”Ø#4°tÑ#;�Õ r6   c                 ó   — | j                   S r)   )ro   rc   s    r4   rN   z?ServerOptionsTests.test_subCommands.<locals>.FakePlugin.options«   s   € Ø—}‘}Ð$r6   N)rS   rT   rU   rr   rN   rX   r6   r4   Ú
FakePluginrl   ¥   s   „ ò<ó
%r6   rt   ÚappleÚbananaÚcoconutÚdonutc              3   óZ   •K  — ‰j                  | t        «       ‰–— ‰–— ‰–— ‰–— y ­wr)   )ÚassertEqualr   )Ú	interfaceru   rv   rw   rx   rQ   s    €€€€€r4   Ú
getPluginsz7ServerOptionsTests.test_subCommands.<locals>.getPlugins³   s+   øè ø€ Ø×Ñ˜Y¬Ô6ØŠMØŠLØŠKØ‹Kùs   ƒ(+N)r   ÚServerOptionsrz   Ú_getPluginsr	   r|   ÚsubCommandsÚziprW   ÚassertIsNonero   rp   )rQ   rt   r|   Úconfigr   ÚexpectedOrderÚ
subCommandÚexpectedCommandr/   ÚshortcutÚparserClassÚdocumentationru   rv   rw   rx   s   `           @@@@r4   Útest_subCommandsz#ServerOptionsTests.test_subCommandsŸ   s  ü€ ÷	%ñ 	%ñ ˜7Ó#ˆÙ˜HÓ%ˆÙ˜YÓ'ˆÙ˜7Ó#ˆ÷	ð 	ô ×%Ñ%Ó'ˆØ×Ñ˜×+Ñ+¬V×->Ñ->Ô?Ø'ˆÔð ×(Ñ(ˆØ ¨°Ð7ˆä+.¨{¸MÓ+Jò 	IÑ'ˆJ˜Ø9CÑ6ˆD�(˜K¨Ø×Ñ˜T ?×#:Ñ#:Ô;Ø×Ñ˜hÔ'Ø×Ñ™[›]¨O×,DÑ,DÓEÑFØ×Ñ˜]¨O×,GÑ,GÕHñ	Ir6   c                 ó\  ‡ ‡‡‡‡	‡
‡—  G d„ d«      } |d«      Š |d«      Š |d«      Š |d«      Š	ˆˆˆˆ	fd„}t        j                  «       }‰ j                  |j                  t        j
                  «       ||_        t        «       |_        ‰ j                  t        |j                  dg«       |j                  j                  «       Š
g Š‰‰‰‰	fD ]-  }ˆ
ˆˆ fd	„} ||j                  «        ||j                  «       Œ/ ‰ j                  ‰t        ‰«      d
j                  ‰
«      «       y)zP
        Reactor names are listed alphabetically by I{--help-reactors}.
        c                   ó   — e Zd Zd„ Zy)úGServerOptionsTests.test_sortedReactorHelp.<locals>.FakeReactorInstallerc                 ó:   — d|z   | _         d|z   | _        d| _        y )Nzname of rn   ztwisted.internet.default)Ú	shortNamerp   Ú
moduleNamerq   s     r4   rr   zPServerOptionsTests.test_sortedReactorHelp.<locals>.FakeReactorInstaller.__init__Ð   s"   € Ø!+¨dÑ!2�”Ø#4°tÑ#;�Ô Ø"<�•r6   N)rS   rT   rU   rr   rX   r6   r4   ÚFakeReactorInstallerrŒ   Ï   s   „ ó=r6   r�   ru   rv   rw   rx   c               3   ó.   •K  — ‰–— ‰–— ‰–— ‰ –— y ­wr)   rX   )ru   rv   rw   rx   s   €€€€r4   ÚgetReactorTypeszBServerOptionsTests.test_sortedReactorHelp.<locals>.getReactorTypesÚ   s   øè ø€ ØŠMØŠLØŠKØ‹Kùs   ƒz--help-reactorsc                 ój   •— ‰j                  | ‰«       ‰j                  ‰j                  | «      «       y r)   )ÚassertInÚappendr+   )ÚsÚ
helpOutputÚindexesrQ   s    €€€r4   ÚgetIndexz;ServerOptionsTests.test_sortedReactorHelp.<locals>.getIndexê   s(   ø€ Ø—‘˜a Ô,Ø—‘˜z×/Ñ/°Ó2Õ3r6   z9reactor descriptions were not in alphabetical order: {!r}N)r   r}   rz   Ú_getReactorTypesr   r’   r   ÚmessageOutputÚassertRaisesÚ
SystemExitÚparseOptionsÚgetvaluerŽ   rp   ÚsortedÚformat)rQ   r�   r’   r‚   Úreactorr™   ru   rv   rw   rx   r—   r˜   s   `     @@@@@@r4   Útest_sortedReactorHelpz)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×(Ñ(Õ)ð	*ð 	×ÑØÜ�7‹OØG×NÑNØóõ	
r6   c                 ó‚   — t        j                  «       }d|_        |j                  «        | j	                  |d   «       y)zS
        postOptions should set no_save to True when a subcommand is used.
        rL   Úno_saveN)r   r}   r„   ÚpostOptionsÚ
assertTrue©rQ   r‚   s     r4   Ú&test_postOptionsSubCommandCausesNoSavez9ServerOptionsTests.test_postOptionsSubCommandCausesNoSaveù   s7   € ô ×%Ñ%Ó'ˆØ"ˆÔØ×ÑÔØ�‰˜˜yÑ)Õ*r6   c                 ót   — t        j                  «       }|j                  «        | j                  |d   «       y)zR
        If no sub command is used, postOptions should not touch no_save.
        r¥   N)r   r}   r¦   ÚassertFalser¨   s     r4   Ú(test_postOptionsNoSubCommandSavesAsUsualz;ServerOptionsTests.test_postOptionsNoSubCommandSavesAsUsual  s1   € ô ×%Ñ%Ó'ˆØ×ÑÔØ×Ñ˜ 	Ñ*Õ+r6   c                 ó¤   — t        j                  «       }t        |«      }t        j                  j
                  D ]  }| j                  ||«       Œ y)zq
        All the profilers that can be used in L{app.AppProfiler} are listed in
        the help output.
        N)r   r}   Ústrr
   ÚAppProfilerÚ	profilersr”   )rQ   r‚   r—   Úprofilers       r4   Útest_listAllProfilersz(ServerOptionsTests.test_listAllProfilers
  sB   € ô
 ×%Ñ%Ó'ˆÜ˜“[ˆ
ÜŸ™×1Ñ1ò 	0ˆHØ�M‰M˜( JÕ/ñ	0r6   útwistd unix not availablec                 óT   — t        j                  «       }| j                  |d   «       y)zG
        The default value for the C{umask} option is L{None}.
        ÚumaskN)r   r}   r�   r¨   s     r4   Útest_defaultUmaskz$ServerOptionsTests.test_defaultUmask  s$   € ô
 ×%Ñ%Ó'ˆØ×Ñ˜& ™/Õ*r6   c                 óÌ   — t        j                  «       }|j                  ddg«       | j                  |d   d«       |j                  ddg«       | j                  |d   d«       y)zh
        The value given for the C{umask} option is parsed as an octal integer
        literal.
        ú--umaskÚ123rµ   éS   Ú0123N)r   r}   rž   rz   r¨   s     r4   Ú
test_umaskzServerOptionsTests.test_umask  s`   € ô ×%Ñ%Ó'ˆØ×Ñ˜Y¨Ð.Ô/Ø×Ñ˜ ™¨"Ô-Ø×Ñ˜Y¨Ð/Ô0Ø×Ñ˜ ™¨"Õ-r6   c                 ór   — t        j                  «       }| j                  t        |j                  ddg«       y)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_invalidUmaskz$ServerOptionsTests.test_invalidUmask(  s/   € ô ×%Ñ%Ó'ˆØ×Ñœ* f×&9Ñ&9¸IÀxÐ;PÕQr6   c                 ó
  — t        j                  «       }| j                  t        |j                  ddg«      }| j                  |j                  d   j                  d«      «       | j                  d|j                  d   «       y)zQ
        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©rQ   r‚   Úes      r4   Ú&test_unimportableConfiguredLogObserverz9ServerOptionsTests.test_unimportableConfiguredLogObserver1  sy   € ô ×%Ñ%Ó'ˆØ×ÑÜ˜×+Ñ+¨jÐ:QÐ-Ró
ˆð 	�‰Ø�F‰F�1‰I× Ñ ðBóô	
ð 	×Ñ˜˜qŸv™v a™yÕ)r6   c                 ó
  — t        j                  «       }| j                  t        |j                  ddg«      }| j                  |j                  d   j                  d«      «       | j                  d|j                  d   «       y)zP
        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_badAttributeWithConfiguredLogObserverz=ServerOptionsTests.test_badAttributeWithConfiguredLogObserverA  sz   € ô ×%Ñ%Ó'ˆØ×ÑÜØ×ÑØÐ:Ð;ó
ˆð
 	�‰Ø�F‰F�1‰I× Ñ ð,óô	
ð 	×Ñ˜˜qŸv™v a™yÕ)r6   c                 óv  — ddl m} t        dk(  rd}nd}dj                  ||j                  |j                  «      }t        «       }t        j                  |¬«      }| j                  t        |j                  dg«      }| j                  |j                  d	«       | j                  |j                  «       |«       y	)
z2
        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Úcoderz   rŸ   )rQ   rÍ   r/   ÚexpectedOutputrÐ   r‚   rÈ   s          r4   Útest_versionzServerOptionsTests.test_versionT  sš   € õ 	&ä˜7Ò"Ø1‰Dà)ˆDØ-×4Ñ4Ø�)×#Ñ# Y×%8Ñ%8ó
ˆô “ˆÜ×%Ñ%¨VÔ4ˆØ×Ñœj¨&×*=Ñ*=À¸}ÓMˆØ�‰�a—f‘f˜dÔ#Ø×Ñ˜Ÿ™Ó*¨NÕ;r6   c                 óˆ   — t        «       }t        j                  |¬«      }| j                  t        |j
                  dg«       y)zI
        Command is printed when an invalid option is requested.
        rÏ   z	web --fooN)r   r   r}   rœ   r   rž   )rQ   rÐ   r‚   s      r4   Ú!test_printSubCommandForUsageErrorz4ServerOptionsTests.test_printSubCommandForUsageErrorh  s5   € ô “ˆÜ×%Ñ%¨VÔ4ˆà×Ñœ* f×&9Ñ&9¸K¸=ÕIr6   N)rS   rT   rU   rV   r‰   r£   r©   r¬   r²   r   Ú_twistd_unixr¶   r¼   r¿   rÉ   rË   rÖ   rØ   rX   r6   r4   ri   ri   š   s—   „ ñò)IòV-
ò^+ò,ò0ñ �ÐÐ9Ó:ñ+ó ;ð+ñ �ÐÐ9Ó:ñ	.ó ;ð	.ñ �ÐÐ9Ó:ñRó ;ðRò*ò *ò&<ó(Jr6   ri   r³   c                   ó.   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚCheckPIDTestsz 
    Tests for L{checkPID}.
    c                 ó^   — | j                  t        j                  dd„ «       t        d«       y)z7
        Nonexistent PID file is not an error.
        Úexistsc                  ó   — y©NFrX   )Ú_s    r4   ú<lambda>z.CheckPIDTests.test_notExists.<locals>.<lambda>|  ó   � r6   znon-existent PID fileN)rD   r:   Úpathr#   rc   s    r4   Útest_notExistszCheckPIDTests.test_notExistsx  s!   € ð 	�
‰
”2—7‘7˜H¡oÔ6ÜÐ(Õ)r6   c                 óö   — | j                  «       }t        |d«      5 }|j                  d«       ddd«       | j                  t        t
        |«      }| j                  d|j                  «       y# 1 sw Y   ŒAxY w)zI
        Non-numeric content in a PID file causes a system exit.
        Úwznon-numericNznon-numeric value)ÚmktempÚopenÚwriterœ   r�   r#   r”   rÔ   )rQ   ÚpidfileÚfrÈ   s       r4   Útest_nonNumericzCheckPIDTests.test_nonNumeric  sc   € ð —+‘+“-ˆÜ�'˜3Óð 	# 1Ø�G‰G�MÔ"÷	#à×Ñœj¬(°GÓ<ˆØ�‰Ð)¨1¯6©6Õ2÷	#ð 	#ús   �A/Á/A8c                 ó*  — | j                  «       }t        |d«      5 }|j                  d«       ddd«       d„ }| j                  t        d|«       | j                  t        t        |«      }| j                  d|j                  «       y# 1 sw Y   Œ[xY w)zE
        Another running twistd server causes a system exit.
        ræ   Ú42Nc                  ó   — y r)   rX   ©ÚpidÚsigs     r4   Úkillz/CheckPIDTests.test_anotherRunning.<locals>.kill‘  s   € Ør6   ró   zAnother twistd server)
rç   rè   ré   rD   r:   rœ   r�   r#   r”   rÔ   ©rQ   rê   rë   ró   rÈ   s        r4   Útest_anotherRunningz!CheckPIDTests.test_anotherRunning‰  sy   € ð —+‘+“-ˆÜ�'˜3Óð 	 1Ø�G‰G�DŒM÷	ò	ð 	�
‰
”2�v˜tÔ$Ø×Ñœj¬(°GÓ<ˆØ�‰Ð-¨q¯v©vÕ6÷	ð 	ús   �B	Â	Bc                 ój  — | j                  «       }t        |d«      5 }|j                  t        t	        j
                  «       dz   «      «       ddd«       d„ }| j                  t        d|«       t        |«       | j                  t        j                  j                  |«      «       y# 1 sw Y   Œ]xY w)zJ
        Stale PID file is removed without causing a system exit.
        ræ   é   Nc                 ó6   — t        t        j                  d«      ‚©NÚfake)ÚOSErrorÚerrnoÚESRCHrð   s     r4   ró   z&CheckPIDTests.test_stale.<locals>.kill   ó   € Üœ%Ÿ+™+ vÓ.Ð.r6   ró   )rç   rè   ré   r®   r:   ÚgetpidrD   r#   r«   rã   rÝ   )rQ   rê   rë   ró   s       r4   Ú
test_stalezCheckPIDTests.test_stale˜  s…   € ð —+‘+“-ˆÜ�'˜3Óð 	* 1Ø�G‰G”CœŸ	™	› a™Ó(Ô)÷	*ò	/ð 	�
‰
”2�v˜tÔ$Ü�ÔØ×ÑœŸ™Ÿ™¨Ó0Õ1÷	*ð 	*ús   �0B)Â)B2c                 ó„  — | j                  «       }t        |d«      5 }|j                  d«       ddd«       d„ }| j                  t        d|«       | j                  t        t        |«      }| j                  |j                  d«       | j                  |j                  d   j                  d«      «       y# 1 sw Y   ŒˆxY w)z�
        An unexpected L{OSError} when checking the validity of a
        PID in a C{pidfile} terminates the process via L{SystemExit}.
        ræ   Ú3581Nc                 ó6   — t        t        j                  d«      ‚rù   ©rû   rü   ÚEBADFrð   s     r4   ró   z2CheckPIDTests.test_unexpectedOSError.<locals>.kill°  rþ   r6   ró   r   zCan't check status of PID)rç   rè   ré   rD   r:   rœ   r�   r#   ÚassertIsNotrÔ   r§   rÄ   rÅ   rô   s        r4   Útest_unexpectedOSErrorz$CheckPIDTests.test_unexpectedOSError§  sš   € ð
 —+‘+“-ˆÜ�'˜3Óð 	 1Ø�G‰G�FŒO÷	ò	/ð 	�
‰
”2�v˜tÔ$Ø×Ñœj¬(°GÓ<ˆØ×Ñ˜Ÿ™ Ô&Ø�‰˜Ÿ™˜q™	×,Ñ,Ð-HÓIÕJ÷	ð 	ús   �B6Â6B?N)	rS   rT   rU   rV   rä   rì   rõ   r   r  rX   r6   r4   rÛ   rÛ   r  s!   „ ñò*ò3ò7ò2óKr6   rÛ   c                   ó   — e Zd ZdZd„ Zd„ Zy)ÚTapFileTestszM
    Test twistd-related functionality that requires a tap file on disk.
    c                 óÖ   — | j                  «       | _        t        | j                  d«      5 }t        j                  t        j                  d«      |«       ddd«       y# 1 sw Y   yxY w)zP
        Create a trivial Application and put it in a tap file on disk.
        ÚwbúHi!N)rç   Útapfilerè   ÚpickleÚdumpr   ÚApplication)rQ   rë   s     r4   ÚsetUpzTapFileTests.setUp¾  sO   € ð —{‘{“}ˆŒÜ�$—,‘, Ó%ð 	7¨Ü�K‰Kœ×+Ñ+¨EÓ2°AÔ6÷	7÷ 	7ñ 	7ús   ¬*AÁA(c                 óö   — t        j                  «       }|j                  d| j                  g«       t	        |«      j                  «       }| j                  t        j                  |«      j                  d«       y)zŽ
        Ensure that the createOrGetApplication call that 'twistd -f foo.tap'
        makes will load the Application out of foo.tap.
        z-fr  N)
r   r}   rž   r  ra   ÚcreateOrGetApplicationrz   r   ÚIServicer/   )rQ   r‚   r]   s      r4   Ú&test_createOrGetApplicationWithTapFilez3TapFileTests.test_createOrGetApplicationWithTapFileÆ  s]   € ô
 ×%Ñ%Ó'ˆØ×Ñ˜T 4§<¡<Ð0Ô1Ü/°Ó7×NÑNÓPˆØ×Ñœ×)Ñ)¨+Ó6×;Ñ;¸UÕCr6   N)rS   rT   rU   rV   r  r  rX   r6   r4   r	  r	  ¹  s   „ ñò7óDr6   r	  c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)ÚTestLoggerFactoryz8
    A logger factory for L{TestApplicationRunner}.
    c                 ó   — || _         y r)   )Úrunner)rQ   r  s     r4   rr   zTestLoggerFactory.__init__Ö  s	   € Øˆ�r6   c                 ó˜   — | j                   j                  j                  d«       t        | j                   d«      | j                   _        y)zC
        Save the logging start on the C{runner} instance.
        Úlogr]   N)r  Úorderr•   ÚhasattrÚhadApplicationLogObserverr\   s     r4   r^   zTestLoggerFactory.startÙ  s3   € ð 	�‰×Ñ× Ñ  Ô'Ü07¸¿¹À]Ó0Sˆ�‰Õ-r6   c                  ó   — y)z%
        Don't log anything.
        NrX   rc   s    r4   ÚstopzTestLoggerFactory.stopà  râ   r6   N)rS   rT   rU   rV   rr   r^   r   rX   r6   r4   r  r  Ñ  s   „ ñòòTór6   r  c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)ÚTestApplicationRunnerz`
    An ApplicationRunner which tracks the environment in which its methods are
    called.
    c                 ór   — t         j                  j                  | |«       g | _        t	        | «      | _        y r)   )r
   ÚApplicationRunnerrr   r  r  r   rP   s     r4   rr   zTestApplicationRunner.__init__ì  s+   € Ü×Ñ×&Ñ& t¨WÔ5ØˆŒ
Ü'¨Ó-ˆ�r6   c                 ó\   — | j                   j                  d«       t        | d«      | _        y )NÚprer]   )r  r•   r  ÚhadApplicationPreApplicationrc   s    r4   rd   z$TestApplicationRunner.preApplicationñ  s#   € Ø�
‰
×Ñ˜%Ô Ü,3°D¸-Ó,HˆÕ)r6   c                 ó\   — | j                   j                  d«       t        | d«      | _        y )NÚpostr]   )r  r•   r  ÚhadApplicationPostApplicationrc   s    r4   rf   z%TestApplicationRunner.postApplicationõ  s#   € Ø�
‰
×Ñ˜&Ô!Ü-4°T¸=Ó-IˆÕ*r6   N)rS   rT   rU   rV   rr   rd   rf   rX   r6   r4   r"  r"  æ  s   „ ñò
.ò
IóJr6   r"  c                   ó    — e Zd ZdZd„ Zd„ Zd„ Zd„ Z e e	e
dd«       d«      d	„ «       Z e e	e
dd«       d«      d
„ «       Zd„ Zd„ Zd„ Zd„ Zy)ÚApplicationRunnerTestszR
    Non-platform-specific tests for the platform-specific ApplicationRunner.
    c                 óª   — t        j                  «       }t        «       | _        d| j                  i|_        t        «       |_        d|_        || _        y )NÚtest_command)	r   r}   rK   ÚserviceMakerÚloadedPluginsÚobjectÚ
subOptionsr„   r‚   r¨   s     r4   r  zApplicationRunnerTests.setUpÿ  sG   € Ü×%Ñ%Ó'ˆÜ,Ó.ˆÔà .°×0AÑ0AÐBˆÔÜ"›HˆÔØ*ˆÔØˆ�r6   c                 óf  — t        | j                  «      }|j                  «        | j                  | j                  j
                  | j                  j                  d«       | j                  | j                  j                  t        j                  |j                  «      j                  d   d«       y)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)ra   r‚   ÚrunrÓ   r/  rN   r2  r   r  r]   Úservices)rQ   Úarunners     r4   Ú,test_applicationRunnerGetsCorrectApplicationzCApplicationRunnerTests.test_applicationRunnerGetsCorrectApplication  s‰   € ô ,¨D¯K©KÓ8ˆØ�‰Œà�‰Ø×Ñ×%Ñ%Ø�K‰K×"Ñ"ð"ô	
ð 	�‰Ø×Ñ×%Ñ%Ü×Ñ˜W×0Ñ0Ó1×:Ñ:¸1Ñ=ð"õ	
r6   c                 ó,  — t        | j                  «      }|j                  «        | j                  |j                  «       | j                  |j                  «       | j                  |j                  «       | j                  |j                  g d¢«       y)z†
        Test thet preApplication and postApplication methods are
        called by ApplicationRunner.run() when appropriate.
        )r&  r  r)  N)
r"  r‚   r4  r«   r'  r§   r*  r  rz   r  )rQ   r–   s     r4   Útest_preAndPostApplicationz1ApplicationRunnerTests.test_preAndPostApplication  sh   € ô
 " $§+¡+Ó.ˆØ	�‰ŒØ×Ñ˜×7Ñ7Ô8Ø�‰˜×7Ñ7Ô8Ø�‰˜×3Ñ3Ô4Ø×Ñ˜Ÿ™Ò"8Õ9r6   c           	      ó  ‡— | j                   j                  |«       g Š G ˆfd„dt        j                  «      }t	        t
        j                  t
        j                  «       G ˆfd„d«      «       } |«       }t        t
        j                  |«       t        t
        j                  |«        || j                   «      }|j                  «        ||_
        |j                  «        | j                  ‰dddd||fd	d
g«       y)a.  
        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                   ó2   •— e Zd Zˆ fd„Zˆ fd„Zˆ fd„Zd„ Zy)ú\ApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeUnixApplicationRunnerc                 ó(   •— ‰j                  d«       y )NÚenvironment©r•   )rQ   ÚchrootÚrundirÚnodaemonrµ   rê   Úeventss         €r4   ÚsetupEnvironmentzmApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeUnixApplicationRunner.setupEnvironment8  s   ø€ Ø—‘˜mÕ,r6   c                 ó0   •— ‰j                  d|||f«       y )NÚ
privilegesr?  )rQ   ÚeuidrF   r1   rC  s       €r4   ÚshedPrivilegeszkApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeUnixApplicationRunner.shedPrivileges;  s   ø€ Ø—‘˜|¨T°3¸Ð<Õ=r6   c                 ó(   •— ‰j                  d«       y )Nr¢   r?  )rQ   r¢   Ú	oldstdoutÚ	oldstderrrC  s       €r4   ÚstartReactorziApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeUnixApplicationRunner.startReactor>  s   ø€ Ø—‘˜iÕ(r6   c                  ó   — y r)   rX   )rQ   rê   s     r4   Ú	removePIDzfApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeUnixApplicationRunner.removePIDA  ó   € Ør6   N)rS   rT   rU   rD  rH  rL  rN  ©rC  s   €r4   ÚFakeUnixApplicationRunnerr<  7  s   ø„ ô-ô>ô)ór6   rQ  c                   óR   •— e Zd ZdZdZdZdZdZdZd„ Z	d„ Z
d„ Zˆ fd„Zˆ fd„Zd„ Zy)úNApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeServiceNc                  ó   — y r)   rX   rq   s     r4   ÚsetNamezVApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeService.setNameM  rO  r6   c                  ó   — y r)   rX   )rQ   Úparents     r4   ÚsetServiceParentz_ApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeService.setServiceParentP  rO  r6   c                  ó   — y r)   rX   rc   s    r4   ÚdisownServiceParentzbApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeService.disownServiceParentS  rO  r6   c                 ó(   •— ‰j                  d«       y )NÚprivilegedStartServicer?  ©rQ   rC  s    €r4   r\  zeApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeService.privilegedStartServiceV  s   ø€ Ø—‘Ð6Õ7r6   c                 ó(   •— ‰j                  d«       y )NÚstartServicer?  r]  s    €r4   r_  z[ApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeService.startServiceY  s   ø€ Ø—‘˜nÕ-r6   c                  ó   — y r)   rX   rc   s    r4   ÚstopServicezZApplicationRunnerTests._applicationStartsWithConfiguredID.<locals>.FakeService.stopService\  rO  r6   )rS   rT   rU   rW  Úrunningr/   ÚprocessNamerF   r1   rU  rX  rZ  r\  r_  ra  rP  s   €r4   ÚFakeServicerS  D  s?   ø„ àˆFØˆGØˆDØˆKØˆCØˆCòòòô8ô.ór6   rd  r>  r\  rF  Fr_  r¢   N)r‚   rž   r   Ú_SomeApplicationRunnerr   r   r  ÚIProcessr   rd   r]   rf   rz   )	rQ   ÚargvrF   r1   rQ  rd  r]   r  rC  s	           @r4   Ú"_applicationStartsWithConfiguredIDz9ApplicationRunnerTests._applicationStartsWithConfiguredID*  sß   ø€ ð 	�‰× Ñ  Ô&àˆö	¬×(EÑ(Eô 	ô 
”W×%Ñ%¤w×'7Ñ'7Ó	8÷	ò 	ó 
9ð	ñ4 "“mˆÜ”W×%Ñ% {Ô3Ü”W×%Ñ% {Ô3á*¨4¯;©;Ó7ˆØ×ÑÔØ(ˆÔØ×ÑÔ à×ÑØàØ(Ø˜u c¨3Ð/ØØðõ		
r6   ÚsetuidNz5Platform does not support --uid/--gid twistd options.c                 ó^   — d}d}| j                  dt        |«      dt        |«      g||«       y)a  
        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)rh  r®   )rQ   rF   r1   s      r4   Ú.test_applicationStartsWithConfiguredNumericIDszEApplicationRunnerTests.test_applicationStartsWithConfiguredNumericIDss  s4   € ð ˆØˆØ×/Ñ/Ø”c˜#“h ¬¨S«Ð2°C¸õ	
r6   c                 ót   — d}d}d}d}t        | j                  ||||«       | j                  d|d|g||«       y)a  
        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}.
        Úfoork  Úbarrl  rm  rn  N)rI   rD   rh  )rQ   rE   rF   r3   r1   s        r4   Ú+test_applicationStartsWithConfiguredNameIDszBApplicationRunnerTests.test_applicationStartsWithConfiguredNameIDs„  sJ   € ð ˆØˆØˆØˆÜ˜$Ÿ*™* d¨C°¸Ô<Ø×/Ñ/Ø�d˜G UÐ+¨S°#õ	
r6   c                 ó¨   — t        «       }t        j                  ddddœ«      }|j                  |dd«       | j	                  |j
                  d«       y)z7
        L{startReactor} calls L{reactor.run}.
        Fr$   ©r$   r±   ÚdebugNz'startReactor did not call reactor.run())ÚDummyReactorr
   r$  rL  r§   Úcalled©rQ   r¢   r  s      r4   Útest_startReactorRunsTheReactorz6ApplicationRunnerTests.test_startReactorRunsTheReactor˜  sL   € ô “.ˆÜ×&Ñ&Ø¨9¸uÑEó
ˆð 	×Ñ˜G T¨4Ô0Ø�‰˜Ÿ™Ð(QÕRr6   c                 óÔ   — t        «       }| j                  t        d|«       t        j                  ddddœ«      }|j                  ddd«       | j                  |j                  «       y)zN
        L{ApplicationRunner} chooses a reactor if none is specified.
        r¢   Fr$   ru  N)rw  rD   r   r
   r$  rL  r§   rx  ry  s      r4   Ú*test_applicationRunnerChoosesReactorIfNonezAApplicationRunnerTests.test_applicationRunnerChoosesReactorIfNone£  sY   € ô “.ˆØ�
‰
”8˜Y¨Ô0Ü×&Ñ&Ø¨9¸uÑEó
ˆð 	×Ñ˜D $¨Ô-Ø�‰˜Ÿ™Õ'r6   c                 óÀ   —  G d„ dt         «      } |«       }t        j                  ddddœ«      }|j                  |dd«       | j	                  d|j
                  «       y)zg
        If the reactor exits with a signal, the application runner caches
        the signal.
        c                   ó   — e Zd ZdZd„ Zd„ Zy)ú[ApplicationRunnerTests.test_applicationRunnerCapturesSignal.<locals>.DummyReactorWithSignalú‹
            A dummy reactor, providing a C{run} method, and setting the
            _exitSignal attribute to a nonzero value.
            c                  ó   — y©z=
                Dummy method, does nothing.
                NrX   rc   s    r4   ÚinstallWakerzhApplicationRunnerTests.test_applicationRunnerCapturesSignal.<locals>.DummyReactorWithSignal.installWaker»  râ   r6   c                 ó   — d| _         y)zZ
                A fake run method setting _exitSignal to a nonzero value
                é   N©Ú_exitSignalrc   s    r4   r4  z_ApplicationRunnerTests.test_applicationRunnerCapturesSignal.<locals>.DummyReactorWithSignal.runÀ  s   € ð $%�Õ r6   N©rS   rT   rU   rV   rƒ  r4  rX   r6   r4   ÚDummyReactorWithSignalr  µ  s   „ ñò
ó
%r6   r‰  Fr$   ru  Nr…  )r   r
   r$  rL  ÚassertEqualsr‡  )rQ   r‰  r¢   r  s       r4   Ú$test_applicationRunnerCapturesSignalz;ApplicationRunnerTests.test_applicationRunnerCapturesSignal¯  s\   € ô	%¤[ô 	%ñ" )Ó*ˆÜ×&Ñ&Ø¨9¸uÑEó
ˆð 	×Ñ˜G T¨4Ô0Ø×Ñ˜!˜V×/Ñ/Õ0r6   c                 ó¶   —  G d„ d«      } |«       }t        j                  ddddœ«      }|j                  |dd«       | j                  d|j                  «       y)z˜
        The runner sets its _exitSignal instance attribute to None if
        the reactor does not implement L{_ISupportsExitSignalCapturing}.
        c                   ó   — e Zd ZdZd„ Zd„ Zy)úiApplicationRunnerTests.test_applicationRunnerIgnoresNoSignal.<locals>.DummyReactorWithExitSignalAttributer€  c                  ó   — yr‚  rX   rc   s    r4   rƒ  zvApplicationRunnerTests.test_applicationRunnerIgnoresNoSignal.<locals>.DummyReactorWithExitSignalAttribute.installWakerÙ  râ   r6   c                 ó   — d| _         y)z‚
                A fake run method setting _exitSignal to a nonzero value
                that should be ignored.
                r…  Nr†  rc   s    r4   r4  zmApplicationRunnerTests.test_applicationRunnerIgnoresNoSignal.<locals>.DummyReactorWithExitSignalAttribute.runÞ  s   € ð
 $%�Õ r6   Nrˆ  rX   r6   r4   Ú#DummyReactorWithExitSignalAttributerŽ  Ó  s   „ ñò
ó
%r6   r‘  Fr$   ru  N)r
   r$  rL  rŠ  r‡  )rQ   r‘  r¢   r  s       r4   Ú%test_applicationRunnerIgnoresNoSignalz<ApplicationRunnerTests.test_applicationRunnerIgnoresNoSignalÍ  sZ   € ÷	%ñ 	%ñ$ 6Ó7ˆÜ×&Ñ&Ø¨9¸uÑEó
ˆð 	×Ñ˜G T¨4Ô0Ø×Ñ˜$ × 2Ñ 2Õ3r6   )rS   rT   rU   rV   r  r7  r9  rh  r   Úgetattrr:   ro  rs  rz  r|  r‹  r’  rX   r6   r4   r,  r,  ú  sˆ   „ ñòò
ò,
:òG
ñR Ù�B˜ $Ó'Ð'Ø?óñ
ó	ð
ñ Ù�B˜ $Ó'Ð'Ø?óñ
ó	ð
ò 	Sò
(ò1ó<4r6   r,  c                   óf   — e Zd ZdZ e«       Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d„ Zd„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zy)Ú*UnixApplicationRunnerSetupEnvironmentTestsaº  
    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                 óÂ  ‡ — ‰ j                   ‰ _        ‰ j                   ‰ _        ‰ j                   ‰ _        d‰ _        t        j                  «       ‰ _        ‰ j                  t
        dˆ fd„«       ‰ j                  t
        dˆ fd„«       ‰ j                  t
        dˆ fd„«       t        t        j                  «       «      ‰ _        ‰ j                  ‰ j                  _        y )NFr@  c                 ó   •— t        ‰d| «      S )NÚroot©Úsetattr©rã   rQ   s    €r4   rá   zBUnixApplicationRunnerSetupEnvironmentTests.setUp.<locals>.<lambda>  s   ø€ ¬g°d¸FÀDÓ.I€ r6   Úchdirc                 ó   •— t        ‰d| «      S )NÚcwdr™  r›  s    €r4   rá   zBUnixApplicationRunnerSetupEnvironmentTests.setUp.<locals>.<lambda>  s   ø€ ¬W°T¸5À$Ó-G€ r6   rµ   c                 ó   •— t        ‰d| «      S )NÚmaskr™  )r   rQ   s    €r4   rá   zBUnixApplicationRunnerSetupEnvironmentTests.setUp.<locals>.<lambda>  s   ø€ ¬W°T¸6À4Ó-H€ r6   )Úunsetr˜  rž  r   Údaemonr:   rÿ   rñ   rD   r!   r   r}   r  Ú	daemonizerc   s   `r4   r  z0UnixApplicationRunnerSetupEnvironmentTests.setUp  s�   ø€ Ø—J‘JˆŒ	Ø—:‘:ˆŒØ—J‘JˆŒ	ØˆŒÜ—9‘9“;ˆŒØ�
‰
”2�xÓ!IÔJØ�
‰
”2�wÓ GÔHØ�
‰
”2�wÓ HÔIÜ+¬F×,@Ñ,@Ó,BÓCˆŒØ $§¡ˆ�‰Õr6   c                 óH   ‡ — d‰ _         ‰ j                  t        dˆ fd„«       y)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                  ó"   •— ‰ j                   dz   S ©Nr÷   )rñ   rc   s   €r4   rá   zFUnixApplicationRunnerSetupEnvironmentTests.daemonize.<locals>.<lambda>  s   ø€ ¨¯©°A©€ r6   N)r¢  rD   r:   ©rQ   r¢   s   ` r4   r£  z4UnixApplicationRunnerSetupEnvironmentTests.daemonize  s   ø€ ð
 ˆŒØ�
‰
”2�xÓ!5Õ6r6   c                 óz   — | j                   j                  ddddd«       | j                  | j                  d«       y)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)r  rD  rz   r˜  rc   s    r4   Útest_chrootz6UnixApplicationRunnerSetupEnvironmentTests.test_chroot  s2   € ð
 	�‰×$Ñ$ Z°°d¸DÀ$ÔGØ×Ñ˜Ÿ™ JÕ/r6   c                 óŽ   — | j                   j                  ddddd«       | j                  | j                  | j                  «       y)z�
        L{UnixApplicationRunner.setupEnvironment} does not change the root of
        the filesystem if passed L{None} for the C{chroot} parameter.
        Nrª  T)r  rD  rÓ   r˜  r¡  rc   s    r4   Útest_noChrootz8UnixApplicationRunnerSetupEnvironmentTests.test_noChroot!  s4   € ð
 	�‰×$Ñ$ T¨3°°d¸DÔAØ�‰�d—i‘i §¡Õ,r6   c                 óz   — | j                   j                  ddddd«       | j                  | j                  d«       y)zŸ
        L{UnixApplicationRunner.setupEnvironment} changes the working directory
        of the process to the path given for the C{rundir} parameter.
        Nr©  T)r  rD  rz   rž  rc   s    r4   Útest_changeWorkingDirectoryzFUnixApplicationRunnerSetupEnvironmentTests.test_changeWorkingDirectory)  s2   € ð
 	�‰×$Ñ$ T¨:°t¸TÀ4ÔHØ×Ñ˜Ÿ™ :Õ.r6   c                 óÈ   — t        t        «       «      5  | j                  j                  ddddd«       ddd«       | j	                  | j
                  «       y# 1 sw Y   Œ%xY w)z�
        L{UnixApplicationRunner.setupEnvironment} daemonizes the process if
        C{False} is passed for the C{nodaemon} parameter.
        Nrª  F)r   ÚFakeDaemonizingReactorr  rD  r§   r¢  rc   s    r4   Útest_daemonizez9UnixApplicationRunnerSetupEnvironmentTests.test_daemonize1  sS   € ô
 Ô4Ó6Ó7ñ 	GØ�K‰K×(Ñ(¨¨s°E¸4ÀÔF÷	Gà�‰˜Ÿ™Õ$÷	Gð 	Gús   ” AÁA!c                 óx   — | j                   j                  ddddd«       | j                  | j                  «       y)z–
        L{UnixApplicationRunner.setupEnvironment} does not daemonize the
        process if C{True} is passed for the C{nodaemon} parameter.
        Nrª  T)r  rD  r«   r¢  rc   s    r4   Útest_noDaemonizez;UnixApplicationRunnerSetupEnvironmentTests.test_noDaemonize:  s0   € ð
 	�‰×$Ñ$ T¨3°°d¸DÔAØ×Ñ˜Ÿ™Õ%r6   c                 ó  — | j                  «       }| j                  j                  dddd|«       t        |d«      5 }t	        |j                  «       «      }ddd«       | j                  | j                  «       y# 1 sw Y   Œ&xY w)z�
        L{UnixApplicationRunner.setupEnvironment} writes the process's PID to
        the file specified by the C{pidfile} parameter.
        Nrª  TÚrb)rç   r  rD  rè   ÚintÚreadrz   rñ   ©rQ   rê   rë   rñ   s       r4   Útest_nonDaemonPIDFilez@UnixApplicationRunnerSetupEnvironmentTests.test_nonDaemonPIDFileB  sm   € ð
 —+‘+“-ˆØ�‰×$Ñ$ T¨3°°d¸GÔDÜ�'˜4Ó ð 	  AÜ�a—f‘f“h“-ˆC÷	 à×Ñ˜˜dŸh™hÕ'÷	 ð 	 ús   ¼A;Á;Bc                 ód  — | j                  «       }t        t        «       «      5  | j                  j	                  dddd|«       ddd«       t        |d«      5 }t        |j                  «       «      }ddd«       | j                  | j                  dz   «       y# 1 sw Y   ŒWxY w# 1 sw Y   Œ5xY w)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±  r  rD  rè   r·  r¸  rz   rñ   r¹  s       r4   Útest_daemonPIDFilez=UnixApplicationRunnerSetupEnvironmentTests.test_daemonPIDFileM  s–   € ð —+‘+“-ˆÜÔ4Ó6Ó7ñ 	JØ�K‰K×(Ñ(¨¨s°E¸4ÀÔI÷	Jä�'˜4Ó ð 	  AÜ�a—f‘f“h“-ˆC÷	 à×Ñ˜˜dŸh™h¨™lÕ+÷		Jð 	Jú÷	 ð 	 ús   ¤ BÁB&ÂB#Â&B/c                 óÊ   — t        t        «       «      5  | j                  j                  ddddd«       ddd«       | j	                  | j
                  d«       y# 1 sw Y   Œ&xY w)z�
        L{UnixApplicationRunner.setupEnvironment} changes the process umask to
        the value specified by the C{umask} parameter.
        Nrª  Fé{   ©r   r±  r  rD  rz   r   rc   s    r4   r¼   z5UnixApplicationRunnerSetupEnvironmentTests.test_umaskZ  sW   € ô
 Ô4Ó6Ó7ñ 	FØ�K‰K×(Ñ(¨¨s°E¸3ÀÔE÷	Fà×Ñ˜Ÿ™ CÕ(÷	Fð 	Fúó   ” AÁA"c                 óŽ   — | j                   j                  ddddd«       | j                  | j                  | j                  «       y)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)r  rD  rÓ   r   r¡  rc   s    r4   Útest_noDaemonizeNoUmaskzBUnixApplicationRunnerSetupEnvironmentTests.test_noDaemonizeNoUmaskc  s4   € ð 	�‰×$Ñ$ T¨3°°d¸DÔAØ�‰�d—i‘i §¡Õ,r6   c                 óÊ   — t        t        «       «      5  | j                  j                  ddddd«       ddd«       | j	                  | j
                  d«       y# 1 sw Y   Œ&xY w)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¿  rc   s    r4   Útest_daemonizedNoUmaskzAUnixApplicationRunnerSetupEnvironmentTests.test_daemonizedNoUmaskl  sW   € ô Ô4Ó6Ó7ñ 	GØ�K‰K×(Ñ(¨¨s°E¸4ÀÔF÷	Gà×Ñ˜Ÿ™ EÕ*÷	Gð 	GúrÀ  N)rS   rT   rU   rV   r1  r¡  r  r£  r«  r­  r¯  r²  r´  rº  r¼  r¼   rÂ  rÅ  rX   r6   r4   r•  r•  í  sL   „ ññ( ‹H€Eò
/ò7ò0ò-ò/ò%ò&ò	(ò,ò)ò-ó+r6   r•  c                   ó4   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)	Ú*UnixApplicationRunnerStartApplicationTestsz>
    Tests for L{UnixApplicationRunner.startApplication}.
    c                 ó¢  ‡— t        j                  «       }|j                  g d¢«       t        j                  d«      }t        |«      | _        g Šˆfd„}t        j                  | j                  j                  «      j                  }t        j                  |«      j                  }|j                  «       }|j                  d«       | j                  ||«       | j                  t
        d|«       | j                  t
        dd„ «       | j                  t        dd	„ «       | j                  j!                  |«       | j                  ‰g d
¢«       y)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                 ó2   •— ‰j                  |||||f«       y r)   )Úextend)rQ   r@  rA  rB  rµ   rê   rÄ   s         €r4   ÚfakeSetupEnvironmentz^UnixApplicationRunnerStartApplicationTests.test_setupEnvironment.<locals>.fakeSetupEnvironment—  s   ø€ Ø�K‰K˜ ¨°5¸'ÐBÕCr6   rQ   rD  rH  c                   ó   — y r)   rX   ©ÚaÚkws     r4   rá   zRUnixApplicationRunnerStartApplicationTests.test_setupEnvironment.<locals>.<lambda>«  râ   r6   ÚstartApplicationc                   ó   — y r)   rX   rÔ  s     r4   rá   zRUnixApplicationRunnerStartApplicationTests.test_setupEnvironment.<locals>.<lambda>¬  râ   r6   )rË  rÌ  Té8   rÎ  N)r   r}   rž   r   r  r!   r  ÚinspectÚ	signaturerD  Ú
parametersÚcopyÚpoprz   rD   r
   r×  )rQ   rN   r]   rÒ  ÚsetupEnvironmentParametersÚfakeSetupEnvironmentParametersrÄ   s         @r4   rÏ  z@UnixApplicationRunnerStartApplicationTests.test_setupEnvironment}  s!  ø€ ô ×&Ñ&Ó(ˆØ×Ñò
ô	
ô ×)Ñ)Ð*AÓBˆÜ+¨GÓ4ˆŒàˆô	Dô &-×%6Ñ%6Ø�K‰K×(Ñ(ó&
ç
‰*ð 	#ô *1×):Ñ):Ø ó*
ç
‰*ð 	'ð *H×)LÑ)LÓ)NÐ&Ø&×*Ñ*¨6Ô2à×ÑÐ3Ð5SÔTà�
‰
Ô(Ð*<Ð>RÔSØ�
‰
Ô(Ð*:Ñ<QÔRØ�
‰
”3Ð*Ñ,AÔBØ�‰×$Ñ$ [Ô1à×Ñ˜ÒWÕXr6   c                 óz   ‡ — ˆ fd„}‰ j                  t        d|«       t        i «      }|j                  ddd«       y)zf
        L{UnixApplicationRunner.shedPrivileges} switches the user ID
        of the process.
        c                 ór   •— ‰j                  | d«       ‰j                  |d«       ‰j                  |d«       y )NéÈ   é6   é#   ©rz   )rF   r1   rG  rQ   s      €r4   ÚswitchUIDPasszUUnixApplicationRunnerStartApplicationTests.test_shedPrivileges.<locals>.switchUIDPass·  s3   ø€ Ø×Ñ˜S #Ô&Ø×Ñ˜S "Ô%Ø×Ñ˜T 2Õ&r6   Ú	switchUIDrå  rã  rä  N)rD   rÙ   r!   rH  )rQ   rç  r  s   `  r4   Útest_shedPrivilegesz>UnixApplicationRunnerStartApplicationTests.test_shedPrivileges±  s6   ø€ ô	'ð
 	�
‰
”< ¨mÔ<Ü& rÓ*ˆØ×Ñ˜b # rÕ*r6   c                 óÌ   — d„ }t        i «      }| j                  t        d|«       | j                  t        |j
                  ddd«      }| j                  |j                  d«       y)z 
        An unexpected L{OSError} when calling
        L{twisted.scripts._twistd_unix.shedPrivileges}
        terminates the process via L{SystemExit}.
        c                 ó6   — t        t        j                  d«      ‚rù   r  )rF   r1   rG  s      r4   ÚswitchUIDFailzZUnixApplicationRunnerStartApplicationTests.test_shedPrivilegesError.<locals>.switchUIDFailÇ  rþ   r6   rè  rå  rã  Nr÷   )r!   rD   rÙ   rœ   r�   rH  rz   rÔ   )rQ   rì  r  Úexcs       r4   Útest_shedPrivilegesErrorzCUnixApplicationRunnerStartApplicationTests.test_shedPrivilegesErrorÀ  sU   € ò	/ô ' rÓ*ˆØ�
‰
”< ¨mÔ<Ø×Ñ¤
¨F×,AÑ,AÀ2ÀsÈDÓQˆØ×Ñ˜Ÿ™ 1Õ%r6   c                 óÔ  ‡ ‡‡— t        ‰ j                  |‰|‰«       ˆ ˆˆfd„}ˆ ˆfd„}ˆ ˆfd„}‰ j                  t        d|«       ‰ j                  t        d|«       ‰ j                  t        d|«       t	        j
                  «       }	|	j                  ddt        ‰«      d	|g«       t        j                  d
«      }
t        |	«      ‰ _        t        |	«      }|j                  |
«       y)zj
        Common code for tests which try to pass the the UID to
        L{UnixApplicationRunner}.
        c                 óN   •— ‰j                  | ‰«       ‰j                  |‰«       y r)   ræ  )rF   r1   rQ   Ú	wantedGidÚ	wantedUids     €€€r4   Ú
initgroupszFUnixApplicationRunnerStartApplicationTests._setUID.<locals>.initgroupsÖ  s#   ø€ Ø×Ñ˜S )Ô,Ø×Ñ˜S )Õ,r6   c                 ó*   •— ‰j                  | ‰«       y r)   ræ  )rF   rQ   rò  s    €€r4   ri  zBUnixApplicationRunnerStartApplicationTests._setUID.<locals>.setuidÚ  ó   ø€ Ø×Ñ˜S )Õ,r6   c                 ó*   •— ‰j                  | ‰«       y r)   ræ  )r1   rQ   rñ  s    €€r4   ÚsetgidzBUnixApplicationRunnerStartApplicationTests._setUID.<locals>.setgidÝ  rõ  r6   ró  ri  r÷  rÉ  rm  rÍ  rÏ  N)rI   rD   r   r:   r   r}   rž   r®   r   r  r!   r  r×  )rQ   Ú
wantedUserrò  ÚwantedGrouprñ  ÚpidFileró  ri  r÷  rN   r]   r  s   ` ` `       r4   Ú_setUIDz2UnixApplicationRunnerStartApplicationTests._setUIDÏ  s¿   ú€ ô
 	˜$Ÿ*™* j°)¸[È)ÔTö	-õ	-õ	-ð 	�
‰
”4˜ zÔ2Ø�
‰
”2�x Ô(Ø�
‰
”2�x Ô(ä×&Ñ&Ó(ˆØ×ÑØ˜7¤C¨	£N°KÀÐIô	
ô ×)Ñ)Ð*AÓBˆÜ+¨GÓ4ˆŒÜ& wÓ/ˆØ×Ñ Õ,r6   c                 óP   — | j                  dddd| j                  «       dz   «       y)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.
        rq  i  rr  i’  z_test_setUidWithoutGid.pidN)rû  rç   rc   s    r4   Útest_setUidWithoutGidz@UnixApplicationRunnerStartApplicationTests.test_setUidWithoutGidí  s'   € ð 	�‰Ø�4˜  d§k¡k£mÐ6RÑ&Rõ	
r6   c                 ó  — t        j                  «       }| j                  d|ddd«       | j                  «       }dj	                  ||«      }| j                  ||d   d   «       | j                  dt        |«      |«       y	)
zz
        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¡   rz   Úlen)rQ   Ú
currentUidÚwarningsShownÚexpectedWarnings       r4   Útest_setUidSameAsCurrentUidzFUnixApplicationRunnerStartApplicationTests.test_setUidSameAsCurrentUid÷  s€   € ô
 —Y‘Y“[ˆ
Ø�‰Ø�z 9¨dÐ4Uô	
ð ×*Ñ*Ó,ˆð-ß-3©V°JÀ
Ó-Kð 	ð 	×Ñ˜¨-¸Ñ*:¸9Ñ*EÔFØ×Ñ˜œC Ó.°Õ>r6   N)
rS   rT   rU   rV   rÏ  ré  rî  rû  rý  r  rX   r6   r4   rÇ  rÇ  w  s'   „ ñò2Yòh+ò&ò-ò<
ó?r6   rÇ  c                   ó   — e Zd ZdZd„ Zd„ Zy)Ú#UnixApplicationRunnerRemovePIDTestsz7
    Tests for L{UnixApplicationRunner.removePID}.
    c                 óV  — t        i «      }| j                  «       }t        j                  |«       t        j                  j                  |d«      }t        |d«      j                  «        |j                  |«       | j                  t        j                  j                  |«      «       y)zp
        L{UnixApplicationRunner.removePID} deletes the file the name of
        which is passed to it.
        zfoo.pidræ   N)r!   rç   r:   Úmakedirsrã   Újoinrè   ÚcloserN  r«   rÝ   )rQ   r  rã   rê   s       r4   Útest_removePIDz2UnixApplicationRunnerRemovePIDTests.test_removePID  su   € ô
 ' rÓ*ˆØ�{‰{‹}ˆÜ
�‰�DÔÜ—'‘'—,‘,˜t YÓ/ˆÜˆW�cÓ× Ñ Ô"Ø×Ñ˜Ô!Ø×ÑœŸ™Ÿ™¨Ó0Õ1r6   c                 ó
  — t        i «      }|j                  d«       | j                  t        «      }| j	                  t        |«      d«       | j	                  |d   j                  j                  t        j                  «       y)zr
        Calling L{UnixApplicationRunner.removePID} with a non-existent filename
        logs an OSError.
        Úfakepidr÷   r   N)	r!   rN  ÚflushLoggedErrorsrû   rz   r  Úvaluerü   ÚENOENT)rQ   r  Úerrorss      r4   Útest_removePIDErrorsz8UnixApplicationRunnerRemovePIDTests.test_removePIDErrors  sb   € ô
 ' rÓ*ˆØ×Ñ˜Ô#Ø×'Ñ'¬Ó0ˆØ×Ñœ˜V› aÔ(Ø×Ñ˜ ™Ÿ™×.Ñ.´·±Õ=r6   N)rS   rT   rU   rV   r  r  rX   r6   r4   r	  r	  
  s   „ ñò2ó	>r6   r	  c                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)ÚFakeNonDaemonizingReactora›  
    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                 ó    — d| _         d| _        y rß   )Ú_beforeDaemonizeCalledÚ_afterDaemonizeCalledrc   s    r4   rr   z"FakeNonDaemonizingReactor.__init__5  s   € Ø&+ˆÔ#Ø%*ˆÕ"r6   c                 ó   — d| _         y ©NT)r  rc   s    r4   ÚbeforeDaemonizez)FakeNonDaemonizingReactor.beforeDaemonize9  s
   € Ø&*ˆÕ#r6   c                 ó   — d| _         y r  )r  rc   s    r4   ÚafterDaemonizez(FakeNonDaemonizingReactor.afterDaemonize<  s
   € Ø%)ˆÕ"r6   c                  ó   — y)z*
        Skip event registration.
        NrX   )rQ   rÄ   rÖ  s      r4   ÚaddSystemEventTriggerz/FakeNonDaemonizingReactor.addSystemEventTrigger?  râ   r6   N)rS   rT   rU   rV   rr   r  r  r!  rX   r6   r4   r  r  )  s   „ ñ	ò+ò+ò*ór6   r  c                   ó   — e Zd ZdZy)r±  z�
    A dummy reactor, providing C{beforeDaemonize} and C{afterDaemonize}
    methods, announcing this, and logging whether the methods have been called.
    N)rS   rT   rU   rV   rX   r6   r4   r±  r±  E  s   „ òr6   r±  c                   ó   — e Zd ZdZdZd„ Zy)rw  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                   rt        d«      ‚d| _         y)zV
        A fake run method, checking that it's been called one and only time.
        zAlready calledTN)rx  ÚRuntimeErrorrc   s    r4   r4  zDummyReactor.runX  s   € ð �;Š;ÜÐ/Ó0Ð0Øˆ�r6   N)rS   rT   rU   rV   rx  r4  rX   r6   r4   rw  rw  M  s   „ ñð €Fór6   rw  c                   óÔ   — e Zd ZdZ ee d«      d„ «       Zd„ Z ee d«      d„ «       Zd„ Z	 ee d«      d„ «       Z
 ee d«      d	„ «       Z ee d«      d
„ «       Zd„ Zd„ Zd„ Zd„ Zy)ÚAppProfilingTestsz'
    Tests for L{app.AppProfiler}.
    zprofile module not availablec                 ó   — t        j                  «       }| j                  «       |d<   d|d<   t        j                  |«      }t        «       }|j                  |«       | j                  |j                  «       t        |d   «      5 }|j                  «       }ddd«       | j                  d«       | j                  d|«       y# 1 sw Y   Œ.xY w)zŒ
        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¯   rw  r4  r§   rx  rè   r¸  r”   ©rQ   r‚   r±   r¢   rë   Údatas         r4   Útest_profilezAppProfilingTests.test_profilef  sª   € ô ×%Ñ%Ó'ˆØ ŸK™K›MˆˆyÑØ&ˆˆzÑÜ—?‘? 6Ó*ˆÜ“.ˆà�‰�WÔà�‰˜Ÿ™Ô'Ü�&˜Ñ#Ó$ð 	¨Ø—6‘6“8ˆD÷	à�‰Ð(¨$Ô/Ø�‰Ð&¨Õ-÷	ð 	úó   ÂCÃCc                 óþ   — t        «       }| j                  t        d|«      } ||«      }|j                  «        |j	                  «        |j                  «       }| j                  d|«       | j                  d|«       y )NrÐ   r)  z(run))r   rD   ÚsysÚprint_statsÚrestorerŸ   r”   )rQ   Ú
statsClassr$   ÚoutrÐ   Ústatsr,  s          r4   Ú
_testStatszAppProfilingTests._testStatsz  sg   € Ü‹jˆð —‘œC ¨3Ó/ˆñ ˜7Ó#ˆØ×ÑÔØ�‰Ôà�|‰|‹~ˆØ�‰Ð&¨Ô-Ø�‰�g˜tÕ$r6   c                 óB  — t        j                  «       }| j                  «       |d<   d|d<   d|d<   t        j                  |«      }t        «       }|j                  |«       | j                  |j                  «       | j                  t        j                  |d   «       y)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¯   rw  r4  r§   rx  r6  r%   ÚStats©rQ   r‚   r±   r¢   s       r4   Útest_profileSaveStatsz'AppProfilingTests.test_profileSaveStats‹  s~   € ô ×%Ñ%Ó'ˆØ ŸK™K›MˆˆyÑØ&ˆˆzÑØ"ˆˆ{ÑÜ—?‘? 6Ó*ˆÜ“.ˆà�‰�WÔà�‰˜Ÿ™Ô'Ø�‰œŸ™ f¨YÑ&7Õ8r6   c                 ó  — t         j                  j                  «       }t        j                  «       }d|d<   t        j                  |«      }dt         j                  d<   	 | j                  t        |j                  d«       t         j                  j                  «        t         j                  j                  |«       y# t         j                  j                  «        t         j                  j                  |«       w xY w)z†
        When the C{profile} module is not present, L{app.ProfilerRunner.run}
        should raise a C{SystemExit} exception.
        r$   r±   N©r0  ÚmodulesrÝ  r   r}   r
   r¯   rœ   r�   r4  ÚclearÚupdate©rQ   ÚsavedModulesr‚   r±   s       r4   Útest_withoutProfilez%AppProfilingTests.test_withoutProfile�  s­   € ô
 —{‘{×'Ñ'Ó)ˆä×%Ñ%Ó'ˆØ&ˆˆzÑÜ—?‘? 6Ó*ˆà!%Œ�‰�IÑð	-Ø×Ñœj¨(¯,©,¸Ô=ä�K‰K×ÑÔÜ�K‰K×Ñ˜|Õ,øô �K‰K×ÑÔÜ�K‰K×Ñ˜|Õ,úó   Á!!C  Ã ?C?c                 óœ  —  G d„ dt         j                  «      }| j                  t         d|«       t        j                  «       }| j                  «       |d<   d|d<   t        j                  |«      }t        «       }t        j                  }| j                  t        |j                  |«       | j                  t        j                  |«       y)z…
        When an error happens during the print of the stats, C{sys.stdout}
        should be restored to its initial value.
        c                   ó   — e Zd Zd„ Zy)úGAppProfilingTests.test_profilePrintStatsError.<locals>.ErroneousProfilec                 ó   — t        d«      ‚)NÚBoom©r%  rc   s    r4   r1  zSAppProfilingTests.test_profilePrintStatsError.<locals>.ErroneousProfile.print_stats·  s   € Ü" 6Ó*Ð*r6   N)rS   rT   rU   r1  rX   r6   r4   ÚErroneousProfilerH  ¶  s   „ ó+r6   rL  ÚProfiler$   r±   N)r$   rM  rD   r   r}   rç   r
   r¯   rw  r0  rÐ   rœ   r%  r4  rÓ   )rQ   rL  r‚   r±   r¢   Ú	oldStdouts         r4   Útest_profilePrintStatsErrorz-AppProfilingTests.test_profilePrintStatsError¯  s“   € ô	+œwŸ™ô 	+ð 	�
‰
”7˜IÐ'7Ô8ä×%Ñ%Ó'ˆØ ŸK™K›MˆˆyÑØ&ˆˆzÑÜ—?‘? 6Ó*ˆÜ“.ˆä—J‘Jˆ	Ø×Ñœ,¨¯©°gÔ>Ø�‰”c—j‘j )Õ,r6   zcProfile module not availablec                 ó   — t        j                  «       }| j                  «       |d<   d|d<   t        j                  |«      }t        «       }|j                  |«       | j                  |j                  «       t        |d   «      5 }|j                  «       }ddd«       | j                  d«       | j                  d|«       y# 1 sw Y   Œ.xY w)z�
        L{app.CProfileRunner.run} should call the C{run} method of the
        reactor and save profile data in the specified file.
        r$   r&   r±   Nr4  r)  r*  r+  s         r4   Útest_cProfilezAppProfilingTests.test_cProfileÆ  s©   € ô ×%Ñ%Ó'ˆØ ŸK™K›MˆˆyÑØ'ˆˆzÑÜ—?‘? 6Ó*ˆÜ“.ˆà�‰�WÔà�‰˜Ÿ™Ô'Ü�&˜Ñ#Ó$ð 	¨Ø—6‘6“8ˆD÷	à�‰�e˜TÔ"Ø�‰Ð&¨Õ-÷	ð 	úr.  c                 óB  — t        j                  «       }| j                  «       |d<   d|d<   d|d<   t        j                  |«      }t        «       }|j                  |«       | j                  |j                  «       | j                  t        j                  |d   «       y)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±   Tr8  Nr9  r;  s       r4   Útest_cProfileSaveStatsz(AppProfilingTests.test_cProfileSaveStatsÚ  s~   € ô ×%Ñ%Ó'ˆØ ŸK™K›MˆˆyÑØ'ˆˆzÑØ"ˆˆ{ÑÜ—?‘? 6Ó*ˆÜ“.ˆà�‰�WÔà�‰˜Ÿ™Ô'Ø�‰œŸ™ f¨YÑ&7Õ8r6   c                 ó  — t         j                  j                  «       }dt         j                  d<   t        j                  «       }d|d<   t        j                  |«      }	 | j                  t        |j                  d«       t         j                  j                  «        t         j                  j                  |«       y# t         j                  j                  «        t         j                  j                  |«       w xY w)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>  rB  s       r4   Útest_withoutCProfilez&AppProfilingTests.test_withoutCProfileí  s­   € ô —{‘{×'Ñ'Ó)ˆØ"&Œ�‰�JÑä×%Ñ%Ó'ˆØ'ˆˆzÑÜ—?‘? 6Ó*ˆð	-Ø×Ñœj¨(¯,©,¸Ô=ä�K‰K×ÑÔÜ�K‰K×Ñ˜|Õ,øô �K‰K×ÑÔÜ�K‰K×Ñ˜|Õ,úrE  c                 óÜ   — t        j                  «       }| j                  «       |d<   d|d<   | j                  t        t
        j                  |«      }| j                  t        |«      d«       y)zq
        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¯   rz   r®   )rQ   r‚   Úerrors      r4   Útest_unknownProfilerz&AppProfilingTests.test_unknownProfilerÿ  sY   € ô
 ×%Ñ%Ó'ˆØ ŸK™K›MˆˆyÑØ%ˆˆzÑà×!Ñ!¤*¬c¯o©o¸vÓFˆØ×Ñœ˜U›Ð%HÕIr6   c                 óf   — t        j                  i «      }| j                  |j                  d«       y)zU
        L{app.Profiler} defaults to the cprofile profiler if not specified.
        ÚcprofileN©r
   r¯   rz   r±   ©rQ   r±   s     r4   Útest_defaultProfilerz&AppProfilingTests.test_defaultProfiler  s(   € ô —?‘? 2Ó&ˆØ×Ñ˜×*Ñ*¨JÕ7r6   c                 ój   — t        j                  ddi«      }| j                  |j                  d«       y)ze
        The case of the profiler name passed to L{app.AppProfiler} is not
        relevant.
        r±   ÚCprOfiler[  Nr\  r]  s     r4   Útest_profilerNameCaseInsentivez0AppProfilingTests.test_profilerNameCaseInsentive  s-   € ô
 —?‘? J°
Ð#;Ó<ˆØ×Ñ˜×*Ñ*¨JÕ7r6   N)rS   rT   rU   rV   r   r$   r-  r6  r<  rD  rO  r&   rQ  rS  rU  rY  r^  ra  rX   r6   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ó8r6   r'  c                 óV   ‡‡— g Št         j                  Šˆˆfd„} | t         d|«       ‰S )a  
    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                 ó>   •— ‰j                  | «        ‰| g|¢­i |¤ŽS r)   r?  )ÚlogFilerÄ   ÚkwargsÚlogFilesÚoldFileLogObservers      €€r4   Úobserverz+_patchTextFileLogObserver.<locals>.observer(  s$   ø€ Ø�‰˜Ô Ù! 'Ð;¨DÒ;°FÑ;Ð;r6   ÚtextFileLogObserver)r   ri  )rD   rh  rf  rg  s     @@r4   Ú_patchTextFileLogObserverrj    s/   ù€ ð €HÜ×3Ñ3Ðõ<ñ 
Œ&Ð'¨Ô2Ø€Or6   c                 óR   ‡— g Š G ˆfd„d«      }| j                  t        d|«       ‰S )zu
    Make fake syslog, and return list to which prefix and then log
    messages will be appended if it is used.
    c                   ó"   •— e Zd Zˆ fd„Zˆ fd„Zy)ú(_setupSyslog.<locals>.fakesyslogobserverc                 ó(   •— ‰j                  |«       y r)   r?  )rQ   ÚprefixÚlogMessagess     €r4   rr   z1_setupSyslog.<locals>.fakesyslogobserver.__init__8  s   ø€ Ø×Ñ˜vÕ&r6   c                 ó(   •— ‰j                  |«       y r)   r?  )rQ   Ú	eventDictrp  s     €r4   Úemitz-_setupSyslog.<locals>.fakesyslogobserver.emit;  s   ø€ Ø×Ñ˜yÕ)r6   N)rS   rT   rU   rr   rs  )rp  s   €r4   Úfakesyslogobserverrm  7  s   ø„ ô	'õ	*r6   rt  ÚSyslogObserver)rD   Úsyslog)ÚtestCasert  rp  s     @r4   Ú_setupSyslogrx  0  s.   ø€ ð
 €K÷*ó *ð ‡N�N”6Ð+Ð-?Ô@ØÐr6   c                   óÊ   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	i e
j                  fd„Zd	„ Zd
„ Zd„ Zd„ Z ee d«       ee d«      d„ «       «       Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚAppLoggerTestsz†
    Tests for L{app.AppLogger}.

    @ivar observers: list of observers installed during the tests.
    @type observers: C{list}
    c                 óL   ‡ — g ‰ _         ˆ fd„}‰ j                  t        d|«       y)zˆ
        Override L{globaLogBeginner.beginLoggingTo} so that we can trace the
        observers installed in C{self.observers}.
        c                 ót   •— | D ]2  }‰j                   j                  |«       t        j                  |«       Œ4 y r)   )Ú	observersr•   r   ÚaddObserver)r}  rh  rQ   s     €r4   ÚbeginLoggingToz,AppLoggerTests.setUp.<locals>.beginLoggingToQ  s2   ø€ Ø%ò 9�Ø—‘×%Ñ% hÔ/Ü"×.Ñ.¨xÕ8ñ9r6   r  N)r}  rD   r   )rQ   r  s   ` r4   r  zAppLoggerTests.setUpJ  s%   ø€ ð
 ˆŒô	9ð
 	�
‰
Ô$Ð&6¸ÕGr6   c                 óP   — | j                   D ]  }t        j                  |«       Œ y)z1
        Remove all installed observers.
        N)r}  r   ÚremoveObserver©rQ   rh  s     r4   ÚtearDownzAppLoggerTests.tearDownX  s%   € ð Ÿ™ò 	8ˆHÜ×-Ñ-¨hÕ7ñ	8r6   c                 óH   — t        t        «       G d„ d«      «       } |«       S )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                   ó   — e Zd Zg Zd„ Zy)ú2AppLoggerTests._makeObserver.<locals>.TestObserverc                 ó:   — | j                   j                  |«       y r)   )Ú_logsr•   )rQ   Úevents     r4   Ú__call__z;AppLoggerTests._makeObserver.<locals>.TestObserver.__call__k  s   € Ø—
‘
×!Ñ! %Õ(r6   N)rS   rT   rU   rˆ  rŠ  rX   r6   r4   ÚTestObserverr†  g  s   „ àˆEó)r6   r‹  )r   r   )rQ   r‹  s     r4   Ú_makeObserverzAppLoggerTests._makeObserver_  s*   € ô 
”\Ó	"÷	)ð 	)ó 
#ð	)ñ ‹~Ðr6   c                 óÆ   — | j                  | j                  |g«       | j                  d|j                  d   d   «       | j                  d|j                  d   d   «       y)z�
        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)rz   r}  r”   rˆ  r‚  s     r4   Ú_checkObserverzAppLoggerTests._checkObserverp  sR   € ð 	×Ñ˜Ÿ™¨(¨Ô4Ø�‰�m X§^¡^°AÑ%6°|Ñ%DÔEØ�‰�o x§~¡~°aÑ'8¸Ñ'FÕGr6   c                 óº   ‡— t        j                  i «      }| j                  «       Šˆfd„|_         |j                  t        «       «       | j                  ‰«       y)z”
        L{app.AppLogger.start} calls L{globalLogBeginner.addObserver}, and then
        writes some messages about twistd and the reactor.
        c                  ó   •— ‰ S r)   rX   ©rh  s   €r4   rá   z+AppLoggerTests.test_start.<locals>.<lambda>�  s   ø€ ¨€ r6   N)r
   Ú	AppLoggerrŒ  Ú_getLogObserverr^   r   r�  )rQ   r   rh  s     @r4   Ú
test_startzAppLoggerTests.test_startz  sG   ø€ ô
 —‘˜rÓ"ˆØ×%Ñ%Ó'ˆÛ!1ˆÔØˆ�‰”]“_Ô%Ø×Ñ˜HÕ%r6   c                 óÔ   — t        «       }| j                  «       }|j                  t        |«       t	        j
                  i «      } |j                  |«       | j                  |«       y)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”  r^   r�  )rQ   r]   rh  r   s       r4   Ú$test_startUsesApplicationLogObserverz3AppLoggerTests.test_startUsesApplicationLogObserver…  sS   € ô $“oˆØ×%Ñ%Ó'ˆØ× Ñ ¤¨xÔ8Ü—‘˜rÓ"ˆØˆ�‰�[Ô!Ø×Ñ˜HÕ%r6   c                 óŒ   ‡— | j                  «       Šdˆfd„i}|j                  |«        ||«      } |j                  |«       ‰S )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                  ó   •— ‰ S r)   rX   r“  s   €r4   rá   z7AppLoggerTests._setupConfiguredLogger.<locals>.<lambda>¤  s   ø€  X€ r6   )rŒ  rA  r^   )rQ   r]   ÚextraLogArgsÚ	appLoggerÚlogArgsr   rh  s         @r4   Ú_setupConfiguredLoggerz%AppLoggerTests._setupConfiguredLogger’  sG   ø€ ð" ×%Ñ%Ó'ˆØÓ-Ð.ˆØ�‰�|Ô$Ù˜7Ó#ˆØˆ�‰�[Ô!Øˆr6   c                 óX   — t        «       }| j                  | j                  |«      «       y)a  
        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Ÿ  r\   s     r4   Ú#test_startUsesConfiguredLogObserverz2AppLoggerTests.test_startUsesConfiguredLogObserverª  s$   € ô $“oˆØ×Ñ˜D×7Ñ7¸ÓDÕEr6   c                 óÜ   — | j                  «       }t        «       }|j                  t        |«       | j	                  | j                  |«      «       | j                  |j                  g «       y)zk
        C{--logger} takes precedence over a L{ILogObserver} component set on
        Application.
        N)rŒ  r   r˜  r   r�  rŸ  rz   rˆ  )rQ   rh  r]   s      r4   Ú(test_configuredLogObserverBeatsComponentz7AppLoggerTests.test_configuredLogObserverBeatsComponent´  sV   € ð
 ×%Ñ%Ó'ˆÜ#“oˆØ× Ñ ¤¨xÔ8Ø×Ñ˜D×7Ñ7¸ÓDÔEØ×Ñ˜Ÿ™¨Õ,r6   c                 óÀ   — g }t        «       }|j                  t        |j                  «       | j	                  | j                  |«      «       | j                  |g «       y)zq
        C{--logger} takes precedence over a L{LegacyILogObserver} component
        set on Application.
        N)r   r˜  ÚLegacyILogObserverr•   r�  rŸ  rz   )rQ   Únonlogsr]   s      r4   Ú.test_configuredLogObserverBeatsLegacyComponentz=AppLoggerTests.test_configuredLogObserverBeatsLegacyComponent¿  sN   € ð
 ˆÜ#“oˆØ× Ñ Ô!3°W·^±^ÔDØ×Ñ˜D×7Ñ7¸ÓDÔEØ×Ñ˜ "Õ%r6   c                 ó<  — g }| j                  «       }t        «       }|j                  t        |«       |j                  t        |j
                  «       t        j                  i «      } |j                  |«       | j                  |«       | j                  |g «       y)zw
        A L{ILogObserver} takes precedence over a L{LegacyILogObserver}
        component set on Application.
        N)rŒ  r   r˜  r   r¥  r•   r
   r”  r^   r�  rz   )rQ   r¦  rh  r]   r   s        r4   Ú.test_loggerComponentBeatsLegacyLoggerComponentz=AppLoggerTests.test_loggerComponentBeatsLegacyLoggerComponentÊ  s}   € ð
 ˆØ×%Ñ%Ó'ˆÜ#“oˆØ× Ñ ¤¨xÔ8Ø× Ñ Ô!3°W·^±^ÔDä—‘˜rÓ"ˆØˆ�‰�[Ô!à×Ñ˜HÔ%Ø×Ñ˜ "Õ%r6   r³   zsyslog not availablec                 ó¢   — t        | «      }t        «       }| j                  | j                  |ddit        «      «       | j                  |g «       y)z`
        C{--logger} takes precedence over a C{--syslog} command line
        argument.
        rv  TN)rx  r   r�  rŸ  r"   rz   )rQ   Úlogsr]   s      r4   Ú%test_configuredLogObserverBeatsSyslogz4AppLoggerTests.test_configuredLogObserverBeatsSyslogÛ  sL   € ô ˜DÓ!ˆÜ#“oˆØ×ÑØ×'Ñ'¨°hÀÐ5EÄ}ÓUô	
ð 	×Ñ˜˜rÕ"r6   c                 óÚ   — t        «       }| j                  «       }| j                  | j                  |ddi«      «       | j	                  t
        j                  j                  |«      «       y)za
        C{--logger} takes precedence over a C{--logfile} command line
        argument.
        Úlogfilerã   N)r   rç   r�  rŸ  r«   r:   rã   rÝ   )rQ   r]   rã   s      r4   Ú&test_configuredLogObserverBeatsLogfilez5AppLoggerTests.test_configuredLogObserverBeatsLogfileé  sV   € ô
 $“oˆØ�{‰{‹}ˆØ×ÑØ×'Ñ'¨°iÀÐ5HÓIô	
ð 	×ÑœŸ™Ÿ™¨Ó-Õ.r6   c                 óÆ  — t        j                  ddi«      }t        | j                  «      } |j                  «        | j                  t        |«      d«       | j                  |d   t        j                  «       t        j                  ddi«      } |j                  «        | j                  t        |«      d«       | j                  |d   t        j                  «       y)z’
        When logfile is empty or set to C{-}, L{app.AppLogger._getLogObserver}
        returns a log observer pointing at C{sys.stdout}.
        r®  ú-r÷   r   Ú r…  N)
r
   r”  rj  rD   r•  rz   r  rÓ   r0  rÐ   )rQ   r   rf  s      r4   Útest_getLogObserverStdoutz(AppLoggerTests.test_getLogObserverStdoutõ  s§   € ô
 —‘ 	¨3Ð/Ó0ˆÜ,¨T¯Z©ZÓ8ˆàˆ×ÑÔ à×Ñœ˜X›¨Ô*Ø�‰�h˜q‘k¤3§:¡:Ô.ä—‘ 	¨2˜Ó/ˆØˆ×ÑÔ à×Ñœ˜X›¨Ô*Ø�‰�h˜q‘k¤3§:¡:Õ.r6   c                 ó”  — t        | j                  «      }| j                  «       }t        j                  d|i«      }|j                  «       }| j                  |j                  j                  «       | j                  t        |«      d«       | j                  |d   j                  t        j                  j                  |«      «       y)z•
        When passing the C{logfile} option, L{app.AppLogger._getLogObserver}
        returns a log observer pointing at the specified path.
        r®  r÷   r   N)rj  rD   rç   r
   r”  r•  Ú
addCleanupÚ_outFiler  rz   r  rã   r:   Úabspath)rQ   rf  ÚfilenameÚsutrh  s        r4   Útest_getLogObserverFilez&AppLoggerTests.test_getLogObserverFile  s‘   € ô
 -¨T¯Z©ZÓ8ˆØ—;‘;“=ˆÜ�m‰m˜Y¨Ð1Ó2ˆà×&Ñ&Ó(ˆØ�‰˜×)Ñ)×/Ñ/Ô0à×Ñœ˜X›¨Ô*Ø×Ñ˜ !™×)Ñ)¬2¯7©7¯?©?¸8Ó+DÕEr6   c                 óT  ‡— g Št        «       }ˆfd„}| j                  t        d|«       t        j                  i «      }||_         |j                  «        | j                  ‰|g«        |j                  «        | j                  ‰|g«       | j                  |j
                  «       y)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                 ó(   •— ‰j                  | «       y r)   r?  )rh  Úremoveds    €r4   Úremovez(AppLoggerTests.test_stop.<locals>.remove   s   ø€ Ø�N‰N˜8Õ$r6   r�  N)	r1  rD   r   r
   r”  Ú	_observerr   rz   r�   )rQ   rh  r¾  r   r½  s       @r4   Ú	test_stopzAppLoggerTests.test_stop  sŽ   ø€ ð ˆÜ“8ˆô	%ð 	�
‰
Ô%Ð'7¸Ô@Ü—‘˜rÓ"ˆØ#ˆÔØˆ�‰ŒØ×Ñ˜ 8 *Ô-Øˆ�‰ŒØ×Ñ˜ 8 *Ô-Ø×Ñ˜&×*Ñ*Õ+r6   c                 óf  ‡‡— g Št        j                  i «      }t        t        «       G ˆfd„d«      «       Šˆfd„|_         |j
                  t        «       «       | j                  dt        ‰d   «      «       | j                  | j                  g«      }| j                  t        |«      d|«       y)zt
        L{app.AppLogger} using a legacy logger observer still works, wrapping
        it in a compat shim.
        c                   ó   •— e Zd ZdZˆ fd„Zy)ú;AppLoggerTests.test_legacyObservers.<locals>.LoggerObserverzX
            An observer which implements the legacy L{LegacyILogObserver}.
            c                 ó(   •— ‰j                  |«       y)z<
                Add C{x} to the logs list.
                Nr?  )rQ   Úxr«  s     €r4   rŠ  zDAppLoggerTests.test_legacyObservers.<locals>.LoggerObserver.__call__:  s   ø€ ð —‘˜A•r6   N)rS   rT   rU   rV   rŠ  ©r«  s   €r4   ÚLoggerObserverrÃ  4  s   ø„ ñõr6   rÇ  c                  ó   •—  ‰ «       S r)   rX   )rÇ  s   €r4   rá   z5AppLoggerTests.test_legacyObservers.<locals>.<lambda>@  s
   ø€ ©.Ó*:€ r6   rŽ  r   N)r
   r”  r   r¥  Ú_observerFactoryr^   r   r”   r   r  Útest_legacyObserversrz   r  )rQ   r   ÚwarningsrÇ  r«  s      @@r4   rÊ  z#AppLoggerTests.test_legacyObservers,  s–   ù€ ð
 ˆÜ—‘˜rÓ"ˆä	Ô'Ó	(÷		ò 		ó 
)ð		ó #;ˆÔØˆ�‰”]“_Ô%à�‰�mÔ%6°t¸A±wÓ%?Ô@Ø×%Ñ% t×'@Ñ'@Ð&AÓBˆØ×Ñœ˜X›¨¨8Õ4r6   c                 óX  ‡— g Št        j                  i «      }ˆfd„|_         |j                  t	        «       «       | j                  dt        ‰d   «      «       | j                  | j                  g«      }| j                  |d   d   d«       | j                  t        |«      d|«       y)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                  ó   •— ‰ j                   S r)   r?  rÆ  s   €r4   rá   zAAppLoggerTests.test_unmarkedObserversDeprecated.<locals>.<lambda>O  s   ø€ ¨¯©€ r6   rŽ  r   r  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•  r^   r   r”   r   r  Ú test_unmarkedObserversDeprecatedrz   r  )rQ   r   rË  r«  s      @r4   rÎ  z/AppLoggerTests.test_unmarkedObserversDeprecatedG  s˜   ø€ ð ˆÜ—‘˜rÓ"ˆÛ!4ˆÔØˆ�‰”]“_Ô%à�‰�mÔ%6°t¸A±wÓ%?Ô@à×%Ñ% t×'LÑ'LÐ&MÓNˆØ×ÑØ�Q‰K˜	Ñ"ð0ô	
ð 	×Ñœ˜X›¨¨8Õ4r6   N)rS   rT   rU   rV   r  rƒ  rŒ  r�  r–  r™  r
   r”  rŸ  r¡  r£  r§  r©  r   rÙ   rv  r¬  r¯  r³  rº  rÀ  rÊ  rÎ  rX   r6   r4   rz  rz  B  sœ   „ ñòHò8òò"Hò	&ò&ð )+°c·m±móò0Fò	-ò	&ò&ñ" �ÐÐ9Ó:Ù�ˆJÐ.Ó/ñ
#ó 0ó ;ð
#ò
/ò/ò&Fò,ò*5ó65r6   rz  c                   óT   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	 e
e d«      d	„ «       Zy
)ÚUnixAppLoggerTestszw
    Tests for L{UnixAppLogger}.

    @ivar signals: list of signal handlers installed.
    @type signals: C{list}
    c                 óL   ‡ — g ‰ _         ˆ fd„}‰ j                  t        d|«       y)zs
        Fake C{signal.signal} for not installing the handlers but saving them
        in C{self.signals}.
        c                 ó@   •— ‰j                   j                  | |f«       y r)   )Úsignalsr•   )rò   rë   rQ   s     €r4   Ú
fakeSignalz,UnixAppLoggerTests.setUp.<locals>.fakeSignalu  s   ø€ Ø�L‰L×Ñ  a Õ)r6   ÚsignalN)rÓ  rD   rÕ  )rQ   rÔ  s   ` r4   r  zUnixAppLoggerTests.setUpn  s#   ø€ ð
 ˆŒô	*ð 	�
‰
”6˜8 ZÕ0r6   c                 ó¢  — t        | j                  «      }t        dddœ«      } |j                  «        | j	                  t        |«      d«       | j                  |d   t        j                  «       t        dddœ«      } |j                  «        | j	                  t        |«      d«       | j                  |d   t        j                  «       y)	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©r®  rB  r÷   r   r²  r…  N)	rj  rD   r"   r•  rz   r  rÓ   r0  rÐ   )rQ   rf  r   s      r4   r³  z,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§:¡:Õ.r6   c                 ó–   — t        dddœ«      }| j                  t        |j                  «      }| j	                  t        |«      d«       y)z
        When daemonized and C{logfile} is set to C{-},
        L{UnixAppLogger._getLogObserver} raises C{SystemExit}.
        r±  Fr×  z&Daemons cannot log to stdout, exiting!N)r"   rœ   r�   r•  rz   r®   )rQ   r   rX  s      r4   Útest_getLogObserverStdoutDaemonz2UnixAppLoggerTests.test_getLogObserverStdoutDaemonŒ  s@   € ô
 ¨3¸EÑBÓCˆØ×!Ñ!¤*¨f×.DÑ.DÓEˆØ×Ñœ˜U›Ð%MÕNr6   c                 ó–  ‡— t        | j                  «      }| j                  «       }t        d|i«      }|j	                  «       }| j                  |j                  j                  «       | j                  t        |«      d«       | j                  |d   j                  t        j                  j                  |«      «       | j                  t        | j                  «      d«       | j                  | j                  d   d   t        j                  «       t!        «       Šˆfd„}||d   _        | j                  d   d   } |dd«       ‰S )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.
        r®  r÷   r   c                  ó(   •— ‰ j                  d «       y r)   )Úcallback)Úds   €r4   Úrotatez:UnixAppLoggerTests.test_getLogObserverFile.<locals>.rotateª  s   ø€ Ø�J‰J�tÕr6   N)rj  rD   rç   r"   r•  rµ  r¶  r  rz   r  rã   r:   r·  rÓ  rÕ  ÚSIGUSR1r   rÞ  )rQ   rf  r¸  r¹  rh  rÞ  Ú	rotateLogrÝ  s          @r4   rº  z*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Ñ&ˆ	Ù�$˜ÔØˆr6   c                 ó  ‡ — ˆ fd„}‰ j                  t        d|«       ‰ j                  «       }t        d|i«      }|j	                  «       }‰ j                  |j                  j                  «       ‰ j                  ‰ j                  g «       y)zy
        If a signal handler is already installed,
        L{UnixAppLogger._getLogObserver} doesn't override it.
        c                 óX   •— ‰j                  | t        j                  «       t        «       S r)   )rz   rÕ  rß  r1  )rò   rQ   s    €r4   ÚfakeGetSignalzVUnixAppLoggerTests.test_getLogObserverDontOverrideSignalHandler.<locals>.fakeGetSignal¹  s   ø€ Ø×Ñ˜S¤&§.¡.Ô1Ü“8ˆOr6   Ú	getsignalr®  N)
rD   rÕ  rç   r"   r•  rµ  r¶  r  rz   rÓ  )rQ   rã  r¸  r¹  rh  s   `    r4   Ú,test_getLogObserverDontOverrideSignalHandlerz?UnixAppLoggerTests.test_getLogObserverDontOverrideSignalHandler³  sn   ø€ ô	ð 	�
‰
”6˜;¨Ô6Ø—;‘;“=ˆÜ˜Y¨Ð1Ó2ˆà×&Ñ&Ó(ˆØ�‰˜×)Ñ)×/Ñ/Ô0à×Ñ˜Ÿ™ rÕ*r6   c                 ód  — t        | j                  «      }t        dddœ«      } |j                  «       }| j	                  |j
                  j                  «       | j                  t        |«      d«       | j                  |d   j                  t        j                  j                  d«      «       y)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²  Fr×  r÷   r   z
twistd.logN)rj  rD   r"   r•  rµ  r¶  r  rz   r  rã   r:   r·  )rQ   rf  r   rh  s       r4   Útest_getLogObserverDefaultFilez1UnixAppLoggerTests.test_getLogObserverDefaultFileÆ  s„   € ô -¨T¯Z©ZÓ8ˆÜ¨2¸5ÑAÓBˆØ)�6×)Ñ)Ó+ˆØ�‰˜×)Ñ)×/Ñ/Ô0à×Ñœ˜X›¨Ô*Ø×Ñ˜ !™×)Ñ)¬2¯7©7¯?©?¸<Ó+HÕIr6   r³   c                 ó¾   — t        | «      }t        dddœ«      } |j                  «       }| j                  |dg«        |ddi«       | j                  |dddig«       y)z’
        If C{syslog} is set to C{True}, L{UnixAppLogger._getLogObserver} starts
        a L{syslog.SyslogObserver} with given C{prefix}.
        Tztest-prefix)rv  ro  rÕ  ÚbN)rx  r"   r•  rz   )rQ   r«  r   rh  s       r4   Útest_getLogObserverSyslogz,UnixAppLoggerTests.test_getLogObserverSyslogÔ  sd   € ô ˜DÓ!ˆÜ¨$¸-ÑHÓIˆØ)�6×)Ñ)Ó+ˆØ×Ñ˜ ˜Ô/Ù�#�s�ÔØ×Ñ˜ °°S¨zÐ:Õ;r6   N)rS   rT   rU   rV   r  r³  rÙ  rº  rå  rç  r   rÙ   rê  rX   r6   r4   rÐ  rÐ  e  sF   „ ñò
1ò/ò$Oòò<+ò&Jñ �ÐÐ9Ó:ñ
<ó ;ñ
<r6   rÐ  z!twistd unix support not availablec                   óp   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚDaemonizeTestszH
    Tests for L{_twistd_unix.UnixApplicationRunner} daemonization.
    c                 óÆ  — t        «       | _        t        j                  «       | _        | j                  t        d| j                  «       t        j                  | j                  «      | _        t        j                  d«      | j                  _        t        j                  | j                  _        t        j                  | j                  _        d„ | j                  _        y )Nr:   r  c                   ó   — y r)   rX   )rÄ   s    r4   rá   z&DaemonizeTests.setUp.<locals>.<lambda>ð  râ   r6   )r   Úmockosr   r}   r‚   rD   rÙ   r!   r  r   r  r]   r0  rÐ   rJ  ÚstderrrK  rL  rc   s    r4   r  zDaemonizeTests.setUpè  sˆ   € Ü“hˆŒÜ×*Ñ*Ó,ˆŒØ�
‰
”<  t§{¡{Ô3Ü"×8Ñ8¸¿¹ÓEˆŒÜ")×"5Ñ"5°eÓ"<ˆ�‰ÔÜ #§
¡
ˆ�‰ÔÜ #§
¡
ˆ�‰ÔÙ#5ˆ�‰Õ r6   c                 ó(  — t        t        «       «      5  | j                  j                  «        ddd«       | j	                  | j
                  j                  g d¢«       | j	                  | j
                  j                  ddg«       y# 1 sw Y   ŒZxY w)zw
        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±  r  rf   rz   rï  ÚactionsÚclosedrc   s    r4   Útest_successzDaemonizeTests.test_successò  su   € ô
 Ô4Ó6Ó7ñ 	*Ø�K‰K×'Ñ'Ô)÷	*à×ÑØ�K‰K×Ñòô	
ð 	×Ñ˜Ÿ™×+Ñ+¨b°"¨XÕ6÷	*ð 	*ús   ”BÂBc                 óŠ  — d| j                   _        d| j                   _        t        t	        «       «      5  | j                  t        | j                  j                  «       ddd«       | j                  | j                   j                  g d¢«       | j                  | j                   j                  dg«       y# 1 sw Y   ŒYxY w)zˆ
        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œ   ÚSystemErrorr  rf   rz   rü  rý  rc   s    r4   Útest_successInParentz#DaemonizeTests.test_successInParent  s™   € ð
 "ˆ�‰ÔØ#ˆ�‰ÔÜÔ4Ó6Ó7ñ 	HØ×Ñœk¨4¯;©;×+FÑ+FÔG÷	Hà×ÑØ�K‰K×Ñòô
	
ð 	×Ñ˜Ÿ™×+Ñ+¨b¨TÕ2÷	Hð 	Hús   ¶+B9Â9Cc                 ó‚  ‡— g Šˆfd„}|| j                   _        t        t        «       «      5  | j                  j                  «        ddd«       | j                  | j                   j                  g d¢«       | j                  | j                   j                  ddg«       | j                  ddg‰«       y# 1 sw Y   ŒnxY w)z‚
        If the C{os.write} call to the status pipe raises an B{EINTR} error,
        the process child retries to write.
        c                 óz   •— ‰j                  | |f«       t        ‰«      dk(  rt        t        j                  «      ‚y r¦  ©r•   r  rû   rü   ÚEINTR)Úfdr,  Úwrittens     €r4   ÚraisingWritez6DaemonizeTests.test_successEINTR.<locals>.raisingWrite$  s3   ø€ Ø�N‰N˜B ˜:Ô&Ü�7‹|˜qÒ ÜœeŸk™kÓ*Ð*ð !r6   N)rò  ró  rô  rö  rô  rù  rû  r÷  )r÷  rø  )	rï  ré   r   r±  r  rf   rz   rü  rý  )rQ   r  r  s     @r4   Útest_successEINTRz DaemonizeTests.test_successEINTR  s£   ø€ ð
 ˆô	+ð
 )ˆ�‰ÔÜÔ4Ó6Ó7ñ 	*Ø�K‰K×'Ñ'Ô)÷	*à×ÑØ�K‰K×Ñòô
	
ð 	×Ñ˜Ÿ™×+Ñ+¨b°"¨XÔ6Ø×Ñ˜* jÐ1°7Õ;÷	*ð 	*ús   ­B5Â5B>c                 óÂ  ‡— g Šˆfd„}|| j                   _        d| j                   _        t        t	        «       «      5  | j                  t        | j                  j                  «       ddd«       | j                  | j                   j                  g d¢«       | j                  | j                   j                  dg«       | j                  ddg‰«       y# 1 sw Y   ŒmxY w)z
        If the C{os.read} call on the status pipe raises an B{EINTR} error, the
        parent child retries to read.
        c                 óz   •— ‰j                  | |f«       t        ‰«      dk(  rt        t        j                  «      ‚y)Nr÷   rø  r  )r  Úsizer¸  s     €r4   ÚraisingReadz=DaemonizeTests.test_successInParentEINTR.<locals>.raisingReadA  s0   ø€ Ø�K‰K˜˜T˜
Ô#Ü�4‹y˜AŠ~ÜœeŸk™kÓ*Ð*Ør6   FN)rò  ró  rô  r  rù  r  )r  r  )rï  r¸  r  r   r±  rœ   r  r  rf   rz   rü  rý  )rQ   r  r¸  s     @r4   Útest_successInParentEINTRz(DaemonizeTests.test_successInParentEINTR:  s»   ø€ ð
 ˆô	ð 'ˆ�‰ÔØ!ˆ�‰ÔÜÔ4Ó6Ó7ñ 	HØ×Ñœk¨4¯;©;×+FÑ+FÔG÷	Hà×ÑØ�K‰K×Ñòô		
ð 	×Ñ˜Ÿ™×+Ñ+¨b¨TÔ2Ø×Ñ˜) YÐ/°Õ6÷	Hð 	Hús   ¾+CÃCc                 óè  ‡—  G ˆfd„dt         j                  «      } |«       }|j                  | j                  j                  «       t        t        «       «      5  | j                  t        | j                  j                  «       ddd«       | j                  | j                  j                  ddddddd	|fd
g«       | j                  | j                  j                  dd	g«       y# 1 sw Y   ŒbxY w)z¶
        Assert L{UnixApplicationRunner.postApplication} writes
        C{reported} to its status pipe if the service raises an
        exception whose message is C{raised}.
        c                   ó   •— e Zd Zˆ fd„Zy)ú6DaemonizeTests.assertErrorWritten.<locals>.FakeServicec                 ó   •— t        ‰«      ‚r)   rK  )rQ   Úraiseds    €r4   r_  zCDaemonizeTests.assertErrorWritten.<locals>.FakeService.startService`  s   ø€ Ü" 6Ó*Ð*r6   N)rS   rT   rU   r_  )r  s   €r4   rd  r  _  s   ø„ õ+r6   rd  Nrò  ró  rô  rö  ré   r÷  rù  rû  )r   rO   rX  r  r]   r   r±  rœ   r%  rf   rz   rï  rü  rý  )rQ   r  Úreportedrd  ÚerrorServices    `   r4   ÚassertErrorWrittenz!DaemonizeTests.assertErrorWrittenX  sÏ   ø€ ö	+œ'Ÿ/™/ô 	+ñ #“}ˆØ×%Ñ% d§k¡k×&=Ñ&=Ô>äÔ4Ó6Ó7ñ 	IØ×Ñœl¨D¯K©K×,GÑ,GÔH÷	Ià×ÑØ�K‰K×ÑàØ ØØØØ˜"˜hÐ'Ø(ðô	
ð 	×Ñ˜Ÿ™×+Ñ+¨b°"¨XÕ6÷	Ið 	Iús   Á+C(Ã(C1c                 ó*   — | j                  dd¬«       y)z„
        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  rc   s    r4   Ú
test_errorzDaemonizeTests.test_errorv  s   € ð
 	×ÑØ'Ð2Wð 	 õ 	
r6   c                 ó*   — | j                  dd¬«       y)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   rc   s    r4   Útest_unicodeErrorz DaemonizeTests.test_unicodeError  s   € ð 	×Ñ xÐ:TÐÕUr6   c                 ó  — d| j                   _        || j                   _        t        «       }| j	                  t
        d|«       t        t        «       «      5  | j                  t        | j                  j                  «       ddd«       | j                  |j                  «       |«       | j                  | j                   j                  |«       | j                  | j                   j                  dg«       y# 1 sw Y   ŒwxY w)a  
        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   rD   r0  r   r±  rœ   r  r  rf   rz   rŸ   rü  rý  )rQ   r  ÚerrorMessageÚmockOSActionsÚerrorIOs        r4   ÚassertErrorInParentBehaviorz*DaemonizeTests.assertErrorInParentBehavior‡  sÁ   € ð "ˆ�‰ÔØ'ˆ�‰ÔÜ“*ˆØ�
‰
”3˜ gÔ.ÜÔ4Ó6Ó7ñ 	HØ×Ñœk¨4¯;©;×+FÑ+FÔG÷	Hà×Ñ˜×)Ñ)Ó+¨\Ô:Ø×Ñ˜Ÿ™×,Ñ,¨mÔ<Ø×Ñ˜Ÿ™×+Ñ+¨b¨TÕ2÷		Hð 	Hús   Á+C8Ã8Dc                 ó0   — | j                  ddg d¢¬«       y)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)  rc   s    r4   Útest_errorInParentz!DaemonizeTests.test_errorInParent˜  s%   € ð 	×(Ñ(Ø8ðBòð 	)õ 	
r6   c                 ó0   — | j                  ddg d¢¬«       y)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-  rc   s    r4   Útest_nonASCIIErrorInParentz)DaemonizeTests.test_nonASCIIErrorInParent®  s%   € ð 	×(Ñ(Ø)ðBòð 	)õ 	
r6   c                 ót   — d}dj                  d«      }| j                  |dj                  |«      g d¢¬«       y)a
  
        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)  )rQ   ÚtruncatedMessageÚreportedMessages      r4   Ú&test_errorInParentWithTruncatedUnicodez5DaemonizeTests.test_errorInParentWithTruncatedUnicodeÄ  sL   € ð AÐð 0×6Ñ6°ÓGˆØ×(Ñ(Ø%ðBßBHÁ&Ø#óCòð 	)õ 	
r6   c                 ó*   — | j                  dd¬«       y)z{
        If an error occurs during daemonization and its message is too
        long, it's truncated by the child.
        ÚÈxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsd   1 RuntimeError: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr  Nr   rc   s    r4   Útest_errorMessageTruncatedz)DaemonizeTests.test_errorMessageTruncatedá  s   € ð
 	×ÑØÐ'Fð 	 õ 	
r6   c                 ó*   — | j                  dd¬«       y)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   â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢â€¢r2  r  Nr   rc   s    r4   Ú!test_unicodeErrorMessageTruncatedz0DaemonizeTests.test_unicodeErrorMessageTruncatedê  s   € ð 	×ÑØ Ø:ð 	 õ 	
r6   c                 óº   — t        «       }| j                  j                  |«       | j                  |j                  «       | j                  |j
                  «       y)z¸
        C{daemonize} indeed calls L{IReactorDaemonize.beforeDaemonize} and
        L{IReactorDaemonize.afterDaemonize} if the reactor implements
        L{IReactorDaemonize}.
        N)r±  r  r£  r§   r  r  r§  s     r4   Útest_hooksCalledzDaemonizeTests.test_hooksCalledõ  sB   € ô )Ó*ˆØ�‰×Ñ˜gÔ&Ø�‰˜×6Ñ6Ô7Ø�‰˜×5Ñ5Õ6r6   c                 óº   — t        «       }| j                  j                  |«       | j                  |j                  «       | j                  |j
                  «       y)zÀ
        C{daemonize} does NOT call L{IReactorDaemonize.beforeDaemonize} or
        L{IReactorDaemonize.afterDaemonize} if the reactor does NOT implement
        L{IReactorDaemonize}.
        N)r  r  r£  r«   r  r  r§  s     r4   Útest_hooksNotCalledz"DaemonizeTests.test_hooksNotCalled   sF   € ô ,Ó-ˆØ�‰×Ñ˜gÔ&Ø×Ñ˜×7Ñ7Ô8Ø×Ñ˜×6Ñ6Õ7r6   N)rS   rT   rU   rV   r  rþ  r  r  r  r  r!  r#  r)  r.  r0  r5  r8  r:  r<  r>  rX   r6   r4   rì  rì  â  sX   „ ñò6ò7ò*3ò,<ò:7ò<7ò<
òVò3ò"
ò,
ò,
ò:
ò	
ò	7ó	8r6   rì  c                   óD   — e Zd ZdZed„ «       Zej                  d„ «       Zy)ÚSignalCapturingMemoryReactorz‰
    MemoryReactor that implements the _ISupportsExitSignalCapturing interface,
    all other operations identical to MemoryReactor.
    c                 ó   — | j                   S r)   ©Ú_valrc   s    r4   r‡  z(SignalCapturingMemoryReactor._exitSignal  s   € à�y‰yÐr6   c                 ó   — || _         y r)   rB  )rQ   Úvals     r4   r‡  z(SignalCapturingMemoryReactor._exitSignal  s	   € àˆ�	r6   N)rS   rT   rU   rV   Úpropertyr‡  ÚsetterrX   r6   r4   r@  r@    s5   „ ñð
 ñó ðð ×Ññó ñr6   r@  c                   ó2   ‡ — e Zd ZdZeZˆ fd„Zd„ Zd„ Zˆ xZ	S )ÚStubApplicationRunnerWithSignalzï
    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         ‰| �  |«       d | _        y r)   )Úsuperrr   Ú_signalValue)rQ   r‚   Ú	__class__s     €r4   rr   z(StubApplicationRunnerWithSignal.__init__'  s   ø€ Ü‰Ñ˜Ô Ø ˆÕr6   c                  ó   — y)z
        Does nothing.
        NrX   rc   s    r4   rd   z.StubApplicationRunnerWithSignal.preApplication+  râ   r6   c                 ó˜   — t        «       }| j                  |_        | j                  |t        j
                  t        j                  «       y)z`
        Instantiate a SignalCapturingMemoryReactor and start it
        in the runner.
        N)r@  rL  r‡  rL  r0  rÐ   rð  r§  s     r4   rf   z/StubApplicationRunnerWithSignal.postApplication0  s4   € ô
 /Ó0ˆØ"×/Ñ/ˆÔØ×Ñ˜'¤3§:¡:¬s¯z©zÕ:r6   )
rS   rT   rU   rV   rZ   rg   rr   rd   rf   Ú__classcell__)rM  s   @r4   rI  rI    s   ø„ ñð &€Mô!òö
;r6   rI  c                 ó   ‡ — ˆ fd„}|S )aI  
    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                 ó,   •— t        | «      }‰|_        |S )a·  
        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
        )rI  rL  )r‚   r  Úsignums     €r4   ÚstubApplicationRunnerFactoryzIstubApplicationRunnerFactoryCreator.<locals>.stubApplicationRunnerFactoryG  s   ø€ ô 1°Ó8ˆØ$ˆÔØˆr6   rX   )rS  rT  s   ` r4   Ú#stubApplicationRunnerFactoryCreatorrU  :  s   ø€ ôð  (Ð'r6   c                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)ÚExitWithSignalTestsz?
    Tests for L{twisted.application.app._exitWithSignal}.
    c                 ó  ‡ — t        j                  «       ‰ _        dt        «       i‰ j                  _        t        «       ‰ j                  _        d‰ j                  _        ddg‰ _        ˆ fd„}‰ j                  t        d|«       y)zM
        Set up the server options and a fake for use by test cases.
        r.  Nc                 óB   •— | ‰j                   d<   |‰j                   d<   y)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ò   rQ   s     €r4   ÚfakeKillz+ExitWithSignalTests.setUp.<locals>.fakeKillj  s%   ø€ ð $'ˆD×Ñ˜aÑ Ø#&ˆD×Ñ˜aÒ r6   ró   )r   r}   r‚   rK   r0  r1  r2  r„   rZ  rD   r:   )rQ   r[  s   ` r4   r  zExitWithSignalTests.setUp`  sg   ø€ ô ×*Ñ*Ó,ˆŒØ%3Ô5EÓ5GÐ$Hˆ�‰Ô!Ü!'£ˆ�‰ÔØ!/ˆ�‰ÔØ! 4˜LˆÔô		'ð 	�
‰
”2�v˜xÕ(r6   c                 óÔ  ‡— ddgŠˆfd„}| j                  t        d|«       t        j                  t        j                  «       | j                  ‰d   t        j                  «       | j                  ‰d   t        j                  «       | j                  | j                  d   t        j                  «       «       | j                  | j                  d   t        j                  «       y)zœ
        exitWithSignal replaces the existing signal handler with the default
        handler and sends the replaced signal to the current process.
        Nc                 ó   •— | ‰d<   |‰d<   y )Nr   r÷   rX   )rò   ÚhandlerÚfakeSignalArgss     €r4   Úfake_signalz<ExitWithSignalTests.test_exitWithSignal.<locals>.fake_signal  s   ø€ Ø #ˆN˜1ÑØ 'ˆN˜1Òr6   rÕ  r   r÷   )
rD   rÕ  r
   Ú_exitWithSignalÚSIGINTrŠ  ÚSIG_DFLrZ  r:   rÿ   )rQ   r`  r_  s     @r4   Útest_exitWithSignalz'ExitWithSignalTests.test_exitWithSignalw  s©   ø€ ð  ˜ˆô	(ð 	�
‰
”6˜8 [Ô1Ü×ÑœFŸM™MÔ*à×Ñ˜.¨Ñ+¬V¯]©]Ô;Ø×Ñ˜.¨Ñ+¬V¯^©^Ô<Ø×Ñ˜$×+Ñ+¨AÑ.´·	±	³Ô<Ø×Ñ˜$×+Ñ+¨AÑ.´·±Õ>r6   c                 óú   — | j                  t        dt        d«      «       t        j                  | j                  «       | j                  | j                  d   «       | j                  | j                  d   «       y)zb
        _exitWithSignal is not called if the runner does not exit with a
        signal.
        re  Nr   r÷   )rD   r   rU  ÚrunAppr‚   r�   rZ  rc   s    r4   Útest_normalExitz#ExitWithSignalTests.test_normalExit‹  sc   € ð
 	�
‰
ÜÐ,Ô.QÐRVÓ.Wô	
ô 	�‰�d—k‘kÔ"Ø×Ñ˜$×+Ñ+¨AÑ.Ô/Ø×Ñ˜$×+Ñ+¨AÑ.Õ/r6   c                 óZ  — | j                  t        dt        t        j                  «      «       t        j
                  | j                  «       | j                  | j                  d   t        j                  «       «       | j                  | j                  d   t        j                  «       y)zP
        _exitWithSignal is called when the runner exits with a signal.
        re  r   r÷   N)rD   r   rU  rÕ  rb  rf  r‚   rŠ  rZ  r:   rÿ   rc   s    r4   Útest_runnerExitsWithSignalz.ExitWithSignalTests.test_runnerExitsWithSignal—  st   € ð 	�
‰
ÜØ$Ü/´·±Ó>ô	
ô
 	�‰�d—k‘kÔ"Ø×Ñ˜$×+Ñ+¨AÑ.´·	±	³Ô<Ø×Ñ˜$×+Ñ+¨AÑ.´·±Õ>r6   N)rS   rT   rU   rV   r  rd  rg  ri  rX   r6   r4   rW  rW  Z  s   „ ñò)ò.?ò(
0ó?r6   rW  )hrV   rü   rÚ  r:   r  rÕ  r0  r<   Ú_grpr9   Ú_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#   rv  r$   r%   r&   rI   rK   r”  rZ   re  ra   ri   rÛ   r	  r  r$  r"  r,  r•  rÇ  r	  r  r±  rw  r'  rj  rx  rz  rÐ  rì  r@  rI  rU  rW  rX   r6   r4   ú<module>r„     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   œI= É=	J
Ê	J
