summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoshe Zadka <moshez@math.huji.ac.il>2001-03-31 13:46:34 +0000
committerMoshe Zadka <moshez@math.huji.ac.il>2001-03-31 13:46:34 +0000
commita8f9bb48a5fb8f9ef84fd9269d0850c30603341f (patch)
tree6063d2218065d49814dcd4b2438ac126311f4be8
parenta4c9d0c124a5df18bd755a74d3f478c18b42e390 (diff)
downloadcpython-a8f9bb48a5fb8f9ef84fd9269d0850c30603341f.tar.gz
- #130306 - statcache.py - full of thread problems.
- Made statcache.forget_dir more portable
-rw-r--r--Lib/statcache.py31
-rw-r--r--Misc/NEWS4
2 files changed, 17 insertions, 18 deletions
diff --git a/Lib/statcache.py b/Lib/statcache.py
index b5147c233d..7eb87b96a9 100644
--- a/Lib/statcache.py
+++ b/Lib/statcache.py
@@ -14,22 +14,24 @@ cache = {}
def stat(path):
"""Stat a file, possibly out of the cache."""
- if cache.has_key(path):
- return cache[path]
+ ret = cache.get(path, None)
+ if ret is not None:
+ return ret
cache[path] = ret = os.stat(path)
return ret
def reset():
"""Reset the cache completely."""
- global cache
- cache = {}
+ cache.clear()
def forget(path):
"""Remove a given item from the cache, if it exists."""
- if cache.has_key(path):
+ try:
del cache[path]
+ except KeyError:
+ pass
def forget_prefix(prefix):
@@ -37,25 +39,18 @@ def forget_prefix(prefix):
n = len(prefix)
for path in cache.keys():
if path[:n] == prefix:
- del cache[path]
+ forget(path)
def forget_dir(prefix):
"""Forget about a directory and all entries in it, but not about
entries in subdirectories."""
- if prefix[-1:] == '/' and prefix <> '/':
- prefix = prefix[:-1]
+ import os.path
+ prefix = os.path.dirname(os.path.join(prefix, "xxx"))
forget(prefix)
- if prefix[-1:] <> '/':
- prefix = prefix + '/'
- n = len(prefix)
for path in cache.keys():
- if path[:n] == prefix:
- rest = path[n:]
- if rest[-1:] == '/': rest = rest[:-1]
- if '/' not in rest:
- del cache[path]
-
+ if path.startswith(prefix) and os.path.dirname(path) == prefix:
+ forget(path)
def forget_except_prefix(prefix):
"""Remove all pathnames except with a given prefix.
@@ -63,7 +58,7 @@ def forget_except_prefix(prefix):
n = len(prefix)
for path in cache.keys():
if path[:n] <> prefix:
- del cache[path]
+ forget(path)
def isdir(path):
diff --git a/Misc/NEWS b/Misc/NEWS
index 45b34a52a2..7690d343c7 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -117,6 +117,10 @@ http://sourceforge.net/tracker/index.php?func=detail&aid=<id>&group_id=5470&atid
- #117745 - UserString.py - Fix two typos in __imul__.
+- #130306 - statcache.py - full of thread problems.
+
+- Made statcache.forget_dir more portable
+
What's New in Python 2.0?
=========================