Skip to content

Commit 8778ac8

Browse files
authored
Simplify WHENCE_END logic (#902)
1 parent 57c392a commit 8778ac8

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

smart_open/s3.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,20 +524,22 @@ def seek(self, offset, whence=constants.WHENCE_START):
524524
start = max(0, offset)
525525
elif whence == constants.WHENCE_CURRENT:
526526
start = max(0, offset + self._position)
527-
else:
527+
elif whence == constants.WHENCE_END:
528528
stop = max(0, -offset)
529529

530530
#
531531
# If we can figure out that we've read past the EOF, then we can save
532532
# an extra API call.
533533
#
534-
if start is None and stop == 0 and self._content_length is None:
535-
# seek(0, WHENCE_END) seeks straight to EOF: make a minimal request to populate _content_length
536-
self._open_body(start=0, stop=0)
537-
self.close()
538-
reached_eof = True
539-
elif self._content_length is None:
540-
reached_eof = False
534+
if self._content_length is None: # _open_body has not been called yet
535+
if start is None and stop == 0:
536+
# seek(0, WHENCE_END) seeks straight to EOF:
537+
# make a minimal request to populate _content_length
538+
self._open_body(start=0, stop=0)
539+
self.close()
540+
reached_eof = True
541+
else:
542+
reached_eof = False
541543
elif start is not None and start >= self._content_length:
542544
reached_eof = True
543545
elif stop == 0:

0 commit comments

Comments
 (0)