code: def stream_with_context(func: Callable) -> Callable:
      
      request_context = _request_ctx_stack.top.copy()
  
      @wraps(func)
      async def generator(*args: Any, **kwargs: Any) -> Any:
          async with request_context:
              async for data in func(*args, **kwargs):
                  yield data
      return generator
docs: Share the current request context with a generator.
  
      This allows the request context to be accessed within a streaming
      generator, for example,
  
      .. code-block:: python
  
          @app.route('/')
          def index() -> AsyncGenerator[bytes, None]:
              @stream_with_context
              async def generator() -> bytes:
                  yield request.method.encode()
                  yield b' '
                  yield request.path.encode()
  
              return generator()