Cache path correction

If we look for a cache item that includes the directory seperator
character, then we should replace it with a different character.
This commit is contained in:
Bryan Schumaker 2010-10-30 12:54:45 -04:00
parent c5a606193a
commit 1136e3f4af
1 changed files with 4 additions and 2 deletions

View File

@ -8,6 +8,7 @@ exists = path.exists
join = path.join
ls = path.ls
rm = path.rm
sep = path.sep
CACHE_DIR = join(path.saria_dir(), "cache")
mkdir(CACHE_DIR)
@ -17,6 +18,7 @@ class CacheObject:
self.path = path
def get(self, key, func, *args):
key = key.replace(sep, "_")
path = join(self.path, key)
if not exists(path):
f = open(path, 'w')
@ -38,7 +40,7 @@ class Cache:
return ls(CACHE_DIR)
def __getitem__(self, key):
key = key.replace(sep, "_")
p = join(CACHE_DIR, key)
if not exists(p):
mkdir(p)
mkdir(p)
return CacheObject(p)