Changeset 549:a2c8c2c58a2a

Show
Ignore:
Timestamp:
2006-10-14 14:49:38 (4 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
add_stat_caching
convert_revision:
svn:778c30c8-61e0-0310-89d4-fe2f97a467b2/branches/add_stat_caching@572
Message:
Add error message to raise of `CacheMissError`.

Added some methods for debugging.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • ftp_stat_cache.py

    r548 r549  
    4646        self._debug = False 
    4747        self.enabled = True 
     48        #self.enabled = False 
    4849 
    49     def _debug_output(self, text): 
    50         if self._debug: 
    51             print "***", text 
     50    def clear(self): 
     51        self._cache.clear() 
    5252 
    5353    def invalidate(self, path): 
     
    5757            pass 
    5858 
    59     def clear(self): 
    60         self._cache.clear() 
    61  
    6259    def __getitem__(self, path): 
     60        """ 
     61        Return the stat entry for the `path`. If there's no stored 
     62        stat entry, raise `CacheMissError`. 
     63        """ 
    6364        try: 
    6465            lines = self._cache[path] 
     
    6768        except KeyError: 
    6869            self._debug_output("Requested path %s ... _not_ found" % path) 
    69             raise CacheMissError 
     70            raise CacheMissError("no path %s in cache" % path) 
    7071 
    7172    def __setitem__(self, path, lines): 
     
    7778 
    7879    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) 
    8089 
    8190    def __str__(self): 
    8291        lines = [] 
    8392        for key in sorted(self._cache): 
    84             lines.append(key) 
     93            lines.append("%s: %s" % (key, self[key])) 
    8594        return "\n".join(lines) 
    8695