Files
segpy/portability.py
T
Robert Smallshire dcac37022d General cleanup.
2014-09-01 13:58:34 +02:00

25 lines
545 B
Python

import os
from util import file_length
def seekable(fh):
"""Determine whether a file-like object supports seeking.
Args:
fh: The file-like-object to be tested.
Returns:
True if the file supports seeking, otherwise False.
"""
try:
return fh.seekable()
except AttributeError:
try:
pos = fh.tell()
try:
fh.seek(0, os.SEEK_END)
finally:
fh.seek(pos)
except AttributeError:
return False
return True