Backwards compat function to determine if a fileobj is seekable :param fileobj: The file-like object to determine if seekable :returns: True, if seekable. False, otherwise.
(fileobj)
| 47 | |
| 48 | |
| 49 | def seekable(fileobj): |
| 50 | """Backwards compat function to determine if a fileobj is seekable |
| 51 | |
| 52 | :param fileobj: The file-like object to determine if seekable |
| 53 | |
| 54 | :returns: True, if seekable. False, otherwise. |
| 55 | """ |
| 56 | # If the fileobj has a seekable attr, try calling the seekable() |
| 57 | # method on it. |
| 58 | if hasattr(fileobj, 'seekable'): |
| 59 | return fileobj.seekable() |
| 60 | # If there is no seekable attr, check if the object can be seeked |
| 61 | # or telled. If it can, try to seek to the current position. |
| 62 | elif hasattr(fileobj, 'seek') and hasattr(fileobj, 'tell'): |
| 63 | try: |
| 64 | fileobj.seek(0, 1) |
| 65 | return True |
| 66 | except OSError: |
| 67 | # If an io related error was thrown then it is not seekable. |
| 68 | return False |
| 69 | # Else, the fileobj is not seekable |
| 70 | return False |
| 71 | |
| 72 | |
| 73 | def readable(fileobj): |