diff options
author | Guido van Rossum <guido@python.org> | 1990-10-21 16:17:34 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1990-10-21 16:17:34 (GMT) |
commit | 40d9304d66edcab3925c75e9d8ad093562cf5d7b (patch) | |
tree | 3bc446bca5a87b869635865bb2f1e97b0b33116b /Lib/statcache.py | |
parent | 6b47ed1f9d21371b33d5a46615edef8b61ac4a94 (diff) | |
download | cpython-40d9304d66edcab3925c75e9d8ad093562cf5d7b.zip cpython-40d9304d66edcab3925c75e9d8ad093562cf5d7b.tar.gz cpython-40d9304d66edcab3925c75e9d8ad093562cf5d7b.tar.bz2 |
Use 'stat' module instead of hardcoding information from <sys/stat.h>.
Diffstat (limited to 'Lib/statcache.py')
-rw-r--r-- | Lib/statcache.py | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/Lib/statcache.py b/Lib/statcache.py index eeb0ca4..36ecc96 100644 --- a/Lib/statcache.py +++ b/Lib/statcache.py @@ -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 @@ cache = {} # 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 @@ def reset(): # 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 forget_except_prefix(prefix): # 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]) |