in urlutils.py [0:0]
def urlcache(url):
""" Get url contents -- optional caching """
if CACHE:
# basename seems to work OK with URLs
cache = join(CACHE, hashurl(url)+".tmp")
if isFileStale(cache):
if DEBUG:
print("Caching %s" % url, file=sys.stderr)
data = geturl(url)
with open(cache,'wb') as w:
w.write(data)
return data
else:
if DEBUG:
print("Using cache for %s" % url, file=sys.stderr)
with open(cache,'r') as r:
return r.read()
else:
if DEBUG:
print("Fetching %s" % url, file=sys.stderr)
return geturl(url)