From: Michael Orlitzky Date: Fri, 16 Sep 2022 18:44:15 +0000 (-0400) Subject: bin/djbdns-logparse.py: add docstring for decode_ip(). X-Git-Tag: 0.0.1~32 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=2229f66e203e85bb804e13b1ced7f60fb77b119b;p=djbdns-logparse.git bin/djbdns-logparse.py: add docstring for decode_ip(). --- diff --git a/bin/djbdns-logparse.py b/bin/djbdns-logparse.py index 8f30e14..f2a69b5 100755 --- a/bin/djbdns-logparse.py +++ b/bin/djbdns-logparse.py @@ -167,6 +167,43 @@ def decode_client(words : list, i : int): words[i] += f" (id {id})" def decode_ip(words, i): + r""" + Helper function to decode the ip field in a dnscache log + entry. + + A single "serverip" field is present in the lame, nodata, + nxdomain, and rr entry types. + + Parameters + ---------- + + words : list + The ``words`` list (a list of fields) from + :func:`handle_dnscache_log`. + + i : int + The index of the ip field within ``words`` + + Returns + ------- + + Nothing; the ``i``th entry in the ``words`` list is modified + in-place. + + Examples + -------- + + >>> words = ["foo", "bar", "7f000001", "quux"] + >>> decode_ip(words, 2) + >>> words + ['foo', 'bar', '127.0.0.1', 'quux'] + + >>> words = ["foo", "00000000000000000000ffff7f000001", "bar", "quux"] + >>> decode_ip(words, 1) + >>> words + ['foo', '0000:0000:0000:0000:0000:ffff:7f00:0001', 'bar', 'quux'] + + """ words[i] = convert_ip(words[i]) def decode_ttl(words, i):