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)
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)
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)
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)
def _raise_for_different_style(self, style: _APIStyle): if self._request_style is not style: raise cygrpc.UsageError(_API_STYLE_ERROR)
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)
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')
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')