def ResolvePrefix(self, prefix, timestamp=None):
    # Break up the timestamp argument.
    if isinstance(timestamp, (list, tuple)):
      start, end = timestamp  # pylint: disable=unpacking-non-sequence
    elif isinstance(timestamp, int):
      start = timestamp
      end = timestamp
    elif timestamp == DataStore.ALL_TIMESTAMPS or timestamp is None:
      start, end = 0, (2 ** 63) - 1
      timestamp = (start, end)
    elif timestamp == DataStore.NEWEST_TIMESTAMP:
      start, end = 0, (2 ** 63) - 1
      # Do not change 'timestamp' since we will use it later.
    else:
      raise ValueError("Value %s is not a valid timestamp" %
                       utils.SmartStr(timestamp))

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

    # Get all results from to_set.
    results = []
    if self.to_set:
      for attribute, values in self.to_set.items():
        if utils.SmartStr(attribute).startswith(prefix):
          results.extend([(attribute, value, ts) for value, ts in values
                          if start <= ts <= end])

    # And also the results from the database.
    ds_results = self.store.ResolvePrefix(self.subject, prefix,
                                          timestamp=timestamp,
                                          token=self.token)

    # Must filter 'to_delete' from 'ds_results'.
    if self.to_delete:
      for val in ds_results:
        attribute, value, ts = val
        if attribute not in self.to_delete:
          results.append(val)
    else:
      results.extend(ds_results)

    if timestamp == DataStore.NEWEST_TIMESTAMP:
      # For each attribute, select the value with the newest timestamp.
      newest_results = {}
      for attribute, value, ts in results:
        current = newest_results.get(attribute, None)
        if current:
          _, _, current_ts = current
          if ts > current_ts:
            newest_results[attribute] = (attribute, value, ts)
        else:
          newest_results[attribute] = (attribute, value, ts)

      results = newest_results.values()

    return sorted(results, key=lambda (a, val, ts): (a, ts, val))
dataset/ETHPy150Open google/grr/grr/lib/data_store.py/CommonTransaction.ResolvePrefix/original