A byte-iterator over the raw response content.
(self, chunk_size: int | None = None)
| 933 | yield line |
| 934 | |
| 935 | def iter_raw(self, chunk_size: int | None = None) -> typing.Iterator[bytes]: |
| 936 | """ |
| 937 | A byte-iterator over the raw response content. |
| 938 | """ |
| 939 | if self.is_stream_consumed: |
| 940 | raise StreamConsumed() |
| 941 | if self.is_closed: |
| 942 | raise StreamClosed() |
| 943 | if not isinstance(self.stream, SyncByteStream): |
| 944 | raise RuntimeError("Attempted to call a sync iterator on an async stream.") |
| 945 | |
| 946 | self.is_stream_consumed = True |
| 947 | self._num_bytes_downloaded = 0 |
| 948 | chunker = ByteChunker(chunk_size=chunk_size) |
| 949 | |
| 950 | with request_context(request=self._request): |
| 951 | for raw_stream_bytes in self.stream: |
| 952 | self._num_bytes_downloaded += len(raw_stream_bytes) |
| 953 | for chunk in chunker.decode(raw_stream_bytes): |
| 954 | yield chunk |
| 955 | |
| 956 | for chunk in chunker.flush(): |
| 957 | yield chunk |
| 958 | |
| 959 | self.close() |
| 960 | |
| 961 | def close(self) -> None: |
| 962 | """ |