o bc}@sTdZddlZddlTddlZddlZddlZddlZddlmZmZzddl Z Wn e y3dZ Ynwe e ddZ e e ddZ e e d dZgd Zeeeed ed d ededd ededd ededd dZdZddZejdr iZded<ded<ded<ded <d!ed"<d#ed$<d%ed&<d'ed(<d)ed*<d+ed,<d-ed.<d/ed0<d1ed2<d3ed4<d5ed6<d7ed8<d9ed:<d;ed<<d=ed><d?ed@<dAedB<dCedD<dEedF<dGedH<dIedJ<dKedL<dMedN<dOedP<dQedR<dSedT<dUedV<dWedX<dYedZ<d[ed\<d]ed^<d_ed`<daedb<dcedd<deedf<dgedh<diedj<dkedl<dmedn<doedp<dqedr<dsedt<duedv<dwedx<dyedz<d{ed|<d}ed~<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<edաGddׄdeZGddلdejZdddۄZe ejd܃r5ddl!Z!dddބZ"edޡe ejd߃rJddl!Z!dddZ#ede ejdrZddZ$ede edride%dfddZ&n e'e%dfddZ&edde&_e ehZ(Gdddej)Z*dddZ+e,Z-e-dfddZ.ddZ/e'ddddddZ0dddZ1dS)aThis 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 [*] send_fds() -- Send file descriptor to the socket. recv_fds() -- Recieve file descriptors from the socket. fromshare() -- create a socket object from data received from socket.share() [*] 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) 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 IntEnum constants: AF_INET, AF_UNIX -- socket domains (first argument to socket() call) SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- socket types (second argument) Integer constants: Many other constants may be defined; these may be used in calls to the setsockopt() and getsockopt() methods. N)*)IntEnumIntFlagEBADF EAGAIN EWOULDBLOCK)fromfdgetfqdncreate_connection create_serverhas_dualstack_ipv6 AddressFamily SocketKindrcC|o|dS)NZAF_isupper startswithCrg/home/lily/lilypond-2.24.1/release/binaries/dependencies/install/Python-3.10.8/lib/python3.10/socket.pyNrrcCr)NZSOCK_rrrrrrSrZMsgFlagcCr)NZMSG_rrrrrrXrZ AddressInfocCr)NZAI_rrrrrr]rz 127.0.0.1z::1cCs"z||WSty|YSw)z{Convert a numeric family value to an IntEnum member. If it's not a known member, return the numeric value itself. ) ValueError)value enum_klassrrr_intenum_convertercs   rwinz)Specified event object handle is invalid.zInsufficient memory available.z#One or more parameters are invalid.WzOverlapped operation aborted.iz2Overlapped I/O event object not in signaled state.iz)Overlapped operation will complete later.izThe 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&'zToo many open files.i('z The socket operation would blocki3'z,A blocking operation is already in progress.i4'zOperation already in progress.i5'zSocket operation on nonsocket.i6'zDestination address required.i7'zMessage too long.i8'zProtocol wrong type for socket.i9'zBad protocol option.i:'zProtocol not supported.i;'zSocket type not supported.i<'zOperation not supported.i='zProtocol family not supported.i>'z0Address family not supported by protocol family.i?'zThe network address is in use.i@'z Cannot assign requested address.iA'zNetwork is down.iB'zNetwork is unreachable.iC'z$Network dropped connection on reset.iD'z!Software caused connection abort.iE'zThe connection has been reset.iF'zNo buffer space available.iG'zSocket is already connected.iH'zSocket is not connected.iI'zThe network has been shut down.iJ'zToo many references.iK'zThe operation timed out.iL'zConnection refused.iM'zCannot translate name.iN'zThe name is too long.iO'zThe host is down.iP'zThe host is unreachable.iQ'zDirectory not empty.iR'zToo many processes.iS'zUser quota exceeded.iT'zDisk quota exceeded.iU'zStale file handle reference.iV'zItem is remote.iW'z!Network subsystem is unavailable.ik'z!Winsock.dll version out of range.il'z(Successful WSAStartup not yet performed.im'zGraceful shutdown in progress.iu'z*No more results from WSALookupServiceNext.iv'zCall has been canceled.iw'z Procedure call table is invalid.ix'zService provider is invalid.iy'z&Service provider failed to initialize.iz'zSystem call failure.i{'zService not found.i|'zClass type not found.i}'i~'zCall was canceled.i'zDatabase query was refused.i'zHost not found.i*z Nonauthoritative host not found.i*zThis is a nonrecoverable error.i*z*Valid name, no data record requested type.i*zQoS receivers.i*z QoS senders.i*zNo QoS senders.i*zQoS no receivers.i+zQoS request confirmed.i+zQoS admission error.i+zQoS policy failure.i+zQoS bad style.i+zQoS bad object.i+zQoS traffic control error.i+zQoS generic error.i+zQoS service type error.i+zQoS flowspec error.i +zInvalid QoS provider buffer.i +zInvalid QoS filter style.i +i +zIncorrect QoS filter count.i +zInvalid QoS object length.i+zIncorrect QoS flow count.i+zUnrecognized QoS object.i+zInvalid QoS policy object.i+zInvalid QoS flow descriptor.i+z'Invalid QoS provider-specific flowspec.i+z)Invalid QoS provider-specific filterspec.i+z&Invalid QoS shape discard mode object.i+z Invalid QoS shaping rate object.i+z!Reserved policy QoS element type.i+errorTabc@s eZdZdS)_GiveupOnSendfileN)__name__ __module__ __qualname__rrrrr$s r$cs(eZdZdZgdZd7ddZddZd d Zd d Zd dZ ddZ ddZ d8ddddddZ e edr) getattr __class__r&r'r5r2r3r4 getsocknamestrerrorZ getpeername)r1closedsZladdrZraddrrrr__repr__s<    zsocket.__repr__cCstd|jjd)Nzcannot pickle z object) TypeErrorr?r%r7rrr __getstate__zsocket.__getstate__cCs6t|}|j|j|j|j|d}|||S)zdup() -> socket object Duplicate the socket. Return a new socket object connected to the same system resource. The new socket is non-inheritable. r5)dupr5r?r2r3r4 settimeout gettimeout)r1fdsockrrrrJs z socket.dupcCsF|\}}t|j|j|j|d}tdur|r|d||fS)zaccept() -> (socket object, address info) Wait for an incoming connection. Return a new socket representing the connection, and the address of the client. For IP sockets, the address info is a pair (hostaddr, port). rINT)Z_acceptr(r2r3r4ZgetdefaulttimeoutrL setblocking)r1rMaddrrNrrraccepts  z socket.acceptr)encodingerrorsnewlinec Cst|hdkstd|fd|v}d|vp| }|s |s Jd|v}d} |r,| d7} |r2| d7} t|| } |jd7_|durDd }|d krKtj}|d krW|sUtd | S|rc|rct| | |} n|rlt| |} n |spJt| |} |rz| St |}t | |||} || _ | S) zmakefile(...) -> an I/O stream connected to the socket The arguments are as for io.open() after the filename, except the only supported mode values are 'r' (default), 'w' and 'b'. >rRbwz&invalid mode %r (only r, w, b allowed)rWrRrVr<Nr,rz!unbuffered streams must be binary) setrSocketIOr*ioDEFAULT_BUFFER_SIZEBufferedRWPairBufferedReaderBufferedWriter text_encoding TextIOWrappermode) r1rb bufferingrSrTrUZwritingZreadingZbinaryZrawmoderawbuffertextrrrmakefile.sB    zsocket.makefilesendfilerc Cs|||||}z|}Wnttjfy$}zt|d}~wwzt|j}Wnt y=}zt|d}~ww|sBdSt |pF|d}| } | dkrUt dt tdr_t} nt} | |tjd} | j} tj} ze | r~| | s~td|r|| }|dkrnrr3r. isinstanceintrFformatrrrrrls  zsocket._check_sendfile_paramscCs2z||||WSty||||YSw)a_sendfile(file[, offset[, count]]) -> sent Send a file until EOF is reached by using high-performance os.sendfile() and return the total number of bytes which were sent. *file* must be a regular file object opened in binary mode. If os.sendfile() is not available (e.g. Windows) or file is not a regular file socket.send() will be used instead. *offset* tells from where to start reading the file. If specified, *count* is the total number of bytes to transmit as opposed to sending the file until EOF is reached. File position is updated on return or also in case of error in which case file.tell() can be used to figure out the number of bytes which were sent. The socket must be of SOCK_STREAM type. Non-blocking sockets are not supported. )rr$rrrrrrhs  zsocket.sendfilecCs.|jdkr |jd8_|jr|dSdS)NrrX)r*r+r9r7rrr_decref_socketioss  zsocket._decref_socketioscCs||dSr6)r9)r1Z_ssrrr _real_closeszsocket._real_closecCs d|_|jdkr|dSdS)NTr)r+r*rr7rrrr9s  z socket.closecsd|_tS)a detach() -> file descriptor Close the socket object without closing the underlying file descriptor. The object cannot be used after this call, but the file descriptor can be reused for other purposes. The file descriptor is returned. T)r+superdetachr7r?rrrs z socket.detachcttjtS)z@Read-only access to the address family for this socket. )rrr2rr7rrrr2z socket.familycr)z-Read-only access to the socket type. )rrr3rr7rrrr3rz socket.typentcCt|Sr6)roZget_handle_inheritabler5r7rrrget_inheritablezsocket.get_inheritablecCt||dSr6)roZset_handle_inheritabler5r1 inheritablerrrset_inheritablerHzsocket.set_inheritablecCrr6)rorr5r7rrrrrcCrr6)rorr5rrrrrrHz&Get the inheritable flag of the socketz&Set the inheritable flag of the socket)r,r,r,N)rRNrN) r%r&r'__doc__ __slots__r0r8r;rErGrJrQrgrtrorrrlrhrr/r(rr9rpropertyr2r3namerr __classcell__rrrrr(sD   +  A $     r(cCst|}t||||S)z fromfd(fd, family, type[, proto]) -> socket object Create a socket object from a duplicate of the given file descriptor. The remaining arguments are the same as for socket(). )rJr()rMr2r3r4Znfdrrrr sr sendmsgc Cs ||tjtjtd|fgS)z send_fds(sock, buffers, fds[, flags[, address]]) -> integer Send the list of file descriptors fds over an AF_UNIX socket. i)rr/ SOL_SOCKET SCM_RIGHTSarray)rNbuffersfdsflagsaddressrrrsend_fds's rrecvmsgc Cstd}||t||j\}}}}|D]!\}} } |tjkr8| tjkr8|| dt| t| |jq|t |||fS)z recv_fds(sock, bufsize, maxfds[, flags]) -> (data, list of file descriptors, msg_flags, address) Receive up to maxfds file descriptors returning the message data and a list containing the descriptors. rN) rrr/CMSG_LENitemsizerr frombytesrlist) rNbufsizeZmaxfdsrrmsgancdatarP cmsg_level cmsg_type cmsg_datarrrrecv_fds3s  rZsharecCstddd|S)z fromshare(info) -> socket object Create a socket object from the bytes object returned by socket.share(pid). r)r()inforrr fromshareGsr socketpaircCsf|durzt}Wn tyt}Ynwt|||\}}t||||}t||||}||fS)aasocketpair([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. N)AF_UNIX NameErrorr-r/rr(r)r2r3r4arVrrrrRs c Cs|tkrt}n |tkrt}ntd|tkrtd|dkr"tdt|||}zT||df|| dd\}}t|||}z'| dz | ||fWn t t fy^Ynw| d|\}} Wn|W|||fS|w)Nz?Only AF_INET and AF_INET6 socket address families are supportedz)Only SOCK_STREAM socket type is supportedrzOnly protocol zero is supportedFT)r- _LOCALHOSTAF_INET6 _LOCALHOST_V6rr.r(bindlistenr@rOconnectrxInterruptedErrorrQr9) r2r3r4hostZlsockrPportZcsockZssock_rrrrgs>     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. cspeZdZdZddZddZddZdd Zd d Zfd d Z ddZ e ddZ e ddZ ddZZS)rZzRaw I/O implementation for stream sockets. This class supports the makefile() method on sockets. It provides the raw I/O interface on top of a socket object. cCsZ|dvr td|tj|||_d|vr|d7}||_d|v|_d|v|_d|_dS)N)rRrWrwrbwbZrwbzinvalid mode: %rrVrRrWF) rr[ RawIOBaser0_sock_mode_reading_writing_timeout_occurred)r1rNrbrrrr0s     zSocketIO.__init__c Csv|||jrtd z|j|WSty"d|_ty:}z |jt vr5WYd}~dSd}~ww)a3Read up to len(b) bytes into the writable buffer *b* and return the number of bytes read. If the socket is non-blocking and no bytes are available, None is returned. If *b* is non-empty, a 0 return value indicates that the connection was shutdown at the other end. z!cannot read from timed out objectTN) _checkClosed_checkReadablerrrrZ recv_intor~rBerrno_blocking_errnosr1rVerrrreadintos   zSocketIO.readintoc CsR||z|j|WSty(}z |jtvr#WYd}~dSd}~ww)aWrite the given bytes or bytearray object *b* to the socket and return the number of bytes written. This can be less than len(b) if not all data could be written. If the socket is non-blocking and no bytes could be written None is returned. N)r_checkWritablerrrBrrrrrrwrites zSocketIO.writecC|jrtd|jS)z2True if the SocketIO is open for reading. I/O operation on closed socket.)rCrrr7rrrreadablezSocketIO.readablecCr)z2True if the SocketIO is open for writing. r)rCrrr7rrrwritablerzSocketIO.writablecs|jrtdtS)z2True if the SocketIO is open for seeking. r)rCrrseekabler7rrrrs zSocketIO.seekablecCs||jS)z=Return the file descriptor of the underlying socket. )rrr5r7rrrr5s zSocketIO.filenocCs|js|SdS)Nr,)rCr5r7rrrrsz SocketIO.namecCs|jSr6)rr7rrrrbsz SocketIO.modecCs*|jrdStj||jd|_dS)zClose the SocketIO object. This doesn't close the underlying socket, except if all references to it have disappeared. N)rCr[rr9rrr7rrrr9s    zSocketIO.close)r%r&r'rr0rrrrrr5rrrbr9rrrrrrZs    rZr<cCsn|}|r |dkr t}z t|\}}}Wn ty Y|Sw|d||D] }d|vr2|Sq)|}|S)atGet 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 and `name` was given, it is returned unchanged. If `name` was empty or '0.0.0.0', hostname from gethostname() is returned. z0.0.0.0r.)stripZ gethostnameZ gethostbyaddrrBinsert)rhostnamealiasesZipaddrsrrrr s"   r c Cs|\}}d}t||dtD]I}|\}}} } } d} z"t||| } |tur(| ||r/| || | d}| WStyV} z| }| durL| WYd} ~ q d} ~ ww|duraz|d}wtd)acConnect 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. Nrz!getaddrinfo returns an empty list) getaddrinfor.r(_GLOBAL_DEFAULT_TIMEOUTrKrrrBr9)rr~Zsource_addressrrr|resafsocktyper4 canonnamesarNrrrrr (s2     r cCsvtr ttdr ttdsdSz"ttt}|ttd WdWdS1s)wYWdSt y:YdSw)zReturn True if the platform supports creating a SOCK_STREAM socket which can handle both AF_INET and AF_INET6 (IPv4 / IPv6) connections. IPPROTO_IPV6 IPV6_V6ONLYFrNT) has_ipv6rtr/r(rr. setsockoptrrrB)rNrrrrUs ( rF)r2backlog reuse_portdualstack_ipv6c CsT|r ttds td|rtstd|tkrtdt|t}z|tjdvr?ttdr?z | t t dWn t y>Ynw|rH| t t dtri|tkri|rX| ttdnttd rittd ri| ttdz||Wnt y}zd |j|f}t |j|d d }~ww|d ur||WS|||WSt y|w) aConvenience function which creates a SOCK_STREAM type socket bound to *address* (a 2-tuple (host, port)) and return the socket object. *family* should be either AF_INET or AF_INET6. *backlog* is the queue size passed to socket.listen(). *reuse_port* dictates whether to use the SO_REUSEPORT socket option. *dualstack_ipv6*: if true and the platform supports it, it will create an AF_INET6 socket able to accept both IPv4 or IPv6 connections. When false it will explicitly disable this option on platforms that enable it by default (e.g. Linux). >>> with create_server(('', 8000)) as server: ... while True: ... conn, addr = server.accept() ... # handle new connection SO_REUSEPORTz+SO_REUSEPORT not supported on this platformz-dualstack_ipv6 not supported on this platformz'dualstack_ipv6 requires AF_INET6 family)rcygwin SO_REUSEADDRrXrrrz+%s (while attempting to bind on address %r)N)rtr/rrrr(r.rorrrrrBrrrrrstrerrorrrr9)rr2rrrrNr|rrrrr esX       r c CsPg}t||||||D]}|\}} }} } |t|tt| t|| | fq |S)aResolve host and port into list of address info entries. Translate the host/port argument into a sequence of 5-tuples that contain all the necessary arguments for creating a socket connected to that service. host is a domain name, a string representation of an IPv4/v6 address or None. port is a string service name such as 'http', a numeric port number or None. By passing None as the value of host and port, you can pass NULL to the underlying C API. The family, type and proto arguments can be optionally specified in order to narrow the list of addresses returned. Passing zero as a value for each of these arguments selects the full range of results. )r/rappendrrr) rrr2r3r4rZaddrlistrrrrrrrrrs r)rr)r<)rrrr)2rr/rosysr[ruenumrrr ImportErrorr>rrr __all__extend_get_exports_list _convert_r%rrrplatformlowerrr#r Exceptionr$r(r rtrrrrr.rr-rrrZr objectrr rr rrrrrsR/         G        $ u - E