You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""Convenience method indicating that the underlying stream is open. TODO: This also assumes that the stream does not auto-close at EOF. Might need to revisit that"""
"""Calling this will ensure that the underlying stream is open, smoothing over issues like socket timeouts to create the illusion of one indefinitely readable file stream"""
757
+
ifnotself._underlying_stream_is_open():
758
+
self._replace_underlying_stream(self.tell())
759
+
760
+
defdetach(self):
761
+
raiseUnsupportedOperation("Detaching from the buffer is not supported")
762
+
763
+
defread(self, __size=-1, /):
764
+
# Read and return up to size bytes. If omitted, None, or Negative, data is read until EOF is reached
765
+
# Empty bytes object returned if stream is EOF
766
+
self._ensure_open_stream()
767
+
out=self._underlying_stream.read(__size)
768
+
self._current_pos_of_underlying_stream+=len(out)
769
+
returnout
770
+
771
+
defread1(self, __size= ...):
772
+
# Read and return up to size bytes, with at most one read() system call
773
+
self._ensure_open_stream()
774
+
out=self._underlying_stream.read1(__size)
775
+
self._current_pos_of_underlying_stream+=len(out)
776
+
returnout
777
+
778
+
defreadinto(self, __buffer):
779
+
# Read up to len(buffer) bytes into buffer and return number of bytes read
780
+
self._ensure_open_stream()
781
+
out=self._underlying_stream.readinto(__buffer)
782
+
self._current_pos_of_underlying_stream+=len(out)
783
+
returnout
784
+
785
+
defreadinto1(self, __buffer):
786
+
# Read up to len(buffer) bytes into buffer with at most one read() system call
787
+
self._ensure_open_stream()
788
+
out=self._underlying_stream.readinto1(__buffer)
789
+
self._current_pos_of_underlying_stream+=len(out)
790
+
returnout
791
+
792
+
defwrite(self, __buffer):
793
+
raiseUnsupportedOperation("SeekableDownloadBinaryIO is used exclusively for read operations")
794
+
795
+
defclose(self):
796
+
"""Close the underlying stream & mark the SeekableBinaryIO stream as closed as well"""
797
+
try:
798
+
self._underlying_stream.close()
799
+
self._closed=True
800
+
except:
801
+
self._underlying_stream=None
802
+
self._closed=True
803
+
804
+
defclosed(self):
805
+
"""Reflects whether we permit additional operations on this stream"""
806
+
returnself._closed
807
+
808
+
deffileno(self):
809
+
raiseUnsupportedOperation("fileno() is not supported on this stream")
810
+
811
+
defflush(self):
812
+
return
813
+
814
+
defisatty(self):
815
+
returnFalse
816
+
817
+
defreadable(self):
818
+
returnTrue
819
+
820
+
defreadline(self, __size=-1):
821
+
self._ensure_open_stream()
822
+
out=self._underlying_stream.readline(__size)
823
+
self._current_pos_of_underlying_stream+=len(out)
824
+
returnout
825
+
826
+
defreadlines(self, __hint=-1):
827
+
self._ensure_open_stream()
828
+
out=self._underlying_stream.readlines(__hint)
829
+
self._current_pos_of_underlying_stream+=len(out)
830
+
returnout
831
+
832
+
defseek(self, __offset, __whence=os.SEEK_SET, /):
833
+
"""
834
+
Change the stream position to the given byte offset, which may necessitate closing the existing client connection and opening a new one.
835
+
836
+
:param __offset: Change the position to the byte offset, relative to the whence reference point
837
+
:param __whence:
838
+
- os.SEEK_SET / 0: Start of the file, offset must be 0 or positive
839
+
- os.SEEK_CUR / 1: Current position, offset may be pos/neg/0
840
+
- os.SEEK_END / 2: End of the file, offset must be 0 or negative
841
+
:return: absolute position of the stream (in the overall file)
0 commit comments