words[i] = query_type.get(int(qt), qt)
def handle_dnscache_log(line) -> bool:
+ """
+ Handle a single log line if it matches the ``dnscache_log_re`` regex.
+
+ Parameters
+ ----------
+
+ line : string
+ The log line that might match ``dnscache_log_re``.
+
+ Returns
+ -------
+
+ ``True`` if the log line was handled (that is, if it was really a
+ dnscache log line), and ``False`` otherwise.
+
+ Examples
+ --------
+
+ >>> line = "2022-09-15 18:37:33.863805500 query 1 7f000001:a3db:4fb9 1 www.example.com."
+ >>> handle_dnscache_log(line)
+ 2022-09-15 18:37:33.863805500 query #1 127.0.0.1:41947 (id 20409) a www.example.com.
+ True
+
+ >>> line = "2022-09-15 18:37:33.863874500 tx 0 1 www.example.com. . c0a80101"
+ >>> handle_dnscache_log(line)
+ 2022-09-15 18:37:33.863874500 tx g=0 a www.example.com. . 192.168.1.1
+ True
+
+ >>> line = "2022-09-15 18:37:33.878529500 rr c0a80101 20865 1 www.example.com. 5db8d822"
+ >>> handle_dnscache_log(line)
+ 2022-09-15 18:37:33.878529500 rr 192.168.1.1 TTL=20865 a www.example.com. 93.184.216.34
+ True
+
+ >>> line = "2022-09-15 18:37:33.878532500 stats 1 43 1 0"
+ >>> handle_dnscache_log(line)
+ 2022-09-15 18:37:33.878532500 stats count=1 motion=43 udp-active=1 tcp-active=0
+ True
+
+ >>> line = "2022-09-15 18:37:33.878602500 sent 1 49"
+ >>> handle_dnscache_log(line)
+ 2022-09-15 18:37:33.878602500 sent #1 49
+ True
+
+ >>> line = "this line is nonsense"
+ >>> handle_dnscache_log(line)
+ False
+
+ """
match = dnscache_log_re.match(line)
if not match:
return False