def _parse_response(proto, response): """Parses the content from a validator response Message. """ try: content = proto() content.ParseFromString(response.content) return content except ValidatorConnectionError: LOGGER.warning('Validator disconnected while waiting for response') raise errors.ValidatorDisconnected() except (DecodeError, AttributeError): LOGGER.error('Validator response was not parsable: %s', response) raise errors.ValidatorResponseInvalid()
async def _send_request(self, request_type, payload): """Uses an executor to send an asynchronous ZMQ request to the validator with the handler's Connection """ try: return await self._connection.send(message_type=request_type, message_content=payload, timeout=self._timeout) except DisconnectError: LOGGER.warning('Validator disconnected while waiting for response') raise errors.ValidatorDisconnected() except asyncio.TimeoutError: LOGGER.warning('Timed out while waiting for validator response') raise errors.ValidatorTimedOut()
async def _try_validator_request(self, message_type, content): """Serializes and sends a Protobuf message to the validator. Handles timeout errors as needed. """ if isinstance(content, BaseMessage): content = content.SerializeToString() future = self._stream.send(message_type=message_type, content=content) try: response = await self._loop.run_in_executor( None, future.result, self._timeout) except FutureTimeoutError: raise errors.ValidatorTimedOut() try: return response.content except ValidatorConnectionError: raise errors.ValidatorDisconnected()