mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 03:44:55 +00:00 
			
		
		
		
	Merged revisions 82766 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k Since 'purge' is an API change, modified it to be _purge for 3.1 and deleted the doc update. ........ r82766 | r.david.murray | 2010-07-10 09:52:13 -0400 (Sat, 10 Jul 2010) | 5 lines 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. ........
This commit is contained in:
		
							parent
							
								
									ee3396901c
								
							
						
					
					
						commit
						ca126a02ea
					
				
					 2 changed files with 11 additions and 2 deletions
				
			
		| 
						 | 
					@ -12,12 +12,17 @@ corresponding to PATTERN.  (It does not compile it.)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
 | 
					
 | 
				
			||||||
__all__ = ["filter", "fnmatch","fnmatchcase","translate"]
 | 
					__all__ = ["filter", "fnmatch", "fnmatchcase", "translate"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_cache = {}  # Maps text patterns to compiled regexen.
 | 
					_cache = {}  # Maps text patterns to compiled regexen.
 | 
				
			||||||
_cacheb = {}  # Ditto for bytes patterns.
 | 
					_cacheb = {}  # Ditto for bytes patterns.
 | 
				
			||||||
_MAXCACHE = 100 # Maximum size of caches
 | 
					_MAXCACHE = 100 # Maximum size of caches
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def _purge():
 | 
				
			||||||
 | 
					    """Clear the pattern cache"""
 | 
				
			||||||
 | 
					    _cache.clear()
 | 
				
			||||||
 | 
					    _cacheb.clear()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def fnmatch(name, pat):
 | 
					def fnmatch(name, pat):
 | 
				
			||||||
    """Test whether FILENAME matches PATTERN.
 | 
					    """Test whether FILENAME matches PATTERN.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,10 +3,14 @@
 | 
				
			||||||
from test import support
 | 
					from test import support
 | 
				
			||||||
import unittest
 | 
					import unittest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from fnmatch import fnmatch, fnmatchcase, _MAXCACHE, _cache, _cacheb
 | 
					from fnmatch import fnmatch, fnmatchcase, _MAXCACHE, _cache, _cacheb, _purge
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class FnmatchTestCase(unittest.TestCase):
 | 
					class FnmatchTestCase(unittest.TestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def tearDown(self):
 | 
				
			||||||
 | 
					        _purge()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def check_match(self, filename, pattern, should_match=1):
 | 
					    def check_match(self, filename, pattern, should_match=1):
 | 
				
			||||||
        if should_match:
 | 
					        if should_match:
 | 
				
			||||||
            self.assertTrue(fnmatch(filename, pattern),
 | 
					            self.assertTrue(fnmatch(filename, pattern),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue