|
1 | 1 | """Repository implementation for Pierre Git Storage SDK.""" |
2 | 2 |
|
| 3 | +import contextlib |
3 | 4 | import warnings |
4 | 5 | from datetime import datetime, timezone |
5 | 6 | from types import TracebackType |
|
51 | 52 | class StreamingResponse: |
52 | 53 | """Stream wrapper that keeps the HTTP client alive until closed.""" |
53 | 54 |
|
54 | | - def __init__(self, response: httpx.Response, client: httpx.AsyncClient) -> None: |
| 55 | + def __init__(self, response: httpx.Response, client: httpx.AsyncClient, stream_context: Optional[contextlib.AbstractAsyncContextManager] = None) -> None: |
55 | 56 | self._response = response |
56 | 57 | self._client = client |
| 58 | + self._stream_context = stream_context |
57 | 59 |
|
58 | 60 | def __getattr__(self, name: str) -> Any: |
59 | 61 | return getattr(self._response, name) |
60 | 62 |
|
61 | 63 | async def aclose(self) -> None: |
62 | 64 | await self._response.aclose() |
| 65 | + if self._stream_context is not None: |
| 66 | + await self._stream_context.__aexit__(None, None, None) |
63 | 67 | await self._client.aclose() |
64 | 68 |
|
65 | 69 | async def __aenter__(self) -> "StreamingResponse": |
@@ -264,7 +268,7 @@ async def get_file_stream( |
264 | 268 | await client.aclose() |
265 | 269 | raise |
266 | 270 |
|
267 | | - return StreamingResponse(response, client) |
| 271 | + return StreamingResponse(response, client, stream_context) |
268 | 272 |
|
269 | 273 | async def get_archive_stream( |
270 | 274 | self, |
@@ -324,7 +328,7 @@ async def get_archive_stream( |
324 | 328 | await client.aclose() |
325 | 329 | raise |
326 | 330 |
|
327 | | - return StreamingResponse(response, client) |
| 331 | + return StreamingResponse(response, client, stream_context) |
328 | 332 |
|
329 | 333 | async def list_files( |
330 | 334 | self, |
|
0 commit comments