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
)
| 1005 | yield chunk |
| 1006 | |
| 1007 | async def aiter_text( |
| 1008 | self, chunk_size: int | None = None |
| 1009 | ) -> typing.AsyncIterator[str]: |
| 1010 | """ |
| 1011 | A str-iterator over the decoded response content |
| 1012 | that handles both gzip, deflate, etc but also detects the content's |
| 1013 | string encoding. |
| 1014 | """ |
| 1015 | decoder = TextDecoder(encoding=self.encoding or "utf-8") |
| 1016 | chunker = TextChunker(chunk_size=chunk_size) |
| 1017 | with request_context(request=self._request): |
| 1018 | async for byte_content in self.aiter_bytes(): |
| 1019 | text_content = decoder.decode(byte_content) |
| 1020 | for chunk in chunker.decode(text_content): |
| 1021 | yield chunk |
| 1022 | text_content = decoder.flush() |
| 1023 | for chunk in chunker.decode(text_content): |
| 1024 | yield chunk # pragma: no cover |
| 1025 | for chunk in chunker.flush(): |
| 1026 | yield chunk |
| 1027 | |
| 1028 | async def aiter_lines(self) -> typing.AsyncIterator[str]: |
| 1029 | decoder = LineDecoder() |