[Python-checkins] r82766 - in python/branches/py3k: Doc/library/fnmatch.rst Lib/fnmatch.py Lib/test/test_fnmatch.py

r.david.murray python-checkins at python.org
Sat Jul 10 15:52:13 CEST 2010


Author: r.david.murray
Date: Sat Jul 10 15:52:13 2010
New Revision: 82766

Log:
Fix 'refleak' introduced by fnmatch cache purge tests.

This introduces a 'purge' function for the fnmatch module analogous
to the 'purge' function in the re module.


Modified:
   python/branches/py3k/Doc/library/fnmatch.rst
   python/branches/py3k/Lib/fnmatch.py
   python/branches/py3k/Lib/test/test_fnmatch.py

Modified: python/branches/py3k/Doc/library/fnmatch.rst
==============================================================================
--- python/branches/py3k/Doc/library/fnmatch.rst	(original)
+++ python/branches/py3k/Doc/library/fnmatch.rst	Sat Jul 10 15:52:13 2010
@@ -82,6 +82,13 @@
       <_sre.SRE_Match object at 0x...>
 
 
+.. function:: purge()
+
+   Clear the internal pattern cache.
+
+   .. versionadded:: 3.2
+
+
 .. seealso::
 
    Module :mod:`glob`

Modified: python/branches/py3k/Lib/fnmatch.py
==============================================================================
--- python/branches/py3k/Lib/fnmatch.py	(original)
+++ python/branches/py3k/Lib/fnmatch.py	Sat Jul 10 15:52:13 2010
@@ -12,12 +12,17 @@
 
 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.
 

Modified: python/branches/py3k/Lib/test/test_fnmatch.py
==============================================================================
--- python/branches/py3k/Lib/test/test_fnmatch.py	(original)
+++ python/branches/py3k/Lib/test/test_fnmatch.py	Sat Jul 10 15:52:13 2010
@@ -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),


More information about the Python-checkins mailing list