Higher order function that takes one of our bound API methods and wraps it to support streaming and returning the raw `APIResponse` object directly.
(func: Callable[P, R])
| 645 | |
| 646 | |
| 647 | def to_streamed_response_wrapper(func: Callable[P, R]) -> Callable[P, ResponseContextManager[APIResponse[R]]]: |
| 648 | """Higher order function that takes one of our bound API methods and wraps it |
| 649 | to support streaming and returning the raw `APIResponse` object directly. |
| 650 | """ |
| 651 | |
| 652 | @functools.wraps(func) |
| 653 | def wrapped(*args: P.args, **kwargs: P.kwargs) -> ResponseContextManager[APIResponse[R]]: |
| 654 | extra_headers: dict[str, str] = {**(cast(Any, kwargs.get("extra_headers")) or {})} |
| 655 | extra_headers[RAW_RESPONSE_HEADER] = "stream" |
| 656 | |
| 657 | kwargs["extra_headers"] = extra_headers |
| 658 | |
| 659 | make_request = functools.partial(func, *args, **kwargs) |
| 660 | |
| 661 | return ResponseContextManager(cast(Callable[[], APIResponse[R]], make_request)) |
| 662 | |
| 663 | return wrapped |
| 664 | |
| 665 | |
| 666 | def async_to_streamed_response_wrapper( |