From: Michael Orlitzky Date: Thu, 15 Sep 2022 14:15:46 +0000 (-0400) Subject: bin/djbdns-logparse.py: add doctest for parse_logfile(). X-Git-Tag: 0.0.1~46 X-Git-Url: http://gitweb.michael.orlitzky.com/?p=djbdns-logparse.git;a=commitdiff_plain;h=5533b90230d1c542efba381b6dba64b0c6826219 bin/djbdns-logparse.py: add doctest for parse_logfile(). --- diff --git a/bin/djbdns-logparse.py b/bin/djbdns-logparse.py index 9af8362..067d9b1 100755 --- a/bin/djbdns-logparse.py +++ b/bin/djbdns-logparse.py @@ -248,7 +248,7 @@ def handle_tinydns_log(line : str, match: re.Match): def parse_logfile(file : typing.TextIO): - """ + r""" Process a single log ``file``. Parameters @@ -257,6 +257,20 @@ def parse_logfile(file : typing.TextIO): file : typing.TextIO An open log file, or stdin. + Examples + -------- + + >>> line = "@4000000063227a320c4f3114 7f000001:9d61:be69 - 0001 www.example.com\n" + >>> from tempfile import NamedTemporaryFile + >>> with NamedTemporaryFile(mode="w", delete=False) as f: + ... _ = f.write(line) + >>> f = open(f.name, 'r') + >>> parse_logfile(f) + 2022-09-14 21:04:40.206516500 dropped query (no authority) from 127.0.0.1:40289 (id 48745): a www.example.com + >>> f.close() + >>> from os import remove + >>> remove(f.name) + """ # Open pipe to tai64nlocal: we will write lines of our input (the # raw log file) to it, and read log lines with readable timestamps