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


ZOc@sdZddlZddlZddlZddlZddlZddlmZmZddl	m
Z
ddlmZm
Z
ddlmZmZmZmZddlmZmZddlmZdd	lmZdd
lmZmZddlmZmZmZddlmZdd
lm Z m!Z!ddl"m#Z#m$Z$ddl%m&Z&m'Z'ej(dZ)ej(dZ*yddl+m,Z,WnEe-k
re.Z,yddlm/Z/Wne-k
re.Z/nXnXyddlm0Z0e1Z2Wne-k
re3Z2nXe3Z4e dkr?ddlm5Z5m6Z6m7Z7e1Z4ne!j8r~yddl9Z9e1Z4Wne-k
rze.Z9nXndej:ej;fdYZ<de=ej:ej;fdYZ>de>fdYZ?e dkre?Z@ne<Z@de>fdYZAde$e#fd YZBd!e=fd"YZCe,e.k	pJe/e.k	r]eeBene2rveeBee
ne4reeBendgZDdS(#s
Posix reactor base class
iN(t
implementstclassImplements(tset(tIReactorUNIXtIReactorUNIXDatagram(tIReactorTCPtIReactorUDPtIReactorSSLt_IReactorArbitrary(tIReactorProcesstIReactorMulticast(tIHalfCloseableDescriptor(terror(ttcptudp(tlogtfailuretutil(tstyles(tplatformTypetplatform(tReactorBaset_SignalReactorMixin(tCONNECTION_DONEtCONNECTION_LOSTsHandler has no fileno methodsFile descriptor lost(ttls(tssl(tunixtposix(tfdesctprocesst_signalst_SocketWakercBs8eZdZdZdZdZdZdZRS(s
    The I{self-pipe trick<http://cr.yp.to/docs/selfpipe.html>}, implemented
    using a pair of sockets rather than pipes (due to the lack of support in
    select() on Windows for pipes), used to wake up the main loop from
    another thread.
    icCs||_tjtjtj}tjtjtj}|jtjtjd|jd|jd|j	|j
|j\}}|jd|jd||_
||_|j
j|_dS(sInitialize.
        is	127.0.0.1iN(s	127.0.0.1i(treactortsockettAF_INETtSOCK_STREAMt
setsockopttIPPROTO_TCPtTCP_NODELAYtbindtlistentconnecttgetsocknametaccepttsetblockingtrtwtfileno(tselfR!tservertclienttreadert
clientaddr((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyt__init__Js	



		cCsRytj|jjdWn1tjk
rM\}}|tjkrNqNnXdS(s&Send a byte to my connection.
        txN(RtuntilConcludesR/tsendR"RterrnotWSAEWOULDBLOCK(R1terrtmsg((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pytwakeUp\s
cCs/y|jjdWntjk
r*nXdS(s+Read some data from my connection.
        i N(R.trecvR"R(R1((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pytdoReadescCs|jj|jjdS(N(R.tcloseR/(R1treason((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pytconnectionLostms
(t__name__t
__module__t__doc__tdisconnectedR6R>R@RC(((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyR As				t_FDWakercBs;eZdZdZdZdZdZdZdZ	RS(s
    The I{self-pipe trick<http://cr.yp.to/docs/selfpipe.html>}, used to wake
    up the main loop from another thread or a signal handler.

    L{_FDWaker} is a base class for waker implementations based on
    writing to a pipe being monitored by the reactor.

    @ivar o: The file descriptor for the end of the pipe which can be
        written to to wake up a reactor monitoring this waker.

    @ivar i: The file descriptor which should be monitored in order to
        be awoken by this waker.
    icsw|_tj\__tjjtjjtjjtjjfd_dS(sInitialize.
        csjS(N(ti((R1(s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyt<lambda>sN(	R!tostpipeRItoRtsetNonBlockingt_setCloseOnExecR0(R1R!((R1s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyR6s	cCstj|jddS(sA
        Read some bytes from the pipe and discard them.
        cSsdS(N(tNone(tdata((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyRJsN(Rt
readFromFDR0(R1((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyR@scCset|dsdSx?|j|jfD]+}ytj|Wq&tk
rPq&Xq&W|`|`dS(s$Close both ends of my pipe.
        RMN(thasattrRIRMRKRAtIOError(R1RBtfd((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyRCs
N(
RDRERFRGRPRIRMR6R@RC(((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyRHss
		t
_UnixWakercBseZdZdZRS(s
    This class provides a simple interface to wake up the event loop.

    This is used by threads or signals to wake up the event loop.
    cCsa|jdk	r]ytjtj|jdWq]tk
rY}|jtjkrZqZq]XndS(s2Write one byte to the pipe, and flush it.
        R7N(	RMRPRR8RKtwritetOSErrorR:tEAGAIN(R1te((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyR>s(RDRERFR>(((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyRVst
_SIGCHLDWakercBs2eZdZdZdZdZdZRS(s}
    L{_SIGCHLDWaker} can wake up a reactor whenever C{SIGCHLD} is
    received.

    @see: L{twisted.internet._signals}
    cCstj||dS(N(RHR6(R1R!((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyR6scCstj|jdS(sJ
        Install the handler necessary to make this waker active.
        N(RtinstallHandlerRM(R1((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pytinstallscCstjddS(sC
        Remove the handler which makes this waker active.
        iN(RR\(R1((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyt	uninstallscCstj|tjdS(s
        Having woken up the reactor in response to receipt of
        C{SIGCHLD}, reap the process which exited.

        This is called whenever the reactor notices the waker pipe is
        writeable, which happens soon after any call to the C{wakeUp}
        method.
        N(RHR@RtreapAllProcesses(R1((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyR@s	
(RDRERFR6R]R^R@(((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyR[s
			tPosixReactorBasecBs^eZdZeeeeeiej	e
je
j6ej	e
je
j6dZ
eZdZdZdZdZdiddddddZddd	Zdded
ZdddZd
dddZdddZddddZd
ddZdddZdddZd
ddZ dZ!dZ"dZ#RS(s
    A basis for reactors that use file descriptors.

    @ivar _childWaker: C{None} or a reference to the L{_SIGCHLDWaker}
        which is used to properly notice child process termination.
    cCs|j||j|j}|ry|r\|jtjkr\tj|r\|j|q|j||j	|n#|j||j	t
j|dS(s
        Utility function for disconnecting a selectable.

        Supports half-close notification, isRead should be boolean indicating
        whether error resulted from doRead().
        N(tremoveReadertgett	__class__RtConnectionDoneRt
providedBytreadConnectionLosttremoveWriterRCRtFailure(R1t
selectabletwhytisReadtfaildicttf((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyt_disconnectSelectables



cCsE|jsA|j||_|jj|j|j|jndS(s
        Install a `waker' to allow threads and signals to wake up the IO thread.

        We use the self-pipe trick (http://cr.yp.to/docs/selfpipe.html) to wake
        the reactor. On Windows we use a pair of sockets.
        N(twakert
_wakerFactoryt_internalReaderstaddt	addReader(R1((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pytinstallWakers	cCsutj|tdkrq|jsWt||_|jj|j|j|jn|jjt	j
ndS(s
        Extend the basic signal handling logic to also support
        handling SIGCHLD to know when to try to reap child processes.
        RN(Rt_handleSignalsRt_childWakerR[RqRrRsR]RR_(R1((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyRus
	
cCs|jr|jjndS(s
        If a child waker was created and installed, uninstall it now.

        Since this disables reactor functionality and is only called
        when the reactor is stopping, it doesn't provide any directly
        useful functionality, but the cleanup of reactor-related
        process-global state that it does helps in unit tests
        involving multiple reactors and is generally just a nice
        thing.
        N(RvR^(R1((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyt_uninstallHandler2s	ic

CsF|j||\}}tdkr|rj|	dk	rEtdntj|||||||||	Stj|||||||||		Sntdkr9|dk	rtdn|dk	rtdn|rtdn|	rtdntr-dd	lm}
|
||||||St	d
n	t	ddS(NRs1Using childFDs is not supported with usePTY=True.twin32s,Setting UID is unsupported on this platform.s,Setting GID is unsupported on this platform.s1The usePTY parameter is not supported on Windows.s1Customizing childFDs is not supported on Windows.i(tProcesss:spawnProcess not available since pywin32 is not installed.s0spawnProcess only available on Windows or POSIX.(
t_checkProcessArgsRRPt
ValueErrorRt
PTYProcessRytwin32processttwisted.internet._dumbwin32proctNotImplementedError(R1tprocessProtocolt
executabletargstenvtpathtuidtgidtusePTYtchildFDsRy((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pytspawnProcessEs.ti cCs)tj|||||}|j|S(sConnects a given L{DatagramProtocol} to the given numeric UDP port.

        @returns: object conforming to L{IListeningPort}.
        (RtPorttstartListening(R1tporttprotocolt	interfacet
maxPacketSizetp((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyt	listenUDPfs
cCs,tj||||||}|j|S(sConnects a given DatagramProtocol to the given numeric UDP port.

        EXPERIMENTAL.

        @returns: object conforming to IListeningPort.
        (Rt
MulticastPortR(R1RRRRtlistenMultipleR((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pytlistenMulticastqs
icCs;tstdtj|||||}|j|S(sC@see: twisted.internet.interfaces.IReactorUNIX.connectUNIX
        sUNIX support is not present(tunixEnabledtAssertionErrorRt	ConnectorR*(R1taddresstfactoryttimeouttcheckPIDtc((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pytconnectUNIXs
i2icCs>tstdtj||||||}|j|S(sK
        @see: twisted.internet.interfaces.IReactorUNIX.listenUNIX
        sUNIX support is not present(RRRRR(R1RRtbacklogtmodetwantPIDR((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyt
listenUNIXs
cCs;tstdtj|||||}|j|S(s
        Connects a given L{DatagramProtocol} to the given path.

        EXPERIMENTAL.

        @returns: object conforming to L{IListeningPort}.
        sUNIX support is not present(RRRtDatagramPortR(R1RRRRR((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pytlistenUNIXDatagrams	
cCs>tstdtj||||||}|j|S(sd
        Connects a L{ConnectedDatagramProtocol} instance to a path.

        EXPERIMENTAL.
        sUNIX support is not present(RRRtConnectedDatagramPortR(R1RRRRtbindAddressR((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pytconnectUNIXDatagrams
cCs)tj|||||}|j|S(s@@see: twisted.internet.interfaces.IReactorTCP.listenTCP
        (R
RR(R1RRRRR((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyt	listenTCPs
cCs,tj||||||}|j|S(sA@see: twisted.internet.interfaces.IReactorTCP.connectTCP
        (R
RR*(R1thostRRRRR((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyt
connectTCPs
c	Cstdk	r:tj|t|}|j|||||Stdk	rutj|||||||}|j|Stst	ddS(sA@see: twisted.internet.interfaces.IReactorSSL.connectSSL
        sSSL support is not presentN(
RRPtTLSMemoryBIOFactorytTrueRRRR*tFalseR(	R1RRRtcontextFactoryRRt
tlsFactoryR((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyt
connectSSLs
cCstdk	rFtj|t|}|j||||}d|_|Stdk	r~tj||||||}|j|Stst	ddS(s@@see: twisted.internet.interfaces.IReactorSSL.listenSSL
        tTLSsSSL support is not presentN(
RRPRRRt_typeRRRR(R1RRRRRRR((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyt	listenSSLs	
cOs@tjddtdd||d<|||}|j|S(Ns@listenWith is deprecated since Twisted 10.1.  See IReactorFDSet.tcategoryt
stackleveliR!(twarningstwarntDeprecationWarningR(R1tportTypeRtkwR((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyt
listenWiths

cOs@tjddtdd||d<|||}|j|S(NsAconnectWith is deprecated since Twisted 10.1.  See IReactorFDSet.RRiR!(RRRR*(R1t
connectorTypeRRR((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pytconnectWiths

cCsit||j}x|D]}|j|qWt|}x|D]}|j|qDWt||BS(sg
        Remove all readers and writers, and list of removed L{IReadDescriptor}s
        and L{IWriteDescriptor}s.

        Meant for calling from subclasses, to implement removeAll, like::

          def removeAll(self):
              return self._removeAll(self._reads, self._writes)

        where C{self._reads} and C{self._writes} are iterables.
        (RRqRaRgtlist(R1treaderstwriterstremovedReadersR4tremovedWriterstwriter((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyt
_removeAlls

N(($RDRERFRRRRR
RRhRRdtConnectionLostRnt_WakerRpRtRPRvRuRwRRRRRRRRRRRRRRR(((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyR`s8"	
		
			t_PollLikeMixincBseZdZdZRS(s
    Mixin for poll-like reactors.

    Subclasses must define the following attributes::

      - _POLL_DISCONNECTED - Bitmask for events indicating a connection was
        lost.
      - _POLL_IN - Bitmask for events indicating there is input to read.
      - _POLL_OUT - Bitmask for events indicating output can be written.

    Must be mixed in to a subclass of PosixReactorBase (for
    _disconnectSelectable).
    cCsd}t}||j@rN||j@rN||jkrEt}t}qt}nyj|jdkrlt	}nK||j@r|j
}t}n|r||j@r|j}t}nWn!t
jd}tjnX|r|j|||ndS(sg
        fd is available for read or write, do the work and raise errors if
        necessary.
        iiN(RPRt_POLL_DISCONNECTEDt_POLL_INt_readsRRRR0t_NO_FILEDESCR@t	_POLL_OUTtdoWritetsystexc_infoRR<Rn(R1RiRUteventRjtinRead((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyt_doReadOrWrite s*			
	
(RDRERFR(((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyRs
(ERFRR"R:RKRtzope.interfaceRRttwisted.python.compatRttwisted.internet.interfacesRRRRRRR	R
Rttwisted.internetRR
Rttwisted.pythonRRRttwisted.persistedRttwisted.python.runtimeRRttwisted.internet.baseRRttwisted.internet.mainRRtConnectionFdescWentAwayt
_NO_FILENORttwisted.protocolsRtImportErrorRPRRRRRtprocessEnabledRRRt	isWindowsR}tLoggert	EphemeralR tobjectRHRVRR[R`Rt__all__(((s>/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.pyt<module>sx"




	


2"4	'&J