]> gitweb.michael.orlitzky.com - djbdns-logparse.git/blobdiff - djbdns/dnscache.py
doc/COPYING: add one for the "or later" bit
[djbdns-logparse.git] / djbdns / dnscache.py
index ac8b41c5656ba747b458832f069123c6f028e06b..450dbd6c5b73151265ebafe84cbb8c129498f03c 100644 (file)
@@ -1,3 +1,6 @@
+r"""
+Functions and data specific to dnscache logs.
+"""
 # Don't clobber the global compile() with a named import.
 import re
 
@@ -207,7 +210,7 @@ def decode_type(words : list, i : int):
 
     """
     qt = words[i]
-    words[i] = QUERY_TYPE_NAME.get(int(qt), qt)
+    words[i] = QUERY_TYPE_NAME[int(qt)]
 
 def handle_dnscache_log(line : str) -> Optional[str]:
     r"""
@@ -289,23 +292,24 @@ def handle_dnscache_log(line : str) -> Optional[str]:
         decode_ttl(words, 1)
         if words[2] not in ("cname", "mx", "ns", "ptr", "soa"):
             decode_type(words, 2)
-            if words[2] == "a":
-                # Decode the response to an 'A' query
-                decode_ip(words, 4)
-            if words[2] == "txt":
-                # Decode the TXT record's data from hex to ASCII.
-                response = words[4]
-                if response.endswith("..."):
-                    ellipsis = "..."
-                    response = response[0:-3]
-                else:
-                    ellipsis = ""
-                length = int(response[0:2], 16)
-                chars = []
-                for i in range(1, len(response)//2):
-                    chars.append(chr(int(response[2*i : (2*i)+2], 16)))
-                txt = "".join(chars)
-                words[4] = f"{length}:\"{txt}{ellipsis}\""
+
+        if words[2] == "a":
+            # Decode the response to an 'A' query
+            decode_ip(words, 4)
+        if words[2] == "txt":
+            # Decode the TXT record's data from hex to ASCII.
+            response = words[4]
+            if response.endswith("..."):
+                ellipsis = "..."
+                response = response[0:-3]
+            else:
+                ellipsis = ""
+            length = int(response[0:2], 16)
+            chars = []
+            for i in range(1, len(response)//2):
+                chars.append(chr(int(response[2*i : (2*i)+2], 16)))
+            txt = "".join(chars)
+            words[4] = f"{length}:\"{txt}{ellipsis}\""
 
     elif event == "sent":
         decode_serial(words, 0)