3 \3k @slddlZddlTddlZddlZddlZddlZddlmZmZy ddlZWne k rddZYnXe eddZ e eddZ e eddZ d d d d d gZejejeejd eddejd eddejdeddejdedddZdZddZeZejjjdriZded<ded<ded<d ed!<d"ed#<d$ed%<d&ed'<d(ed)<d*ed+<d,ed-<d.ed/<d0ed1<d2ed3<d4ed5<d6ed7<ejd8Gd9d:d:eZGd;d<drd?d@Z!ejd@e edArde"dfdBdAZ#ne$e"dfdCdAZ#ejdAdDe#_%e e hZ&GdEdFdFej'Z(dMdHd Z)e*Z+e+dfdId Z,dNdJdKZ-dS)ON)*)IntEnumIntFlagEBADF EAGAIN EWOULDBLOCKfromfdgetfqdncreate_connection AddressFamily SocketKindcCs|jo|jdS)NZAF_)isupper startswith)Cr/usr/lib64/python3.6/socket.pyLsrcCs|jo|jdS)NZSOCK_)rr)rrrrrQsZMsgFlagcCs|jo|jdS)NZMSG_)rr)rrrrrVsZ AddressInfocCs|jo|jdS)NZAI_)rr)rrrrr[sz 127.0.0.1z::1c Cs"y||Stk r|SXdS)N) ValueError)valueZ enum_klassrrr_intenum_converterasrwinzThe operation was interrupted.i'zA bad file handle was passed.i'zPermission denied.i'z!A fault occurred on the network??i'z#An invalid operation was attempted.i&'z The socket operation would blocki3'z,A blocking operation is already in progress.i4'zThe network address is in use.i@'zThe connection has been reset.iF'zThe network has been shut down.iJ'zThe operation timed out.iL'zConnection refused.iM'zThe name is too long.iO'zThe host is down.iP'zThe host is unreachable.iQ'errorTabc@s eZdZdS)_GiveupOnSendfileN)__name__ __module__ __qualname__rrrrrsrcs0eZdZdddgZeeddfddZdd Zd d Zd d Z ddZ ddZ ddZ d7ddddddZ eedr~d8ddZn d9ddZd:ddZddZd;d d!Zd"d#Zejfd$d%Zd&d'Zfd(d)Zefd*d+Zefd,d-Zejd.kr d/d0Zd1d2Znd3d0Zd4d2Zd5e_ d6e_ Z!S)<socket __weakref___io_refs_closedrNcCs$tjj|||||d|_d|_dS)NrF)_socketr__init__r r!)selffamilytypeprotofilenorrrr#szsocket.__init__cCs|S)Nr)r$rrr __enter__szsocket.__enter__cGs|js|jdS)N)r!close)r$argsrrr__exit__szsocket.__exit__cCst|dd}d|jj|jj|r"dnd|j|j|j|jf}|sy |j}|r^|dt |7}Wnt k rtYnXy |j }|r|dt |7}Wnt k rYnX|d7}|S) Nr!Fz,<%s.%s%s fd=%i, family=%s, type=%s, proto=%iz [closed]z , laddr=%sz , raddr=%s>) getattr __class__rrr(r%r&r' getsocknamestrerrorZ getpeername)r$closedsZladdrZraddrrrr__repr__s0   zsocket.__repr__cCs tddS)NzCannot serialize socket object) TypeError)r$rrr __getstate__szsocket.__getstate__cCs6t|j}|j|j|j|j|d}|j|j|S)N)r()dupr(r0r%r&r' settimeout gettimeout)r$fdsockrrrr9s z socket.dupcCsZ|j\}}|jtjdd@}t|j||j|d}tdkrR|jrR|j d||fS)NZ SOCK_NONBLOCKr)r(T) Z_acceptr&globalsgetrr%r'Zgetdefaulttimeoutr; setblocking)r$r<addrr&r=rrraccepts   z socket.acceptr)encodingerrorsnewlinec Cst|dddhks td|fd|k}d|kp4| }d|k}d} |rN| d7} |rZ| d7} t|| } |jd7_|dkr~d }|dkrtj}|dkr|std| S|r|rtj| | |} n|rtj| |} n tj| |} |r| Stj | |||} || _ | S) NrCwbz&invalid mode %r (only r, w, b allowed)r-rz!unbuffered streams must be binary) setrSocketIOr ioDEFAULT_BUFFER_SIZEBufferedRWPairBufferedReaderBufferedWriter TextIOWrappermode) r$rS bufferingrDrErFZwritingZreadingZbinaryZrawmoderawbuffertextrrrmakefiles<  zsocket.makefilesendfilec2Cs|j||||j}y |j}Wn0ttjfk rR}zt|WYdd}~XnXytj|j}Wn*t k r}zt|WYdd}~XnX|sdS|s|n|}|j } | dkrt dt t drt j} nt j} | j|t jd} | j} tj} zx| r| |  rtjd|r0|| }|dkr0Py| ||||}Wn^tk rf| s`| wYqt k r}z| dkrt||dWYdd}~XqX|dkrP||7}| |7} qW| S| dkrt |dr|j|XdS)Nrz&non-blocking sockets are not supported PollSelectorz timed outseek)_check_sendfile_paramsr(AttributeErrorrMUnsupportedOperationrosfstatst_sizeOSErrorr;rhasattr selectorsrZZSelectSelectorregisterZ EVENT_WRITEZselectrYr"timeoutBlockingIOErrorr[)r$fileoffsetcountZsocknor(errZfsize blocksizerfZselector total_sentZselector_selectZ os_sendfilesentrrr_sendfile_use_sendfiles`         zsocket._sendfile_use_sendfilecCs tddS)Nz,os.sendfile() not available on this platform)r)r$rhrirjrrrroGsc Cs|j||||jdkr"td|r0|j||r>t|dnd}d}|j}|j}zx|rrt|||}|dkrrPt||}|sPxLy ||} Wntk rwYqX|| 7}| t |kr|| d}qPqWqVW|S|dkot |dr|j||XdS)Nrz&non-blocking sockets are not supportedi r[) r\r;rr[minreadsend memoryviewrglenrc) r$rhrirjrlrmZ file_readZ sock_senddatarnrrr_sendfile_use_sendKs<      zsocket._sendfile_use_sendcCsddt|ddkrtd|jt@s*td|dk r`t|tsJtdj||dkr`tdj|dS)NrHrSz$file should be opened in binary modez+only SOCK_STREAM type sockets are supportedz+count must be a positive integer (got {!r})r)r/rr& SOCK_STREAM isinstanceintr7format)r$rhrirjrrrr\os   zsocket._check_sendfile_paramsc Cs2y|j|||Stk r,|j|||SXdS)N)rorrv)r$rhrirjrrrrY|szsocket.sendfilecCs*|jdkr|jd8_|jr&|jdS)NrrI)r r!r*)r$rrr_decref_socketioss zsocket._decref_socketioscCs|j|dS)N)r*)r$Z_ssrrr _real_closeszsocket._real_closecCsd|_|jdkr|jdS)NTr)r!r r|)r$rrrr*s z socket.closecsd|_tjS)NT)r!superdetach)r$)r0rrr~sz socket.detachcsttjtS)N)rr}r%r )r$)r0rrr%sz socket.familycsttjtS)N)rr}r&r)r$)r0rrr&sz socket.typentcCstj|jS)N)r_Zget_handle_inheritabler()r$rrrget_inheritableszsocket.get_inheritablecCstj|j|dS)N)r_Zset_handle_inheritabler()r$ inheritablerrrset_inheritableszsocket.set_inheritablecCstj|jS)N)r_rr()r$rrrrscCstj|j|dS)N)r_rr()r$rrrrrsz&Get the inheritable flag of the socketz&Set the inheritable flag of the socket)rCN)rN)rN)rN)rN)"rrr __slots__AF_INETrwr#r)r,r6r8r9rBrXrcr_rorvr\rYr{r"rr|r*r~propertyr%r&namerr__doc__ __classcell__rr)r0rrs:   )  A  $    rcCst|}t||||S)N)r9r)r<r%r&r'Znfdrrrr sZsharecCstddd|S)Nr)r)inforrr fromsharesr socketpairc Csh|dkr*yt}Wntk r(t}YnXtj|||\}}t||||j}t||||j}||fS)N)ZAF_UNIX NameErrorrr"rrr~)r%r&r'arHrrrrs c Cs|tkrt}n|tkrt}ntd|tkr4td|dkrDtdt|||}z|j|df|j|j dd\}}t|||}yP|j dy|j ||fWnt t fk rYnX|j d|j\}} Wn|jYnXWd|jX||fS)Nz?Only AF_INET and AF_INET6 socket address families are supportedz)Only SOCK_STREAM socket type is supportedrzOnly protocol zero is supportedFT)r _LOCALHOSTZAF_INET6 _LOCALHOST_V6rrwrbindZlistenr1r@connectrgInterruptedErrorrBr*) r%r&r'hostZlsockrAportZcsockZssock_rrrrs8      a8socketpair([family[, type[, proto]]]) -> (socket object, socket object) Create a pair of socket objects from the sockets returned by the platform socketpair() function. The arguments are the same as for socket() except the default family is AF_UNIX if defined on the platform; otherwise, the default is AF_INET. csleZdZddZddZddZddZd d Zfd d Zd dZ e ddZ e ddZ ddZ ZS)rLcCsZ|d krtd|tjj|||_d|kr6|d7}||_d|k|_d|k|_d |_dS) NrCrGrwrbwbrwbzinvalid mode: %rrHF)rCrGrrrr) rrM RawIOBaser#_sock_mode_reading_writing_timeout_occurred)r$r=rSrrrr#0s    zSocketIO.__init__cCs|j|j|jrtdxby |jj|Stk rHd|_Yq tk r|}z|jdt krjdSWYdd}~Xq Xq WdS)Nz!cannot read from timed out objectTr) _checkClosed_checkReadablerrbrZ recv_intorfr3r+_blocking_errnos)r$rHerrrreadinto<s zSocketIO.readintocCsX|j|jy |jj|Stk rR}z|jdtkr@dSWYdd}~XnXdS)Nr)r_checkWritablerrrr3r+r)r$rHrrrrwriteSs zSocketIO.writecCs|jrtd|jS)NzI/O operation on closed socket.)r4rr)r$rrrreadablecszSocketIO.readablecCs|jrtd|jS)NzI/O operation on closed socket.)r4rr)r$rrrwritablejszSocketIO.writablecs|jrtdtjS)NzI/O operation on closed socket.)r4rr}seekable)r$)r0rrrqszSocketIO.seekablecCs|j|jjS)N)rrr()r$rrrr(xszSocketIO.filenocCs|js|jSdSdS)NrIrJ)r4r()r$rrrr~sz SocketIO.namecCs|jS)N)r)r$rrrrSsz SocketIO.modecCs*|jr dStjj||jjd|_dS)N)r4rMrr*rr{)r$rrrr*s   zSocketIO.close)rrrr#rrrrrr(rrrSr*rrr)r0rrLs    rLr-c Csp|j}| s|dkrt}yt|\}}}Wntk rBYn*X|jd|x|D]}d|krVPqVW|}|S)Nz0.0.0.0r.)stripZ gethostnameZ gethostbyaddrr3insert)rZhostnamealiasesZipaddrsrrrr s   cCs|\}}d}xt||dtD]}|\}}} } } d} y>t||| } |tk rR| j||r`| j|| j| d}| Stk r} z| }| dk r| jWYdd} ~ XqXqW|dk r|ntddS)Nrz!getaddrinfo returns an empty list) getaddrinforwr_GLOBAL_DEFAULT_TIMEOUTr:rrr3r*)ZaddressrfZsource_addressrrrkresafsocktyper' canonnamesar=rrrrr s*    c CsTg}xJtj||||||D]2}|\}} }} } |jt|tt| t|| | fqW|S)N)r"rappendrr r) rrr%r&r'flagsZaddrlistrrrrrrrrrs r)r)r-)rrrr).r"r_sysrMrdenumrrerrno ImportErrorr/rrr __all__extend_get_exports_list_convertrrrrrZ _realsocketplatformlowerrrr Exceptionrr rcrrwrrrrrrLr objectrr rrrrr1s            C   $ u  '