]Rc@s\ddlZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z m Z m Z mZddlmZddlmZmZddlmZddlmZddlmZdd lmZmZdd lmZdd lm 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$e j5e4fd%YZ6d&Z7d'Z8d(Z9dS(*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"t ImportErrorRtProfiletruncalltrunRt dump_statsRtsyststdouttopent print_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. cCsyddl}Wn)ttfk r;}|jd|nX|j|j}|j|j|jrkdS|j j |j}|j |j dt |jd|_|j|jjdS(s9 Run reactor under the hotshot profiler. iNthotshottw(t hotshot.statsR$RRR%RR&R'Rtstatstloadt strip_dirst sort_statsR+tstreamR,R-(RR.R2RR/R((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. iNtcProfileR3R9(R;tpstatsR$RR%R&R'RR(RR+tStatsR7R8R,R-(RR.R;R<RR/R9R((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:}st AppProfilercBs2eZdZied6ed6ed6ZdZRS(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(tgettFalsetNonetlowerRAt profilersR'R(RtoptionsRRRA((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRs(RRR R!R1R:RFR(((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(RBt _logfilenameRDt_observerFactory(RRG((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( RLRDt getComponentR t_getLogObservert _observerRtstartLoggingWithObservert _initialLog(Rt applicationtobserver((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytstarts   cCsWddlm}tjdtjtjtj ftjdt |j fdS(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.pyRQs 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-( RKR)R*RtLogFilet fromFullPathRtFileLogObservertemit(RtlogFile((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRNs cCs<tjd|jdk r8tj|jd|_ndS(s0 Print twistd stop log message. sServer Shut Down.N(RRVRORDtremoveObserver(R((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytstops N( RRR RDRORRTRQRNRb(((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRHs    cCsCd}d}d}|tj_|tj_|tj_dS(NcSs;|j|jddlm}|jd|jdS(Ni(R.ii(tclear_all_breakst set_continueRUR.t callLaterRb(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_stop scSstjddS(Ni(tost_exit(R((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytset_quit s(tpdbtPdbRkRgRh(RgRhRk((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytfixPdbs      cCs|d krddlm}ny|drK|d k r|j|qn~|dr|t_|t_tjdkrt j t j dt j t j dnt 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(Rlt set_trace(targs((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyt4scWs tjS(N(RlRq(Rr((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRs5stnodaemonsTWISTD-CRASH.logR#tfileN(RDRUR.R'R)R*tstderrRt platformTypetsignaltSIGUSR2tSIGINTRnRlR&R+t tracebackt print_exctflush(tconfigt oldstdoutt oldstderrRAR.Ru((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytrunReactorWithLoggings*        cCs|rtjdSdSdS(Ns Passphrase: (tgetpassRD(tneeded((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyt getPassphraseDs cCs |rtjd}ndSdS(NsEncryption passphrase: (Rt getPasswordRD(Rt passphrase((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytgetSavePassphraseLstApplicationRunnercBsPeZdZeZeZdZdZdZ dZ dZ dZ 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(R~tprofilerFactoryRAt loggerFactoryRJ(RR~((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRms cCsG|j|j|_|jj|j|j|jjdS(s& Run the application. N(tpreApplicationtcreateOrGetApplicationRRRJRTtpostApplicationRb(R((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyR'ss   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(RR~RA(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( R~t subCommandt loadedPluginst makeServicet subOptionsR t ApplicationttapnametsetServiceParentRtgetApplication(RtplgtserRRR((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRs ( RRR R>RRHRRR'RRRR(((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRTs  cCs/gdddgD] }||r|||f^qd}|didd6j|d|d}}y7tjd|tj|||}tjdWntk r*}d |}t|tr|jdd kr|d 7}nt j dtj tj|tj t jd |d nX|S( NtpythontsourceRuitpickleis Loading %s...sLoaded.sFailed to load application: %sRRsN 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 (RBRRVR tloadApplicationt Exceptiont isinstancetKeyErrorRrR{R|RtdeferrR)texit(R~RttRtfilenametstyleRRR((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 e j 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 messageOutputtwriteRt descriptionR(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|n X||dRFt optParametersRRt CompleteFilest CompleteDirsRRRt getPluginsRRRtopt_bRRRRtproperty(((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyRsL                 cCsY|}y|jWn1tjk rJ}|GHdtjd|fGHn X||dS(Ns%s: %si(RRterrorR)R(trunAppRR~tue((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyR'zs cCsitj|||}tj|j|t|}|rFd}ntj|jd|d|dS(NRR(R RR t IPersistabletsetStyleRRDtsave(tfileinttypeinRtfileoutttypeouttencryptRR((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyt convertStyles   cCswddlm}tj|j|rTtj|}|jdd|jdn|jddtj|j dS(Ni(R.taftertshutdowntbefore( RUR.R tIServicet startServiceR RtaddSystemEventTriggerRt stopService(RRRR.R/((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pytstartApplications ((:R)RiRlRR{RxtoperatorRttwisted.pythonRRRRRRttwisted.python.versionsRttwisted.python.reflectRR ttwisted.python.deprecateR ttwisted.python.logR ttwisted.persistedR ttwisted.applicationR RRURttwistedRRttwisted.application.reactorsRRtobjectRR!R1R:R>RHRnRDRRRRRRRRRR'RR(((s;/usr/lib/python2.7/dist-packages/twisted/application/app.pyts<H. )P .  j  5h