ó o©ŠOc @s\dZddlmZmZmZddlmZddlmZddl m Z ddl m Z ddl mZdefd „ƒYZd efd „ƒYZd efd „ƒYZddd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZddd„ƒYZddd„Zdd„Zdd dddddddg ZdS(sa Service architecture for Twisted. Services are arranged in a hierarchy. At the leafs of the hierarchy, the services which actually interact with the outside world are started. Services can be named or anonymous -- usually, they will be named if there is need to access them through the hierarchy (from a parent or a sibling). Maintainer: Moshe Zadka i’’’’(t implementst Interfacet Attribute(tnamedAny(t components(tdefer(tsob(tIPlugint IServiceMakercBs;eZdZedƒZedƒZedƒZd„ZRS(sź An object which can be used to construct services in a flexible way. This interface should most often be implemented along with L{twisted.plugin.IPlugin}, and will most often be used by the 'twistd' command. sA short string naming this Twisted plugin, for example 'web' or 'pencil'. This name will be used as the subcommand of 'twistd'.sLA brief summary of the features provided by this Twisted application plugin.scA C{twisted.python.usage.Options} subclass defining the configuration options for this application.cCsdS(s Create and return an object providing L{twisted.application.service.IService}. @param options: A mapping (typically a C{dict} or L{twisted.python.usage.Options} instance) of configuration options to desired configuration values. N((toptions((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyt makeService/s(t__name__t __module__t__doc__Rttapnamet descriptionR R (((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRs   t ServiceMakercBsTeZdZeeeƒd„Zd„ZeeƒŒZd„Z ee ƒŒZ RS(sO Utility class to simplify the definition of L{IServiceMaker} plugins. cCs(||_||_||_||_dS(N(tnametmoduleRR(tselfRRRR((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyt__init__As   cCsd„}|fS(NcSst|jƒjS(N(RRtOptions(R((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pytgetIs((R((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR Hs cCsd„}|fS(NcSst|jƒjS(N(RRR (R((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRPs((R((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR Os ( R R R RRRRR tpropertyR (((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR;s    tIServicecBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(s A service. Run start-up and shut-down code at the appropriate times. @type name: C{string} @ivar name: The name of the service (or None) @type running: C{boolean} @ivar running: Whether the service is running. cCsdS(s“ Set the name of the service. @type name: C{str} @raise RuntimeError: Raised if the service already has a parent. N((R((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pytsetNamecscCsdS(sx Set the parent of the service. This method is responsible for setting the C{parent} attribute on this service (the child service). @type parent: L{IServiceCollection} @raise RuntimeError: Raised if the service already has a parent or if the service has a name and the parent already has a child by that name. N((tparent((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pytsetServiceParentkscCsdS(s× Use this API to remove an L{IService} from an L{IServiceCollection}. This method is used symmetrically with L{setServiceParent} in that it sets the C{parent} attribute on the child. @rtype: L{Deferred} @return: a L{Deferred} which is triggered when the service has finished shutting down. If shutting down is immediate, a value can be returned (usually, C{None}). N((((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pytdisownServiceParentvscCsdS(s$ Start the service. N((((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyt startServiceƒscCsdS(s" Stop the service. @rtype: L{Deferred} @return: a L{Deferred} which is triggered when the service has finished shutting down. If shutting down is immediate, a value can be returned (usually, C{None}). N((((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyt stopServiceˆscCsdS(s² Do preparation work for starting the service. Here things which should be done before changing directory, root or shedding privileges are done. N((((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pytprivilegedStartService’s( R R R RRRRRR(((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRWs    tServicecBsieZdZeeƒdZd Zd Zd„Z d„Z d„Z d„Z d„Z d„Zd„ZRS( sŻ Base class for services. Most services should inherit from this class. It handles the book-keeping reponsibilities of starting and stopping, as well as not serializing this book-keeping information. icCs)|jjƒ}d|kr%|d=n|S(Ntrunning(t__dict__tcopy(Rtdict((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyt __getstate__Ŗs  cCs+|jdk rtdƒ‚n||_dS(Ns%cannot change name when parent exists(RtNonet RuntimeErrorR(RR((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR°scCsH|jdk r|jƒnt||ƒ}||_|jj|ƒdS(N(RR&RtIServiceCollectiont addService(RR((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRµs   cCs|jj|ƒ}d|_|S(N(Rt removeServiceR&(Rtd((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR¼s cCsdS(N((R((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRĮscCs d|_dS(Ni(R!(R((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRÄscCs d|_dS(Ni(R!(R((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRĒsN(R R R RRR!R&RRR%RRRRRR(((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR ›s       R(cBs2eZdZd„Zd„Zd„Zd„ZRS(sÓ Collection of services. Contain several services, and manage their start-up/shut-down. Services can be accessed by name if they have a name, and it is always possible to iterate over them. cCsdS(sĻ Get the child service with a given name. @type name: C{str} @rtype: L{IService} @raise KeyError: Raised if the service has no child with the given name. N((R((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pytgetServiceNamedÕscCsdS(s: Get an iterator over all child services. N((((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyt__iter__ßscCsdS(s Add a child service. Only implementations of L{IService.setServiceParent} should use this method. @type service: L{IService} @raise RuntimeError: Raised if the service has a child with the given name. N((tservice((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR)äscCsdS(só Remove a child service. Only implementations of L{IService.disownServiceParent} should use this method. @type service: L{IService} @raise ValueError: Raised if the given service is not a child. @rtype: L{Deferred} @return: a L{Deferred} which is triggered when the service has finished shutting down. If shutting down is immediate, a value can be returned (usually, C{None}). N((R.((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR*šs(R R R R,R-R)R*(((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR(Ģs   t MultiServicecBs`eZdZeeƒd„Zd„Zd„Zd„Zd„Z d„Z d„Z d„Z RS( s Straightforward Service Container. Hold a collection of services, and manage them in a simplistic way. No service will wait for another, but this object itself will not finish shutting down until all of its child services will finish. cCsg|_i|_d|_dS(N(tservicest namedServicesR&R(R((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR s  cCs,tj|ƒx|D]}|jƒqWdS(N(R R(RR.((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRs  cCs,tj|ƒx|D]}|jƒqWdS(N(R R(RR.((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRs  cCs`tj|ƒg}t|ƒ}|jƒx'|D]}|jtj|jƒƒq0Wtj|ƒS(N(R RtlisttreversetappendRt maybeDeferredt DeferredList(RtlR0R.((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRs    cCs |j|S(N(R1(RR((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR,%scCs t|jƒS(N(titerR0(R((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR-(scCs~|jdk rJ|j|jkr7td|jƒ‚n||j|j^s cCshtjƒ}xBtƒtj||ƒt||ƒfD]}|j|ddƒq4Wt|ƒj|ƒ|S(s Return a compound class. Return an object supporting the L{IService}, L{IServiceCollection}, L{IProcess} and L{sob.IPersistable} interfaces, with the given parameters. Always access the return value by explicit casting to one of the interfaces. t ignoreClassi( Rt ComponentizedR/Rt PersistentR>t addComponentRR(RR<R=trettcomp((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyt Applicationvs .cCs=|dkr$tj|d|ƒ}ntj|||ƒ}|S(s` Load Application from a given file. The serialization format it was saved in should be given as C{kind}, and is one of C{pickle}, C{source}, C{xml} or C{python}. If C{passphrase} is given, the application was encrypted with the given passphrase. @type filename: C{str} @type kind: C{str} @type passphrase: C{str} tpythont application(RtloadValueFromFiletload(tfilenametkindt passphraseRG((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pytloadApplication‡s RERMN(((R tzope.interfaceRRRttwisted.python.reflectRttwisted.pythonRttwisted.internetRttwisted.persistedRttwisted.pluginRRtobjectRRR R(R/R:R>R&RERMt__all__(((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyts&"D15C