]> gitweb.michael.orlitzky.com - djbdns-logparse.git/blobdiff - djbdns/dnscache.py
djbdns/*.py: add module docstrings.
[djbdns-logparse.git] / djbdns / dnscache.py
index 0d9de08592c903967ce988f355a798086661fd5d..fcd0a0d050c5f8fb8d04ca85d83a12a7324cb650 100644 (file)
@@ -1,11 +1,14 @@
+r"""
+Functions and data specific to dnscache logs.
+"""
 # Don't clobber the global compile() with a named import.
 import re
 
 from typing import Optional
-from djbdns.common import *
+from djbdns.common import QUERY_TYPE_NAME, TIMESTAMP_PAT, convert_ip
 
 # The regex to match dnscache log lines.
-dnscache_log_re = re.compile(fr'({timestamp_pat}) (\w+)(.*)')
+DNSCACHE_LOG_RE = re.compile(fr'({TIMESTAMP_PAT}) (\w+)(.*)')
 
 
 def decode_client(words : list, i : int):
@@ -59,8 +62,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,17 +210,17 @@ 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"""
-    Handle a single log line if it matches the ``dnscache_log_re`` regex.
+    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``.
+        The log line that might match ``DNSCACHE_LOG_RE``.
 
     Returns
     -------
@@ -253,7 +256,7 @@ def handle_dnscache_log(line : str) -> Optional[str]:
         >>> handle_dnscache_log(line)
 
     """
-    match = dnscache_log_re.match(line)
+    match = DNSCACHE_LOG_RE.match(line)
     if not match:
         return None