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

Class BoundSyncStream

httpx/_client.py:139–159  ·  view source on GitHub ↗

A byte stream that is bound to a given response instance, and that ensures the `response.elapsed` is set once the response is closed.

Source from the content-addressed store, hash-verified

137
138
139class BoundSyncStream(SyncByteStream):
140 """
141 A byte stream that is bound to a given response instance, and that
142 ensures the `response.elapsed` is set once the response is closed.
143 """
144
145 def __init__(
146 self, stream: SyncByteStream, response: Response, start: float
147 ) -> None:
148 self._stream = stream
149 self._response = response
150 self._start = start
151
152 def __iter__(self) -> typing.Iterator[bytes]:
153 for chunk in self._stream:
154 yield chunk
155
156 def close(self) -> None:
157 elapsed = time.perf_counter() - self._start
158 self._response.elapsed = datetime.timedelta(seconds=elapsed)
159 self._stream.close()
160
161
162class BoundAsyncStream(AsyncByteStream):

Callers 1

_send_single_requestMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected