1 import os, md5, urllib, time
5 def __init__(self, dir):
14 s = urllib.urlopen(url)
20 def fetch(self, url, expire = 3600):
21 path = pj(self.dir, self.mangle(url))
22 if os.path.exists(path):
23 if time.time() - os.stat(path).st_mtime < expire:
27 if not os.path.isdir(self.dir):
29 with open(path, "w") as f:
33 home = os.getenv("HOME")
34 if home is None or not os.path.isdir(home):
35 raise Exception("Could not find home directory for HTTP caching")
36 default = cache(pj(home, ".manga", "htcache"))
38 def fetch(url, expire = 3600):
39 return default.fetch(url, expire)