Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../proc/self/root/lib64/python3....
File: socket.py
# Wrapper module for _socket, providing some additional facilities
[0] Fix | Delete
# implemented in Python.
[1] Fix | Delete
[2] Fix | Delete
"""\
[3] Fix | Delete
This module provides socket operations and some related functions.
[4] Fix | Delete
On Unix, it supports IP (Internet Protocol) and Unix domain sockets.
[5] Fix | Delete
On other systems, it only supports IP. Functions specific for a
[6] Fix | Delete
socket are available as methods of the socket object.
[7] Fix | Delete
[8] Fix | Delete
Functions:
[9] Fix | Delete
[10] Fix | Delete
socket() -- create a new socket object
[11] Fix | Delete
socketpair() -- create a pair of new socket objects [*]
[12] Fix | Delete
fromfd() -- create a socket object from an open file descriptor [*]
[13] Fix | Delete
fromshare() -- create a socket object from data received from socket.share() [*]
[14] Fix | Delete
gethostname() -- return the current hostname
[15] Fix | Delete
gethostbyname() -- map a hostname to its IP number
[16] Fix | Delete
gethostbyaddr() -- map an IP number or hostname to DNS info
[17] Fix | Delete
getservbyname() -- map a service name and a protocol name to a port number
[18] Fix | Delete
getprotobyname() -- map a protocol name (e.g. 'tcp') to a number
[19] Fix | Delete
ntohs(), ntohl() -- convert 16, 32 bit int from network to host byte order
[20] Fix | Delete
htons(), htonl() -- convert 16, 32 bit int from host to network byte order
[21] Fix | Delete
inet_aton() -- convert IP addr string (123.45.67.89) to 32-bit packed format
[22] Fix | Delete
inet_ntoa() -- convert 32-bit packed format IP to string (123.45.67.89)
[23] Fix | Delete
socket.getdefaulttimeout() -- get the default timeout value
[24] Fix | Delete
socket.setdefaulttimeout() -- set the default timeout value
[25] Fix | Delete
create_connection() -- connects to an address, with an optional timeout and
[26] Fix | Delete
optional source address.
[27] Fix | Delete
[28] Fix | Delete
[*] not available on all platforms!
[29] Fix | Delete
[30] Fix | Delete
Special objects:
[31] Fix | Delete
[32] Fix | Delete
SocketType -- type object for socket objects
[33] Fix | Delete
error -- exception raised for I/O errors
[34] Fix | Delete
has_ipv6 -- boolean value indicating if IPv6 is supported
[35] Fix | Delete
[36] Fix | Delete
IntEnum constants:
[37] Fix | Delete
[38] Fix | Delete
AF_INET, AF_UNIX -- socket domains (first argument to socket() call)
[39] Fix | Delete
SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- socket types (second argument)
[40] Fix | Delete
[41] Fix | Delete
Integer constants:
[42] Fix | Delete
[43] Fix | Delete
Many other constants may be defined; these may be used in calls to
[44] Fix | Delete
the setsockopt() and getsockopt() methods.
[45] Fix | Delete
"""
[46] Fix | Delete
[47] Fix | Delete
import _socket
[48] Fix | Delete
from _socket import *
[49] Fix | Delete
[50] Fix | Delete
import os, sys, io, selectors
[51] Fix | Delete
from enum import IntEnum, IntFlag
[52] Fix | Delete
[53] Fix | Delete
try:
[54] Fix | Delete
import errno
[55] Fix | Delete
except ImportError:
[56] Fix | Delete
errno = None
[57] Fix | Delete
EBADF = getattr(errno, 'EBADF', 9)
[58] Fix | Delete
EAGAIN = getattr(errno, 'EAGAIN', 11)
[59] Fix | Delete
EWOULDBLOCK = getattr(errno, 'EWOULDBLOCK', 11)
[60] Fix | Delete
[61] Fix | Delete
__all__ = ["fromfd", "getfqdn", "create_connection",
[62] Fix | Delete
"AddressFamily", "SocketKind"]
[63] Fix | Delete
__all__.extend(os._get_exports_list(_socket))
[64] Fix | Delete
[65] Fix | Delete
# Set up the socket.AF_* socket.SOCK_* constants as members of IntEnums for
[66] Fix | Delete
# nicer string representations.
[67] Fix | Delete
# Note that _socket only knows about the integer values. The public interface
[68] Fix | Delete
# in this module understands the enums and translates them back from integers
[69] Fix | Delete
# where needed (e.g. .family property of a socket object).
[70] Fix | Delete
[71] Fix | Delete
IntEnum._convert(
[72] Fix | Delete
'AddressFamily',
[73] Fix | Delete
__name__,
[74] Fix | Delete
lambda C: C.isupper() and C.startswith('AF_'))
[75] Fix | Delete
[76] Fix | Delete
IntEnum._convert(
[77] Fix | Delete
'SocketKind',
[78] Fix | Delete
__name__,
[79] Fix | Delete
lambda C: C.isupper() and C.startswith('SOCK_'))
[80] Fix | Delete
[81] Fix | Delete
IntFlag._convert(
[82] Fix | Delete
'MsgFlag',
[83] Fix | Delete
__name__,
[84] Fix | Delete
lambda C: C.isupper() and C.startswith('MSG_'))
[85] Fix | Delete
[86] Fix | Delete
IntFlag._convert(
[87] Fix | Delete
'AddressInfo',
[88] Fix | Delete
__name__,
[89] Fix | Delete
lambda C: C.isupper() and C.startswith('AI_'))
[90] Fix | Delete
[91] Fix | Delete
_LOCALHOST = '127.0.0.1'
[92] Fix | Delete
_LOCALHOST_V6 = '::1'
[93] Fix | Delete
[94] Fix | Delete
[95] Fix | Delete
def _intenum_converter(value, enum_klass):
[96] Fix | Delete
"""Convert a numeric family value to an IntEnum member.
[97] Fix | Delete
[98] Fix | Delete
If it's not a known member, return the numeric value itself.
[99] Fix | Delete
"""
[100] Fix | Delete
try:
[101] Fix | Delete
return enum_klass(value)
[102] Fix | Delete
except ValueError:
[103] Fix | Delete
return value
[104] Fix | Delete
[105] Fix | Delete
_realsocket = socket
[106] Fix | Delete
[107] Fix | Delete
# WSA error codes
[108] Fix | Delete
if sys.platform.lower().startswith("win"):
[109] Fix | Delete
errorTab = {}
[110] Fix | Delete
errorTab[10004] = "The operation was interrupted."
[111] Fix | Delete
errorTab[10009] = "A bad file handle was passed."
[112] Fix | Delete
errorTab[10013] = "Permission denied."
[113] Fix | Delete
errorTab[10014] = "A fault occurred on the network??" # WSAEFAULT
[114] Fix | Delete
errorTab[10022] = "An invalid operation was attempted."
[115] Fix | Delete
errorTab[10035] = "The socket operation would block"
[116] Fix | Delete
errorTab[10036] = "A blocking operation is already in progress."
[117] Fix | Delete
errorTab[10048] = "The network address is in use."
[118] Fix | Delete
errorTab[10054] = "The connection has been reset."
[119] Fix | Delete
errorTab[10058] = "The network has been shut down."
[120] Fix | Delete
errorTab[10060] = "The operation timed out."
[121] Fix | Delete
errorTab[10061] = "Connection refused."
[122] Fix | Delete
errorTab[10063] = "The name is too long."
[123] Fix | Delete
errorTab[10064] = "The host is down."
[124] Fix | Delete
errorTab[10065] = "The host is unreachable."
[125] Fix | Delete
__all__.append("errorTab")
[126] Fix | Delete
[127] Fix | Delete
[128] Fix | Delete
class _GiveupOnSendfile(Exception): pass
[129] Fix | Delete
[130] Fix | Delete
[131] Fix | Delete
class socket(_socket.socket):
[132] Fix | Delete
[133] Fix | Delete
"""A subclass of _socket.socket adding the makefile() method."""
[134] Fix | Delete
[135] Fix | Delete
__slots__ = ["__weakref__", "_io_refs", "_closed"]
[136] Fix | Delete
[137] Fix | Delete
def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None):
[138] Fix | Delete
# For user code address family and type values are IntEnum members, but
[139] Fix | Delete
# for the underlying _socket.socket they're just integers. The
[140] Fix | Delete
# constructor of _socket.socket converts the given argument to an
[141] Fix | Delete
# integer automatically.
[142] Fix | Delete
_socket.socket.__init__(self, family, type, proto, fileno)
[143] Fix | Delete
self._io_refs = 0
[144] Fix | Delete
self._closed = False
[145] Fix | Delete
[146] Fix | Delete
def __enter__(self):
[147] Fix | Delete
return self
[148] Fix | Delete
[149] Fix | Delete
def __exit__(self, *args):
[150] Fix | Delete
if not self._closed:
[151] Fix | Delete
self.close()
[152] Fix | Delete
[153] Fix | Delete
def __repr__(self):
[154] Fix | Delete
"""Wrap __repr__() to reveal the real class name and socket
[155] Fix | Delete
address(es).
[156] Fix | Delete
"""
[157] Fix | Delete
closed = getattr(self, '_closed', False)
[158] Fix | Delete
s = "<%s.%s%s fd=%i, family=%s, type=%s, proto=%i" \
[159] Fix | Delete
% (self.__class__.__module__,
[160] Fix | Delete
self.__class__.__qualname__,
[161] Fix | Delete
" [closed]" if closed else "",
[162] Fix | Delete
self.fileno(),
[163] Fix | Delete
self.family,
[164] Fix | Delete
self.type,
[165] Fix | Delete
self.proto)
[166] Fix | Delete
if not closed:
[167] Fix | Delete
try:
[168] Fix | Delete
laddr = self.getsockname()
[169] Fix | Delete
if laddr:
[170] Fix | Delete
s += ", laddr=%s" % str(laddr)
[171] Fix | Delete
except error:
[172] Fix | Delete
pass
[173] Fix | Delete
try:
[174] Fix | Delete
raddr = self.getpeername()
[175] Fix | Delete
if raddr:
[176] Fix | Delete
s += ", raddr=%s" % str(raddr)
[177] Fix | Delete
except error:
[178] Fix | Delete
pass
[179] Fix | Delete
s += '>'
[180] Fix | Delete
return s
[181] Fix | Delete
[182] Fix | Delete
def __getstate__(self):
[183] Fix | Delete
raise TypeError("Cannot serialize socket object")
[184] Fix | Delete
[185] Fix | Delete
def dup(self):
[186] Fix | Delete
"""dup() -> socket object
[187] Fix | Delete
[188] Fix | Delete
Duplicate the socket. Return a new socket object connected to the same
[189] Fix | Delete
system resource. The new socket is non-inheritable.
[190] Fix | Delete
"""
[191] Fix | Delete
fd = dup(self.fileno())
[192] Fix | Delete
sock = self.__class__(self.family, self.type, self.proto, fileno=fd)
[193] Fix | Delete
sock.settimeout(self.gettimeout())
[194] Fix | Delete
return sock
[195] Fix | Delete
[196] Fix | Delete
def accept(self):
[197] Fix | Delete
"""accept() -> (socket object, address info)
[198] Fix | Delete
[199] Fix | Delete
Wait for an incoming connection. Return a new socket
[200] Fix | Delete
representing the connection, and the address of the client.
[201] Fix | Delete
For IP sockets, the address info is a pair (hostaddr, port).
[202] Fix | Delete
"""
[203] Fix | Delete
fd, addr = self._accept()
[204] Fix | Delete
# If our type has the SOCK_NONBLOCK flag, we shouldn't pass it onto the
[205] Fix | Delete
# new socket. We do not currently allow passing SOCK_NONBLOCK to
[206] Fix | Delete
# accept4, so the returned socket is always blocking.
[207] Fix | Delete
type = self.type & ~globals().get("SOCK_NONBLOCK", 0)
[208] Fix | Delete
sock = socket(self.family, type, self.proto, fileno=fd)
[209] Fix | Delete
# Issue #7995: if no default timeout is set and the listening
[210] Fix | Delete
# socket had a (non-zero) timeout, force the new socket in blocking
[211] Fix | Delete
# mode to override platform-specific socket flags inheritance.
[212] Fix | Delete
if getdefaulttimeout() is None and self.gettimeout():
[213] Fix | Delete
sock.setblocking(True)
[214] Fix | Delete
return sock, addr
[215] Fix | Delete
[216] Fix | Delete
def makefile(self, mode="r", buffering=None, *,
[217] Fix | Delete
encoding=None, errors=None, newline=None):
[218] Fix | Delete
"""makefile(...) -> an I/O stream connected to the socket
[219] Fix | Delete
[220] Fix | Delete
The arguments are as for io.open() after the filename, except the only
[221] Fix | Delete
supported mode values are 'r' (default), 'w' and 'b'.
[222] Fix | Delete
"""
[223] Fix | Delete
# XXX refactor to share code?
[224] Fix | Delete
if not set(mode) <= {"r", "w", "b"}:
[225] Fix | Delete
raise ValueError("invalid mode %r (only r, w, b allowed)" % (mode,))
[226] Fix | Delete
writing = "w" in mode
[227] Fix | Delete
reading = "r" in mode or not writing
[228] Fix | Delete
assert reading or writing
[229] Fix | Delete
binary = "b" in mode
[230] Fix | Delete
rawmode = ""
[231] Fix | Delete
if reading:
[232] Fix | Delete
rawmode += "r"
[233] Fix | Delete
if writing:
[234] Fix | Delete
rawmode += "w"
[235] Fix | Delete
raw = SocketIO(self, rawmode)
[236] Fix | Delete
self._io_refs += 1
[237] Fix | Delete
if buffering is None:
[238] Fix | Delete
buffering = -1
[239] Fix | Delete
if buffering < 0:
[240] Fix | Delete
buffering = io.DEFAULT_BUFFER_SIZE
[241] Fix | Delete
if buffering == 0:
[242] Fix | Delete
if not binary:
[243] Fix | Delete
raise ValueError("unbuffered streams must be binary")
[244] Fix | Delete
return raw
[245] Fix | Delete
if reading and writing:
[246] Fix | Delete
buffer = io.BufferedRWPair(raw, raw, buffering)
[247] Fix | Delete
elif reading:
[248] Fix | Delete
buffer = io.BufferedReader(raw, buffering)
[249] Fix | Delete
else:
[250] Fix | Delete
assert writing
[251] Fix | Delete
buffer = io.BufferedWriter(raw, buffering)
[252] Fix | Delete
if binary:
[253] Fix | Delete
return buffer
[254] Fix | Delete
text = io.TextIOWrapper(buffer, encoding, errors, newline)
[255] Fix | Delete
text.mode = mode
[256] Fix | Delete
return text
[257] Fix | Delete
[258] Fix | Delete
if hasattr(os, 'sendfile'):
[259] Fix | Delete
[260] Fix | Delete
def _sendfile_use_sendfile(self, file, offset=0, count=None):
[261] Fix | Delete
self._check_sendfile_params(file, offset, count)
[262] Fix | Delete
sockno = self.fileno()
[263] Fix | Delete
try:
[264] Fix | Delete
fileno = file.fileno()
[265] Fix | Delete
except (AttributeError, io.UnsupportedOperation) as err:
[266] Fix | Delete
raise _GiveupOnSendfile(err) # not a regular file
[267] Fix | Delete
try:
[268] Fix | Delete
fsize = os.fstat(fileno).st_size
[269] Fix | Delete
except OSError as err:
[270] Fix | Delete
raise _GiveupOnSendfile(err) # not a regular file
[271] Fix | Delete
if not fsize:
[272] Fix | Delete
return 0 # empty file
[273] Fix | Delete
blocksize = fsize if not count else count
[274] Fix | Delete
[275] Fix | Delete
timeout = self.gettimeout()
[276] Fix | Delete
if timeout == 0:
[277] Fix | Delete
raise ValueError("non-blocking sockets are not supported")
[278] Fix | Delete
# poll/select have the advantage of not requiring any
[279] Fix | Delete
# extra file descriptor, contrarily to epoll/kqueue
[280] Fix | Delete
# (also, they require a single syscall).
[281] Fix | Delete
if hasattr(selectors, 'PollSelector'):
[282] Fix | Delete
selector = selectors.PollSelector()
[283] Fix | Delete
else:
[284] Fix | Delete
selector = selectors.SelectSelector()
[285] Fix | Delete
selector.register(sockno, selectors.EVENT_WRITE)
[286] Fix | Delete
[287] Fix | Delete
total_sent = 0
[288] Fix | Delete
# localize variable access to minimize overhead
[289] Fix | Delete
selector_select = selector.select
[290] Fix | Delete
os_sendfile = os.sendfile
[291] Fix | Delete
try:
[292] Fix | Delete
while True:
[293] Fix | Delete
if timeout and not selector_select(timeout):
[294] Fix | Delete
raise _socket.timeout('timed out')
[295] Fix | Delete
if count:
[296] Fix | Delete
blocksize = count - total_sent
[297] Fix | Delete
if blocksize <= 0:
[298] Fix | Delete
break
[299] Fix | Delete
try:
[300] Fix | Delete
sent = os_sendfile(sockno, fileno, offset, blocksize)
[301] Fix | Delete
except BlockingIOError:
[302] Fix | Delete
if not timeout:
[303] Fix | Delete
# Block until the socket is ready to send some
[304] Fix | Delete
# data; avoids hogging CPU resources.
[305] Fix | Delete
selector_select()
[306] Fix | Delete
continue
[307] Fix | Delete
except OSError as err:
[308] Fix | Delete
if total_sent == 0:
[309] Fix | Delete
# We can get here for different reasons, the main
[310] Fix | Delete
# one being 'file' is not a regular mmap(2)-like
[311] Fix | Delete
# file, in which case we'll fall back on using
[312] Fix | Delete
# plain send().
[313] Fix | Delete
raise _GiveupOnSendfile(err)
[314] Fix | Delete
raise err from None
[315] Fix | Delete
else:
[316] Fix | Delete
if sent == 0:
[317] Fix | Delete
break # EOF
[318] Fix | Delete
offset += sent
[319] Fix | Delete
total_sent += sent
[320] Fix | Delete
return total_sent
[321] Fix | Delete
finally:
[322] Fix | Delete
if total_sent > 0 and hasattr(file, 'seek'):
[323] Fix | Delete
file.seek(offset)
[324] Fix | Delete
else:
[325] Fix | Delete
def _sendfile_use_sendfile(self, file, offset=0, count=None):
[326] Fix | Delete
raise _GiveupOnSendfile(
[327] Fix | Delete
"os.sendfile() not available on this platform")
[328] Fix | Delete
[329] Fix | Delete
def _sendfile_use_send(self, file, offset=0, count=None):
[330] Fix | Delete
self._check_sendfile_params(file, offset, count)
[331] Fix | Delete
if self.gettimeout() == 0:
[332] Fix | Delete
raise ValueError("non-blocking sockets are not supported")
[333] Fix | Delete
if offset:
[334] Fix | Delete
file.seek(offset)
[335] Fix | Delete
blocksize = min(count, 8192) if count else 8192
[336] Fix | Delete
total_sent = 0
[337] Fix | Delete
# localize variable access to minimize overhead
[338] Fix | Delete
file_read = file.read
[339] Fix | Delete
sock_send = self.send
[340] Fix | Delete
try:
[341] Fix | Delete
while True:
[342] Fix | Delete
if count:
[343] Fix | Delete
blocksize = min(count - total_sent, blocksize)
[344] Fix | Delete
if blocksize <= 0:
[345] Fix | Delete
break
[346] Fix | Delete
data = memoryview(file_read(blocksize))
[347] Fix | Delete
if not data:
[348] Fix | Delete
break # EOF
[349] Fix | Delete
while True:
[350] Fix | Delete
try:
[351] Fix | Delete
sent = sock_send(data)
[352] Fix | Delete
except BlockingIOError:
[353] Fix | Delete
continue
[354] Fix | Delete
else:
[355] Fix | Delete
total_sent += sent
[356] Fix | Delete
if sent < len(data):
[357] Fix | Delete
data = data[sent:]
[358] Fix | Delete
else:
[359] Fix | Delete
break
[360] Fix | Delete
return total_sent
[361] Fix | Delete
finally:
[362] Fix | Delete
if total_sent > 0 and hasattr(file, 'seek'):
[363] Fix | Delete
file.seek(offset + total_sent)
[364] Fix | Delete
[365] Fix | Delete
def _check_sendfile_params(self, file, offset, count):
[366] Fix | Delete
if 'b' not in getattr(file, 'mode', 'b'):
[367] Fix | Delete
raise ValueError("file should be opened in binary mode")
[368] Fix | Delete
if not self.type & SOCK_STREAM:
[369] Fix | Delete
raise ValueError("only SOCK_STREAM type sockets are supported")
[370] Fix | Delete
if count is not None:
[371] Fix | Delete
if not isinstance(count, int):
[372] Fix | Delete
raise TypeError(
[373] Fix | Delete
"count must be a positive integer (got {!r})".format(count))
[374] Fix | Delete
if count <= 0:
[375] Fix | Delete
raise ValueError(
[376] Fix | Delete
"count must be a positive integer (got {!r})".format(count))
[377] Fix | Delete
[378] Fix | Delete
def sendfile(self, file, offset=0, count=None):
[379] Fix | Delete
"""sendfile(file[, offset[, count]]) -> sent
[380] Fix | Delete
[381] Fix | Delete
Send a file until EOF is reached by using high-performance
[382] Fix | Delete
os.sendfile() and return the total number of bytes which
[383] Fix | Delete
were sent.
[384] Fix | Delete
*file* must be a regular file object opened in binary mode.
[385] Fix | Delete
If os.sendfile() is not available (e.g. Windows) or file is
[386] Fix | Delete
not a regular file socket.send() will be used instead.
[387] Fix | Delete
*offset* tells from where to start reading the file.
[388] Fix | Delete
If specified, *count* is the total number of bytes to transmit
[389] Fix | Delete
as opposed to sending the file until EOF is reached.
[390] Fix | Delete
File position is updated on return or also in case of error in
[391] Fix | Delete
which case file.tell() can be used to figure out the number of
[392] Fix | Delete
bytes which were sent.
[393] Fix | Delete
The socket must be of SOCK_STREAM type.
[394] Fix | Delete
Non-blocking sockets are not supported.
[395] Fix | Delete
"""
[396] Fix | Delete
try:
[397] Fix | Delete
return self._sendfile_use_sendfile(file, offset, count)
[398] Fix | Delete
except _GiveupOnSendfile:
[399] Fix | Delete
return self._sendfile_use_send(file, offset, count)
[400] Fix | Delete
[401] Fix | Delete
def _decref_socketios(self):
[402] Fix | Delete
if self._io_refs > 0:
[403] Fix | Delete
self._io_refs -= 1
[404] Fix | Delete
if self._closed:
[405] Fix | Delete
self.close()
[406] Fix | Delete
[407] Fix | Delete
def _real_close(self, _ss=_socket.socket):
[408] Fix | Delete
# This function should not reference any globals. See issue #808164.
[409] Fix | Delete
_ss.close(self)
[410] Fix | Delete
[411] Fix | Delete
def close(self):
[412] Fix | Delete
# This function should not reference any globals. See issue #808164.
[413] Fix | Delete
self._closed = True
[414] Fix | Delete
if self._io_refs <= 0:
[415] Fix | Delete
self._real_close()
[416] Fix | Delete
[417] Fix | Delete
def detach(self):
[418] Fix | Delete
"""detach() -> file descriptor
[419] Fix | Delete
[420] Fix | Delete
Close the socket object without closing the underlying file descriptor.
[421] Fix | Delete
The object cannot be used after this call, but the file descriptor
[422] Fix | Delete
can be reused for other purposes. The file descriptor is returned.
[423] Fix | Delete
"""
[424] Fix | Delete
self._closed = True
[425] Fix | Delete
return super().detach()
[426] Fix | Delete
[427] Fix | Delete
@property
[428] Fix | Delete
def family(self):
[429] Fix | Delete
"""Read-only access to the address family for this socket.
[430] Fix | Delete
"""
[431] Fix | Delete
return _intenum_converter(super().family, AddressFamily)
[432] Fix | Delete
[433] Fix | Delete
@property
[434] Fix | Delete
def type(self):
[435] Fix | Delete
"""Read-only access to the socket type.
[436] Fix | Delete
"""
[437] Fix | Delete
return _intenum_converter(super().type, SocketKind)
[438] Fix | Delete
[439] Fix | Delete
if os.name == 'nt':
[440] Fix | Delete
def get_inheritable(self):
[441] Fix | Delete
return os.get_handle_inheritable(self.fileno())
[442] Fix | Delete
def set_inheritable(self, inheritable):
[443] Fix | Delete
os.set_handle_inheritable(self.fileno(), inheritable)
[444] Fix | Delete
else:
[445] Fix | Delete
def get_inheritable(self):
[446] Fix | Delete
return os.get_inheritable(self.fileno())
[447] Fix | Delete
def set_inheritable(self, inheritable):
[448] Fix | Delete
os.set_inheritable(self.fileno(), inheritable)
[449] Fix | Delete
get_inheritable.__doc__ = "Get the inheritable flag of the socket"
[450] Fix | Delete
set_inheritable.__doc__ = "Set the inheritable flag of the socket"
[451] Fix | Delete
[452] Fix | Delete
def fromfd(fd, family, type, proto=0):
[453] Fix | Delete
""" fromfd(fd, family, type[, proto]) -> socket object
[454] Fix | Delete
[455] Fix | Delete
Create a socket object from a duplicate of the given file
[456] Fix | Delete
descriptor. The remaining arguments are the same as for socket().
[457] Fix | Delete
"""
[458] Fix | Delete
nfd = dup(fd)
[459] Fix | Delete
return socket(family, type, proto, nfd)
[460] Fix | Delete
[461] Fix | Delete
if hasattr(_socket.socket, "share"):
[462] Fix | Delete
def fromshare(info):
[463] Fix | Delete
""" fromshare(info) -> socket object
[464] Fix | Delete
[465] Fix | Delete
Create a socket object from the bytes object returned by
[466] Fix | Delete
socket.share(pid).
[467] Fix | Delete
"""
[468] Fix | Delete
return socket(0, 0, 0, info)
[469] Fix | Delete
__all__.append("fromshare")
[470] Fix | Delete
[471] Fix | Delete
if hasattr(_socket, "socketpair"):
[472] Fix | Delete
[473] Fix | Delete
def socketpair(family=None, type=SOCK_STREAM, proto=0):
[474] Fix | Delete
"""socketpair([family[, type[, proto]]]) -> (socket object, socket object)
[475] Fix | Delete
[476] Fix | Delete
Create a pair of socket objects from the sockets returned by the platform
[477] Fix | Delete
socketpair() function.
[478] Fix | Delete
The arguments are the same as for socket() except the default family is
[479] Fix | Delete
AF_UNIX if defined on the platform; otherwise, the default is AF_INET.
[480] Fix | Delete
"""
[481] Fix | Delete
if family is None:
[482] Fix | Delete
try:
[483] Fix | Delete
family = AF_UNIX
[484] Fix | Delete
except NameError:
[485] Fix | Delete
family = AF_INET
[486] Fix | Delete
a, b = _socket.socketpair(family, type, proto)
[487] Fix | Delete
a = socket(family, type, proto, a.detach())
[488] Fix | Delete
b = socket(family, type, proto, b.detach())
[489] Fix | Delete
return a, b
[490] Fix | Delete
[491] Fix | Delete
else:
[492] Fix | Delete
[493] Fix | Delete
# Origin: https://gist.github.com/4325783, by Geert Jansen. Public domain.
[494] Fix | Delete
def socketpair(family=AF_INET, type=SOCK_STREAM, proto=0):
[495] Fix | Delete
if family == AF_INET:
[496] Fix | Delete
host = _LOCALHOST
[497] Fix | Delete
elif family == AF_INET6:
[498] Fix | Delete
host = _LOCALHOST_V6
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function