MCPcopy Index your code
hub / github.com/RustPython/RustPython / socket

Class socket

Lib/socket.py:218–546  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 9

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 1

hasattrFunction · 0.85

Tested by

no test coverage detected