Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/test/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyc


iNc@sdZddlZddlZddlZddlZddlZddlZyddlZddlZWne	k
re
ZZnXyddlZWne	k
rddlZnXddl
mZddlmZddlmZddlmZddlmZddlmZmZmZdd	lmZdd
lmZddlm Z ddl!m"Z"dd
l#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*yddlm+Z+Wne	k
re
Z+nXyddlm,Z,Wne	k
re
Z,n!Xddl-m.Z.ddl-m/Z/yddl0Z0Wne	k
rIe
Z0nXyddl1Z1ddl2Z1Wne	e3fk
re
Z1nXyddl4Z4ddl5Z5Wne	k
re
Z5nXe6ede
e
krdZ7ne
Z7dZ8de9fdYZ:dej;fdYZ<dej=fdYZ>dej?fdYZ@d ej?fd!YZAd"e9fd#YZBd$ejCfd%YZDd&ej?fd'YZEd(ej?fd)YZFd*ej?fd+YZGd,ej?fd-YZHd.e9fd/YZId0ej?fd1YZJd2ZKd3ZLd4ej?fd5YZMd6ej?fd7YZNd8ej?fd9YZOdS(:sE
Tests for L{twisted.application.app} and L{twisted.scripts.twistd}.
iN(t
implements(tverifyObject(tunittest(tplugin(t
IServiceMaker(tservicetapptreactors(ttwistd(tlog(t
UsageError(tILogObserver(tVersion(t
Componentized(tDeferred(tUserDatabase(tsyslog(t_twistd_unix(tUnixApplicationRunner(t
UnixAppLoggertsetuids5Platform does not support --uid/--gid twistd options.cstjtj}tjtjt}|j||j	||j
|j|j|j
fd}|td|j|td|dS(su
    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.
    csSt}||jj<||jj<t|}i|6|S(N(tlisttindextgr_nametgr_gidttuple(tnametresult(tgrouptgrenttgid(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytgetgrnamos
tgetpwnamRN(tpwdtgetpwuidtostgetuidtgrptgetgrgidtgetgidRtaddUsert	pw_passwdtpw_gidtpw_gecostpw_dirtpw_shellR (tpatchtusertuidRRtpwenttdatabaseR((RRRs</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytpatchUserDatabaseNs	tMockServiceMakercBseZdZdZdZRS(sO
    A non-implementation of L{twisted.application.service.IServiceMaker}.
    tueoacCs||_tj|_|jS(se
        Take a L{usage.Options} instance and return a
        L{service.IService} provider.
        (toptionsRtService(tselfR6((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytmakeServices	(t__name__t
__module__t__doc__ttapnameR9(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR4{stCrippledAppLoggercBseZdZdZRS(s*
    @see: CrippledApplicationRunner.
    cCsdS(N((R8tapplication((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytstarts(R:R;R<R@(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR>stCrippledApplicationRunnercBs&eZdZeZdZdZRS(s
    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.
    cCsdS(N((R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytpreApplicationscCsdS(N((R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytpostApplications(R:R;R<R>t
loggerFactoryRBRC(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRAs	tServerOptionsTestcBseZdZdZdZdZdZdZdZdZ	dZ
edkrd	Z
e
e_e	_e
_nd
ZdZRS(
sT
    Non-platform-specific tests for the pltaform-specific ServerOptions class.
    cs,dtfdY}|d|d|d|dfd}tj}j|jtj||_|j}g}x~t||D]m\}}|\}}	}
}j||j	j|	dj|
|jfj||jqWdS(	sh
        subCommands is built from IServiceMaker plugins, and is sorted
        alphabetically.
        t
FakePlugincBseZdZdZRS(cSs'||_d||_d||_dS(Nsoptions for sdescription of (R=t_optionstdescription(R8R((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt__init__s	
cSs|jS(N(RG(R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR6s(R:R;RIR6(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRFs	tappletbananatcoconuttdonutc3s(j|tVVVVdS(N(tassertEqualR(t	interface(RLRJR8RMRK(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt
getPluginss
N(
tobjectRt
ServerOptionsRNt_getPluginsRRPtsubCommandstzipR=tNoneRGRH(R8RFRPtconfigRTt
expectedOrdert
subCommandtexpectedCommandRtshortcuttparserClasst
documentation((RLRJR8RMRKs</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_subCommandss"			cs6dtfdY}|d|d|d|dfd}tj}j|jtj||_tj|_j	t
|jdg|jjgxIfD]5}fd	}||j
||jqWjtd
fdS(sP
        Reactor names are listed alphabetically by I{--help-reactors}.
        tFakeReactorInstallercBseZdZRS(cSsd||_d||_dS(Nsname of sdescription of (t	shortNameRH(R8R((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRIs
(R:R;RI(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR_sRJRKRLRMc3sVVVVdS(N(((RMRLRKRJ(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytgetReactorTypesss--help-reactorscs*j|jj|dS(N(tassertIntappendR(ts(t
helpOutputR8tindexes(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytgetIndexss7reactor descriptions were not in alphabetical order: %rN(RQRRRRNt_getReactorTypesRRatStringIOt
messageOutputtassertRaisest
SystemExittparseOptionstgetvalueR`RHtsorted(R8R_RaRWtreactorRg((RLRJR8ReRMRfRKs</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_sortedReactorHelps*	
cCs7tj}d|_|j|j|dtdS(sS
        postOptions should set no_save to True when a subcommand is used.
        R5tno_saveN(RRRRYtpostOptionsRNtTrue(R8RW((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt&test_postOptionsSubCommandCausesNoSaves	
cCs.tj}|j|j|dtdS(sR
        If no sub command is used, postOptions should not touch no_save.
        RrN(RRRRsRNtFalse(R8RW((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt(test_postOptionsNoSubCommandSavesAsUsual
s
cCsCtj}t|}x$tjjD]}|j||q%WdS(sq
        All the profilers that can be used in L{app.AppProfiler} are listed in
        the help output.
        N(RRRtstrRtAppProfilert	profilersRb(R8RWRetprofiler((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_listAllProfilersscCs$tj}|j|dddS(sG
        The default value for the C{umask} option is C{None}.
        tumaskN(RRRRNRV(R8RW((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_defaultUmaskscCs^tj}|jddg|j|dd|jddg|j|dddS(sh
        The value given for the C{umask} option is parsed as an octal integer
        literal.
        s--umaskt123R}iSt0123N(RRRRmRN(R8RW((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt
test_umask&s
cCs,tj}|jt|jddgdS(s
        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}.
        s--umasktabcdefN(RRRRkR
Rm(R8RW((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_invalidUmask2sstwistd unix not availablecCsbtj}|jt|jddg}|j|jdjd|jd|jddS(sQ
        C{--logger} with an unimportable module raises a L{UsageError}.
        s--loggersno.such.module.I.hopeiseLogger 'no.such.module.I.hope' could not be imported: 'no.such.module.I.hope' does not name an objects
N(	RRRRkR
Rmt
assertTruetargst
startswithtassertNotIn(R8RWte((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt&test_unimportableConfiguredLogObserver?s
cCsbtj}|jt|jddg}|j|jdjd|jd|jddS(sP
        C{--logger} with a non-existent object raises a L{UsageError}.
        s--loggerstwisted.test.test_twistd.FOOBARisiLogger 'twisted.test.test_twistd.FOOBAR' could not be imported: 'module' object has no attribute 'FOOBAR's
N(	RRRRkR
RmRRRR(R8RWR((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt*test_badAttributeWithConfiguredLogObserverLs
N(R:R;R<R^RqRuRwR|R~RRRRVtmsgtskipRR(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyREs	+	*	
							
tTapFileTestcBs eZdZdZdZRS(sM
    Test twistd-related functionality that requires a tap file on disk.
    cCsH|j|_t|jd}tjtjd||jdS(sP
        Create a trivial Application and put it in a tap file on disk.
        twbsHi!N(tmktempttapfiletfiletpickletdumpRtApplicationtclose(R8tf((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytsetUp_scCsTtj}|jd|jgt|j}|jtj|j	ddS(s
        Ensure that the createOrGetApplication call that 'twistd -f foo.tap'
        makes will load the Application out of foo.tap.
        s-fsHi!N(
RRRRmRRAtcreateOrGetApplicationRNRtIServiceR(R8RWR?((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt&test_createOrGetApplicationWithTapFileis(R:R;R<RR(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRZs	
tTestLoggerFactorycBs)eZdZdZdZdZRS(s8
    A logger factory for L{TestApplicationRunner}.
    cCs
||_dS(N(trunner(R8R((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRIzscCs/|jjjdt|jd|j_dS(sC
        Save the logging start on the C{runner} instance.
        R	R?N(RtorderRcthasattrthadApplicationLogObserver(R8R?((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR@~s	cCsdS(s%
        Don't log anything.
        N((R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytstops(R:R;R<RIR@R(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRus			tTestApplicationRunnercBs)eZdZdZdZdZRS(s`
    An ApplicationRunner which tracks the environment in which its methods are
    called.
    cCs/tjj||g|_t||_dS(N(RtApplicationRunnerRIRRtlogger(R8R6((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRIs	cCs&|jjdt|d|_dS(NtpreR?(RRcRthadApplicationPreApplication(R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRBscCs&|jjdt|d|_dS(NtpostR?(RRcRthadApplicationPostApplication(R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRCs(R:R;R<RIRBRC(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRs		tApplicationRunnerTestcBs_eZdZdZdZdZdZdZee_	dZ
ee
_	dZRS(sR
    Non-platform-specific tests for the platform-specific ApplicationRunner.
    cCsMtj}t|_i|jd6|_t|_d|_||_dS(Nttest_command(	RRRR4tserviceMakert
loadedPluginsRQt
subOptionsRYRW(R8RW((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRs	cCsht|j}|j|j|jj|jjd|j|jjtj|j	j
dddS(s
        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.
        sKServiceMaker.makeService needs to be passed the correct sub Command object.isPServiceMaker.makeService's result needs to be set as a child of the Application.N(RARWtruntassertIdenticalRR6RRRR?tservices(R8tarunner((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt,test_applicationRunnerGetsCorrectApplications
	cCsit|j}|j|j|j|j|j|j|j|j|j	dddgdS(s
        Test thet preApplication and postApplication methods are
        called by ApplicationRunner.run() when appropriate.
        RR	RN(
RRWRtassertFalseRRRRRNR(R8Rd((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_preAndPostApplications
cs|jj|gdtjffdY}dtffdY}|}ttj|ttj|||j}|j	||_
|j|jdddt
||fdd	gd
S(s.
        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.
        tFakeUnixApplicationRunnercs>eZfdZfdZfdZdZRS(csjddS(Ntenvironment(Rc(R8tchroottrundirtnodaemonR}tpidfile(tevents(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytsetupEnvironmentscsjd|||fdS(Nt
privileges(Rc(R8teuidR0R(R(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytshedPrivilegesscsjddS(NRp(Rc(R8Rpt	oldstdoutt	oldstderr(R(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytstartReactorscSsdS(N((R8R((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt	removePIDs(R:R;RRRR((R(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRstFakeServicecsoeZeejejdZdZdZ	dZ
dZdZfdZ
fdZdZRS(cSsdS(N((R8R((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytsetNamescSsdS(N((R8tparent((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytsetServiceParentscSsdS(N((R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytdisownServiceParentscsjddS(NtprivilegedStartService(Rc(R8(R(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRscsjddS(NtstartService(Rc(R8(R(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRscSsdS(N((R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytstopServicesN(R:R;RRRtIProcessRVtprocessNameR0RRRRRRR((R(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRs			RRRRRpN(RWRmRt_SomeApplicationRunnerRQRRRRRBR?RCRNRv(R8targvR0RRRR?R((Rs</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt"_applicationStartsWithConfiguredIDs		
	
cCs;d}d}|jdt|dt|g||dS(s
        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}.
        iis--uids--gidN(RRx(R8R0R((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt.test_applicationStartsWithConfiguredNumericIDsscCsTd}d}d}d}t|j|||||jd|d|g||dS(s

        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}.
        tfooitbaris--uids--gidN(R3R.R(R8R/R0RR((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt+test_applicationStartsWithConfiguredNameIDs%scCsWt}tjitd6dd6td6}|j|dd|j|jddS(s7
        L{startReactor} calls L{reactor.run}.
        tprofileR{tdebugs'startReactor did not call reactor.run()N(tDummyReactorRRRvRRVRtcalled(R8RpR((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_startReactorRunsTheReactor6s		
(R:R;R<RRRRRt
setuidSkipRRR(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRs	
		
	C				t*UnixApplicationRunnerSetupEnvironmentTestscBseZdZedkr!dZneZdZdZ	dZ
dZdZdZ
dZd	Zd
ZdZdZd
ZRS(s
    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.
    stwistd unix not availablecsj_j_j_t_tj_j	tdfdj	tdfdj	tdfdj	t
djti_
dS(NRcstd|S(Ntroot(tsetattr(tpath(R8(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt<lambda>dstchdircstd|S(Ntcwd(R(R(R8(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyResR}cstd|S(Ntmask(R(R(R8(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRfst	daemonize(tunsetRRRRvtdaemonR#tgetpidtpidR.RRRR(R8((R8s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR^s	cs)t_jtdfddS(s
        Indicate that daemonization has happened and change the PID so that the
        value written to the pidfile can be tested in the daemonization case.
        RcsjdS(Ni(R((R8(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRqsN(RtRR.R#(R8((R8s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRks	cCs3|jjddtdd|j|jddS(s
        L{UnixApplicationRunner.setupEnvironment} changes the root of the
        filesystem if passed a non-C{None} value for the C{chroot} parameter.
        s/foo/bart.N(RRRtRVRNR(R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_chroottscCs6|jjddtdd|j|j|jdS(s
        L{UnixApplicationRunner.setupEnvironment} does not change the root of
        the filesystem if passed C{None} for the C{chroot} parameter.
        RN(RRRVRtRRR(R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt
test_noChroot}scCs3|jjddtdd|j|jddS(s
        L{UnixApplicationRunner.setupEnvironment} changes the working directory
        of the process to the path given for the C{rundir} parameter.
        s/foo/barN(RRRVRtRNR(R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_changeWorkingDirectoryscCs0|jjddtdd|j|jdS(s
        L{UnixApplicationRunner.setupEnvironment} daemonizes the process if
        C{False} is passed for the C{nodaemon} parameter.
        RN(RRRVRvRR(R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_daemonizescCs0|jjddtdd|j|jdS(s
        L{UnixApplicationRunner.setupEnvironment} does not daemonize the
        process if C{True} is passed for the C{nodaemon} parameter.
        RN(RRRVRtRR(R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_noDaemonizescCsg|j}|jjddtd|t|}t|j}|j|j	||j
dS(s
        L{UnixApplicationRunner.setupEnvironment} writes the process's PID to
        the file specified by the C{pidfile} parameter.
        RN(RRRRVRtRtinttreadRRNR(R8RtfObjR((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_nonDaemonPIDFiles
cCsk|j}|jjddtd|t|}t|j}|j|j	||j
ddS(s
        L{UnixApplicationRunner.setupEnvironment} writes the daemonized
        process's PID to the file specified by the C{pidfile} parameter if
        C{nodaemon} is C{False}.
        RiN(RRRRVRvRRRRRNR(R8RRR((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_daemonPIDFiles
cCs3|jjddtdd|j|jddS(s
        L{UnixApplicationRunner.setupEnvironment} changes the process umask to
        the value specified by the C{umask} parameter.
        Ri{N(RRRVRvRNR(R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRscCs6|jjddtdd|j|j|jdS(s
        L{UnixApplicationRunner.setupEnvironment} doesn't change the process
        umask if C{None} is passed for the C{umask} parameter and C{True} is
        passed for the C{nodaemon} parameter.
        RN(RRRVRtRRR(R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_noDaemonizeNoUmaskscCs3|jjddtdd|j|jddS(s
        L{UnixApplicationRunner.setupEnvironment} changes the process umask to
        C{0077} if C{None} is passed for the C{umask} parameter and C{False} is
        passed for the C{nodaemon} parameter.
        Ri?N(RRRVRvRNR(R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_daemonizedNoUmasksN(R:R;R<RRVRRQRRRRRRRRRRRRR(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyREs 			
													
				
t*UnixApplicationRunnerStartApplicationTestscBs,eZdZedkr!dZndZRS(s>
    Tests for L{UnixApplicationRunner.startApplication}.
    stwistd unix not availablec
stj}|jddddddddd	g	tjd
}t||_gfd}|jtj	|jj
tj	||jtd||jtd
d|jtdd|jj
||jddtdd	gdS(s
        L{UnixApplicationRunner.startApplication} calls
        L{UnixApplicationRunner.setupEnvironment} with the chroot, rundir,
        nodaemon, umask, and pidfile parameters from the configuration it is
        constructed with.
        s
--nodaemons--umaskt0070s--chroots/foo/chroots--rundirs/foo/rundirs	--pidfiles/foo/pidfilettest_setupEnvironmentcs j|||||fdS(N(textend(R8RRRR}R(R(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytfakeSetupEnvironmentsRRc_sdS(N(RV(tatkw((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRststartApplicationc_sdS(N(RV(RR((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRsi8N(RRRRmRRRRRNtinspectt
getargspecRR.RRRt(R8R6R?R((Rs</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRs*
N(R:R;R<RRVRR(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRs	tUnixApplicationRunnerRemovePIDcBs5eZdZedkr!dZndZdZRS(s7
    Tests for L{UnixApplicationRunner.removePID}.
    stwistd unix not availablecCswti}|j}tj|tjj|d}t|dj|j||j	tjj
|dS(sp
        L{UnixApplicationRunner.removePID} deletes the file the name of
        which is passed to it.
        sfoo.pidtwN(RRR#tmakedirsRtjoinRRRRtexists(R8RRR((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_removePIDs

cCs_ti}|jd|jt}|jt|d|j|djjtjdS(sr
        Calling L{UnixApplicationRunner.removePID} with a non-existent filename logs
        an OSError.
        tfakepidiiN(	RRtflushLoggedErrorstOSErrorRNtlentvalueterrnotENOENT(R8Rterrors((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_removePIDErrorss

N(R:R;R<RRVRRR(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRs
		RcBseZdZeZdZRS(s
    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}
    cCs%|jrtdnt|_dS(sV
        A fake run method, checking that it's been called one and only time.
        sAlready calledN(RtRuntimeErrorRt(R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR3s	(R:R;R<RvRR(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR)stAppProfilingTestCasecBsUeZdZdZedkr-de_ndZdZedkrWde_ndZ	dZ
edkrde
_ndZedkrde_nd	Z
edkrde
_nd
ZdZedkrde_ndZedkrd
e_ndZedkr/d
e_ndZdZdZdZRS(s'
    Tests for L{app.AppProfiler}.
    cCstj}|j|d<d|d<tj|}t}|j||j|jt	|dj
}|jd||jd|dS(s
        L{app.ProfileRunner.run} should call the C{run} method of the reactor
        and save profile data in the specified file.
        RR{sDummyReactor.runsfunction callsN(RRRRRRyRRRRRRRb(R8RWR{Rptdata((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_profileBs
	
sprofile module not availablecCsqtj}|jtd|}||}|j|j|j}|jd||jd|dS(Ntstdoutsfunction callss(run)(RiR.tsystprint_statstrestoreRnRb(R8t
statsClassRtoutRtstatsR((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt
_testStatsXs

cCstj}|j|d<d|d<t|d<tj|}t}|j||j|j	|j
tj|ddS(s
        With the C{savestats} option specified, L{app.ProfileRunner.run}
        should save the raw stats object instead of a summary output.
        RR{t	savestatsN(
RRRRRtRRyRRRRRtpstatstStats(R8RWR{Rp((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_profileSaveStatsjs

	
cCstjj}tj}d|d<tj|}dtjd<z|jt	|j
dWdtjjtjj|XdS(s
        When the C{profile} module is not present, L{app.ProfilerRunner.run}
        should raise a C{SystemExit} exception.
        RR{N(
RtmodulestcopyRRRRRyRVRkRlRtcleartupdate(R8tsavedModulesRWR{((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_withoutProfiles


cCsdtjfdY}|jtd|tj}|j|d<d|d<tj|}t}t	j
}|jt|j
||jt	j
|dS(s
        When an error happens during the print of the stats, C{sys.stdout}
        should be restored to its initial value.
        tErroneousProfilecBseZdZRS(cSstddS(NtBoom(R
(R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRs(R:R;R(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR#stProfileRR{N(RR%R.RRRRRRyRRRRkR
RR(R8R#RWR{Rpt	oldStdout((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_profilePrintStatsErrors
		cCstj}|j|d<d|d<tj|}t}|j||j|jt	|dj
}|jd||jd|dS(s
        L{app.HotshotRunner.run} should call the C{run} method of the reactor
        and save profile data in the specified file.
        RthotshotR{Rsfunction callsN(RRRRRRyRRRRRRRb(R8RWR{RpR((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_hotshots
	
shotshot module not availablecCstj}|j|d<d|d<t|d<tj|}t}|j||j|j	|j
tjj
|ddS(s
        With the C{savestats} option specified, L{app.HotshotRunner.run} should
        save the raw stats object instead of a summary output.
        RR(R{RN(RRRRRtRRyRRRRRR(Rtload(R8RWR{Rp((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_hotshotSaveStatss

	
cCstjj}dtjd<tj}d|d<tj|}z|jt	|j
dWdtjjtjj|XdS(s
        When the C{hotshot} module is not present, L{app.HotshotRunner.run}
        should raise a C{SystemExit} exception and log the C{ImportError}.
        R(R{N(
RRRRVRRRRRyRkRlRRR (R8R!RWR{((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_withoutHotshots


cCsdtjfdY}|jtd|tj}|j|d<d|d<tj|}t}t	j
}|jt|j
||jt	j
|dS(s
        When an error happens while printing the stats, C{sys.stdout}
        should be restored to its initial value.
        tErroneousStatscBseZdZRS(cSstddS(NR$(R
(R8((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRs(R:R;R(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR-sRRR(R{N(RRR.RRRRRRyRRRRkR
RR(R8R-RWR{RpR&((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_hotshotPrintStatsErrors
		cCstj}|j|d<d|d<tj|}t}|j||j|jt	|dj
}|jd||jd|dS(s
        L{app.CProfileRunner.run} should call the C{run} method of the
        reactor and save profile data in the specified file.
        RtcProfileR{Rsfunction callsN(RRRRRRyRRRRRRRb(R8RWR{RpR((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt
test_cProfiles
	
scProfile module not availablecCstj}|j|d<d|d<t|d<tj|}t}|j||j|j	|j
tj|ddS(s
        With the C{savestats} option specified,
        L{app.CProfileRunner.run} should save the raw stats object
        instead of a summary output.
        RR/R{RN(
RRRRRtRRyRRRRRRR(R8RWR{Rp((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_cProfileSaveStatss

	
cCstjj}dtjd<tj}d|d<tj|}z|jt	|j
dWdtjjtjj|XdS(s
        When the C{cProfile} module is not present,
        L{app.CProfileRunner.run} should raise a C{SystemExit}
        exception and log the C{ImportError}.
        R/R{N(
RRRRVRRRRRyRkRlRRR (R8R!RWR{((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_withoutCProfile+s


cCsXtj}|j|d<d|d<|jttj|}|jt|ddS(sq
        Check that L{app.AppProfiler} raises L{SystemExit} when given an
        unknown profiler name.
        RtfoobarR{s!Unsupported profiler name: foobarN(	RRRRRkRlRRyRNRx(R8RWterror((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_unknownProfiler>s

cCs&tji}|j|jddS(sT
        L{app.Profiler} defaults to the hotshot profiler if not specified.
        R(N(RRyRNR{(R8R{((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_defaultProfilerKscCs-tjidd6}|j|jddS(se
        The case of the profiler name passed to L{app.AppProfiler} is not
        relevant.
        tHotShotR{R(N(RRyRNR{(R8R{((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_profilerNameCaseInsentiveSsN(R:R;R<RRRVRRRR"R'R)R(R+R,R.R0R/R1R2R5R6R8(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR=s@													
	cs5gtjfd}|td|S(s
    Patch L{log.FileLogObserver} to record every call and keep a reference to
    the passed log file for tests.

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

    @return: the list that keeps track of the log files.
    @rtype: C{list}
    csj||S(N(Rc(tlogFile(toldFileLobObservertlogFiles(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytFileLogObserveris
R<(R	R<(R.R<((R:R;s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt_patchFileLogObserver]s

	cs9gdtffdY}|jtd|S(su
    Make fake syslog, and return list to which prefix and then log
    messages will be appended if it is used.
    tfakesyslogobservercs&eZfdZfdZRS(csj|dS(N(Rc(R8tprefix(tlogMessages(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRIxscsj|dS(N(Rc(R8t	eventDict(R@(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytemitzs(R:R;RIRB((R@(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR>wstSyslogObserver(RQR.R(ttestCaseR>((R@s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt_setupSyslogqstAppLoggerTestCasecBseZdZdZdZdZdZdZiej	dZ
dZdZd	Z
edks~edkrd
e
_ndZdZd
ZdZRS(s
    Tests for L{app.AppLogger}.

    @ivar observers: list of observers installed during the tests.
    @type observers: C{list}
    cs/g_fd}jtd|dS(sx
        Override L{log.addObserver} so that we can trace the observers
        installed in C{self.observers}.
        cs!jj|tj|dS(N(t	observersRcR	taddObserver(tobserver(R8(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytstartLoggingWithObserversRJN(RGR.R	(R8RJ((R8s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRs	cCs%x|jD]}tj|q
WdS(s1
        Remove all installed observers.
        N(RGR	tremoveObserver(R8RI((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttearDownscCsU|j|j|jg|jd|ddd|jd|ddddS(s
        Ensure that initial C{twistd} logs are written to the given list.

        @type logs: C{list}
        @param logs: The list whose C{append} method was specified as the
            initial log observer.
        sstarting upitmessages
reactor classiN(RNRGRcRb(R8tlogs((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt_checkObserverscsHtji}gfd|_|jt|jdS(s
        L{app.AppLogger.start} calls L{log.addObserver}, and then writes some
        messages about twistd and the reactor.
        csjS(N(Rc((RI(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRsN(Rt	AppLoggert_getLogObserverR@R
RO(R8R((RIs</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt
test_starts
cCsOt}g}|jt|jtji}|j||j|dS(s
        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
tsetComponentRRcRRPR@RO(R8R?RNR((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt$test_startUsesApplicationLogObservers	
csFgifdd6}|j|||}|j|S(s
        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.
        csjS(N(Rc((RN(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRsR(R R@(R8R?textraLogArgst	appLoggertlogArgsR((RNs</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt_setupConfiguredLoggers

cCs#t}|j|j|dS(s
        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
RORX(R8R?((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt#test_startUsesConfiguredLogObservers	cCsLg}t}|jt|j|j|j||j|gdS(sh
        C{--logger} takes precedence over a ILogObserver component set on
        Application.
        N(R
RSRRcRORXRN(R8tnonlogsR?((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt(test_configuredLogObserverBeatsComponents
	cCsLt|}t}|j|j|itd6t|j|gdS(s`
        C{--logger} takes precedence over a C{--syslog} command line
        argument.
        RN(RER
RORXRtRRN(R8RNR?((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt%test_configuredLogObserverBeatsSyslogs	

s&Not on POSIX, or syslog not available.cCsRt}|j}|j|j|idd6|jtjj|dS(sa
        C{--logger} takes precedence over a C{--logfile} command line
        argument.
        RtlogfileN(R
RRORXRR#RR(R8R?R((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt&test_configuredLogObserverBeatsLogfiles
	cCstjidd6}t|j}|j}|jt|d|j|dtj	tjidd6}|j}|jt|d|j|dtj	dS(s
        When logfile is empty or set to C{-}, L{app.AppLogger._getLogObserver}
        returns a log observer pointing at C{sys.stdout}.
        t-R]iitiN(
RRPR=R.RQRNRRRR(R8RR;RI((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_getLogObserverStdoutscCszt|j}|j}tji|d6}|j}|jt|d|j|djt	jj
|dS(s
        When passing the C{logfile} option, L{app.AppLogger._getLogObserver}
        returns a log observer pointing at the specified path.
        R]iiN(R=R.RRRPRQRNRRR#tabspath(R8R;tfilenameRRI((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_getLogObserverFile#scsgt}fd}|jtd|tji}||_|j|j|g|j|j|g|j|jddS(s
        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.
        csj|dS(N(Rc(RI(tremoved(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytremove;sRKN(
RQR.R	RRPt	_observerRRNRRV(R8RIRfR((Res</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt	test_stop3s		

N(R:R;R<RRLRORRRTRRPRXRYR[R\RRVRRR^RaRdRh(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRFs"			
								tUnixAppLoggerTestCasecBszeZdZed
kr!dZndZdZdZdZ	dZ
dZdZe
d
krxd	e_nRS(sw
    Tests for L{UnixAppLogger}.

    @ivar signals: list of signal handlers installed.
    @type signals: C{list}
    stwistd unix not availablecs/g_fd}jtd|dS(ss
        Fake C{signal.signal} for not installing the handlers but saving them
        in C{self.signals}.
        csjj||fdS(N(tsignalsRc(tsigR(R8(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt
fakeSignalXstsignalN(RjR.Rm(R8Rl((R8s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRRs	cCst|j}tidd6td6}|j}|jt|d|j|dtj	tidd6td6}|j}|jt|d|j|dtj	dS(	s
        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_R]RiiR`iN(
R=R.RRtRQRNRRRR(R8R;RRI((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRa]scCsItidd6td6}|jt|j}|jt|ddS(s
        When daemonized and C{logfile} is set to C{-},
        L{UnixAppLogger._getLogObserver} raises C{SystemExit}.
        R_R]Rs&Daemons cannot log to stdout, exiting!N(RRvRkRlRQRNRx(R8RR4((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_getLogObserverStdoutDaemonpscst|j}|j}ti|d6}|j}|jt|d|j|djtjj	||jt|j
d|j|j
ddtjt
fd}||d_|j
dd}|ddS(s
        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]iicsjddS(N(tcallbackRV((td(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pytrotatesN(R=R.RRRQRNRRR#RbRjRmtSIGUSR1RRqRV(R8R;RcRRIRqt	rotateLog((Rps</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRdzs	

csdfd}jtd|j}ti|d6}|j}jjgdS(sy
        If a signal handler is already installed,
        L{UnixAppLogger._getLogObserver} doesn't override it.
        csj|tjtS(N(RNRmRrRQ(Rk(R8(s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt
fakeGetSignalst	getsignalR]N(R.RmRRRQRNRj(R8RtRcRRI((R8s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt,test_getLogObserverDontOverrideSignalHandlerscCsrt|j}tidd6td6}|j}|jt|d|j|djtjj	ddS(s
        When daemonized and C{logfile} is empty, the observer returned by
        L{UnixAppLogger._getLogObserver} points at C{twistd.log} in the current
        directory.
        R`R]Riis
twistd.logN(
R=R.RRvRQRNRRR#Rb(R8R;RRI((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_getLogObserverDefaultFilescCswt|}titd6dd6}|j}|j|dg|idd6|j|didd6gdS(s
        If C{syslog} is set to C{True}, L{UnixAppLogger._getLogObserver} starts
        a L{syslog.SyslogObserver} with given C{prefix}.
        Rstest-prefixR?tbRN(RERRtRQRN(R8RNRRI((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_getLogObserverSyslogssSyslog not availableN(R:R;R<RRVRRRaRnRdRvRwRyR(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRiHs				
				tDeprecationTestscBseZdZdZRS(s(
    Tests for deprecated features.
    cCsg}tj|j|jtj|j|jtddddtj|j	t
|d|jd|ddd|jd|dddd	S(
s2
        L{app.initialLog} is deprecated.
        tTwistediiisstarting upRMs
reactor classiN(R	RHRct
addCleanupRKtcallDeprecatedRRt
initialLogRNRRb(R8RN((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyttest_initialLogs"(R:R;R<R(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRzs(PR<RmRR	R#RRiR!R%tImportErrorRVtcPickleRtzope.interfaceRtzope.interface.verifyRt
twisted.trialRttwistedRttwisted.application.serviceRttwisted.applicationRRRttwisted.scriptsRttwisted.pythonR	ttwisted.python.usageR
ttwisted.python.logRttwisted.python.versionsRttwisted.python.componentsR
ttwisted.internet.deferRttwisted.python.fakepwdRRRttwisted.scripts._twistd_unixRRRR(t
hotshot.statsRlRR/tgetattrRR3RQR4RPR>RRAtTestCaseRERRRRRRRRRRR=RERFRiRz(((s</usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt<module>s$$










		-
,#!