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


0Nc@sdZddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
ddlmZm
Z
mZeedsednddlmZmZmZmZmZmZmZddlmZdd	lmZmZmZmZd
ej fdYZ dZ!d
e"fdYZ#de#ej$fdYZ$dej%fdYZ&dej'fdYZ(de#ej$fdYZ)de)fdYZ*dS(s
Various asynchronous TCP/IP classes.

End users shouldn't use this module directly - use the reactor APIs instead.

Maintainer: Itamar Shtull-Trauring
iN(tEINTRtEMSGSIZEtEAGAINtEWOULDBLOCKtECONNREFUSED(t
implementstimplementsOnlyt
implementedBytAF_UNIXs+UNIX sockets not supported on this platform(tbasettcptudpterrort
interfacestprotocoltaddress(tCannotListenError(tlockfiletlogtreflecttfailuretServercBs#eZdZdZdZRS(cCs,tjj||||df|||dS(N(R
Rt__init__tNone(tselftsockRtclienttservert	sessionnotreactor((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRscCstj|jjS(N(RtUNIXAddresstsockettgetsockname(R((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pytgetHost!scCstj|jS(N(RRthostname(R((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pytgetPeer$s(t__name__t
__module__RR!R#(((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRs		cCs|d dkS(s
    Determine whether the given unix socket path is in a filesystem namespace.

    While most PF_UNIX sockets are entries in the filesystem, Linux 2.2 and
    above support PF_UNIX sockets in an "abstract namespace" that does not
    correspond to any path. This function returns C{True} if the given socket
    path is stored in the filesystem and C{False} if the path is in this
    abstract namespace.
    it((tpath((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyt_inFilesystemNamespace)s
t	_UNIXPortcBseZdZRS(cCsFtjdkst|jr0|jj}n	|j}tj|S(sMReturns a UNIXAddress.

        This indicates the server's address.
        ii(ii(tsystversion_infoR(tportRR RR(RR'((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyR!7s	(R$R%R!(((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyR)6stPortcBsheZejZejZeZd	Z
ddd	ddZdZdZ
dZdZdZRS(
i2iicCs5tjj||||d|||_||_dS(NR(R
R-RtmodetwantPID(RtfileNametfactorytbacklogR.RR/((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRMs	cCsDtj|jj}t|dr5d||jfSd|fSdS(NRs
<%s on %r>s<%s (not listening)>(RtqualR1t	__class__thasattrR,(RtfactoryName((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyt__repr__RscCs
tj|S(N(RR(Rtname((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyt
_buildAddrYscCstjd|j|j|jf|jrtj|jd|_|jj	sot
d|jdfq|jjsy5t
jtj
|jjrtj|jnWqqXqn|jjy |j}|j|jWn+tjk
r}t
d|j|fnmXt|jrCtj|j|jn|j|jt|_||_|jj|_d|_|j dS(s
        Create and bind my socket, and begin listening on it.

        This is called on unserialization, and must be called after creating a
        server to begin listening on the specified port.
        s%s starting on %rs.locksCannot acquire lockidN(!Rtmsgt
_getLogPrefixR1R,R/RtFilesystemLocktlockFiletlockRRtcleantstattS_ISSOCKtostst_modetremovetdoStarttcreateInternetSockettbindRRR(tchmodR.tlistenR2tTruet	connectedtfilenot
numberAcceptststartReading(Rtskttle((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pytstartListening\s4		

			cCs!tjdt|jfdS(s0
        Log message for closing socket
        s(UNIX Port %s Closed)N(RR:treprR,(R((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyt_logConnectionLostMsgscCsXt|jr"tj|jn|jdk	rA|jjntjj	||dS(N(
R(R,RBtunlinkR=RtunlockR
R-tconnectionLost(Rtreason((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRVs
N(R$R%RRt
addressFamilytSOCK_STREAMt
socketTypeRt	transportRR=RR7R9RQRSRV(((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyR-Fs					,	tClientcBsAeZdZejZejZdddZ	dZ
dZRS(sA client for Unix sockets.icCsx||_||_|_|rUtj|drU|jddtj||n|j|j	|j
d|dS(Ns.lock(t	connectortrealAddresstaddrRtisLockedt_finishInitRRtBadFileErrort	doConnectRF(RtfilenameR]RtcheckPID((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRs	"cCstj|jS(N(RRR_(R((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyR#scCs
tjdS(N(RRR(R((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyR!sN(R$R%t__doc__RRRXRYRZRRR#R!(((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyR\s			t	ConnectorcBs#eZdZdZdZRS(cCs/tjj||||||_||_dS(N(R	t
BaseConnectorRRRe(RRR1ttimeoutRRe((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRs	cCst|j||j|jS(N(R\RRRe(R((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyt_makeTransportscCstj|jS(N(RR(R((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pytgetDestinations(R$R%RRjRk(((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRgs		tDatagramPortcBsfeZdZeejejZddd	dZ
dZdZdZ
d	dZdZRS(
s*Datagram UNIX port, listening for packets.i icCs/tjj|||d|d|||_dS(s.Initialize with address to listen on.
        t
maxPacketSizeRN(RR-RR.(RR_tprotoRmR.R((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRs"cCsDtj|jj}t|dr5d||jfSd|fSdS(NRs
<%s on %r>s<%s (not listening)>(RR3RR4R5R,(RtprotocolName((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyR7scCstjd|jjt|jfy,|j}|jrQ|j|jnWn.tj	k
r}t	j
d|j|fnX|jrt|jrt
j|j|jnd|_||_|jj|_dS(Ns%s starting on %si(RR:RR4RRR,RFRGRRRRR(RBRHR.RKRL(RRORP((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyt_bindSockets&			cCsy|jj||SWnltjk
r}|jd}|tkrU|j||S|tkrptjdq|tkrqnXdS(sWrite a datagram.ismessage too longN(	RtsendtoRtargsRtwriteRtMessageLengthErrorR(RtdatagramRtsetno((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRss
cCstjdt|jtjj||t|drL|jj	nd|_
|jj|`|`
t|dr|jjd|`ndS(sCleans up my socket.
        s(Port %s Closed)RitdN(RR:RRR,R	tBasePortRVR5RtdoStopRKRtcloseRLRxtcallbackR(RRW((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRVs	
cCs tj|jjd|_dS(Ns (UDP)(RR3RR4tlogstr(R((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyt	setLogStrsN(R$R%RfRR
tIUNIXDatagramTransportRRRXRRR7RpRsRVR~(((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRls
				tConnectedDatagramPortcBsieZdZeejeejddd	d	dZ
dZdZdZ
dZdZRS(
s+
    A connected datagram UNIX socket.
    i icCsAt|tjsttj||||||||_dS(N(t
isinstanceRtConnectedDatagramProtocoltAssertionErrorRlRt
remoteaddr(RR_RnRmR.tbindAddressR((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRscCsLy+|j|jj|j|jWn|jtjnXdS(N(RpRtconnectRt_connectToProtocoltconnectionFailedRtFailure(R((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRQs
cCs$|j|jj||`dS(s
        Called when a connection fails. Stop listening on the socket.

        @type reason: L{Failure}
        @param reason: Why the connection failed.
        N(t
stopListeningRR(RRW((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRs
cCsd}x||jkry?|jj|j\}}|t|7}|jj|Wq	tjk
r}|jd}|t	t
tfkrdS|tkr|jj
qq	tjq	Xq	WdS(s=
        Called when my socket is ready for reading.
        iN(t
maxThroughputRtrecvfromRmtlenRtdatagramReceivedRRrRRRRtconnectionRefusedRtdeferr(RtreadtdataR_RvRw((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pytdoRead+s
cCsy|jj|SWntjk
r}|jd}|tkrO|j|S|tkrjtjdq|tkr|j	j
q|tkrqnXdS(s#
        Write a datagram.
        ismessage too longN(RtsendRRrRRsRRtRRRR(RRRvRw((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRsAs

cCstj|jS(N(RRR(R((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyR#XsN(R$R%RfRR
tIUNIXDatagramConnectedTransportRR	RyRRRQRRRsR#(((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyRs						(+RfRBR*R@RterrnoRRRRRtzope.interfaceRRRR5tImportErrorttwisted.internetR	R
RRR
RRttwisted.internet.errorRttwisted.pythonRRRRRR(tobjectR)R-t
BaseClientR\RhRgRlR(((s9/usr/lib/python2.7/dist-packages/twisted/internet/unix.pyt<module>s 0(4"	
R
M