[Python-checkins] CVS: python/dist/src/Lib glob.py,1.9,1.10 fnmatch.py,1.11,1.12

Martin v. L?wis loewis@users.sourceforge.net
2001年6月05日 23:24:40 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv4997
Modified Files:
	glob.py fnmatch.py 
Log Message:
Patch #409973: Speedup glob.glob, add fnmatch.filter.
Index: glob.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/glob.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** glob.py	2001年01月20日 23:34:12	1.9
--- glob.py	2001年06月06日 06:24:38	1.10
***************
*** 19,23 ****
 return []
 dirname, basename = os.path.split(pathname)
! if has_magic(dirname):
 list = glob(dirname)
 else:
--- 19,25 ----
 return []
 dirname, basename = os.path.split(pathname)
! if not dirname:
! return glob1(os.curdir, basename)
! elif has_magic(dirname):
 list = glob(dirname)
 else:
***************
*** 44,53 ****
 except os.error:
 return []
! result = []
! for name in names:
! if name[0] != '.' or pattern[0] == '.':
! if fnmatch.fnmatch(name, pattern):
! result.append(name)
! return result
 
 
--- 46,52 ----
 except os.error:
 return []
! if pattern[0]!='.':
! names=filter(lambda x: x[0]!='.',names)
! return fnmatch.filter(names,pattern)
 
 
Index: fnmatch.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/fnmatch.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** fnmatch.py	2001年03月21日 18:05:48	1.11
--- fnmatch.py	2001年06月06日 06:24:38	1.12
***************
*** 38,41 ****
--- 38,61 ----
 return fnmatchcase(name, pat)
 
+ def filter(names, pat):
+ """Return the subset of the list NAMES that match PAT"""
+ import os,posixpath
+ result=[]
+ pat=os.path.normcase(pat)
+ if not _cache.has_key(pat):
+ res = translate(pat)
+ _cache[pat] = re.compile(res)
+ match=_cache[pat].match
+ if os.path is posixpath:
+ # normcase on posix is NOP. Optimize it away from the loop.
+ for name in names:
+ if match(name):
+ result.append(name)
+ else:
+ for name in names:
+ if match(os.path.normcase(name)):
+ result.append(name)
+ return result
+ 
 def fnmatchcase(name, pat):
 """Test whether FILENAME matches PATTERN, including case.

AltStyle によって変換されたページ (->オリジナル) /