def ReadData(self, source):
    """Parses source option and reads appropriate data source.

    Args:
      source: Source of Appstats data. Either filename if being read from
        a file or MEMCACHE if being read from memcache.
    Returns:
      errormessage: An error message to display to the user if an error occured
        while reading data, None if no error occured.
      recordlist: A list of Appstats records in RequestStatProto protobuf format
        in reverse chronological order (i.e. most recent first).
    """
    errormessage = None
    recordlist = None
    if source == 'MEMCACHE':

      recordlist = loader.FromMemcache()
    else:
      rootdir = self.GetRoot()
      if rootdir is None:
        errormessage = 'No parent directory has app.yaml!'
        return errormessage, recordlist
      source_root = os.path.join(rootdir, source)
      try:
        outfile = mockable_open(source_root, 'rb')
      except __HOLE__:
        logging.error('Cannot open %s', source)
        errormessage = 'Unable to open file!'
        return errormessage, recordlist
      mtime = os.path.getmtime(source_root)
      if cache.IsCached(source, mtime):
        logging.info('Using cached records from %s', source)
        recordlist = cache.recordlist
      else:
        logging.info('Reading fresh records from %s', source)
        recordlist = loader.UnpickleFromFile(outfile)
        cache.Insert(source, mtime, recordlist)
    return errormessage, recordlist
dataset/ETHPy150Open AppScale/appscale/AppServer/google/appengine/ext/analytics/main.py/StatsPage.ReadData