Mercurial > cpython-lru_cache-weakref
diff Lib/statcache.py @ 21:961696ef3ab7 legacy-trunk
Use 'stat' module instead of hardcoding information from <sys/stat.h>.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sun, 21 Oct 1990 16:17:34 +0000 |
| parents | 5570dbb1ce55 |
| children | 683edb0c4463 |
line wrap: on
line diff
--- a/Lib/statcache.py Sun Oct 21 16:17:08 1990 +0000 +++ b/Lib/statcache.py Sun Oct 21 16:17:34 1990 +0000 @@ -4,7 +4,7 @@ # There are functions to reset the cache or to selectively remove items. import posix - +from stat import * # The cache. # Keys are pathnames, values are `posix.stat' outcomes. @@ -15,10 +15,8 @@ # Stat a file, possibly out of the cache. # def stat(path): - try: + if cache.has_key(path): return cache[path] - except RuntimeError: - pass cache[path] = ret = posix.stat(path) return ret @@ -37,10 +35,8 @@ # Remove a given item from the cache, if it exists. # def forget(path): - try: + if cache.has_key(path): del cache[path] - except RuntimeError: - pass # Remove all pathnames with a given prefix. @@ -84,7 +80,7 @@ # def isdir(path): try: - # mode is st[0]; type is mode/4096; S_IFDIR is 4 - return stat(path)[0] / 4096 = 4 - except RuntimeError: + st = stat(path) + except posix.error: return 0 + return S_ISDIR(st[ST_MODE])
