From 4ebe364277b62785821003a8161a2081618b23a5 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 5 Dec 2004 04:55:14 +0000 Subject: Remove the deprecated statcache module. --- Lib/lib-old/statcache.py | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ Lib/posixfile.py | 6 ---- Lib/statcache.py | 82 ------------------------------------------------ Lib/test/test___all__.py | 3 -- Lib/test/test_sundry.py | 3 -- Misc/NEWS | 2 ++ 6 files changed, 84 insertions(+), 94 deletions(-) create mode 100644 Lib/lib-old/statcache.py delete mode 100644 Lib/statcache.py diff --git a/Lib/lib-old/statcache.py b/Lib/lib-old/statcache.py new file mode 100644 index 0000000..d478393 --- /dev/null +++ b/Lib/lib-old/statcache.py @@ -0,0 +1,82 @@ +"""Maintain a cache of stat() information on files. + +There are functions to reset the cache or to selectively remove items. +""" + +import warnings +warnings.warn("The statcache module is obsolete. Use os.stat() instead.", + DeprecationWarning) +del warnings + +import os as _os +from stat import * + +__all__ = ["stat","reset","forget","forget_prefix","forget_dir", + "forget_except_prefix","isdir"] + +# The cache. Keys are pathnames, values are os.stat outcomes. +# Remember that multiple threads may be calling this! So, e.g., that +# path in cache returns 1 doesn't mean the cache will still contain +# path on the next line. Code defensively. + +cache = {} + +def stat(path): + """Stat a file, possibly out of the cache.""" + ret = cache.get(path, None) + if ret is None: + cache[path] = ret = _os.stat(path) + return ret + +def reset(): + """Clear the cache.""" + cache.clear() + +# For thread saftey, always use forget() internally too. +def forget(path): + """Remove a given item from the cache, if it exists.""" + try: + del cache[path] + except KeyError: + pass + +def forget_prefix(prefix): + """Remove all pathnames with a given prefix.""" + for path in cache.keys(): + if path.startswith(prefix): + forget(path) + +def forget_dir(prefix): + """Forget a directory and all entries except for entries in subdirs.""" + + # Remove trailing separator, if any. This is tricky to do in a + # x-platform way. For example, Windows accepts both / and \ as + # separators, and if there's nothing *but* a separator we want to + # preserve that this is the root. Only os.path has the platform + # knowledge we need. + from os.path import split, join + prefix = split(join(prefix, "xxx"))[0] + forget(prefix) + for path in cache.keys(): + # First check that the path at least starts with the prefix, so + # that when it doesn't we can avoid paying for split(). + if path.startswith(prefix) and split(path)[0] == prefix: + forget(path) + +def forget_except_prefix(prefix): + """Remove all pathnames except with a given prefix. + + Normally used with prefix = '/' after a chdir(). + """ + + for path in cache.keys(): + if not path.startswith(prefix): + forget(path) + +def isdir(path): + """Return True if directory, else False.""" + try: + st = stat(path) + except _os.error: + return False + return S_ISDIR(st.st_mode) diff --git a/Lib/posixfile.py b/Lib/posixfile.py index 5a7ed06..ddfdb78 100644 --- a/Lib/posixfile.py +++ b/Lib/posixfile.py @@ -53,12 +53,6 @@ f.lock(mode [, len [, start [, whence]]]) query only """ -import warnings -warnings.warn( - "The posixfile module is obsolete and will disappear in the future", - DeprecationWarning) -del warnings - class _posixfile_: """File wrapper class that provides extra POSIX file routines.""" diff --git a/Lib/statcache.py b/Lib/statcache.py deleted file mode 100644 index d478393..0000000 --- a/Lib/statcache.py +++ /dev/null @@ -1,82 +0,0 @@ -"""Maintain a cache of stat() information on files. - -There are functions to reset the cache or to selectively remove items. -""" - -import warnings -warnings.warn("The statcache module is obsolete. Use os.stat() instead.", - DeprecationWarning) -del warnings - -import os as _os -from stat import * - -__all__ = ["stat","reset","forget","forget_prefix","forget_dir", - "forget_except_prefix","isdir"] - -# The cache. Keys are pathnames, values are os.stat outcomes. -# Remember that multiple threads may be calling this! So, e.g., that -# path in cache returns 1 doesn't mean the cache will still contain -# path on the next line. Code defensively. - -cache = {} - -def stat(path): - """Stat a file, possibly out of the cache.""" - ret = cache.get(path, None) - if ret is None: - cache[path] = ret = _os.stat(path) - return ret - -def reset(): - """Clear the cache.""" - cache.clear() - -# For thread saftey, always use forget() internally too. -def forget(path): - """Remove a given item from the cache, if it exists.""" - try: - del cache[path] - except KeyError: - pass - -def forget_prefix(prefix): - """Remove all pathnames with a given prefix.""" - for path in cache.keys(): - if path.startswith(prefix): - forget(path) - -def forget_dir(prefix): - """Forget a directory and all entries except for entries in subdirs.""" - - # Remove trailing separator, if any. This is tricky to do in a - # x-platform way. For example, Windows accepts both / and \ as - # separators, and if there's nothing *but* a separator we want to - # preserve that this is the root. Only os.path has the platform - # knowledge we need. - from os.path import split, join - prefix = split(join(prefix, "xxx"))[0] - forget(prefix) - for path in cache.keys(): - # First check that the path at least starts with the prefix, so - # that when it doesn't we can avoid paying for split(). - if path.startswith(prefix) and split(path)[0] == prefix: - forget(path) - -def forget_except_prefix(prefix): - """Remove all pathnames except with a given prefix. - - Normally used with prefix = '/' after a chdir(). - """ - - for path in cache.keys(): - if not path.startswith(prefix): - forget(path) - -def isdir(path): - """Return True if directory, else False.""" - try: - st = stat(path) - except _os.error: - return False - return S_ISDIR(st.st_mode) diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py index 3bddcad..683867a 100644 --- a/Lib/test/test___all__.py +++ b/Lib/test/test___all__.py @@ -9,8 +9,6 @@ warnings.filterwarnings("ignore", ".* 'pre' .*", DeprecationWarning, r'pre$') warnings.filterwarnings("ignore", ".* regsub .*", DeprecationWarning, r'^regsub$') -warnings.filterwarnings("ignore", ".* statcache .*", DeprecationWarning, - r'statcache$') class AllTest(unittest.TestCase): @@ -148,7 +146,6 @@ class AllTest(unittest.TestCase): self.check_all("socket") self.check_all("sre") self.check_all("_strptime") - self.check_all("statcache") self.check_all("symtable") self.check_all("tabnanny") self.check_all("tarfile") diff --git a/Lib/test/test_sundry.py b/Lib/test/test_sundry.py index 5112183..ef28700 100644 --- a/Lib/test/test_sundry.py +++ b/Lib/test/test_sundry.py @@ -3,8 +3,6 @@ import warnings warnings.filterwarnings('ignore', r".*posixfile module", DeprecationWarning, 'posixfile$') -warnings.filterwarnings('ignore', r".*statcache module", - DeprecationWarning, 'statcache$') from test.test_support import verbose @@ -80,7 +78,6 @@ import shlex import shutil import smtplib import sndhdr -import statcache import statvfs import stringold import sunau diff --git a/Misc/NEWS b/Misc/NEWS index ee0e03a..4733bfb 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -21,6 +21,8 @@ Extension Modules Library ------- +- the depecated statcache module was removed. + - the shelve module no longer uses the deprecated binary parameter. - the pstats module no longer uses the deprecated ignore() method. -- cgit v0.12