Exemplo n.º 1
0
    async def write(self, request: RequestType) -> None:
        # If no queue was created it means that requests
        # should be expected through an iterators provided
        # by the caller.
        if self._write_to_iterator_queue is None:
            raise cygrpc.UsageError(_API_STYLE_ERROR)

        try:
            call = await self._interceptors_task
        except (asyncio.CancelledError, AioRpcError):
            raise asyncio.InvalidStateError(_RPC_ALREADY_FINISHED_DETAILS)

        if call.done():
            raise asyncio.InvalidStateError(_RPC_ALREADY_FINISHED_DETAILS)
        elif call._done_writing_flag:
            raise asyncio.InvalidStateError(_RPC_HALF_CLOSED_DETAILS)

        # Write might never end up since the call could abrubtly finish,
        # we give up on the first awaitable object that finishes..
        _, _ = await asyncio.wait(
            (self._write_to_iterator_queue.put(request), call),
            return_when=asyncio.FIRST_COMPLETED)

        if call.done():
            raise asyncio.InvalidStateError(_RPC_ALREADY_FINISHED_DETAILS)
Exemplo n.º 2
0
    async def done_writing(self) -> None:
        """Signal peer that client is done writing.

        This method is idempotent.
        """
        # If no queue was created it means that requests
        # should be expected through an iterators provided
        # by the caller.
        if self._write_to_iterator_queue is None:
            raise cygrpc.UsageError(_API_STYLE_ERROR)

        try:
            call = await self._interceptors_task
        except asyncio.CancelledError:
            raise asyncio.InvalidStateError(_RPC_ALREADY_FINISHED_DETAILS)

        await self._write_to_iterator_queue_interruptible(
            _InterceptedStreamRequestMixin._FINISH_ITERATOR_SENTINEL, call)
Exemplo n.º 3
0
    async def done_writing(self) -> None:
        """Signal peer that client is done writing.

        This method is idempotent.
        """
        # If no queue was created it means that requests
        # should be expected through an iterators provided
        # by the caller.
        if self._write_to_iterator_queue is None:
            raise cygrpc.UsageError(_API_STYLE_ERROR)

        try:
            call = await self._interceptors_task
        except asyncio.CancelledError:
            raise asyncio.InvalidStateError(_RPC_ALREADY_FINISHED_DETAILS)

        # Write might never end up since the call could abrubtly finish,
        # we give up on the first awaitable object that finishes.
        _, _ = await asyncio.wait((self._write_to_iterator_queue.put(
            InterceptedStreamUnaryCall._FINISH_ITERATOR_SENTINEL), call),
                                  return_when=asyncio.FIRST_COMPLETED)
Exemplo n.º 4
0
    async def write(self, request: RequestType) -> None:
        # If no queue was created it means that requests
        # should be expected through an iterators provided
        # by the caller.
        if self._write_to_iterator_queue is None:
            raise cygrpc.UsageError(_API_STYLE_ERROR)

        try:
            call = await self._interceptors_task
        except (asyncio.CancelledError, AioRpcError):
            raise asyncio.InvalidStateError(_RPC_ALREADY_FINISHED_DETAILS)

        if call.done():
            raise asyncio.InvalidStateError(_RPC_ALREADY_FINISHED_DETAILS)
        elif call._done_writing_flag:
            raise asyncio.InvalidStateError(_RPC_HALF_CLOSED_DETAILS)

        await self._write_to_iterator_queue_interruptible(request, call)

        if call.done():
            raise asyncio.InvalidStateError(_RPC_ALREADY_FINISHED_DETAILS)
Exemplo n.º 5
0
Arquivo: _call.py Projeto: Kvnyu/culie
 def _raise_for_different_style(self, style: _APIStyle):
     if self._request_style is not style:
         raise cygrpc.UsageError(_API_STYLE_ERROR)
Exemplo n.º 6
0
Arquivo: _call.py Projeto: Kvnyu/culie
 def _update_response_style(self, style: _APIStyle):
     if self._response_style is _APIStyle.UNKNOWN:
         self._response_style = style
     elif self._response_style is not style:
         raise cygrpc.UsageError(_API_STYLE_ERROR)
Exemplo n.º 7
0
 def _raise_for_different_style(self, style: _APIStyle):
     if self._request_style is not style:
         raise cygrpc.UsageError(
             'Please don\'t mix two styles of API for streaming requests')
Exemplo n.º 8
0
 def _update_response_style(self, style: _APIStyle):
     if self._response_style is _APIStyle.UNKNOWN:
         self._response_style = style
     elif self._response_style is not style:
         raise cygrpc.UsageError(
             'Please don\'t mix two styles of API for streaming responses')