MCPcopy Create free account
hub / github.com/rthalley/dnspython / make_socket

Function make_socket

dns/query.py:324–354  ·  view source on GitHub ↗

Make a socket. This function uses the module's ``socket_factory`` to make a socket of the specified address family and type. *af*, a ``socket.AddressFamily`` or ``int`` is the address family, either ``socket.AF_INET`` or ``socket.AF_INET6``. *type*, a ``socket.SocketKind`` is

(
    af: socket.AddressFamily | int,
    type: socket.SocketKind,
    source: Any | None = None,
)

Source from the content-addressed store, hash-verified

322
323
324def make_socket(
325 af: socket.AddressFamily | int,
326 type: socket.SocketKind,
327 source: Any | None = None,
328) -> socket.socket:
329 """Make a socket.
330
331 This function uses the module's ``socket_factory`` to make a socket of the
332 specified address family and type.
333
334 *af*, a ``socket.AddressFamily`` or ``int`` is the address family, either
335 ``socket.AF_INET`` or ``socket.AF_INET6``.
336
337 *type*, a ``socket.SocketKind`` is the type of socket, e.g. ``socket.SOCK_DGRAM``,
338 a datagram socket, or ``socket.SOCK_STREAM``, a stream socket. Note that the
339 ``proto`` attribute of a socket is always zero with this API, so a datagram socket
340 will always be a UDP socket, and a stream socket will always be a TCP socket.
341
342 *source* is the source address and port to bind to, if any. The default is
343 ``None`` which will bind to the wildcard address and a randomly chosen port.
344 If not ``None``, it should be a (low-level) address tuple appropriate for *af*.
345 """
346 s = socket_factory(af, type, 0)
347 try:
348 s.setblocking(False)
349 if source is not None:
350 s.bind(source)
351 return s
352 except Exception:
353 s.close()
354 raise
355
356
357def make_ssl_socket(

Callers 7

connect_tcpMethod · 0.85
make_ssl_socketFunction · 0.85
_make_socketFunction · 0.85
udpFunction · 0.85
tcpFunction · 0.85
xfrFunction · 0.85
inbound_xfrFunction · 0.85

Calls 1

closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…