MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / socket

Class socket

tools/python-3.11.9-amd64/Lib/socket.py:214–538  ·  view source on GitHub ↗

A subclass of _socket.socket adding the makefile() method.

Source from the content-addressed store, hash-verified

212
213
214class socket(_socket.socket):
215
216 """A subclass of _socket.socket adding the makefile() method."""
217
218 __slots__ = ["__weakref__", "_io_refs", "_closed"]
219
220 def __init__(self, family=-1, type=-1, proto=-1, fileno=None):
221 # For user code address family and type values are IntEnum members, but
222 # for the underlying _socket.socket they're just integers. The
223 # constructor of _socket.socket converts the given argument to an
224 # integer automatically.
225 if fileno is None:
226 if family == -1:
227 family = AF_INET
228 if type == -1:
229 type = SOCK_STREAM
230 if proto == -1:
231 proto = 0
232 _socket.socket.__init__(self, family, type, proto, fileno)
233 self._io_refs = 0
234 self._closed = False
235
236 def __enter__(self):
237 return self
238
239 def __exit__(self, *args):
240 if not self._closed:
241 self.close()
242
243 def __repr__(self):
244 """Wrap __repr__() to reveal the real class name and socket
245 address(es).
246 """
247 closed = getattr(self, '_closed', False)
248 s = "<%s.%s%s fd=%i, family=%s, type=%s, proto=%i" \
249 % (self.__class__.__module__,
250 self.__class__.__qualname__,
251 " [closed]" if closed else "",
252 self.fileno(),
253 self.family,
254 self.type,
255 self.proto)
256 if not closed:
257 # getsockname and getpeername may not be available on WASI.
258 try:
259 laddr = self.getsockname()
260 if laddr:
261 s += ", laddr=%s" % str(laddr)
262 except (error, AttributeError):
263 pass
264 try:
265 raddr = self.getpeername()
266 if raddr:
267 s += ", raddr=%s" % str(raddr)
268 except (error, AttributeError):
269 pass
270 s += '>'
271 return s

Callers 9

mainFunction · 0.90
mainFunction · 0.90
acceptMethod · 0.85
fromfdFunction · 0.85
fromshareFunction · 0.85
socketpairFunction · 0.85
create_connectionFunction · 0.85
has_dualstack_ipv6Function · 0.85
create_serverFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected