12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- def cache(self,cache, path):
- self.fc = None
- if not use.cache:return
- if path.count(':/'): return
- if cache:
- mkdir(cache%'')
- else:
- cache = '%s'
- try:
- os.stat( path)
- print('hit',end=' ')
- return path
- except:
- self.fc = path
- print('miss',end=' ')
- print(path)
- def store(self):
- if self.valid:
- print('cacheget',self.fc,end=' ')
- try:
- with open(self.fc,'wb') as f:
- f.write( self.u.read() )
- print('ok')
- except Exception as e:
- print('fail',e)
- return self
- def __init__(self, path, mode="rb"):
- hit=''
- self.valid = False
- if path.count('/')==2:
- hit = '/'.join( ('',path.split('/')[1] , '%s', ) )
- hit = self.cache(hit, path)
- if hit: return
- if not path.count(':/'):
- path = ''.join( (use.srv , path, ) )
- print('GET',path)
- try:
- self.u = await_(klib.urlopen(path))
- self.valid = True
- except Exception as e:
- self.u = str(e)
- if e.args[0]==2:
- pdb('404',path)
- return
- pdb('50:',e)
|