From c76959990f000aea20ce55a93842d011edacaacb Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 14 Sep 2022 21:30:53 -0400 Subject: [PATCH] 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. --- bin/{djbdns-logparse => djbdns-logparse.py} | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) rename bin/{djbdns-logparse => djbdns-logparse.py} (95%) 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" -- 2.43.2