test for stream-ness in Py 3/Py 2 compatible manner
This commit is contained in:
committed by
Matvey Adzhigirey
parent
9ebc76bcdc
commit
91925bb920
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user