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

ó
¬nNc	@sCdZddlZddlmZddlmZddlmZddlm	Z	d„Z
dejfd	„ƒYZd
efd„ƒYZ
defd
„ƒYZidd6dd6ZddlZx¿djƒD]±Zx¨djƒD]šZedkredkrqàneƒdeZidd6jeeƒZeeeƒZejeeefied6ed6ƒZeeƒee<qàWqÍWde
fd„ƒYZdefd„ƒYZdefd„ƒYZd ejfd!„ƒYZd"eje fd#„ƒYZ!dd d$d"ggd%jƒD]#ZdjƒD]Zee^q%qZ"dS(&sø
Reactor-based Services

Here are services to run clients, servers and periodic services using
the reactor.

If you want to run a server service, L{StreamServerEndpointService} defines a
service that can wrap an arbitrary L{IStreamServerEndpoint
<twisted.internet.interfaces.IStreamServerEndpoint>}
as an L{IService}. See also L{twisted.application.strports.service} for
constructing one of these directly from a descriptive string.

Additionally, this module (dynamically) defines various Service subclasses that
let you represent clients and servers in a Service hierarchy.  Endpoints APIs
should be preferred for stream server services, but since those APIs do not yet
exist for clients or datagram services, many of these are still useful.

They are as follows::

  TCPServer, TCPClient,
  UNIXServer, UNIXClient,
  SSLServer, SSLClient,
  UDPServer, UDPClient,
  UNIXDatagramServer, UNIXDatagramClient,
  MulticastServer

These classes take arbitrary arguments in their constructors and pass
them straight on to their respective reactor.listenXXX or
reactor.connectXXX calls.

