From: Michael Orlitzky Date: Thu, 15 Sep 2022 01:30:53 +0000 (-0400) Subject: bin/djbdns-logparse.py: add .py extension and doctests for convert_ip(). X-Git-Tag: 0.0.1~54 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=c76959990f000aea20ce55a93842d011edacaacb;p=djbdns-logparse.git bin/djbdns-logparse.py: add .py extension and doctests for convert_ip(). Without the rename, "python -m doctest" isn't smart enough to figure out that this thing is a python file. --- diff --git a/bin/djbdns-logparse b/bin/djbdns-logparse.py similarity index 95% rename from bin/djbdns-logparse rename to bin/djbdns-logparse.py index 2e184d8..50161fa 100755 --- a/bin/djbdns-logparse +++ b/bin/djbdns-logparse.py @@ -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"