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

Function tcp

dns/query.py:1204–1271  ·  view source on GitHub ↗

Return the response obtained after sending a query via TCP. *q*, a ``dns.message.Message``, the query to send *where*, a ``str`` containing an IPv4 or IPv6 address, where to send the message. *timeout*, a ``float`` or ``None``, the number of seconds to wait before the query ti

(
    q: dns.message.Message,
    where: str,
    timeout: float | None = None,
    port: int = 53,
    source: str | None = None,
    source_port: int = 0,
    one_rr_per_rrset: bool = False,
    ignore_trailing: bool = False,
    sock: Any | None = None,
)

Source from the content-addressed store, hash-verified

1202
1203
1204def tcp(
1205 q: dns.message.Message,
1206 where: str,
1207 timeout: float | None = None,
1208 port: int = 53,
1209 source: str | None = None,
1210 source_port: int = 0,
1211 one_rr_per_rrset: bool = False,
1212 ignore_trailing: bool = False,
1213 sock: Any | None = None,
1214) -> dns.message.Message:
1215 """Return the response obtained after sending a query via TCP.
1216
1217 *q*, a ``dns.message.Message``, the query to send
1218
1219 *where*, a ``str`` containing an IPv4 or IPv6 address, where
1220 to send the message.
1221
1222 *timeout*, a ``float`` or ``None``, the number of seconds to wait before the
1223 query times out. If ``None``, the default, wait forever.
1224
1225 *port*, an ``int``, the port send the message to. The default is 53.
1226
1227 *source*, a ``str`` containing an IPv4 or IPv6 address, specifying
1228 the source address. The default is the wildcard address.
1229
1230 *source_port*, an ``int``, the port from which to send the message.
1231 The default is 0.
1232
1233 *one_rr_per_rrset*, a ``bool``. If ``True``, put each RR into its own
1234 RRset.
1235
1236 *ignore_trailing*, a ``bool``. If ``True``, ignore trailing
1237 junk at end of the received message.
1238
1239 *sock*, a ``socket.socket``, or ``None``, the connected socket to use for the
1240 query. If ``None``, the default, a socket is created. Note that
1241 if a socket is provided, it must be a nonblocking connected stream
1242 socket, and *where*, *port*, *source* and *source_port* are ignored.
1243
1244 Returns a ``dns.message.Message``.
1245 """
1246
1247 wire = q.to_wire()
1248 (begin_time, expiration) = _compute_times(timeout)
1249 if sock:
1250 cm: contextlib.AbstractContextManager = contextlib.nullcontext(sock)
1251 else:
1252 (af, destination, source) = _destination_and_source(
1253 where, port, source, source_port, True
1254 )
1255 assert af is not None
1256 cm = make_socket(af, socket.SOCK_STREAM, source)
1257 with cm as s:
1258 if not sock:
1259 # pylint: disable=possibly-used-before-assignment
1260 _connect(s, destination, expiration) # pyright: ignore
1261 send_tcp(s, wire, expiration)

Callers 2

udp_with_fallbackFunction · 0.70
tlsFunction · 0.70

Calls 8

_compute_timesFunction · 0.85
_destination_and_sourceFunction · 0.85
make_socketFunction · 0.85
_connectFunction · 0.85
is_responseMethod · 0.80
send_tcpFunction · 0.70
receive_tcpFunction · 0.70
to_wireMethod · 0.45

Tested by

no test coverage detected