Skip to content

Commit c56bf6b

Browse files
committed
Fix read_bytes() in Python 2 on 'file' objects
1 parent a405326 commit c56bf6b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kaitaistruct.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ def read_bytes(self, n):
300300
)
301301

302302
is_satisfiable = True
303-
if self._io.seekable():
303+
# in Python 2, there is a common error ['file' object has no
304+
# attribute 'seekable'], so we need to make sure that seekable() exists
305+
if callable(getattr(self._io, 'seekable', None)) and self._io.seekable():
304306
num_bytes_available = self.size() - self.pos()
305307
is_satisfiable = (n <= num_bytes_available)
306308

0 commit comments

Comments
 (0)