Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dnsviz/dnsviz.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'dnsviz/util.py')
-rw-r--r--dnsviz/util.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/dnsviz/util.py b/dnsviz/util.py
index 8efed82..f4c6c71 100644
--- a/dnsviz/util.py
+++ b/dnsviz/util.py
@@ -184,3 +184,13 @@ def get_client_address(server):
ip = IPAddr(s.getsockname()[0])
s.close()
return ip
+
+def io_try_buffered(f, mode, closefd=True):
+ """Try opening buffered reader, but allow unbuffered on failure.
+
+ Required to pass tests under pytest."""
+ try:
+ return io.open(f.fileno(), mode, closefd=closefd)
+ except io.UnsupportedOperation:
+ # raised by f.fileno()
+ return f