ó zfc@sìdZddlZddlTddlmZddlmZyddlZWnek r_n”Xeed„Z ddlm Z ddlm Z m Z mZmZmZmZmZmZmZmZmZydd lmZWnek rònXddlZddlZddlZydd lmZWn!ek rNdd lmZnXyddlZWnek rxeZnXeed d ƒZeed dƒZ ddgZ!e!j"ej#eƒƒe$Z%ej&j'ƒj(dƒr‰iZ)de)dd?d@fZ,ej-dAkräe,dBfZ,nej&dCkre,dDfZ,ndEdFdGdHdIdJfZ.dKe/fdL„ƒYZ0dMe/fdN„ƒYZ1dO„Z2x]e,D]UZ3ee2e3ƒZ4e3e4_5ee%e3ƒje4_ee4ee1ƒZ6e7e1e3e6ƒqWWe1Z$Z8dPe/fdQ„ƒYZ9e/ƒZ:e:edR„Z;dS(SsThis 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_addt 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(tRAND_egd(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ßR!tdocsthe socket familycCs |jjS(N(RLRU(RS((s/usr/lib64/python2.7/socket.pyRcàR!sthe socket typecCs |jjS(N(RLRV(RS((s/usr/lib64/python2.7/socket.pyRcáR!sthe 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/<scCs—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 writelinesJs c Csöt|j|jƒ}|j}|jddƒ|dkr¼tƒ|_xitr±y|jj|ƒ}Wn/t k r–}|j dt krqIn‚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.pyRTsZ                 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Ùqn‚nX|sêPn|jdƒ}|dkr;|d7}|j|| ƒ|jj||ƒ~Pn|j|ƒqW|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„RRlRNRLR>RŒR|R&RERRxtfindR( RSRR’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 readliness   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ŠRR˜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(scConnect 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. A 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’    L  $                        ,    ÿ-