Your IP : 172.28.240.42


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


oUNc@sddlZddlZddlZddlZddlZddlZddlmZddlm	Z	m
Z
mZmZm
Z
mZddlmZddlmZmZddlmZddlmZddlmZdd	lmZmZdd
lmZddlm Z m!Z!ddl"m#Z#dd
l"m$Z$de%fdYZ&de&fdYZ'de&fdYZ(de&fdYZ)de%fdYZ*de%fdYZ+dZ,dddZ.dZ/dZ0de%fdYZ1d Z2d!Z3d"d.d#YZ4d$ej5e4fd%YZ6d&Z7d'Z8eed(d)d*d+e8Z8d,Z9d-Z:dS(/iN(t
attrgetter(truntimetlogtusagetfailuretutiltlogfile(tVersion(tqualtnamedAny(t
deprecated(tILogObserver(tsob(tservicetreactors(tdefer(t	copyrighttplugin(tinstallReactor(t
NoSuchReactort_BasicProfilercBs eZdZdZdZRS(s
    @ivar saveStats: if C{True}, save the stats information instead of the
        human readable format
    @type saveStats: C{bool}

    @ivar profileOutput: the name of the file use to print profile data.
    @type profileOutput: C{str}
    cCs||_||_dS(N(t
profileOutputt	saveStats(tselfRR((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyt__init__"s	cCs*d||f}|d7}t|dS(s
        Helper method to report an import error with a profile module. This
        has to be explicit because some of these modules are removed by
        distributions due to them being non-free.
        sFailed to import module %s: %ss
This is most likely caused by your operating system not including
the module due to it being non-free. Either do not use the option
--profile, or install the module; your operating system vendor
may provide it in a separate package.
N(t
SystemExit(Rtmoduletets((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyt_reportImportError's(t__name__t
__module__t__doc__RR(((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRs	t
ProfileRunnercBseZdZdZRS(s1
    Runner for the standard profile module.
    cCsyddl}Wn#tk
r5}|jd|nX|j}|j|j|jrn|j|jnNt	j
t|jd}t	_
z|jWd|t	j
t	_
}|j
XdS(s:
        Run reactor under the standard profiler.
        iNtprofileta(R"tImportErrorRtProfiletruncalltrunRt
dump_statsRtsyststdouttopentprint_statstclose(RtreactorR"Rtpttmp((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyR'=s	(RRR R'(((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyR!8st
HotshotRunnercBseZdZdZRS(s0
    Runner for the hotshot profile module.
    cCs0yddl}Wn)ttfk
r;}|jd|nX|j|j}|j|j|jrkdS|j	j
|j}|j|jdt
|dddk	rt|jd|_|j|jjnNtjt|jd}t_z|jWd|tjt_}|jXdS(s9
        Run reactor under the hotshot profiler.
        iNthotshottstreamtw(t
hotshot.statsR$RRR%RR&R'Rtstatstloadt
strip_dirst
sort_statstgetattrtNoneR+R3R,R-R)R*(RR.R2RR/RR0((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyR'Ys(	


(RRR R'(((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyR1TstCProfileRunnercBseZdZdZRS(s)
    Runner for the cProfile module.
    cCsyddl}ddl}Wn#tk
rA}|jd|nX|j}|j|j|jrz|j|j	nRt
|j	d}|j|d|}|j|j
d|j|jdS(s:
        Run reactor under the cProfile profiler.
        iNtcProfileR4R3(R=tpstatsR$RR%R&R'RR(RR+tStatsR8R9R,R-(RR.R=R>RR/R3R((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyR's	


(RRR R'(((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyR<stAppProfilercBs2eZdZied6ed6ed6ZdZRS(s
    Class which selects a specific profile runner based on configuration
    options.

    @ivar profiler: the name of the selected profiler.
    @type profiler: C{str}
    R"R2tcprofilecCs|jdt}|jdd}|jddj|_|j|jkry|j|j||}|j|_ntd|jfdS(Nt	savestatsR"tprofilerR2sUnsupported profiler name: %s(tgettFalseR;tlowerRCt	profilersR'R(RtoptionsRRRC((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRs(RRR R!R1R<RGR(((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyR@s
t	AppLoggercBsAeZdZdZdZdZdZdZdZ	RS(s
    Class managing logging faciliy of the application.

    @ivar _logfilename: The name of the file to which to log, if other than the
        default.
    @type _logfilename: C{str}

    @ivar _observerFactory: Callable object that will create a log observer, or
        None.

    @ivar _observer: log observer added at C{start} and removed at C{stop}.
    @type _observer: C{callable}
    cCs1|jdd|_|jdp'd|_dS(NRttlogger(RDt_logfilenameR;t_observerFactory(RRH((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRscCsr|jdk	r|j}n|jtd}|dkrK|j}n||_tj|j|jdS(s
        Initialize the logging system.

        If a customer logger was specified on the command line it will be
        used. If not, and an L{ILogObserver} component has been set on
        C{application}, then it will be used as the log observer.  Otherwise a
        log observer will be created based on the command-line options for
        built-in loggers (e.g. C{--logfile}).

        @param application: The application on which to check for an
            L{ILogObserver}.
        N(	RMR;tgetComponentRt_getLogObservert	_observerRtstartLoggingWithObservert_initialLog(Rtapplicationtobserver((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytstarts
	cCsWddlm}tjdtjtjtj	ftjdt
|jfdS(s1
        Print twistd start log message.
        i(R.stwistd %s (%s %s) starting up.sreactor class: %s.N(ttwisted.internetR.RtmsgRtversionR)t
executableRtshortPythonVersionRt	__class__(RR.((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRRs
cCsJ|jdks|jr%tj}ntjj|j}tj|jS(sr
        Create a log observer to be added to the logging system before running
        this application.
        t-(	RLR)R*RtLogFiletfromFullPathRtFileLogObservertemit(RtlogFile((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyROscCs<tjd|jdk	r8tj|jd|_ndS(s0
        Print twistd stop log message.
        sServer Shut Down.N(RRWRPR;tremoveObserver(R((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytstops
N(
RRR R;RPRRURRRORc(((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRIs
				cCsCd}d}d}|tj_|tj_|tj_dS(NcSs;|j|jddlm}|jd|jdS(Ni(R.ii(tclear_all_breakstset_continueRVR.t	callLaterRc(RtargR.((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytdo_stops


cSs	dGHdS(NsEstop - Continue execution, then cleanly shutdown the twisted reactor.((R((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyt	help_stopscSstjddS(Ni(tost_exit(R((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytset_quits(tpdbtPdbRlRhRi(RhRiRl((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytfixPdb
s			cCs|dkrddlm}ny|drK|dk	r|j|qn~|dr|t_|t_tjdkrt	j	t	j
dt	j	t	jdntt
j|jn
|jWnC|dr|}ntd	d
}tjd||jnXdS(
sN
    Start the reactor, using profiling if specified by the configuration, and
    log any error happening in the process.

    @param config: configuration of the twistd application.
    @type config: L{ServerOptions}

    @param oldstdout: initial value of C{sys.stdout}.
    @type oldstdout: C{file}

    @param oldstderr: initial value of C{sys.stderr}.
    @type oldstderr: C{file}

    @param profiler: object used to run the reactor with profiling.
    @type profiler: L{AppProfiler}

    @param reactor: The reactor to use.  If C{None}, the global reactor will
        be used.
    i(R.R"tdebugtposixcWs
tjS(N(Rmt	set_trace(targs((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyt<lambda>>scWs
tjS(N(RmRr(Rs((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRt?stnodaemonsTWISTD-CRASH.logR#tfileN(R;RVR.R'R)R*tstderrRtplatformTypetsignaltSIGUSR2tSIGINTRoRmR&R+t	tracebackt	print_exctflush(tconfigt	oldstdoutt	oldstderrRCR.Rv((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytrunReactorWithLogging s*

		
	cCs|rtjdSdSdS(NsPassphrase: (tgetpassR;(tneeded((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyt
getPassphraseNs
cCs |rtjd}ndSdS(NsEncryption passphrase: (RtgetPasswordR;(Rt
passphrase((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytgetSavePassphraseVstApplicationRunnercBsPeZdZeZeZdZdZdZ	dZ
dZdZRS(s
    An object which helps running an application based on a config object.

    Subclass me and implement preApplication and postApplication
    methods. postApplication generally will want to run the reactor
    after starting the application.

    @ivar config: The config object, which provides a dict-like interface.

    @ivar application: Available in postApplication, but not
       preApplication. This is the application object.

    @ivar profilerFactory: Factory for creating a profiler object, able to
        profile the application if options are set accordingly.

    @ivar profiler: Instance provided by C{profilerFactory}.

    @ivar loggerFactory: Factory for creating object responsible for logging.

    @ivar logger: Instance provided by C{loggerFactory}.
    cCs1||_|j||_|j||_dS(N(RtprofilerFactoryRCt
loggerFactoryRK(RR((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRws	cCsG|j|j|_|jj|j|j|jjdS(s&
        Run the application.
        N(tpreApplicationtcreateOrGetApplicationRSRKRUtpostApplicationRc(R((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyR'}s


cCs t|j|||j|dS(s
        Run the reactor with the given configuration.  Subclasses should
        probably call this from C{postApplication}.

        @see: L{runReactorWithLogging}
        N(RRRC(RR.RR((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytstartReactorscCs
tdS(s
        Override in subclass.

        This should set up any state necessary before loading and
        running the Application.
        N(tNotImplementedError(R((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRscCs
tdS(s
        Override in subclass.

        This will be called after the application has been loaded (so
        the C{application} attribute will be set). Generally this
        should start the application and run the reactor.
        N(R(R((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRscCs|jjrY|jj|jj}|j|jj}tj|j}|j|n%t	|jd}t
|j|}|S(s
        Create or load an Application based on the parameters found in the
        given L{ServerOptions} instance.

        If a subcommand was used, the L{service.IServiceMaker} that it
        represents will be used to construct a service to be added to
        a newly-created Application.

        Otherwise, an application will be loaded based on parameters in
        the config.
        t	encrypted(Rt
subCommandt
loadedPluginstmakeServicet
subOptionsR
tApplicationttapnametsetServiceParentRtgetApplication(RtplgtserRSR((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRs(
RRR R@RRIRRR'RRRR(((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyR^s		
		
	cCs/gdddgD] }||r|||f^qd}|didd6j|d|d}}y7tjd|tj|||}tjdWntk
r*}d	|}t|tr|jdd
kr|d7}nt	j
dtjtj|tjt
jd|dnX|S(
NtpythontsourceRvitpickleis
Loading %s...sLoaded.sFailed to load application: %sRSsN
Could not find 'application' in the file. To use 'twistd -y', your .tac
file must create a suitable object (e.g., by calling service.Application())
and store it in a variable named 'application'. twistd loads your .tac file
and scans the global variables for one of this name.

Please read the 'Using Application' HOWTO for details.
s
(RDRRWR
tloadApplicationt	Exceptiont
isinstancetKeyErrorRsR|R}RtdeferrR)texit(RRttRtfilenametstyleRSR((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRs"7,
"


cCs)tjgtjD]}|j^qS(N(RtCompleteListRtgetReactorTypest	shortName(tr((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyt_reactorActionstReactorSelectionMixincBsWeZdZejdied6ZejZ	e
ejZ
dZdZeZRS(s
    Provides options for selecting a reactor to install.

    If a reactor is installed, the short name which was used to locate it is
    saved as the value for the C{"reactor"} key.
    t
optActionsR.cCs_t|jdtd}x.|D]&}|jjd|j|jfq%WtddS(sE
        Display a list of possibly available reactor names.
        tkeyRs    %-4s	%s
iN(tsortedt_getReactorTypesRt
messageOutputtwriteRtdescriptionR(RtrctsR((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytopt_help_reactorss

cCszyt|Wn[tk
r=d|f}tj|n9tk
rk}d|f}tj|nX||d<dS(sX
        Which reactor to use (see --help-reactors for a list of possibilities)
        scThe specified reactor does not exist: '%s'.
See the list of available reactors with --help-reactorsstThe specified reactor cannot be used, failed with error: %s.
See the list of available reactors with --help-reactorsR.N(RRRt
UsageErrorR(RRRWR((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytopt_reactors	


(RRR RtCompletionsRtcompDataR)R*RtstaticmethodRRRRRtopt_r(((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRs				t
ServerOptionscBsxeZdZdd.dgdddgdddggZd	d
d.dgdd.d.d
gddd.dgdd.dddjejgddddgddd.dgddd.dgdd d!d"ggZe	j
d#d/gd$ie	jd%d6e	jd&d6e	jd'd6e	jd6Z
eejZd(Zd)ZeZd*Zd.d+Zd,Zd-ZeeZRS(0sQtwistd reads a twisted.application.service.Application out of a file and runs it.RBsBsave the Stats object rather than the text output of the profiler.tno_savetosdo not save state on shutdownRRs(The specified tap/aos file is encrypted.Rtls%log to a specified file, - for stdoutRKsA fully-qualified name to a log observer factory to use for the initial log observer.  Takes precedence over --logfile and --syslog (when available).R"R/s6Run in profile mode, dumping results to specified fileRCR2s!Name of the profiler to use (%s).s, Rvtfs
twistd.tapsread the given .tap fileRtys:read an application from within a Python file (implies -o)RRs2Read an application from a .tas file (AOT format).trundirtdt.s-Change to a supplied directory before runningtmutuallyExclusiveRs*.taps
*.(tac|py)s*.tascOs$t|d<tjj|||dS(NRp(RERtOptionsR(RR#tkw((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRGs
cCs%tjttjt|d<dS(s
        Run the application in the Python Debugger (implies nodaemon),
        sending SIGUSR2 will drop into debugger
        RpN(RtsetDebuggingtTrueRtstartDebugMode(R((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyt	opt_debugLs

cCsItjtjyddl}Wntk
r4dSX|jtjdS(s
        Print an insanely verbose log of everything that happens.
        Useful when debugging freezes or locks in complex code.iN(R)tsettraceRtspewert	threadingR$(RR((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytopt_spewWs
cCs<|dkr%tjdpdg}ntjj||dS(Nis--help(R;R)targvRRtparseOptions(RRH((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRcscCs|js|dr t|d<n|ddk	r~yt|d|d<Wq~tk
rz}tjd|d|fq~XndS(NRRRKs%Logger '%s' could not be imported: %s(RRR;R	RRR(RR((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytpostOptionsis
	ccso|jtj}i|_xMt|dtdD]3}||j|j<|jd|d|jfVq4WdS(NRRcSs
|jS(N(RH(tplug((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRt~s(	t_getPluginsR
t
IServiceMakerRRRRR;R(RtpluginsR((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytsubCommandsts		N(sfilespythonssource(RRtlongdescR;toptFlagstjoinR@RGt
optParametersRRt
CompleteFilestCompleteDirsRRRt
getPluginsRRRtopt_bRRRRtproperty(((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRsL															cCsY|}y|jWn1tjk
rJ}|GHdtjd|fGHnX||dS(Ns%s: %si(RRterrorR)R(trunAppRRtue((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyR's	cCstijdS(N(RIRR(((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyt
initialLogstTwistediiicCsitj|||}tj|j|t|}|rFd}ntj|jd|d|dS(NRR(R
RRtIPersistabletsetStyleRR;tsave(tfileinttypeinRtfileoutttypeouttencryptRS((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytconvertStyles	cCswddlm}tj|j|rTtj|}|jdd|jdn|jddtj|j	dS(Ni(R.taftertshutdowntbefore(
RVR.R
tIServicetstartServiceRRtaddSystemEventTriggerRtstopService(RSRR.R/((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytstartApplications((;R)RjRmRR|RytoperatorRttwisted.pythonRRRRRRttwisted.python.versionsRttwisted.python.reflectRR	ttwisted.python.deprecateR
ttwisted.python.logRttwisted.persistedRttwisted.applicationR
RRVRttwistedRRttwisted.application.reactorsRRtobjectRR!R1R<R@RIRoR;RRRRRRRRRR'RRR(((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyt<module>s@H. 3P	.		j		5h		!