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/service.pyc


Nc	@s\dZddlmZmZmZddlmZddlmZddl	m
Z
ddlmZddl
mZdefd	YZd
efdYZdefd
YZdddYZdefdYZdefdYZdefdYZdddYZdddZddZdd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;eZdZedZedZedZdZRS(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.pytmakeService/s(t__name__t
__module__t__doc__RttapnametdescriptionR	R
(((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRs			tServiceMakercBsTeZdZeeedZdZeeZdZ	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|jjS(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|jjS(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	(
RRR
RRRRR	tpropertyR
(((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR;s
			tIServicecBsDeZdZdZdZdZdZdZdZRS(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<defer.Deferred>}
        @return: a L{Deferred<defer.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startServicescCsdS(s"
        Stop the service.

        @rtype: L{Deferred<defer.Deferred>}
        @return: a L{Deferred<defer.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.pytstopServicescCsdS(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.pytprivilegedStartServices(	RRR
RRRRRR(((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRWs
			
		
tServicecBsieZdZeedZd	Zd	ZdZ	dZ
dZdZdZ
dZdZRS(
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}|jdr(|d=n|S(Ntrunning(t__dict__tcopythas_key(Rtdict((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyt__getstate__s
cCs+|jdk	rtdn||_dS(Ns%cannot change name when parent exists(RtNonetRuntimeErrorR(RR((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRscCsH|jdk	r|jnt||}||_|jj|dS(N(RR'RtIServiceCollectiont
addService(RR((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRs

	cCs|jj|}d|_|S(N(Rt
removeServiceR'(Rtd((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRs	cCsdS(N((R((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRscCs
d|_dS(Ni(R!(R((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRscCs
d|_dS(Ni(R!(R((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRsN(RRR
RRR!R'RRR&RRRRRR(((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR s
						R)cBs2eZdZdZdZdZdZRS(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.pytgetServiceNamedscCsdS(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<defer.Deferred>}
        @return: a L{Deferred<defer.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(RRR
R-R.R*R+(((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR)s
	
		tMultiServicecBs`eZdZeedZdZdZdZdZ	dZ
dZdZ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]}|jqWdS(N(R R(RR/((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRs

cCs,tj|x|D]}|jqWdS(N(R R(RR/((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRs

cCs`tj|g}t|}|jx'|D]}|jtj|jq0Wtj|S(N(R RtlisttreversetappendRt
maybeDeferredtDeferredList(RtlR1R/((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRs


cCs|j|S(N(R2(RR((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR-%scCs
t|jS(N(titerR1(R((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR.(scCs|jdk	rM|jj|jr:td|jn||j|j<n|jj||jr}|j|j	ndS(Ns,cannot have two services with same name '%s'(
RR'R2R$R(R1R5R!RR(RR/((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR*+s	
cCsD|jr|j|j=n|jj||jr<|jSdSdS(N(RR2R1tremoveR!RR'(RR/((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR+7s		
(
RRR
RR)RRRRR-R.R*R+(((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR0s
								tIProcesscBs2eZdZedZedZedZRS(sa
    Process running parameters.

    Represents parameters for how processes should be run.
    sv
        A C{str} giving the name the process should have in ps (or C{None}
        to leave the name alone).
        s{
        An C{int} giving the user id as which the process should run (or
        C{None} to leave the UID alone).
        s|
        An C{int} giving the group id as which the process should run (or
        C{None} to leave the GID alone).
        (RRR
RtprocessNametuidtgid(((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR;Ds		tProcesscBs-eZdZeedZdddZRS(s
    Process running parameters.

    Sets up uid/gid in the constructor, and has a default
    of C{None} as C{processName}.
    cCs||_||_dS(s=
        Set uid and gid.

        @param uid: The user ID as whom to execute the process.  If
            this is C{None}, no attempt will be made to change the UID.

        @param gid: The group ID as whom to execute the process.  If
            this is C{None}, no attempt will be made to change the GID.
        N(R=R>(RR=R>((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyRhs
	N(RRR
RR;R'R<R(((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyR?^s
cCshtj}xBttj||t||fD]}|j|ddq4Wt|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.
    tignoreClassi(	Rt
ComponentizedR0Rt
PersistentR?taddComponentRR(RR=R>trettcomp((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pytApplicationvs
	.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}
    tpythontapplication(RtloadValueFromFiletload(tfilenametkindt
passphraseRH((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pytloadApplications
RFRNN(((R
tzope.interfaceRRRttwisted.python.reflectRttwisted.pythonRttwisted.internetRttwisted.persistedRttwisted.pluginRRtobjectRRR R)R0R;R?R'RFRNt__all__(((s?/usr/lib/python2.7/dist-packages/twisted/application/service.pyt<module>s&"D15C