A byte stream that is bound to a given response instance, and that ensures the `response.elapsed` is set once the response is closed.
| 137 | |
| 138 | |
| 139 | class 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 | |
| 162 | class BoundAsyncStream(AsyncByteStream): |
no outgoing calls
no test coverage detected