<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ResolvePrefix(self, subject, attribute_prefix, timestamp=None, limit=None):
 """Resolve all attributes for a subject starting with a prefix."""

    subject = utils.SmartUnicode(subject)

    if timestamp in [None, self.NEWEST_TIMESTAMP, self.ALL_TIMESTAMPS]:
      start, end = 0, (2**63) - 1
    # Does timestamp represent a range?
    elif isinstance(timestamp, (list, tuple)):
      start, end = timestamp  # pylint: disable=unpacking-non-sequence
    else:
      raise ValueError("Invalid timestamp: %s" % timestamp)

    start = int(start)
    end = int(end)

    # TODO(hanuszczak): Make this function accept only one attribute prefix and
    # only a unicode object.
    if isinstance(attribute_prefix, string_types):
      attribute_prefix = [attribute_prefix]

    try:
      record = self.subjects[subject]
    except KeyError:
      return []

    # Holds all the attributes which matched. Keys are attribute names, values
    # are lists of timestamped data.
    results = {}
    nr_results = 0
    for prefix in attribute_prefix:
      for attribute, values in iteritems(record):
        if limit and nr_results >= limit:
          break
        # TODO(hanuszczak): After resolving the TODO comment above this call to
        # `unicode` should be redundant.
        if str(attribute).startswith(prefix):
          for encoded_value, ts in values:
            results_list = results.setdefault(attribute, [])
            # If we are always after the latest ts we clear older ones.
            if (results_list and timestamp in [self.NEWEST_TIMESTAMP, None] and
                results_list[0][1] < ts):
              results_list = []
              results[attribute] = results_list

            # Timestamp outside the range, drop it.
            elif ts < start or ts > end:
              continue

            value = self._value_converter.Decode(attribute, encoded_value)
            results_list.append((attribute, ts, value))
            nr_results += 1
            if limit and nr_results >= limit:
              break

    result = []
    for attribute_name, values in sorted(iteritems(results)):
      # Values are triples of (attribute_name, timestamp, data). We want to
      # sort by timestamp.
      for _, ts, data in sorted(values, key=lambda x: x[1], reverse=True):
        # Return triples (attribute_name, data, timestamp).
        result.append((attribute_name, data, ts))
    return result