ó EŃŐfc@sĘdZddlZddlTddlmZddlmZyddlZWnek r_nrXeed„Z ddlm Z ddlm Z m Z mZmZmZmZmZmZmZmZmZmZddlZddlZddlZydd lmZWn!ek r,dd lmZnXyddlZWnek rVeZnXeed d ƒZeed d ƒZ ddgZ!e!j"ej#eƒƒe$Z%ej&j'ƒj(dƒrgiZ)de)dd?fZ,ej-d@krÂe,dAfZ,nej&dBkráe,dCfZ,ndDdEdFdGdHdIfZ.dJe/fdK„ƒYZ0dLe/fdM„ƒYZ1dN„Z2x]e,D]UZ3ee2e3ƒZ4e3e4_5ee%e3ƒje4_ee4ee1ƒZ6e7e1e3e6ƒq5We1Z$Z8dOe/fdP„ƒYZ9e/ƒZ:e:edQ„Z;dS(RsThis module provides socket operations and some related functions. On Unix, it supports IP (Internet Protocol) and Unix domain sockets. On other systems, it only supports IP. Functions specific for a socket are available as methods of the socket object. Functions: socket() -- create a new socket object socketpair() -- create a pair of new socket objects [*] fromfd() -- create a socket object from an open file descriptor [*] gethostname() -- return the current hostname gethostbyname() -- map a hostname to its IP number gethostbyaddr() -- map an IP number or hostname to DNS info getservbyname() -- map a service name and a protocol name to a port number getprotobyname() -- map a protocol name (e.g. 'tcp') to a number ntohs(), ntohl() -- convert 16, 32 bit int from network to host byte order htons(), htonl() -- convert 16, 32 bit int from host to network byte order inet_aton() -- convert IP addr string (123.45.67.89) to 32-bit packed format inet_ntoa() -- convert 32-bit packed format IP to string (123.45.67.89) ssl() -- secure socket layer support (only available if configured) socket.getdefaulttimeout() -- get the default timeout value socket.setdefaulttimeout() -- set the default timeout value create_connection() -- connects to an address, with an optional timeout and optional source address. [*] not available on all platforms! Special objects: SocketType -- type object for socket objects error -- exception raised for I/O errors has_ipv6 -- boolean value indicating if IPv6 is supported Integer constants: AF_INET, AF_UNIX -- socket domains (first argument to socket() call) SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- socket types (second argument) Many other constants may be defined; these may be used in calls to the setsockopt() and getsockopt() methods. i˙˙˙˙N(t*(tpartial(t MethodTypecCs5ddl}tjdtddƒ|j|||ƒS(Ni˙˙˙˙s;socket.ssl() is deprecated. Use ssl.wrap_socket() instead.t stackleveli(tssltwarningstwarntDeprecationWarningtsslwrap_simple(tsocktkeyfiletcertfilet_realssl((s/usr/lib64/python2.7/socket.pyR:s   (tSSLError( tRAND_addtRAND_egdt RAND_statustSSL_ERROR_ZERO_RETURNtSSL_ERROR_WANT_READtSSL_ERROR_WANT_WRITEtSSL_ERROR_WANT_X509_LOOKUPtSSL_ERROR_SYSCALLt SSL_ERROR_SSLtSSL_ERROR_WANT_CONNECTt SSL_ERROR_EOFtSSL_ERROR_INVALID_ERROR_CODE(tStringIOtEBADFi tEINTRitgetfqdntcreate_connectiontwinsThe operation was interrupted.i'sA bad file handle was passed.i'sPermission denied.i's!A fault occurred on the network??i's#An invalid operation was attempted.i&'s The socket operation would blocki3's,A blocking operation is already in progress.i4'sThe network address is in use.i@'sThe connection has been reset.iF'sThe network has been shut down.iJ'sThe operation timed out.iL'sConnection refused.iM'sThe name is too long.iO'sThe host is down.iP'sThe host is unreachable.iQ'terrorTabtcCs“|jƒ}| s|dkr+tƒ}nyt|ƒ\}}}Wntk rWn8X|jd|ƒx$|D]}d|kroPqoqoW|}|S(sGet fully qualified domain name from name. An empty argument is interpreted as meaning the local host. First the hostname returned by gethostbyaddr() is checked, then possibly existing aliases. In case no FQDN is available, hostname from gethostname() is returned. s0.0.0.0it.(tstript gethostnamet gethostbyaddrterrortinsert(tnamethostnametaliasestipaddrs((s/usr/lib64/python2.7/socket.pyR|s     tbindtconnectt connect_extfilenotlistent getpeernamet getsocknamet getsockoptt setsockopttsendallt setblockingt settimeoutt gettimeouttshutdowntnttioctltriscost sleeptaskwtrecvtrecvfromt recv_intot recvfrom_intotsendtsendtot _closedsocketcBs7eZgZd„ZeZZZZZZ eZ RS(cGsttdƒ‚dS(NsBad file descriptor(R&R(targs((s/usr/lib64/python2.7/socket.pyt_dummyŠs( t__name__t __module__t __slots__RFRBR>R@RCR?RAt __getattr__(((s/usr/lib64/python2.7/socket.pyRD§s t _socketobjectcBsĚeZejZddgeeƒZeeddd„Z e ee d„Z ej je _d„Zejje_d„Zddd „Zed „d d ƒZed „d dƒZed„d dƒZRS(t_sockt __weakref__icCsX|dkr!t|||ƒ}n||_x'tD]}t||t||ƒƒq1WdS(N(tNonet _realsocketRLt_delegate_methodstsetattrtgetattr(tselftfamilyttypetprotoRLtmethod((s/usr/lib64/python2.7/socket.pyt__init__šs    cCs=|ƒ|_|jj}x|D]}||||ƒqWdS(N(RLRF(RSRDRPRQtdummyRW((s/usr/lib64/python2.7/socket.pytcloseŔs   cCs(|jjƒ\}}td|ƒ|fS(NRL(RLtacceptRK(RSR taddr((s/usr/lib64/python2.7/socket.pyR[ÉscCstd|jƒS(sadup() -> socket object Return a new socket object connected to the same system resource.RL(RKRL(RS((s/usr/lib64/python2.7/socket.pytdupÎstri˙˙˙˙cCst|j||ƒS(sžmakefile([mode[, bufsize]]) -> file object Return a regular file object corresponding to the socket. The mode and bufsize arguments are as for the built-in open() function.(t _fileobjectRL(RStmodetbufsize((s/usr/lib64/python2.7/socket.pytmakefileÔscCs |jjS(N(RLRT(RS((s/usr/lib64/python2.7/socket.pytŰstdocsthe socket familycCs |jjS(N(RLRU(RS((s/usr/lib64/python2.7/socket.pyRcÜssthe socket typecCs |jjS(N(RLRV(RS((s/usr/lib64/python2.7/socket.pyRcÝssthe socket protocolN(RGRHROt__doc__tlistRPRItAF_INETt SOCK_STREAMRNRXRDRQRZR[R]RbtpropertyRTRURV(((s/usr/lib64/python2.7/socket.pyRKłs   cGst|j|ƒ|ŒS(N(RRRL(R(RSRE((s/usr/lib64/python2.7/socket.pytmethßsR_c Bs×eZdZdZdZddddddd d d d g Zd ded„Zd„Ze eddƒZ d„Z d„Z d„Z d„Zd„Zd„Zdd„Zdd„Zdd„Zd„Zd„ZRS(s-Faux file object attached to a socket object.i sR`Rat softspaceRLt _rbufsizet _wbufsizet_rbuft_wbuft _wbuf_lent_closetrbi˙˙˙˙cCsŹ||_||_|dkr*|j}n||_t|_|dkrTd|_n$|dkro|j|_n ||_||_tƒ|_ g|_ d|_ ||_ dS(Nii( RLR`tdefault_bufsizeRatFalseRkRlRmRRnRoRpRq(RSR R`RaRZ((s/usr/lib64/python2.7/socket.pyRXös               cCs |jdkS(N(RLRN(RS((s/usr/lib64/python2.7/socket.pyt _getclosedsRdsTrue if the file is closedcCsDz|jr|jƒnWd|jr6|jjƒnd|_XdS(N(RLtflushRqRZRN(RS((s/usr/lib64/python2.7/socket.pyRZs   cCsy|jƒWnnXdS(N(RZ(RS((s/usr/lib64/python2.7/socket.pyt__del__scCsĺ|jrádj|jƒ}g|_d|_t|j|jƒ}t|ƒ}d}t|ƒ}z<x5||krš|jj ||||!ƒ||7}qfWWd||krÝ||}~~|jj |ƒt|ƒ|_nXndS(NR!i( RotjoinRptmaxRlRstlent memoryviewRLR5tappend(RStdatat buffer_sizet data_sizet write_offsettviewt remainder((s/usr/lib64/python2.7/socket.pyRv$s"       cCs |jjƒS(N(RLR/(RS((s/usr/lib64/python2.7/socket.pyR/8scCs—t|ƒ}|sdS|jj|ƒ|jt|ƒ7_|jdks†|jdkred|ks†|jdkr“|j|jkr“|jƒndS(Niis (tstrRoR|RpRzRmRv(RSR}((s/usr/lib64/python2.7/socket.pytwrite;s !cCsxtdtt|ƒƒ}|jttt|ƒƒ7_|jj|ƒ|j dksg|j|j krt|j ƒndS(Ni( tfilterRNtmapRƒRptsumRzRotextendRmRv(RSRftlines((s/usr/lib64/python2.7/socket.pyt writelinesFs c Csöt|j|jƒ}|j}|jddƒ|dkrźtƒ|_xitrąy|jj|ƒ}Wn/t k r–}|j dt krqIn‚nX|sĄPn|j |ƒqIW|j ƒS|jƒ}||kr|jdƒ|j|ƒ}tƒ|_|jj |jƒƒ|Stƒ|_xĂtrç||}y|jj|ƒ}Wn/t k r|}|j dt krvq%n‚nX|s‡Pnt|ƒ} | |krŞ| rŞ|S| |krĘ|j |ƒ~Pn|j |ƒ|| 7}~q%W|j ƒSdS(Nii(RyRlRsRntseekRtTrueRLR>R&RERR„tgetvaluettelltreadRz( RStsizetrbufsizetbufR}tetbuf_lentrvtlefttn((s/usr/lib64/python2.7/socket.pyRPsZ                 c Cs|j}|jddƒ|jƒdkr”|jdƒ|j|ƒ}|jdƒsht|ƒ|krŽtƒ|_|jj|jƒƒ|S~n|dkrV|j dkrp|jdƒ|jƒg}tƒ|_d}|j j }xwt rby:x3|dkr*|dƒ}|sPn|j|ƒqřWWn/tk r]}|jdtkrWqěn‚nXPqěWdj|ƒS|jddƒtƒ|_x˝t rKy|j j |j ƒ}Wn/tk rß}|jdtkrŮqn‚nX|sęPn|jdƒ}|dkr;|d7}|j|| ƒ|jj||ƒ~Pn|j|ƒqW|jƒS|jddƒ|jƒ} | |krŔ|jdƒ|j|ƒ} tƒ|_|jj|jƒƒ| Stƒ|_x=t r y|j j |j ƒ}Wn/tk r}|jdtkrqĎn‚nX|s*Pn|| } |jdd| ƒ}|dkr™|d7}|jj||ƒ| rŽ|j|| ƒPq™|| Snt|ƒ} | |krź| rź|S| | krń|j|| ƒ|jj|| ƒPn|j|ƒ| | 7} qĎW|jƒSdS(Niis iR!(RnR‹RŽtreadlinetendswithRzRR„RRlRNRLR>RŒR|R&RERRxtfindR( RSRR’tblinetbuffersR}R>R“tnlR”R•R–R—((s/usr/lib64/python2.7/socket.pyR˜–sŽ  !                          icCsfd}g}xStra|jƒ}|s+Pn|j|ƒ|t|ƒ7}|r||krPqqW|S(Ni(RŒR˜R|Rz(RStsizehintttotalRftline((s/usr/lib64/python2.7/socket.pyt readlines˙s   cCs|S(N((RS((s/usr/lib64/python2.7/socket.pyt__iter__scCs|jƒ}|st‚n|S(N(R˜t StopIteration(RSR ((s/usr/lib64/python2.7/socket.pytnexts  (RGRHReRsR(RIRtRXRuRitclosedRZRwRvR/R„RŠRR˜RĄR˘R¤(((s/usr/lib64/python2.7/socket.pyR_ës(       F i  cCs|\}}d}xĆt||dtƒD]Ż}|\}}} } } d} yYt||| ƒ} |tk rz| j|ƒn|r| j|ƒn| j| ƒ| SWq(tk rÖ} | }| dk r×| j ƒq×q(Xq(W|dk rđ|‚n tdƒ‚dS(sdConnect to *address* and return the socket object. Convenience function. Connect to *address* (a 2-tuple ``(host, port)``) and return the socket object. Passing the optional *timeout* parameter will set the timeout on the socket instance before attempting to connect. If no *timeout* is supplied, the global default timeout setting returned by :func:`getdefaulttimeout` is used. If *source_address* is set it must be a tuple of (host, port) for the socket to bind as a source address before making the connection. An host of '' or port 0 tells the OS to use the default. is!getaddrinfo returns an empty listN( RNt getaddrinfoRhtsockett_GLOBAL_DEFAULT_TIMEOUTR7R,R-R&RZ(taddressttimeouttsource_addressthosttportterrtrestaftsocktypeRVt canonnametsaR t_((s/usr/lib64/python2.7/socket.pyRs(      (<Ret_sockett functoolsRttypesRt_sslt ImportErrorRNRR tsslerrorRRRRRRRRRRRRtostsysRt cStringIORterrnoRRRRt__all__Rˆt_get_exports_listR§ROtplatformtlowert startswithR R|Rt_socketmethodsR(RPtobjectRDRKRjt_mtpRGtmRQt SocketTypeR_R¨R(((s/usr/lib64/python2.7/socket.pyt-sŠ    R$                        ,    ˙-