X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=djbdns%2Fio.py;h=c3952bed7da220119a68604e2ed6d0f26d098114;hb=b27861b89fbed3b7223535114ad2ae1864f78a52;hp=75422c01387032f0a0aab6e87e8f40fac411d010;hpb=c965f2fea1788a7faba2c67a4f05c27d5c34373b;p=djbdns-logparse.git diff --git a/djbdns/io.py b/djbdns/io.py index 75422c0..c3952be 100644 --- a/djbdns/io.py +++ b/djbdns/io.py @@ -1,3 +1,7 @@ +r""" +Functions that perform input/output. This forms a layer between the +executable itself and the more libraryish modules. +""" from subprocess import Popen, PIPE from typing import TextIO from djbdns.dnscache import handle_dnscache_log @@ -20,6 +24,8 @@ def parse_logfile(file : TextIO): >>> from tempfile import NamedTemporaryFile >>> with NamedTemporaryFile(mode="w", delete=False) as f: ... _ = f.write(line) + >>> from os import environ + >>> environ["TZ"] = "UTC+4" >>> 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 @@ -37,6 +43,11 @@ def parse_logfile(file : TextIO): text=True, bufsize=0) as tai: + if not tai.stdin or not tai.stdout: + # Mypy tells me that this can happen, based on the type + # annotations in the standard library I guess? + return + for line in file: tai.stdin.write(line) line = tai.stdout.readline()