1 import os, md5, urllib, time
5 def __init__(self, dir):
13 def fetch(self, url, expire = 3600):
14 path = pj(self.dir, self.mangle(url))
15 if os.path.exists(path):
16 if time.time() - os.stat(path).st_mtime < expire:
19 s = urllib.urlopen(url)
24 if not os.path.isdir(self.dir):
26 with open(path, "w") as f:
30 home = os.getenv("HOME")
31 if home is None or not os.path.isdir(home):
32 raise Exception("Could not find home directory for HTTP caching")
33 default = cache(pj(home, ".manga", "htcache"))
35 def fetch(url, expire = 3600):
36 return default.fetch(url, expire)