MCPcopy Index your code
hub / github.com/python/cpython / socket

Class socket

Lib/socket.py:219–555  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 8

acceptMethod · 0.70
fromfdFunction · 0.70
fromshareFunction · 0.70
_fallback_socketpairFunction · 0.70
socketpairFunction · 0.70
create_connectionFunction · 0.70
has_dualstack_ipv6Function · 0.70
create_serverFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…