'Resolve all attributes for a subject starting with a prefix.'

@utils.Synchronized
def ResolvePrefix(self, subject, attribute_prefix, token=None, timestamp=None, limit=None):

    subject = utils.SmartUnicode(subject)
    if (timestamp in [None, self.NEWEST_TIMESTAMP, self.ALL_TIMESTAMPS]):
        (start, end) = (0, ((2 ** 63) - 1))
    elif isinstance(timestamp, (list, tuple)):
        (start, end) = timestamp
    else:
        raise ValueError(('Invalid    timestamp:    %s' % timestamp))
    start = int(start)
    end = int(end)
    if isinstance(attribute_prefix, str):
        attribute_prefix = [attribute_prefix]
    subject = utils.SmartUnicode(subject)
    try:
        record = self.subjects[subject]
    except KeyError:
        return []
    results = {}
    nr_results = 0
    for prefix in attribute_prefix:
        for (attribute, values) in record.iteritems():
            if (limit and (nr_results >= limit)):
                break
            if utils.SmartStr(attribute).startswith(prefix):
                for (value, ts) in values:
                    results_list = results.setdefault(attribute, [])
                    if (results_list and (timestamp == self.NEWEST_TIMESTAMP) and (results_list[0][1] < ts)):
                        results_list = []
                        results[attribute] = results_list
                    elif ((ts < start) or (ts > end)):
                        continue
                    results_list.append((attribute, ts, value))
                    nr_results += 1
                    if (limit and (nr_results >= limit)):
                        break
    result = []
    for (attribute_name, values) in sorted(results.items()):
        for (_, ts, data) in sorted(values, key=(lambda x: x[1]), reverse=True):
            result.append((attribute_name, data, ts))
    return result
