]> gitweb.michael.orlitzky.com - djbdns-logparse.git/commitdiff
bin/djbdns-logparse.py: add .py extension and doctests for convert_ip().
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 15 Sep 2022 01:30:53 +0000 (21:30 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 15 Sep 2022 01:30:53 +0000 (21:30 -0400)
Without the rename, "python -m doctest" isn't smart enough to figure
out that this thing is a python file.

bin/djbdns-logparse.py [moved from bin/djbdns-logparse with 95% similarity]

similarity index 95%
rename from bin/djbdns-logparse
rename to bin/djbdns-logparse.py
index 2e184d814228a39d1992cd3eb581dba317dc74d7..50161fa827d046885d3f6ea135aeed978cd5e2bd 100755 (executable)
@@ -46,10 +46,20 @@ query_drop_reason = {
     }
 
 
-def convert_ip(ip):
-    """Convert a hex string representing an IP address to conventional
+def convert_ip(ip : str):
+    """
+    Convert a hex string representing an IP address to conventional
     human-readable form, ie. dotted-quad decimal for IPv4, and
     8 colon-separated hex shorts for IPv6.
+
+    Examples
+    --------
+
+        >>> convert_ip("7f000001")
+        '127.0.0.1'
+        >>> convert_ip("00000000000000000000ffff7f000001")
+        '0000:0000:0000:0000:0000:ffff:7f00:0001'
+
     """
     if len(ip) == 8:
         # IPv4, eg. "7f000001" -> "127.0.0.1"