test for stream-ness in Py 3/Py 2 compatible manner

This commit is contained in:
Oliver Beckstein authored and Matvey Adzhigirey committed 2018-03-19 22:34:22 -07:00
1 parent 9ebc76bcdc
commit 91925bb920
1 file changed
+4 -3
+4 -3
View File
@@ -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)