+++ /dev/null
-"""Read and cache directory listings.\r
-\r
-The listdir() routine returns a sorted list of the files in a directory,\r
-using a cache to avoid reading the directory more often than necessary.\r
-The annotate() routine appends slashes to directories."""\r
-from warnings import warnpy3k\r
-warnpy3k("the dircache module has been removed in Python 3.0", stacklevel=2)\r
-del warnpy3k\r
-\r
-import os\r
-\r
-__all__ = ["listdir", "opendir", "annotate", "reset"]\r
-\r
-cache = {}\r
-\r
-def reset():\r
- """Reset the cache completely."""\r
- global cache\r
- cache = {}\r
-\r
-def listdir(path):\r
- """List directory contents, using cache."""\r
- try:\r
- cached_mtime, list = cache[path]\r
- del cache[path]\r
- except KeyError:\r
- cached_mtime, list = -1, []\r
- mtime = os.stat(path).st_mtime\r
- if mtime != cached_mtime:\r
- list = os.listdir(path)\r
- list.sort()\r
- cache[path] = mtime, list\r
- return list\r
-\r
-opendir = listdir # XXX backward compatibility\r
-\r
-def annotate(head, list):\r
- """Add '/' suffixes to directories."""\r
- for i in range(len(list)):\r
- if os.path.isdir(os.path.join(head, list[i])):\r
- list[i] = list[i] + '/'\r