def read_expected_message(self, expected_types, error_handler=None):
    message = self.read_message()
    if isinstance(message, expected_types):
        return message
    elif isinstance(message, messages.ErrorResponse):
        if (error_handler is not None):
            error_handler(message)
        else:
            raise errors.DatabaseError(message.error_message())
    else:
        msg = 'Received unexpected message type: {}. '.format(type(message).__name__)
        if isinstance(expected_types, tuple):
            msg += 'Expected types: {}'.format(', '.join([t.__name__ for t in expected_types]))
        else:
            msg += 'Expected type: {}'.format(expected_types.__name__)
        self._logger.error(msg)
        raise errors.MessageError(msg)
def read_expected_message(self, expected_types, error_handler=None):
    message = self.read_message()
    if isinstance(message, expected_types):
        return message
    elif isinstance(message, messages.ErrorResponse):
        if (error_handler is not None):
            error_handler(message)
        else:
            raise errors.DatabaseError(message.error_message())
    else:
        msg = 'Received unexpected message type: {}. '.format(type(message).__name__)
        if isinstance(expected_types, tuple):
            msg += 'Expected types: {}'.format(', '.join([t.__name__ for t in expected_types]))
        else:
            msg += 'Expected type: {}'.format(expected_types.__name__)
        self._logger.error(msg)
        raise errors.MessageError(msg)