Your IP : 172.28.240.42


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


6Mc@sBdZddlZddlmZmZddlZddlZddlmZm	Z	m
Z
ddlZddlm
Z
ddlmZddlmZmZmZddlmZmZdd	lmZmZdd
lmZmZmZmZmZmZddlm Z m!Z!m"Z"ddl#m$Z%m&Z&dd
l'm(Z(m)Z)ddl*m+Z+ddlm,Z,de+j-fdYZ.de/fdYZ0dfdYZ1de/fdYZ2de/fdYZ3e&j4ree3ende+j-fdYZ5dej6fdYZ7de/fdYZ8gZ9dS( s8
Very basic functionality for a Reactor implementation.
iN(t
implementstclassImplements(theappushtheappoptheapify(tset(t
unsignedID(tIReactorCoretIReactorTimetIReactorThreads(tIResolverSimpletIReactorPluggableResolver(t
IConnectortIDelayedCall(tfdesctmainterrortabstracttdefertthreads(tlogtfailuretreflect(tsecondstplatform(tDeferredtDeferredList(tstyles(t
threadabletDelayedCallcBs{eZeeeZd
ZedZ	dZ
dZdZdZ
dZdZdZdZd	ZRS(cCs||||f\|_|_|_|_||_||_||_d|_|_d|_	|j
r}tjd |_
ndS(sR
        @param time: Seconds from the epoch at which to call C{func}.
        @param func: The callable to call.
        @param args: The positional arguments to pass to the callable.
        @param kw: The keyword arguments to pass to the callable.
        @param cancel: A callable which will be called with this
            DelayedCall before cancellation.
        @param reset: A callable which will be called with this
            DelayedCall after changing this DelayedCall's scheduled
            execution time. The callable should adjust any necessary
            scheduling details to ensure this DelayedCall is invoked
            at the new appropriate time.
        @param seconds: If provided, a no-argument callable which will be
            used to determine the current time any time that information is
            needed.
        iiN(ttimetfunctargstkwtresettert	cancellerRt	cancelledtcalledtdelayed_timetdebugt	tracebacktformat_stacktcreator(tselfRRR R!tcanceltresetR((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt__init__*s*					cCs|j|jS(sReturn the time at which this call will fire

        @rtype: C{float}
        @return: The number of seconds after the epoch at which this call is
        scheduled to be made.
        (RR&(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytgetTimeEscCsq|jrtjnX|jr*tjnC|j|d|_|jr[t||_n|`	|`
|`dS(sUnschedule this call

        @raise AlreadyCancelled: Raised if this call has already been
        unscheduled.

        @raise AlreadyCalled: Raised if this call has already been made.
        iN(R$RtAlreadyCancelledR%t
AlreadyCalledR#R'tstrt_strRR R!(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyR,Ns		
		cCs|jrtjnf|jr*tjnQ|j|}||jkrkd|_||_|j|n||j|_dS(ssReschedule this call for a different time

        @type secondsFromNow: C{float}
        @param secondsFromNow: The number of seconds from the time of the
        C{reset} call at which this call will be scheduled.

        @raise AlreadyCancelled: Raised if this call has been cancelled.
        @raise AlreadyCalled: Raised if this call has already been made.
        iN(	R$RR0R%R1RRR&R"(R+tsecondsFromNowtnewTime((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyR-as
				cCsf|jrtjnM|jr*tjn8|j|7_|jdkrb|j|j|ndS(siReschedule this call for a later time

        @type secondsLater: C{float}
        @param secondsLater: The number of seconds after the originally
        scheduled time for which to reschedule this call.

        @raise AlreadyCancelled: Raised if this call has been cancelled.
        @raise AlreadyCalled: Raised if this call has already been made.
        iN(R$RR0R%R1R&tactivate_delayR"(R+tsecondsLater((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytdelayxs
		
cCs|j|j7_d|_dS(Ni(RR&(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyR6scCs|jp|jS(sDetermine whether this call is still pending

        @rtype: C{bool}
        @return: True if this call has not yet been made or cancelled,
        False otherwise.
        (R$R%(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytactivescCs|j|jkS(s
        Implement C{<=} operator between two L{DelayedCall} instances.

        Comparison is based on the C{time} attribute (unadjusted by the
        delayed time).
        (R(R+tother((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt__le__scCs|j|jkS(s
        Implement C{<} operator between two L{DelayedCall} instances.

        Comparison is based on the C{time} attribute (unadjusted by the
        delayed time).
        (R(R+R:((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt__lt__scCs|jdk	r|jSt|drt|jdrr|jj}t|jdr|jjjd|}qqtj|j}nd}|j	}dt
||j||j|j
fg}|dk	r|jd|df|jrA|jdjg|jD]}tj|^q|jrA|jdqAn|jr|jdjg|jjD]%\}}d	|tj|f^qfn|jd
n|jr|jddj|jn|jd
dj|S(NRt	func_nametim_classt.s.<DelayedCall 0x%x [%ss] called=%s cancelled=%st t(s, s%s=%st)s

traceback at creation: 

%ss    t>t(R3tNonethasattrRR=R>t__name__Rt	safe_reprRRRR%R$textendR tappendtjoinR!t	iteritemsR'R*(R+RtnowtLtetktv((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt__str__s4	5		N	 
N(RGt
__module__RR
tFalseR'RER3truntimeSecondsR.R/R,R-R8R6R9R;R<RR(((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyR"s
							
	
	
tThreadedResolvercBsHeZdZeedZdZdZdZd
d	Z	RS(s
    L{ThreadedResolver} uses a reactor, a threadpool, and
    L{socket.gethostbyname} to perform name lookups without blocking the
    reactor thread.  It also supports timeouts indepedently from whatever
    timeout logic L{socket.gethostbyname} might have.

    @ivar reactor: The reactor the threadpool of which will be used to call
        L{socket.gethostbyname} and the I/O thread of which the result will be
        delivered.
    cCs||_i|_dS(N(treactort_runningQueries(R+RW((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyR.s	cCs&tjd||f}tj|S(Nsaddress %r not found: %s(RtDNSLookupErrorRtFailure(R+tnameterr((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt_failscCs:|j|\}}|j|=|j|j|ddS(Ns
timeout error(RXterrbackR](R+R[tlookupDeferredtuserDeferredt
cancelCall((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt_cleanups
cCsy|j|\}}Wntk
r*nVX|j|=|jt|tjrs|j|j||jn
|j	|dS(N(
RXtKeyErrorR,t
isinstanceRRZR^R]tgetErrorMessagetcallback(R+tresultR[R_R`Ra((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt
_checkTimeouts


"iiii-cCs|rt|}nd}tj}tj|j|jjtj|}|jj	||j
||}||f|j|<|j|j
|||S(s1
        See L{twisted.internet.interfaces.IResolverSimple.getHostByName}.

        Note that the elements of C{timeout} are summed and the result is used
        as a timeout for the lookup.  Any intermediate timeout or retry logic
        is left up to the platform via L{socket.gethostbyname}.
        i<(tsumRRRtdeferToThreadPoolRWt
getThreadPooltsockett
gethostbynamet	callLaterRbRXtaddBothRh(R+R[ttimeoutttimeoutDelayR`R_Ra((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt
getHostByNames	(iiii-(
RGRSt__doc__RR
R.R]RbRhRr(((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRVs

				tBlockingResolvercBseZeeddZRS(iiii-cCsaytj|}Wn:tjk
rOd|f}tj|}tj|SXtj|SdS(Nsaddress %r not found(RlRmRRYRtfailtsucceed(R+R[RptaddresstmsgR\((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRrs
(iiii-(RGRSRR
Rr(((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRts
t_ThreePhaseEventcBsMeZdZdZdZdZdZdZdZdZ	RS(s
    Collection of callables (with arguments) which can be invoked as a group in
    a particular order.

    This provides the underlying implementation for the reactor's system event
    triggers.  An instance of this class tracks triggers for all phases of a
    single type of event.

    @ivar before: A list of the before-phase triggers containing three-tuples
        of a callable, a tuple of positional arguments, and a dict of keyword
        arguments

    @ivar finishedBefore: A list of the before-phase triggers which have
        already been executed.  This is only populated in the C{'BEFORE'} state.

    @ivar during: A list of the during-phase triggers containing three-tuples
        of a callable, a tuple of positional arguments, and a dict of keyword
        arguments

    @ivar after: A list of the after-phase triggers containing three-tuples
        of a callable, a tuple of positional arguments, and a dict of keyword
        arguments

    @ivar state: A string indicating what is currently going on with this
        object.  One of C{'BASE'} (for when nothing in particular is happening;
        this is the initial value), C{'BEFORE'} (when the before-phase triggers
        are in the process of being executed).
    cCs(g|_g|_g|_d|_dS(NtBASE(tbeforetduringtaftertstate(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyR.@s			cOsJ|dkrtdnt||j|||f||||fS(s
        Add a trigger to the indicate phase.

        @param phase: One of C{'before'}, C{'during'}, or C{'after'}.

        @param callable: An object to be called when this event is triggered.
        @param *args: Positional arguments to pass to C{callable}.
        @param **kwargs: Keyword arguments to pass to C{callable}.

        @return: An opaque handle which may be passed to L{removeTrigger} to
            reverse the effects of calling this method.
        R{R|R}s
invalid phase(sbeforesduringsafter(RctgetattrRJ(R+tphasetcallableR tkwargs((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt
addTriggerGs
cCst|d|j|S(sS
        Remove a previously added trigger callable.

        @param handle: An object previously returned by L{addTrigger}.  The
            trigger added by that call will be removed.

        @raise ValueError: If the trigger associated with C{handle} has already
            been removed or if C{handle} is not a valid handle.
        tremoveTrigger_(RR~(R+thandle((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt
removeTriggerZs
cCszy|\}}}}Wn#ttfk
r;tdn;X|dkrWtdnt||j|||fdS(sN
        Just try to remove the trigger.

        @see: removeTrigger
        sinvalid trigger handleR{R|R}s
invalid phaseN(sbeforesduringsafter(t	TypeErrort
ValueErrorRcRtremove(R+RRRR R((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytremoveTrigger_BASEgscCsp|\}}}}|dkr+|j|S|||f|jkr_tjddtddn
|j|dS(s
        Remove the trigger if it has yet to be executed, otherwise emit a
        warning that in the future an exception will be raised when removing an
        already-executed trigger.

        @see: removeTrigger
        R{sdRemoving already-fired system event triggers will raise an exception in a future version of Twisted.tcategoryt
stackleveliN(RtfinishedBeforetwarningstwarntDeprecationWarning(R+RRRR R((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytremoveTrigger_BEFOREws

cCsd|_g|_g}x|jr|jjd\}}}|jj|||fy|||}WntjqXt|tr|j|qqWt	|j
|jdS(s8
        Call the triggers added to this event.
        tBEFOREiN(R~RR{tpopRJRR\RdRRtaddCallbackt_continueFiring(R+t
beforeResultsRR RRg((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt	fireEvents		cCs}d|_g|_xd|j|jfD]P}xG|rt|jd\}}}y|||Wq.tjq.Xq.Wq%WdS(sJ
        Call the during and after phase triggers for this event.
        RziN(R~RR|R}RRR\(R+tignoredRRR R((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRs			(
RGRSRsR.RRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRy#s			
			tReactorBasecBseZdZeeeeeZeZ	e
Ze
Ze
ZdZdZd2ZdZdZdZdZdZdZd	Zd
ZdZdZd
Zd3dZdZdZdZ dZ!dZ"dZ#ddZ$dZ%dZ&dZ'dZ(dZ)d Z*e+e,Z-d!Z.d"Z/d#Z0d$Z1d%Z2d&Z3d'Z4d(Z5e6j7rd2Z8d2Z9d2Z:d)Z;d*Z<d+Z=d,Z>d-Z?d.Z@d/ZAd0ZBn	d1Z<RS(4s
    Default base class for Reactors.

    @type _stopped: C{bool}
    @ivar _stopped: A flag which is true between paired calls to C{reactor.run}
        and C{reactor.stop}.  This should be replaced with an explicit state
        machine.

    @type _justStopped: C{bool}
    @ivar _justStopped: A flag which is true between the time C{reactor.stop}
        is called and the time the shutdown system event is fired.  This is
        used to determine whether that event should be fired after each
        iteration through the mainloop.  This should be replaced with an
        explicit state machine.

    @type _started: C{bool}
    @ivar _started: A flag which is true from the time C{reactor.run} is called
        until the time C{reactor.run} returns.  This is used to prevent calls
        to C{reactor.run} on a running reactor.  This should be replaced with
        an explicit state machine.

    @ivar running: See L{IReactorCore.running}

    @ivar _registerAsIOThread: A flag controlling whether the reactor will
        register the thread it is running in as the I/O thread when it starts.
        If C{True}, registration will be done, otherwise it will not be.
    stwisted.internet.reactorcCsg|_i|_g|_g|_d|_t|_t|_t|_t|_	t
|_d|_
|jdd|j|jdd|j|jdd|jtjr|jn|jdS(NiR|tstartuptshutdown(tthreadCallQueuet_eventTriggerst_pendingTimedCallst_newTimedCallst_cancellationsRTtrunningt_startedt_justStoppedt_startedBeforeRt_internalReadersREtwakertaddSystemEventTriggert_reallyStartRunningtcrasht
disconnectAllRtsupportsThreadst_initThreadstinstallWaker(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyR.s$										
cCs ttj|jddS(Ns did not implement installWaker(tNotImplementedErrorRtqualt	__class__(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRscCs+tj|st|j}||_|S(N(R
t
providedBytAssertionErrortresolver(R+RtoldResolver((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytinstallResolvers		cCs|jr|jjndS(s)
        Wake up the event loop.
        N(RtwakeUp(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRs	cCs ttj|jddS(sV
        Do one iteration over the readers and writers which have been added.
        s did not implement doIterationN(RRRR(R+R8((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytdoIterationscCs ttj|jddS(Ns did not implement addReader(RRRR(R+treader((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt	addReaderscCs ttj|jddS(Ns did not implement addWriter(RRRR(R+twriter((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt	addWriterscCs ttj|jddS(Ns did not implement removeReader(RRRR(R+R((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytremoveReaderscCs ttj|jddS(Ns did not implement removeWriter(RRRR(R+R((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytremoveWriterscCs ttj|jddS(Ns did not implement removeAll(RRRR(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt	removeAllscCs ttj|jddS(Ns did not implement getReaders(RRRR(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt
getReaders$scCs ttj|jddS(Ns did not implement getWriters(RRRR(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt
getWriters)siiii-cCsB|stjdStj|r/tj|S|jj||S(s8Return a Deferred that will resolve a hostname.
        s0.0.0.0(RRvRtisIPAddressRRr(R+R[Rp((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytresolve.s


cCs:|jrtjdnt|_t|_t|_dS(sD
        See twisted.internet.interfaces.IReactorCore.stop.
        s&Can't stop reactor that isn't running.N(t_stoppedRtReactorNotRunningtTrueRR(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytstop;s			cCs,t|_t|_|jdd|jdS(s
        See twisted.internet.interfaces.IReactorCore.crash.

        Reset reactor state tracking attributes and re-initialize certain
        state-transition helpers which were set up in C{__init__} but later
        destroyed (through use).
        R|RN(RTRRRR(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRGs		cGs!tjd|j|jdS(s#Handle a SIGINT interrupt.
        sReceived SIGINT, shutting down.N(RRxtcallFromThreadR(R+R ((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytsigIntTs
cGs!tjd|j|jdS(s%Handle a SIGBREAK interrupt.
        s!Received SIGBREAK, shutting down.N(RRxRR(R+R ((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytsigBreakZs
cGs!tjd|j|jdS(s$Handle a SIGTERM interrupt.
        s Received SIGTERM, shutting down.N(RRxRR(R+R ((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytsigTerm`s
cCsC|j}x0|D](}tj||jtjtjqWdS(s;Disconnect every reader, and writer in the system.
        N(RRtcallWithLoggertconnectionLostRRZRtCONNECTION_LOST(R+tselectablesR((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRfs

	icCs|j|j|dS(s>See twisted.internet.interfaces.IReactorCore.iterate.
        N(trunUntilCurrentR(R+R8((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytiterateps
cCs/|jj|}|dk	r+|jndS(sFSee twisted.internet.interfaces.IReactorCore.fireSystemEvent.
        N(RtgetRER(R+t	eventTypetevent((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytfireSystemEventwscOsat|std|||jkr>t|j|<n||j|j||||fS(sLSee twisted.internet.interfaces.IReactorCore.addSystemEventTrigger.
        s%s is not callable(RRRRyR(R+t_phaset
_eventTypet_fR R!((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRs
cCs$|\}}|j|j|dS(sOSee twisted.internet.interfaces.IReactorCore.removeSystemEventTrigger.
        N(RR(R+t	triggerIDRR((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytremoveSystemEventTriggerscOs6|jr|||n|jdd|||SdS(sFSee twisted.internet.interfaces.IReactorCore.callWhenRunning.
        R}RN(RR(R+t	_callableR R!((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytcallWhenRunnings	cCsi|jrtjn|jr0tjnt|_t|_|jrXt	j
n|jddS(s
        Method called when reactor starts: do some initialization and fire
        startup events.

        Don't call this directly, call reactor.run() instead: it should take
        care of calling this.

        This method is somewhat misnamed.  The reactor will not necessarily be
        in the running state by the time this method returns.  The only
        guarantee is that it will be on its way to the running state.
        RN(RRtReactorAlreadyRunningRtReactorNotRestartableRRTRt_registerAsIOThreadRtregisterAsIOThreadR(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytstartRunnings					
cCs
t|_dS(s
        Method called to transition to the running state.  This should happen
        in the I{during startup} event trigger phase.
        N(RR(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRsc
Ost|std|tj|ko6dknsNtd|ft|j|||||j|jd|j}|jj	||S(s@See twisted.internet.interfaces.IReactorTime.callLater.
        s%s is not callableis,%s is not greater than or equal to 0 secondsR(
RRtsystmaxintRRt_cancelCallLatert_moveCallLaterSoonerRRJ(R+t_secondsRR R!ttple((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRns"	cCs|j}yp|j|}||}xF|dkrm|dd}|||krVPn||||<|}q(W|||<Wntk
rnXdS(Niii(RtindexR(R+Rtheaptpostelttparent((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRs	


cCs|jd7_dS(Ni(R(R+R((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRscCs*g|j|jD]}|js|^qS(sReturn all the outstanding delayed calls in the system.
        They are returned in no particular order.
        This method is not efficient -- it is really only meant for
        test cases.(RRR$(R+tx((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytgetDelayedCallsscCsVxF|jD];}|jr+|jd8_q
|jt|j|q
Wg|_dS(Ni(RR$RR6RR(R+tcall((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt_insertNewDelayedCallss	
cCs8|j|jsdStd|jdj|jS(Ni(RRREtmaxRR(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRps
	c
Csm|jrd}t|j}xY|jD]N\}}}y|||WntjnX|d7}||kr(Pq(q(W|j|4|jr|jqn|j|j}x%|jr|jdj|krt	|j}|j
r|jd8_qn|jdkr1|j
t|j|qny#d|_|j|j|jWqtjt|drd}|dd7}|d7}|dj|jjjdd	7}|d7}tj|qqXqW|jd
krG|jt|jd?krGd|_g|jD]}	|	j
s|	^q|_t|jn|jrit|_|jdndS(
s%Run all pending timed calls.
        iiR*s
s# C: previous exception occurred in sa DelayedCall created here:
s C:RDs
 C:i2RN(RtlenRR\RRRRRRR$RR&R6RR%RR R!tdeferrRFRKR*trstriptreplaceRxRRRTR(
R+tcountttotaltftaR!RMRROR((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRs^	

	
"	
	

(
			c	s$tjfd}t|ttfs?tdng}xB|D]:}||}|dkrytdqL|j|qLWd}|dk	ri}xu|jD]d\}}||}|dkrtdn||}|dkr	tdn|||<qWn||fS(s
        Check for valid arguments and environment to spawnProcess.

        @return: A two element tuple giving values to use when creating the
        process.  The first element of the tuple is a C{list} of C{str}
        giving the values for argv of the child process.  The second element
        of the tuple is either C{None} if C{env} was C{None} or a C{dict}
        mapping C{str} environment keys to C{str} environment values.
        csvt|trSy|j}Wntk
r6dSXtjddtddnt|trrd|krr|SdS(sS
            Return either a str or None.  If the given value is not
            allowable for some reason, None is returned.  Otherwise, a
            possibly different object which should be used in place of arg
            is returned.  This forces unicode encoding to happen now, rather
            than implicitly later.
            sgArgument strings and environment keys/values passed to reactor.spawnProcess should be str, not unicode.RRitN(	RdtunicodetencodetUnicodeEncodeErrorRERRRR2(targ(tdefaultEncoding(s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt
argCheckerXs

s!Arguments must be a tuple or lists$Arguments contain a non-string values%Environment contains a non-string keys'Environment contains a non-string valueN(	RtgetdefaultencodingRdttupletlistRRERJRL(	R+R tenvRt
outputArgsRt	outputEnvtkeytval((Rs9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt_checkProcessArgs:s,
cCst|_t||_dS(N(RtusingThreadsRVR(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRs	cOsFt|std|f|jj|||f|jdS(s\
            See L{twisted.internet.interfaces.IReactorThreads.callFromThread}.
            s%s is not callableN(RRRRJR(R+RR R!((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRscCs_ddlm}|jddd|_|j|jj|_|jdd|j|_dS(	sO
            Create the threadpool accessible with callFromThread.
            i(t
threadpoolii
stwisted.internet.reactorR|RN(	ttwisted.pythonR
t
ThreadPoolRtstartt_threadpoolStartupIDRt_stopThreadPooltthreadpoolShutdownID(R+R
((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt_initThreadPoolscCsdS(N((R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt_uninstallHandlerscCs}|j|jg}x<td|D]+}y|j|Wq"tk
rLq"Xq"Wd|_d|_|jjd|_dS(s4
            Stop the reactor threadpool.  This method is only valid if there
            is currently a threadpool (created by L{_initThreadPool}).  It
            is not intended to be called directly; instead, it will be
            called by a shutdown trigger created in L{_initThreadPool}.
            N(RRtfilterRERRR
R(R+ttriggersttrigger((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRs
		
cCs#|jdkr|jn|jS(s[
            See L{twisted.internet.interfaces.IReactorThreads.getThreadPool}.
            N(R
RER(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRks
cOs|jj|||dS(sZ
            See L{twisted.internet.interfaces.IReactorThreads.callInThread}.
            N(RktcallInThread(R+RR R((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRscCs|jjd|dS(sc
            See L{twisted.internet.interfaces.IReactorThreads.suggestThreadPoolSize}.
            t
maxthreadsN(RktadjustPoolsize(R+tsize((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytsuggestThreadPoolSizescOs<t|std|f|jj|||fdS(Ns%s is not callable(RRRRJ(R+RR R!((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRsN(iiii-(CRGRSRsRRRRRRRRTt	installedR	RtRR.REt_lockRRRRRRRRRRRRRRRRRRRRRRRRRtstaticmethodRURRnRRRRRpRRRRR
RRRRRRRRkRR(((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRsr														
		
				
		
							
						
	@	N								t
BaseConnectorcBsueZdZeedZdZdZdZ	dZ
dZdZdZ
dZd	Zd
ZRS(sdBasic implementation of connector.

    State can be: "connecting", "connected", "disconnected"
    icCs(d|_||_||_||_dS(Ntdisconnected(R~RWtfactoryRp(R+R RpRW((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyR.s			cCs?|jdkr|jn|jdkr;|jjndS(s!Disconnect whatever our state is.t
connectingt	connectedN(R~tstopConnectingt	transporttloseConnection(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt
disconnects
cCs|jdkrtdnd|_|jsF|jjd|_n|j|_}|jdk	r|j	j
|j|jtj
|_n|jj|dS(s"Start connection to remote server.Rscan't connect in this stateR!iN(R~tRuntimeErrortfactoryStartedR tdoStartt_makeTransportR$RpRERWRntfailIfNotConnectedRtTimeoutErrort	timeoutIDtstartedConnecting(R+R$((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytconnects		
*cCsG|jdkrtjdnd|_|jjtj|`dS(sStop attempting to connect.R!swe're not trying to connectRN(R~RtNotConnectingErrorR$R+t	UserError(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyR#s
	cCsA|jdk	r=y|jjWntk
r3nX|`ndS(N(R-RER,R(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt
cancelTimeouts
cCs#d|_|j|jj|S(NR"(R~R2R t
buildProtocol(R+taddr((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyR3s	
cCs[|jd|_d|_|jj|||jdkrW|jjd|_ndS(NRi(R2RER$R~R tclientConnectionFailedtdoStopR((R+treason((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytconnectionFaileds
		
cCsHd|_|jj|||jdkrD|jjd|_ndS(NRi(R~R tclientConnectionLostR6R((R+R7((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyR%s
	
cCs ttj|jddS(Ns! did not implement getDestination(RRRR(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytgetDestination-sN(RGRSRsRRRER-R(R.R&R/R#R2R3R8RR:(((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRs
								
	tBasePortcBs,eZdZdZdZdZdZRS(siBasic implementation of a ListeningPort.

    Note: This does not actually implement IListeningPort.
    cCs<tj|j|j}|jdtj|j|S(Ni(Rlt
addressFamilyt
socketTypetsetblockingRt_setCloseOnExectfileno(R+ts((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytcreateInternetSocket=s
cCstdtj|jdS(sRaises a RuntimeErrorsdoWrite called on a %sN(R'RRR(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytdoWriteDsN(RGRSRsRER<R=RBRC(((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyR;4s
	t_SignalReactorMixincBsGeZdZeZdZedZdZedZ	dZ
RS(sK
    Private mixin to manage signals: it installs signal handlers at start time,
    and define run method.

    It can only be used mixed in with L{ReactorBase}, and has to be defined
    first in the inheritance (so that method resolution order finds
    startRunning first).

    @type _installSignalHandlers: C{bool}
    @ivar _installSignalHandlers: A flag which indicates whether any signal
        handlers will be installed during startup.  This includes handlers for
        SIGCHLD to monitor child processes, and SIGINT, SIGTERM, and SIGBREAK
        to stop the reactor.
    cCsyddl}Wntk
r1tjddSX|j|j|jkrf|j|j|jn|j|j|j	t
|dr|j|j|jndS(sI
        Install the signal handlers for the Twisted event loop.
        iNsEWarning: signal module unavailable -- not installing signal handlers.tSIGBREAK(
tsignaltImportErrorRRxt	getsignaltSIGINTtdefault_int_handlerRtSIGTERMRRFRER(R+RF((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt_handleSignals\s

cCs||_tj|dS(so
        Extend the base implementation in order to remember whether signal
        handlers should be installed later.

        @type installSignalHandlers: C{bool}
        @param installSignalHandlers: A flag which, if set, indicates that
            handlers for a number of (implementation-defined) signals should be
            installed during startup.
        N(t_installSignalHandlersRR(R+tinstallSignalHandlers((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRqs
	cCs'tj||jr#|jndS(s
        Extend the base implementation by also installing signal handlers, if
        C{self._installSignalHandlers} is true.
        N(RRRMRL(R+((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRs
	cCs|jd||jdS(NRN(RtmainLoop(R+RN((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pytrunscCsx|jryFx?|jrP|j|j}|jo=|}|j|qWWntjdtjqXtjdqWdS(NsUnexpected error in main loop.sMain loop terminated.(RRRpRRRRxR\(R+tt2tt((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyROs

(RGRSRsRTRMRLRRRRPRO(((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyRDJs		(:RsRltzope.interfaceRRRRtheapqRRRR(ttwisted.python.compatRttwisted.python.utilRttwisted.internet.interfacesRRR	R
RRR
ttwisted.internetRRRRRRRRRRttwisted.python.runtimeRRURttwisted.internet.deferRRttwisted.persistedRRt	EphemeralRtobjectRVRtRyRRRtFileDescriptorR;RDt__all__(((s9/usr/lib/python2.7/dist-packages/twisted/internet/base.pyt<module>s<.D-U\