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

Method iter_text

httpx/_models.py:907–924  ·  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

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

Callers 4

iter_linesMethod · 0.95
test_iter_textFunction · 0.95

Calls 8

iter_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_iter_textFunction · 0.76