X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Flib%2Fcache.py;fp=sima%2Flib%2Fcache.py;h=c4170de8c1b1f5885642105f67c86fb3b18bf287;hb=85f15b7261386985e8bb7f9b357e55b5f21c21a7;hp=d7175617c171849dfcef0a4a47a93a8072707f09;hpb=63563d000f2646724c1ff91eb6fcca01f5201d23;p=mpd-sima.git diff --git a/sima/lib/cache.py b/sima/lib/cache.py index d717561..c4170de 100644 --- a/sima/lib/cache.py +++ b/sima/lib/cache.py @@ -35,13 +35,16 @@ from ..utils.filelock import FileLock class BaseCache: def get(self, key): - raise NotImplemented() + """Get cache value""" + raise NotImplementedError def set(self, key, value): - raise NotImplemented() + """Set cache value""" + raise NotImplementedError def delete(self, key): - raise NotImplemented() + """Remove cache value""" + raise NotImplementedError class DictCache(BaseCache): @@ -72,8 +75,8 @@ class FileCache: if not os.path.isdir(self.directory): os.mkdir(self.directory) - def encode(self, x): - return md5(x.encode('utf-8')).hexdigest() + def encode(self, val): + return md5(val.encode('utf-8')).hexdigest() def _fn(self, name): return os.path.join(self.directory, self.encode(name)) @@ -86,15 +89,15 @@ class FileCache: def set(self, key, value): name = self._fn(key) with FileLock(name): - with codecs.open(name, 'w+b') as fh: - dump(value, fh) + with codecs.open(name, 'w+b') as flh: + dump(value, flh) def delete(self, key): if not self.forever: os.remove(self._fn(key)) def __iter__(self): - for dirpath, dirnames, filenames in os.walk(self.directory): + for dirpath, _, filenames in os.walk(self.directory): for item in filenames: name = os.path.join(dirpath, item) yield load(codecs.open(name, 'rb'))