예제 #1
0
    async def retrieve_response_body(response: Response) -> bytes:
        class async_iterator_wrapper:
            def __init__(self, obj):
                self._it = iter(obj)

            def __aiter__(self):
                return self

            async def __anext__(self):
                try:
                    value = next(self._it)
                except StopIteration:
                    raise StopAsyncIteration
                return value

        resp_body = [section async for section in response.__dict__['body_iterator']]
        response.__setattr__('body_iterator', async_iterator_wrapper(resp_body))
        return resp_body[0]