示例#1
0
文件: wiki_dicts.py 项目: aahlad/soar
    def _load_dict(self):
        request = self.request
        dict_name = self.name

        page = Page(request, dict_name)
        if page.exists():
            arena = 'pagedicts'
            key = wikiutil.quoteWikinameFS(dict_name)
            cache = caching.CacheEntry(request,
                                       arena,
                                       key,
                                       scope='wiki',
                                       use_pickle=True)
            try:
                cache_mtime = cache.mtime()
                page_mtime = wikiutil.version2timestamp(page.mtime_usecs())
                # TODO: fix up-to-date check mtime granularity problems.
                #
                # cache_mtime is float while page_mtime is integer
                # The comparision needs to be done on the lowest type of both
                if int(cache_mtime) > int(page_mtime):
                    # cache is uptodate
                    return cache.content()
                else:
                    raise caching.CacheError
            except caching.CacheError:
                # either cache does not exist, is erroneous or not uptodate: recreate it
                d = super(WikiDict, self)._load_dict()
                cache.update(d)
                return d
        else:
            raise DictDoesNotExistError(dict_name)
示例#2
0
 def _load_dict(self):
     dict_name = self.name
     if flaskg.unprotected_storage.has_item(dict_name):
         item = flaskg.unprotected_storage.get_item(dict_name)
         rev = item.get_revision(-1)
         somedict = rev.get(SOMEDICT, {})
         return somedict
     else:
         raise DictDoesNotExistError(dict_name)
示例#3
0
 def _load_dict(self):
     dict_name = self.name
     item = flaskg.unprotected_storage[dict_name]
     try:
         rev = item[CURRENT]
         somedict = rev.meta.get(SOMEDICT, {})
         return somedict
     except KeyError:
         raise DictDoesNotExistError(dict_name)
示例#4
0
 def __getitem__(self, dict_name):
     """
     Get a dict by its name. First match counts.
     """
     for backend in self._backends:
         try:
             return backend[dict_name]
         except DictDoesNotExistError:
             pass
     raise DictDoesNotExistError(dict_name)
示例#5
0
 def _retrieve_items(self, dict_name):
     try:
         return self._dicts[dict_name]
     except KeyError:
         raise DictDoesNotExistError(dict_name)