Changeset 572
- Timestamp:
- 2006-10-14 14:49:38 (2 years ago)
- Files:
-
- branches/add_stat_caching/ftp_stat_cache.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/add_stat_caching/ftp_stat_cache.py
r571 r572 46 46 self._debug = False 47 47 self.enabled = True 48 #self.enabled = False 48 49 49 def _debug_output(self, text): 50 if self._debug: 51 print "***", text 50 def clear(self): 51 self._cache.clear() 52 52 53 53 def invalidate(self, path): … … 57 57 pass 58 58 59 def clear(self):60 self._cache.clear()61 62 59 def __getitem__(self, path): 60 """ 61 Return the stat entry for the `path`. If there's no stored 62 stat entry, raise `CacheMissError`. 63 """ 63 64 try: 64 65 lines = self._cache[path] … … 67 68 except KeyError: 68 69 self._debug_output("Requested path %s ... _not_ found" % path) 69 raise CacheMissError 70 raise CacheMissError("no path %s in cache" % path) 70 71 71 72 def __setitem__(self, path, lines): … … 77 78 78 79 def __contains__(self, path): 79 return path in self._cache 80 return (path in self._cache) 81 82 # the following methods are only intended for debugging! 83 def _debug_output(self, text): 84 if self._debug: 85 print "***", text 86 87 def __len__(self): 88 return len(self._cache) 80 89 81 90 def __str__(self): 82 91 lines = [] 83 92 for key in sorted(self._cache): 84 lines.append( key)93 lines.append("%s: %s" % (key, self[key])) 85 94 return "\n".join(lines) 86 95
