def set_attributes(self, fw_spec, defaults):
    """
    Setup the attributes for an object.

    Those in the fw_spec takes the precedence.

    Args:
      self: The object whose attribute to be set
      fw_spec: A dictionary of the properties to be considerred
      defaults: A dictionary of the keys and its default values

    Returns:
      None

    """

    for key, default in defaults.items():
        if key in fw_spec:
            setattr(self, key, fw_spec[key])
        else:
            value = self.get(key, default)
            setattr(self, key, value)
    return self