From: Michael Orlitzky Date: Sat, 17 Sep 2022 23:51:34 +0000 (-0400) Subject: djbdns/dnscache.py: add docstring for decode_type(). X-Git-Tag: 0.0.1~22 X-Git-Url: http://gitweb.michael.orlitzky.com/?p=djbdns-logparse.git;a=commitdiff_plain;h=ec25d9f12cd94407476a2d12c6ae31ee8ab90945 djbdns/dnscache.py: add docstring for decode_type(). --- diff --git a/djbdns/dnscache.py b/djbdns/dnscache.py index ff1e4da..a7fc56d 100644 --- a/djbdns/dnscache.py +++ b/djbdns/dnscache.py @@ -171,6 +171,39 @@ def decode_serial(words : list, i : int): words[i] = f"#{words[i]}" def decode_type(words : list, i : int): + r""" + Helper function to decode the type field in a dnscache log + entry. + + A single "type" field is present in cached, nodata, query, rr, and + tx entries. Unlike with tinydns entries, dnscache logs have + this field already in decimal, so we just look up the + corresponding name in the query type map. + + Parameters + ---------- + + words : list + A list with the "type" string at index ``i`` + + i : int + The index of the type field within ``words`` + + Returns + ------- + + Nothing; the ``i``th entry in the ``words`` list is modified + in-place. + + Examples + -------- + + >>> words = ["2", "7f000001:b848:0f0b", "16", "example.com."] + >>> decode_type(words, 2) + >>> words + ['2', '7f000001:b848:0f0b', 'txt', 'example.com.'] + + """ qt = words[i] words[i] = query_type.get(int(qt), qt)