ยปCore Development>Code coverage>Lib/dircache.py

Python code coverage for Lib/dircache.py

#countcontent
1n/a"""Read and cache directory listings.
2n/a
3n/aThe listdir() routine returns a sorted list of the files in a directory,
4n/ausing a cache to avoid reading the directory more often than necessary.
51The annotate() routine appends slashes to directories."""
61from warnings import warnpy3k
71warnpy3k("the dircache module has been removed in Python 3.0", stacklevel=2)
81del warnpy3k
9n/a
101import os
11n/a
121__all__ = ["listdir", "opendir", "annotate", "reset"]
13n/a
141cache = {}
15n/a
161def reset():
17n/a """Reset the cache completely."""
18n/a global cache
191 cache = {}
20n/a
211def listdir(path):
22n/a """List directory contents, using cache."""
235 try:
245 cached_mtime, list = cache[path]
253 del cache[path]
262 except KeyError:
272 cached_mtime, list = -1, []
285 mtime = os.stat(path).st_mtime
294 if mtime != cached_mtime:
302 list = os.listdir(path)
312 list.sort()
324 cache[path] = mtime, list
334 return list
34n/a
351opendir = listdir # XXX backward compatibility
36n/a
371def annotate(head, list):
38n/a """Add '/' suffixes to directories."""
394 for i in range(len(list)):
403 if os.path.isdir(os.path.join(head, list[i])):
411 list[i] = list[i] + '/'