'Map key-value pair to an objects attribute.
Args:
subject: _ObjectMapper of object that will receive new attribute.
key: Key of attribute.
value: Value of new attribute.
Raises:
UnexpectedAttribute when the key is not a validated attribute of
the subject value class.'

def MapTo(self, subject, key, value):

    assert isinstance(subject.value, validation.ValidatedBase)
    try:
        attribute = subject.value.GetValidator(key)
    except validation.ValidationError as err:
        raise yaml_errors.UnexpectedAttribute(err)
    if isinstance(value, _ObjectMapper):
        value.set_value(attribute.expected_type())
        value = value.value
    elif isinstance(value, _ObjectSequencer):
        value.set_constructor(self._GetRepeated(attribute))
        value = value.value
    subject.see(key)
    try:
        subject.value.Set(key, value)
    except validation.ValidationError as e:
        try:
            error_str = str(e)
        except Exception:
            error_str = '<unknown>'
        try:
            value_str = str(value)
        except Exception:
            value_str = '<unknown>'
        e.message = ("Unable    to    assign    value    '%s'    to    attribute    '%s':\n%s" % (value_str, key, error_str))
        raise e
    except Exception as e:
        try:
            error_str = str(e)
        except Exception:
            error_str = '<unknown>'
        try:
            value_str = str(value)
        except Exception:
            value_str = '<unknown>'
        message = ("Unable    to    assign    value    '%s'    to    attribute    '%s':\n%s" % (value_str, key, error_str))
        raise validation.ValidationError(message, e)
