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

This commit is contained in:
Oliver Beckstein
2018-03-15 15:36:09 -07:00
committed by Matvey Adzhigirey
parent 9ebc76bcdc
commit 91925bb920

View File

@@ -23,9 +23,10 @@ def open_file_for_reading(filename):
the object is just passed through (the stream is attempted to be the object is just passed through (the stream is attempted to be
reset to the beginning with ``fseek(0)``). reset to the beginning with ``fseek(0)``).
""" """
if hasattr(filename, 'next') and hasattr(filename, 'read') \ if (hasattr(filename, 'next') or hasattr(filename, '__next__')) \
and hasattr(filename, 'readline') and hasattr(filename, 'readlines') \ and hasattr(filename, 'read') \
and hasattr(filename, 'close'): and hasattr(filename, 'readline') and hasattr(filename, 'readlines') \
and hasattr(filename, 'close'):
# already a stream # already a stream
try: try:
filename.fseek(0) filename.fseek(0)