MCPcopy
hub / github.com/encode/httpx / aiter_text

Method aiter_text

httpx/_models.py:1007–1026  ·  view source on GitHub ↗

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
    )

Source from the content-addressed store, hash-verified

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()

Callers 4

aiter_linesMethod · 0.95
test_aiter_textFunction · 0.95

Calls 8

aiter_bytesMethod · 0.95
decodeMethod · 0.95
decodeMethod · 0.95
flushMethod · 0.95
flushMethod · 0.95
TextDecoderClass · 0.85
TextChunkerClass · 0.85
request_contextFunction · 0.85

Tested by 3

test_aiter_textFunction · 0.76