A str-iterator over the decoded response content that handles both gzip, deflate, etc but also detects the content's string encoding.
(self, chunk_size: int | None = None)
| 905 | yield chunk |
| 906 | |
| 907 | def iter_text(self, chunk_size: int | None = None) -> typing.Iterator[str]: |
| 908 | """ |
| 909 | A str-iterator over the decoded response content |
| 910 | that handles both gzip, deflate, etc but also detects the content's |
| 911 | string encoding. |
| 912 | """ |
| 913 | decoder = TextDecoder(encoding=self.encoding or "utf-8") |
| 914 | chunker = TextChunker(chunk_size=chunk_size) |
| 915 | with request_context(request=self._request): |
| 916 | for byte_content in self.iter_bytes(): |
| 917 | text_content = decoder.decode(byte_content) |
| 918 | for chunk in chunker.decode(text_content): |
| 919 | yield chunk |
| 920 | text_content = decoder.flush() |
| 921 | for chunk in chunker.decode(text_content): |
| 922 | yield chunk # pragma: no cover |
| 923 | for chunk in chunker.flush(): |
| 924 | yield chunk |
| 925 | |
| 926 | def iter_lines(self) -> typing.Iterator[str]: |
| 927 | decoder = LineDecoder() |