

def _recv_message(self, expected_type=None):
    'Reads a message from Google TV.\n\n    Args:\n      expected_type: If provided, verifies that the inner message is of the\n          expected type.\n\n    Returns:\n      The inner message received from Google TV.\n\n    Raises:\n      AssertionError: If a bad status was received from Google TV.\n      MessageTypeError: If an expected_type was provided and the received type\n          does not match the expected.\n    '
    types = polo_pb2.OuterMessage
    message_types = {
        types.MESSAGE_TYPE_CONFIGURATION: polo_pb2.Configuration,
        types.MESSAGE_TYPE_CONFIGURATION_ACK: polo_pb2.ConfigurationAck,
        types.MESSAGE_TYPE_OPTIONS: polo_pb2.Options,
        types.MESSAGE_TYPE_PAIRING_REQUEST: polo_pb2.PairingRequest,
        types.MESSAGE_TYPE_PAIRING_REQUEST_ACK: polo_pb2.PairingRequestAck,
        types.MESSAGE_TYPE_SECRET: polo_pb2.Secret,
        types.MESSAGE_TYPE_SECRET_ACK: polo_pb2.SecretAck,
    }
    data = self.recv()
    req = polo_pb2.OuterMessage.FromString(data)
    assert (req.status == polo_pb2.OuterMessage.STATUS_OK)
    if (expected_type and (expected_type != req.type)):
        expected = message_types[expected_type].__name__
        actual = message_types[req.type].__name__
        raise MessageTypeError(('Expected %s but received %s' % (expected, actual)))
    message_type = message_types[req.type]
    message = message_type.FromString(req.payload)
    return message

dataset/ETHPy150Open stevenle/googletv-anymote/googletv/__init__.py PairingProtocol._recv_message/original