]> gitweb.michael.orlitzky.com - djbdns-logparse.git/commitdiff
djbdns/*.py: don't clobber id() and type() built-ins.
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 22 Sep 2022 01:41:31 +0000 (21:41 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 22 Sep 2022 01:41:31 +0000 (21:41 -0400)
djbdns/common.py
djbdns/dnscache.py
djbdns/tinydns.py

index 138101141d12339640854684adc258ca5a803a12..06124bf2ef03135d7177b18787a61d8bf7ed31b0 100644 (file)
@@ -12,7 +12,7 @@ timestamp_pat = r'[\d-]+ [\d:\.]+'
 #
 # Note that mapping here is non-exhaustive, and that tinydns will
 # log responses for record types that it does not know about.
-query_type = {
+query_type_name = {
       1: "a",
       2: "ns",
       5: "cname",
index 0d9de08592c903967ce988f355a798086661fd5d..7fed987195c3d39b466512a57258f6b28411d818 100644 (file)
@@ -59,8 +59,8 @@ def decode_client(words : list, i : int):
 
     if len(chunks) == 3:
         # For a "query" entry's clientip:clientport:id field.
-        id = int(chunks[2], 16)
-        words[i] += f" (id {id})"
+        packet_id = int(chunks[2], 16)
+        words[i] += f" (id {packet_id})"
 
 def decode_ip(words : list, i : int):
     r"""
@@ -207,7 +207,7 @@ def decode_type(words : list, i : int):
 
     """
     qt = words[i]
-    words[i] = query_type.get(int(qt), qt)
+    words[i] = query_type_name.get(int(qt), qt)
 
 def handle_dnscache_log(line : str) -> Optional[str]:
     r"""
index 34cedef376c9829d2c668e2cb8c807cbe279301e..d647156f7b03bec45ac23a5605dc868e31d4d942 100644 (file)
@@ -65,33 +65,34 @@ def handle_tinydns_log(line : str) -> Optional[str]:
     if not match:
         return None
 
-    (timestamp, ip, port, id, code, type, name) = match.groups()
+    (timestamp, ip, port, request_id, code, query_type, name) = match.groups()
     ip = convert_ip(ip)
     port = int(port, 16)
-    id = int(id, 16)
+    request_id = int(request_id, 16)
 
     # Convert the "type" field to a human-readable record type name
     # using the query_type dictionary. If the right name isn't present
     # in the dictionary, we use the (decimal) type id instead.
-    type = int(type, 16)                # "001c" -> 28
-    type = query_type.get(type, type)   # 28 -> "aaaa"
+    query_type = int(query_type, 16)                     # "001c" -> 28
+    query_type = query_type_name.get(query_type, type)   # 28 -> "aaaa"
 
     line_tpl = "{timestamp} "
 
     reason = query_drop_reason[code]
     if code == "+":
-        line_tpl += "sent response to {ip}:{port} (id {id}): {type} {name}"
+        line_tpl += "sent response to {ip}:{port} (id {request_id}): "
+        line_tpl += "{query_type} {name}"
     else:
         line_tpl += "dropped query ({reason}) from {ip}:{port}"
         if code != "/":
             # If the query can actually be parsed, the log line is a
             # bit more informative than it would have been otherwise.
-            line_tpl += " (id {id}): {type} {name}"
+            line_tpl += " (id {request_id}): {query_type} {name}"
 
     return line_tpl.format(timestamp=timestamp,
                            reason=reason,
                            ip=ip,
                            port=port,
-                           id=id,
-                           type=type,
+                           request_id=request_id,
+                           query_type=query_type,
                            name=name)