]> granicus.if.org Git - python/commitdiff
Fix 'refleak' introduced by fnmatch cache purge tests.
authorR. David Murray <rdmurray@bitdance.com>
Sat, 10 Jul 2010 13:52:13 +0000 (13:52 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Sat, 10 Jul 2010 13:52:13 +0000 (13:52 +0000)
This introduces a 'purge' function for the fnmatch module analogous
to the 'purge' function in the re module.

Doc/library/fnmatch.rst
Lib/fnmatch.py
Lib/test/test_fnmatch.py

index 7fa6148180404fcc4082e997cc85625d45ba7b2b..ec78ed2e8234079c08eacfe9486a63caf57d53f8 100644 (file)
@@ -82,6 +82,13 @@ patterns.
       <_sre.SRE_Match object at 0x...>
 
 
+.. function:: purge()
+
+   Clear the internal pattern cache.
+
+   .. versionadded:: 3.2
+
+
 .. seealso::
 
    Module :mod:`glob`
index 26ae4ccb14d70533fa13a69b7d38ad82a1786da1..aa682bb8d5d8a246f8b41ea46c649379c1d8e5d5 100644 (file)
@@ -12,12 +12,17 @@ corresponding to PATTERN.  (It does not compile it.)
 
 import re
 
-__all__ = ["filter", "fnmatch","fnmatchcase","translate"]
+__all__ = ["filter", "fnmatch", "fnmatchcase", "purge", "translate"]
 
 _cache = {}  # Maps text patterns to compiled regexen.
 _cacheb = {}  # Ditto for bytes patterns.
 _MAXCACHE = 100 # Maximum size of caches
 
+def purge():
+    """Clear the pattern cache"""
+    _cache.clear()
+    _cacheb.clear()
+
 def fnmatch(name, pat):
     """Test whether FILENAME matches PATTERN.
 
index 81b9ce68389f262ea04f9ed22bfb12e703120777..496f145c02a3e4b1526ca690d8c148c547180d0e 100644 (file)
@@ -3,10 +3,14 @@
 from test import support
 import unittest
 
-from fnmatch import fnmatch, fnmatchcase, _MAXCACHE, _cache, _cacheb
+from fnmatch import fnmatch, fnmatchcase, _MAXCACHE, _cache, _cacheb, purge
 
 
 class FnmatchTestCase(unittest.TestCase):
+
+    def tearDown(self):
+        purge()
+
     def check_match(self, filename, pattern, should_match=1, fn=fnmatch):
         if should_match:
             self.assertTrue(fn(filename, pattern),