For example, the following service starts a web server on port 8080:
C{TCPServer(8080, server.Site(r))}.  See the documentation for the
reactor.listen/connect* methods for more information.
iÿÿÿÿN(tlog(tservice(ttask(tCancelledErrorcCs(|dkr ddlm}|S|SdS(sR
    @return: the argument, or the global reactor if the argument is C{None}.
    iÿÿÿÿ(treactorN(tNonettwisted.internetR(tmaybeReactorR((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyt_maybeGlobalReactor1st_VolatileDataServicecBseZgZd„ZRS(cCs@tjj|ƒ}x'|jD]}||kr||=qqW|S(N(RtServicet__getstate__tvolatile(tselftdtattr((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR@s
(t__name__t
__module__RR(((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR	<st_AbstractServercBsVeZdZdgZdZdZdZd„Zd„Z	d„Z
d„Zd„ZRS(s
    @cvar volatile: list of attribute to remove from pickling.
    @type volatile: C{list}

    @ivar method: the type of method to call on the reactor, one of B{TCP},
        B{UDP}, B{SSL} or B{UNIX}.
    @type method: C{str}

    @ivar reactor: the current running reactor.
    @type reactor: a provider of C{IReactorTCP}, C{IReactorUDP},
        C{IReactorSSL} or C{IReactorUnix}.

    @ivar _port: instance of port set when the service is started.
    @type _port: a provider of L{twisted.internet.interfaces.IListeningPort}.
    t_portcOs7||_d|kr*|jdƒ|_n||_dS(NR(targstpopRtkwargs(R
RR((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyt__init__`s	cCs#tjj|ƒ|jƒ|_dS(N(RR
tprivilegedStartServicet_getPortR(R
((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyRgscCs5tjj|ƒ|jdkr1|jƒ|_ndS(N(RR
tstartServiceRRR(R
((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyRlscCs<tjj|ƒ|jdk	r8|jjƒ}|`|SdS(N(RR
tstopServiceRRt
stopListening(R
R((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyRrs
cCs/tt|jƒd|jfƒ|j|jŽS(sî
        Wrapper around the appropriate listen method of the reactor.

        @return: the port object returned by the listen method.
        @rtype: an object providing
            L{twisted.internet.interfaces.IListeningPort}.
        slisten%s(tgetattrRRtmethodRR(R
((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR|sN(
RRt__doc__RRRRRRRRRR(((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyRIs					
t_AbstractClientcBsMeZdZdgZdZdZdZd„Zd„Z	d„Z
d„ZRS(s&
    @cvar volatile: list of attribute to remove from pickling.
    @type volatile: C{list}

    @ivar method: the type of method to call on the reactor, one of B{TCP},
        B{UDP}, B{SSL} or B{UNIX}.
    @type method: C{str}

    @ivar reactor: the current running reactor.
    @type reactor: a provider of C{IReactorTCP}, C{IReactorUDP},
        C{IReactorSSL} or C{IReactorUnix}.

    @ivar _connection: instance of connection set when the service is started.
    @type _connection: a provider of L{twisted.internet.interfaces.IConnector}.
    t_connectioncOs7||_d|kr*|jdƒ|_n||_dS(NR(RRRR(R
RR((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyRŸs	cCs#tjj|ƒ|jƒ|_dS(N(RR
Rt_getConnectionR!(R
((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR¦scCs9tjj|ƒ|jdk	r5|jjƒ|`ndS(N(RR
RR!Rt
disconnect(R
((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR«s
cCs/tt|jƒd|jfƒ|j|jŽS(sà
        Wrapper around the appropriate connect method of the reactor.

        @return: the port object returned by the connect method.
        @rtype: an object providing L{twisted.internet.interfaces.IConnector}.
        s	connect%s(RRRRRR(R
((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR"²sN(RRRRRRRR!RRRR"(((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR ‰s				szConnect to %(tran)s

Call reactor.connect%(method)s when the service starts, with the
arguments given to the constructor.
tClientsúServe %(tran)s clients

Call reactor.listen%(method)s when the service starts, with the
arguments given to the constructor. When the service stops,
stop listening. See twisted.internet.interfaces for documentation
on arguments to the reactor method.
tServers'TCP UNIX SSL UDP UNIXDatagram Multicasts
Server Clientt	Multicastt	_AbstracttWithtGenericRRt
GenericServercBseZdZdZd„ZRS(sX
    Serve Generic clients

    Call reactor.listenWith when the service starts, with the arguments given to
    the constructor. When the service stops, stop listening. See
    twisted.internet.interfaces for documentation on arguments to the reactor
    method.

    This service is deprecated (because reactor.listenWith is deprecated).
    R(cOs0tjddtddƒtj|||ŽdS(Ns-GenericServer was deprecated in Twisted 10.1.tcategoryt
stackleveli(twarningstwarntDeprecationWarningRR(R
RR((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyRês
(RRRRR(((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR*Ýs
t
GenericClientcBseZdZdZd„ZRS(sÒ
    Connect to Generic.

    Call reactor.connectWith when the service starts, with the arguments given
    to the constructor.

    This service is deprecated (because reactor.connectWith is deprecated).
    R(cOs0tjddtddƒtj|||ŽdS(Ns-GenericClient was deprecated in Twisted 10.1.R+R,i(R-R.R/R R(R
RR((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyRþs
(RRRRR(((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR0óstTimerServicecBs;eZdZdgZd„Zd„Zd„Zd„ZRS(sÎService to periodically call a function

    Every C{step} seconds call the given function with the given arguments.
    The service starts the calls when it starts, and cancels them
    when it stops.
    t_loopcOs||_|||f|_dS(N(tsteptcall(R
R3tcallableRR((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyRs	cCsctjj|ƒ|j\}}}tj|||Ž|_|jj|jdt	ƒj
|jƒdS(Ntnow(RR
RR4RtLoopingCallR2tstartR3tTruet
addErrbackt_failed(R
R5RR((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyRscCst|j_tj|ƒdS(N(tFalseR2trunningRterr(R
twhy((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR; scCs,|jjr|jjƒntjj|ƒS(N(R2R=tstopRR
R(R
((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR's(RRRRRRR;R(((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR1s			
	tCooperatorServicecBs2eZdZd„Zd„Zd„Zd„ZRS(sb
    Simple L{service.IService} which starts and stops a L{twisted.internet.task.Cooperator}.
    cCstjdtƒ|_dS(Ntstarted(Rt
CooperatorR<tcoop(R
((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR2scCs|jj|ƒS(N(RDt	coiterate(R
titerator((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyRE6scCs|jjƒdS(N(RDR8(R
((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR:scCs|jjƒdS(N(RDR@(R
((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR>s(RRRRRERR(((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyRA.s
			tStreamServerEndpointServicecBs8eZdZdZd„Zd„Zd„Zd„ZRS(sP
    A L{StreamServerEndpointService} is an L{IService} which runs a server on a
    listening port described by an L{IStreamServerEndpoint
    <twisted.internet.interfaces.IStreamServerEndpoint>}.

    @ivar factory: A server factory which will be used to listen on the
        endpoint.

    @ivar endpoint: An L{IStreamServerEndpoint
        <twisted.internet.interfaces.IStreamServerEndpoint>} provider
        which will be used to listen when the service starts.

    @ivar _waitingForPort: a Deferred, if C{listen} has yet been invoked on the
        endpoint, otherwise None.

    @ivar _raiseSynchronously: Defines error-handling behavior for the case
        where C{listen(...)} raises an exception before C{startService} or
        C{privilegedStartService} have completed.

    @type _raiseSynchronously: C{bool}

    @since: 10.2
    cCs||_||_d|_dS(N(tendpointtfactoryRt_waitingForPort(R
RHRI((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR^s		csktjjˆƒˆjjˆjƒˆ_g‰‡‡fd†}ˆjj|ƒˆrgˆdjƒndS(s2
        Start listening on the endpoint.
        cs<ˆjrˆj|ƒn|jtƒs8tj|ƒndS(N(t_raiseSynchronouslytappendtcheckRRR>(R>(R
t	raisedNow(s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pythandleItks	iN(	RR
RRHtlistenRIRJR:traiseException(R
RO((R
RNs@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyRdscCs0tjj|ƒ|jdkr,|jƒndS(su
        Start listening on the endpoint, unless L{privilegedStartService} got
        around to it already.
        N(RR
RRJRR(R
((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyRuscsHˆjjƒd„}ˆjj|ƒ}‡fd†}|j|ƒ|S(s
        Stop listening on the port if it is already listening, otherwise,
        cancel the attempt to listen.

        @return: a L{Deferred<twisted.internet.defer.Deferred>} which fires
            with C{None} when the port has stopped listening.
        cSs|dk	r|jƒSdS(N(RR(tport((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pytstopItˆscs
tˆ_|S(N(R<R=(tpassthrough(R
(s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyR@Œs	(RJtcanceltaddCallbacktaddBoth(R
RSRR@((R
s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyRs
	
N(	RRRRRKRRRR(((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyRGCs			
tMulticastServers%Generic TCP UNIX SSL UDP UNIXDatagram(#RR-ttwisted.pythonRttwisted.applicationRRRttwisted.internet.deferRRR
R	RR t_docttypestsplitttrantsidetglobalstbasetgetRtvarstdoct	ClassTypetklassR*R0R1RAtobjectRGt__all__(((s@/usr/lib/python2.7/dist-packages/twisted/application/internet.pyt<module>&sB	
@5
'Q