From 91925bb92092d3b180a9c086e81822a3fdec6939 Mon Sep 17 00:00:00 2001 From: Oliver Beckstein Date: Thu, 15 Mar 2018 15:36:09 -0700 Subject: [PATCH] test for stream-ness in Py 3/Py 2 compatible manner --- propka/lib.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/propka/lib.py b/propka/lib.py index 799d97c..509d4b2 100644 --- a/propka/lib.py +++ b/propka/lib.py @@ -23,9 +23,10 @@ def open_file_for_reading(filename): the object is just passed through (the stream is attempted to be reset to the beginning with ``fseek(0)``). """ - if hasattr(filename, 'next') and hasattr(filename, 'read') \ - and hasattr(filename, 'readline') and hasattr(filename, 'readlines') \ - and hasattr(filename, 'close'): + if (hasattr(filename, 'next') or hasattr(filename, '__next__')) \ + and hasattr(filename, 'read') \ + and hasattr(filename, 'readline') and hasattr(filename, 'readlines') \ + and hasattr(filename, 'close'): # already a stream try: filename.fseek(0)